diff --git a/src/main/java/com/peanut/modules/master/controller/TaihuTalentController.java b/src/main/java/com/peanut/modules/master/controller/TaihuTalentController.java index df21e606..00cca243 100644 --- a/src/main/java/com/peanut/modules/master/controller/TaihuTalentController.java +++ b/src/main/java/com/peanut/modules/master/controller/TaihuTalentController.java @@ -2,16 +2,28 @@ 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") @@ -20,6 +32,71 @@ 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 params){ + MPJLambdaWrapper 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 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 params){ + List collect = courseToTalentService.list(new LambdaQueryWrapper() + .eq(CourseToTalent::getTalentId, params.get("talentId"))) + .stream().map(CourseToTalent::getCourseId).collect(Collectors.toList()); + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.rightJoin(CourseToTaihumed.class,CourseToTaihumed::getCourseId,CourseEntity::getId); + wrapper.selectAll(CourseEntity.class); + if (collect.size() != 0){ + wrapper.notIn(CourseEntity::getId,collect); + } + wrapper.like(StringUtils.isNotBlank(params.get("title").toString()),CourseEntity::getTitle,params.get("title")); + Page 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() + .eq(CourseToTalent::getCourseId, courseToTalent.getCourseId()) + .eq(CourseToTalent::getTalentId, courseToTalent.getTalentId())); + if(one != null){ + return R.error(501,"绑定失败,绑定关系已将存在"); + } + courseToTalentService.save(courseToTalent); + return R.ok(); + } + + //解绑课程和太湖英才 + @RequestMapping("/unbindCourseAndTalent") + public R unbindCourseAndTalent(@RequestBody CourseToTalent courseToTalent){ + boolean b = courseToTalentService.removeById(courseToTalent.getId()); + if(b){ + return R.ok(); + }else { + return R.error("error"); + } + } + + //太湖英才列表 @RequestMapping("/getTaihuTalents") @@ -49,8 +126,11 @@ public class TaihuTalentController { //删除太湖英才 @RequestMapping("/delTaihuTalent") + @Transactional public R delTaihuTalent(@RequestBody TaihuTalent taihuTalent){ taihuTalentService.removeById(taihuTalent); + courseToTalentService.remove(new LambdaQueryWrapper() + .eq(CourseToTalent::getTalentId,taihuTalent.getId())); return R.ok(); }