160 lines
7.5 KiB
Java
160 lines
7.5 KiB
Java
package com.peanut.modules.master.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.peanut.common.utils.DateUtils;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.common.entity.CourseCatalogueEntity;
|
|
import com.peanut.modules.common.entity.CourseEntity;
|
|
import com.peanut.modules.common.entity.MyUserEntity;
|
|
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
|
import com.peanut.modules.common.to.AddCourses;
|
|
import com.peanut.modules.common.vo.AddCoursesFrag;
|
|
import com.peanut.modules.master.service.CourseCatalogueService;
|
|
import com.peanut.modules.master.service.UserCourseBuyService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.io.*;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 用户开课管理
|
|
*/
|
|
@Slf4j
|
|
@RestController("masterUserCourseBuy")
|
|
@RequestMapping("master/userCourseBuy")
|
|
public class UserCourseBuyController {
|
|
|
|
@Autowired
|
|
private UserCourseBuyService userCourseBuyService;
|
|
@Autowired
|
|
private CourseCatalogueService courseCatalogueService;
|
|
|
|
@RequestMapping("/listByPage")
|
|
public R listByPage(@RequestBody Map<String, Object> params) {
|
|
MPJLambdaWrapper<UserCourseBuyEntity> wrapper = new MPJLambdaWrapper();
|
|
wrapper.leftJoin(MyUserEntity.class, MyUserEntity::getId, UserCourseBuyEntity::getUserId);
|
|
wrapper.leftJoin(CourseEntity.class, CourseEntity::getId, UserCourseBuyEntity::getCourseId);
|
|
wrapper.leftJoin(CourseCatalogueEntity.class, CourseCatalogueEntity::getId, UserCourseBuyEntity::getCatalogueId);
|
|
wrapper.select("t.id,t.user_id userId,t.course_id courseId,t.catalogue_id catalogueId,t.create_time createTime," +
|
|
"t.come,t.days,t.start_time startTime,t.end_time endTime,t.del_flag expire,t1.tel,t2.title courseName,t3.title catalogueName");
|
|
if (StringUtils.isNotEmpty(params.get("userInfo").toString())) {
|
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
|
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("userId").toString())) {
|
|
wrapper.eq(MyUserEntity::getId,params.get("userId"));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("courseName").toString())) {
|
|
wrapper.like(CourseEntity::getTitle,params.get("courseName"));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("come").toString())) {
|
|
wrapper.like(UserCourseBuyEntity::getCome,params.get("come"));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("expire").toString())) {
|
|
wrapper.eq(UserCourseBuyEntity::getDelFlag,params.get("expire"));
|
|
}
|
|
//查询出过期课程
|
|
wrapper.disableLogicDel();
|
|
wrapper.orderByDesc(UserCourseBuyEntity::getDelFlag);
|
|
wrapper.orderByDesc(UserCourseBuyEntity::getCreateTime);
|
|
Page<Map<String, Object>> page = userCourseBuyService.pageMaps(new Page<>(
|
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
|
return R.ok().put("result", page);
|
|
}
|
|
|
|
@RequestMapping("/insertUserCourseBuy")
|
|
@Transactional
|
|
public R insertUserCourseBuy(@RequestBody Map<String, Object> params) {
|
|
int userId = Integer.parseInt(params.get("userId").toString());
|
|
int courseId = Integer.parseInt(params.get("courseId").toString());
|
|
String catalogueId = params.get("catalogueId").toString();
|
|
int days = Integer.parseInt(params.get("days").toString());
|
|
String come = params.get("come").toString();
|
|
String[] catalogueIds = catalogueId.split(",");
|
|
for (String id : catalogueIds) {
|
|
UserCourseBuyEntity userCourseBuyEntity = userCourseBuyService.getOne(new LambdaQueryWrapper<UserCourseBuyEntity>()
|
|
.eq(UserCourseBuyEntity::getCatalogueId,id)
|
|
.eq(UserCourseBuyEntity::getUserId,userId));
|
|
if (userCourseBuyEntity==null){
|
|
userCourseBuyEntity = new UserCourseBuyEntity();
|
|
userCourseBuyEntity.setUserId(userId);
|
|
userCourseBuyEntity.setCourseId(courseId);
|
|
userCourseBuyEntity.setCatalogueId(Integer.parseInt(id));
|
|
userCourseBuyEntity.setDays(days);
|
|
userCourseBuyEntity.setCome(come);
|
|
userCourseBuyService.save(userCourseBuyEntity);
|
|
}else {
|
|
CourseCatalogueEntity catalogueEntity = courseCatalogueService.getById(id);
|
|
return R.error(catalogueEntity.getTitle()+"已开通");
|
|
}
|
|
}
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/delayUserCourseBuy")
|
|
public R delayUserCourseBuy(@RequestBody Map<String, Object> params) {
|
|
UserCourseBuyEntity userCourseBuyEntity = userCourseBuyService.getById(params.get("id").toString());
|
|
int days = Integer.parseInt(params.get("days").toString());
|
|
userCourseBuyEntity.setDays(userCourseBuyEntity.getDays()+days);
|
|
if (userCourseBuyEntity.getEndTime()!=null){
|
|
userCourseBuyEntity.setEndTime(DateUtils.addDateDays(userCourseBuyEntity.getEndTime(),days));
|
|
}
|
|
userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";延期(管理员操作:"+days+","+DateUtils.format(new Date(),"yyyyMMdd")+")");
|
|
userCourseBuyService.updateById(userCourseBuyEntity);
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/readExcelForAddCourse")
|
|
public R readExcelForAddCourse(@RequestBody Map<String,String> params){
|
|
String filePath = params.get("file");
|
|
Map<String, ArrayList> stringArrayListMap = userCourseBuyService.readExcelForAddCourse(filePath);
|
|
return R.ok().put("result",stringArrayListMap);
|
|
}
|
|
|
|
@RequestMapping("/AddCourses")
|
|
public R AddCourses(@RequestBody AddCourses addCourses){
|
|
Map<String, ArrayList<AddCoursesFrag>> stringArrayListMap = userCourseBuyService.addCourses(addCourses);
|
|
return R.ok().put("result",stringArrayListMap);
|
|
}
|
|
|
|
|
|
private void searchUser(String phone){
|
|
userCourseBuyService.addCourseForUser(phone);
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/expireUserCourseBuy")
|
|
@Transactional
|
|
public R expireUserCourseBuy(@RequestBody Map<String, Object> params) {
|
|
UserCourseBuyEntity userCourseBuyEntity = userCourseBuyService.getById(params.get("id").toString());
|
|
userCourseBuyEntity.setCome(userCourseBuyEntity.getCome()+";终止(管理员操作)");
|
|
if (userCourseBuyEntity.getStartTime()!=null){
|
|
userCourseBuyEntity.setStartTime(new Date());
|
|
}
|
|
userCourseBuyEntity.setEndTime(new Date());
|
|
userCourseBuyService.updateById(userCourseBuyEntity);
|
|
userCourseBuyService.removeById(params.get("id").toString());
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
|
|
}
|