From 2280276a584d82f6fe18a17b2e3adfb6c252b7f5 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Tue, 21 May 2024 18:05:55 +0800 Subject: [PATCH] bug --- .../CourseMedicineMarketController.java | 132 ++++++------------ .../impl/CourseMedicineServiceImpl.java | 4 +- 2 files changed, 46 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/peanut/modules/master/controller/CourseMedicineMarketController.java b/src/main/java/com/peanut/modules/master/controller/CourseMedicineMarketController.java index 58cc6f43..a407aab1 100644 --- a/src/main/java/com/peanut/modules/master/controller/CourseMedicineMarketController.java +++ b/src/main/java/com/peanut/modules/master/controller/CourseMedicineMarketController.java @@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.ObjectUtils; import com.peanut.common.utils.R; -import com.peanut.modules.common.entity.CourseEntity; -import com.peanut.modules.common.entity.CourseMedicineMarketEntity; -import com.peanut.modules.common.entity.CourseToMedicineMarketEntity; -import com.peanut.modules.common.entity.CourseToSociologyMarketEntity; +import com.peanut.modules.common.entity.*; import com.peanut.modules.common.to.ParamTo; import com.peanut.modules.master.service.CourseMedicineMarketService; import com.peanut.modules.master.service.CourseService; @@ -44,58 +41,41 @@ public class CourseMedicineMarketController { return R.ok().put("result", marketsTree); } - /** - * 获取营销标签列表 - */ - @RequestMapping(path = "/getMakertListByPid") - public R getMakertListByPid(String pid) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); - wrapper.eq(CourseMedicineMarketEntity::getPid,pid); - wrapper.orderByAsc(CourseMedicineMarketEntity::getSort); - wrapper.orderByAsc(CourseMedicineMarketEntity::getCreateTime); - List marketTopList = marketService.list(wrapper); - return R.ok().put("result", marketTopList); - } - @RequestMapping(path = "/getMarketById") - public R getMarketById(String id) { + public R getMarketById(@RequestBody Map map) { + int id = map.get("id"); return R.ok().put("result",marketService.getById(id)); } - @RequestMapping(path = "/saveOrUpdateMarket") - public R saveOrUpdateMarket(@RequestBody CourseMedicineMarketEntity market) { - if (market.getId()==null){ - if(market.getPid()==0){ - marketService.save(market); - return R.ok().put("result",market); - }else { - CourseMedicineMarketEntity m = marketService.getById(market.getPid()); - if (m.getIsLast()==1){ - return R.error("请将父标签设置为非最后一集"); - }else { - marketService.save(market); - return R.ok().put("result",market); - } - } - }else { - if (market.getIsLast() == 1){ - List mList = marketService.list(new LambdaQueryWrapper() - .eq(CourseMedicineMarketEntity::getPid,market.getId())); - if (mList.size()>0){ - return R.error("请先删除子集,再设置为最后一集"); - }else { - marketService.saveOrUpdate(market); - return R.ok().put("result",market); - } - }else { - marketService.saveOrUpdate(market); - return R.ok().put("result",market); + @RequestMapping("/addSociologyMarket") + public R addSociologyMarket(@RequestBody CourseMedicineMarketEntity courseMedicineMarketEntity){ + marketService.save(courseMedicineMarketEntity); + return R.ok().put("market",courseMedicineMarketEntity); + } + + @RequestMapping("/editSociologyMarket") + public R editSociologyMarket(@RequestBody CourseMedicineMarketEntity courseMedicineMarketEntity){ + CourseMedicineMarketEntity old = marketService.getById(courseMedicineMarketEntity.getId()); + if(courseMedicineMarketEntity.getIsLast()==1&&old.getIsLast()==0){//非终节点到终结点,要排除是否存在子集 + Integer integer = marketService.getBaseMapper().selectCount(new LambdaQueryWrapper().eq(CourseMedicineMarketEntity::getPid, courseMedicineMarketEntity.getId())); + if(integer>0){ + return R.error("请先清空子集再操作!"); } } + + if(courseMedicineMarketEntity.getIsLast()==0&&old.getIsLast()==1){ + Integer integer = toMarketService.getBaseMapper().selectCount(new LambdaQueryWrapper().eq(CourseToMedicineMarketEntity::getMedicineMarketId, courseMedicineMarketEntity.getId())); + if(integer>0){ + return R.error("请先清空绑定的课程后,再操作"); + } + } + marketService.updateById(courseMedicineMarketEntity); + return R.ok().put("market",courseMedicineMarketEntity); } @RequestMapping(path = "/delMarket") - public R delMarket(String id) { + public R delMarket(@RequestBody Map map) { + int id = map.get("id"); CourseMedicineMarketEntity market = marketService.getById(id); if (market.getIsLast()==1){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); @@ -118,22 +98,6 @@ public class CourseMedicineMarketController { } } - /** - * 获取营销标签下课程 - */ -// @RequestMapping(path = "/getCourseByMarketId") -// public R getCourseByMarket(@RequestBody Map params) { -// MPJLambdaWrapper wrapper = new MPJLambdaWrapper(); -// wrapper.leftJoin(CourseEntity.class,CourseEntity::getId, CourseToMedicineMarketEntity::getCourseId); -// wrapper.selectAll(CourseEntity.class); -// wrapper.like(CourseEntity::getTitle,params.get("title")); -// wrapper.eq(CourseToMedicineMarketEntity::getMedicineMarketId,params.get("marketId")); -// Page res = toMarketService.pageMaps(new Page<>( -// Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper); -// return R.ok().put("result", res); -// } - - @RequestMapping(path = "/getCourseByMarketId") public R getCourseByMarketId(@RequestBody Map map){ int marketId = map.get("marketId"); @@ -154,35 +118,27 @@ public class CourseMedicineMarketController { return R.ok().put("page",page1); } - @RequestMapping(path = "/saveToMarket") - public R saveToMarket(@RequestBody Map params) { - if (!StringUtils.isEmpty(params.get("courseId").toString())){ - String[] ids = params.get("courseId").toString().split(","); - if (ids.length > 0) { - for (String id : ids) { - CourseToMedicineMarketEntity toMarket = new CourseToMedicineMarketEntity(); - toMarket.setMedicineMarketId(Integer.parseInt(params.get("marketId").toString())); - toMarket.setCourseId(Integer.parseInt(id)); - toMarketService.save(toMarket); - } - } + @RequestMapping("/bindCourseAndMedicineMarket") + public R bindCourseAndMedicineMarket(@RequestBody Map map){ + int marketId = map.get("marketId"); + int courseId = map.get("courseId"); + Integer integer = toMarketService.getBaseMapper().selectCount(new LambdaQueryWrapper().eq(CourseToMedicineMarketEntity::getMedicineMarketId, marketId).eq(CourseToMedicineMarketEntity::getCourseId, courseId)); + if(integer>0){ + return R.error("不可重复绑定"); } + CourseToMedicineMarketEntity courseToMedicineMarketEntity = new CourseToMedicineMarketEntity(); + courseToMedicineMarketEntity.setMedicineMarketId(marketId); + courseToMedicineMarketEntity.setCourseId(courseId); + toMarketService.save(courseToMedicineMarketEntity); return R.ok(); } - @RequestMapping(path = "/delToMarket") - public R delToMarket(String marketId,String courseId) { - if(StringUtils.isNotEmpty(courseId)){ - String[] productIds = courseId.split(","); - for(String id : productIds){ - LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); - wrapper.eq(CourseToMedicineMarketEntity::getMedicineMarketId,marketId); - wrapper.eq(CourseToMedicineMarketEntity::getCourseId,id); - toMarketService.remove(wrapper); - } - return R.ok(); - } - return R.error("参数为空"); + @RequestMapping("/unbindCourseAndMedicineMarket") + public R unbindCourseAndMedicineMarket(@RequestBody Map map){ + int marketId = map.get("marketId"); + int courseId = map.get("courseId"); + toMarketService.getBaseMapper().delete(new LambdaQueryWrapper().eq(CourseToMedicineMarketEntity::getMedicineMarketId,marketId).eq(CourseToMedicineMarketEntity::getCourseId,courseId)); + return R.ok(); } } diff --git a/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java index 37344744..254fa068 100644 --- a/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java +++ b/src/main/java/com/peanut/modules/master/service/impl/CourseMedicineServiceImpl.java @@ -52,8 +52,8 @@ public class CourseMedicineServiceImpl extends ServiceImpl().eq(CourseToMedicine::getMedicalId, courseMedicine.getId())); - if(courseToSociologyEntity!=null){ + Integer integer = toMedicalDao.selectCount(new LambdaQueryWrapper().eq(CourseToMedicine::getMedicalId, courseMedicine.getId())); + if(integer>0){ return R.error(502,"更新失败,请先把此项与课程的关联关系清空后才可把此标签变成普通标签"); } }