153 lines
6.9 KiB
Java
153 lines
6.9 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.R;
|
|
import com.peanut.modules.common.entity.CourseEntity;
|
|
import com.peanut.modules.common.entity.CourseToTaihumed;
|
|
import com.peanut.modules.common.entity.CourseToTalent;
|
|
import com.peanut.modules.common.entity.TaihuTalent;
|
|
import com.peanut.modules.common.service.CourseToTaihumedService;
|
|
import com.peanut.modules.common.service.CourseToTalentService;
|
|
import com.peanut.modules.common.service.TaihuTalentService;
|
|
import com.peanut.modules.common.to.ParamTo;
|
|
import com.peanut.modules.master.service.CourseService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
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.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Slf4j
|
|
@RestController("masterTaihuTalent")
|
|
@RequestMapping("master/taihuTalent")
|
|
public class TaihuTalentController {
|
|
|
|
@Autowired
|
|
private TaihuTalentService taihuTalentService;
|
|
@Autowired
|
|
private CourseService courseService;
|
|
@Autowired
|
|
private CourseToTalentService courseToTalentService;
|
|
@Autowired
|
|
private CourseToTaihumedService courseToTaihumedService;
|
|
|
|
|
|
//太湖英才课程列表
|
|
@RequestMapping("/getCourseListForTalent")
|
|
public R getCourseListForTalent(@RequestBody Map<String,Object> params){
|
|
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
|
wrapper.rightJoin(CourseToTalent.class,CourseToTalent::getCourseId,CourseEntity::getId);
|
|
wrapper.selectAll(CourseEntity.class);
|
|
wrapper.eq(CourseToTalent::getTalentId,params.get("talentId"));
|
|
wrapper.like(StringUtils.isNotBlank(params.get("title").toString()),CourseEntity::getTitle,params.get("title"));
|
|
Page<CourseEntity> page = courseService.page(new Page<>(Long.parseLong(params.get("current").toString()),
|
|
Long.parseLong(params.get("limit").toString())), wrapper);
|
|
return R.ok().put("page",page);
|
|
}
|
|
|
|
//太湖英才可绑定课程列表
|
|
@RequestMapping("/getCourseListCanTalent")
|
|
public R getCourseListCanTalent(@RequestBody Map<String,Object> params){
|
|
MPJLambdaWrapper<CourseEntity> wrapper = new MPJLambdaWrapper<>();
|
|
wrapper.rightJoin(CourseToTaihumed.class,CourseToTaihumed::getCourseId,CourseEntity::getId);
|
|
wrapper.selectAll(CourseEntity.class);
|
|
String sql = "select 1 from course_to_talent where del_flag = 0 and course_id = t1.course_id and talent_id = "+params.get("talentId");
|
|
wrapper.notExists(sql);
|
|
wrapper.like(StringUtils.isNotBlank(params.get("title").toString()),CourseEntity::getTitle,params.get("title"));
|
|
Page<CourseEntity> page = courseService.page(new Page<>(Long.parseLong(params.get("current").toString()),
|
|
Long.parseLong(params.get("limit").toString())), wrapper);
|
|
return R.ok().put("page",page);
|
|
}
|
|
|
|
//绑定课程和太湖英才
|
|
@RequestMapping("/bindCourseAndTalent")
|
|
public R bindCourseAndTalent(@RequestBody CourseToTalent courseToTalent){
|
|
CourseToTalent one = courseToTalentService.getOne(new LambdaQueryWrapper<CourseToTalent>()
|
|
.eq(CourseToTalent::getCourseId, courseToTalent.getCourseId())
|
|
.eq(CourseToTalent::getTalentId, courseToTalent.getTalentId()));
|
|
if(one != null){
|
|
return R.error(501,"绑定失败,绑定关系已将存在");
|
|
}
|
|
Long count = courseToTalentService.count(new LambdaQueryWrapper<CourseToTalent>()
|
|
.eq(CourseToTalent::getCourseId, courseToTalent.getCourseId()));
|
|
List<CourseToTaihumed> ctts = courseToTaihumedService.list(new LambdaQueryWrapper<CourseToTaihumed>()
|
|
.eq(CourseToTaihumed::getCourseId,courseToTalent.getCourseId()));
|
|
for (CourseToTaihumed ctt:ctts){
|
|
if (count>0&&(ctt.getTaihumedId()==99||ctt.getTaihumedId()==100)){
|
|
return R.error(501,"绑定失败,此课程只能绑定一人");
|
|
}
|
|
}
|
|
courseToTalentService.save(courseToTalent);
|
|
return R.ok();
|
|
}
|
|
|
|
//解绑课程和太湖英才
|
|
@RequestMapping("/unbindCourseAndTalent")
|
|
public R unbindCourseAndTalent(@RequestBody CourseToTalent courseToTalent){
|
|
CourseToTalent ctt = courseToTalentService.getOne(new LambdaQueryWrapper<CourseToTalent>()
|
|
.eq(CourseToTalent::getCourseId,courseToTalent.getCourseId())
|
|
.eq(CourseToTalent::getTalentId,courseToTalent.getTalentId()));
|
|
boolean b = courseToTalentService.removeById(ctt.getId());
|
|
if(b){
|
|
return R.ok();
|
|
}else {
|
|
return R.error("error");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//太湖英才列表
|
|
@RequestMapping("/getTaihuTalents")
|
|
public R getTaihuTalents(@RequestBody Map<String,Object> params){
|
|
LambdaQueryWrapper<TaihuTalent> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.like(StringUtils.isNotEmpty(params.get("name").toString()),TaihuTalent::getName,params.get("name"));
|
|
wrapper.like(StringUtils.isNotEmpty(params.get("region").toString()),TaihuTalent::getRegion,params.get("region"));
|
|
wrapper.orderByDesc(TaihuTalent::getCreateTime);
|
|
Page<TaihuTalent> pageRes = taihuTalentService.page(new Page<>(Long.parseLong(params.get("current").toString())
|
|
, Long.parseLong(params.get("limit").toString())),wrapper);
|
|
return R.ok().put("pageRes",pageRes);
|
|
}
|
|
|
|
//新增太湖英才
|
|
@RequestMapping("/addTaihuTalent")
|
|
public R addTaihuTalent(@RequestBody TaihuTalent taihuTalent){
|
|
taihuTalentService.save(taihuTalent);
|
|
return R.ok();
|
|
}
|
|
|
|
//修改太湖英才
|
|
@RequestMapping("/updateTaihuTalent")
|
|
public R updateTaihuTalent(@RequestBody TaihuTalent taihuTalent){
|
|
taihuTalentService.updateById(taihuTalent);
|
|
return R.ok();
|
|
}
|
|
|
|
//删除太湖英才
|
|
@RequestMapping("/delTaihuTalent")
|
|
@Transactional
|
|
public R delTaihuTalent(@RequestBody TaihuTalent taihuTalent){
|
|
taihuTalentService.removeById(taihuTalent);
|
|
courseToTalentService.remove(new LambdaQueryWrapper<CourseToTalent>()
|
|
.eq(CourseToTalent::getTalentId,taihuTalent.getId()));
|
|
return R.ok();
|
|
}
|
|
|
|
//太湖英才详情
|
|
@RequestMapping("/taihuTalentInfo")
|
|
public R taihuTalentInfo(@RequestBody Map<String,Object> params){
|
|
TaihuTalent taihuTalent = taihuTalentService.getById(params.get("id").toString());
|
|
return R.ok().put("taihuTalent",taihuTalent);
|
|
}
|
|
|
|
|
|
}
|