This commit is contained in:
wangjinlei
2024-05-21 18:05:55 +08:00
parent 58d6741d45
commit 2280276a58
2 changed files with 46 additions and 90 deletions

View File

@@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.ObjectUtils; import com.peanut.common.utils.ObjectUtils;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CourseEntity; import com.peanut.modules.common.entity.*;
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.to.ParamTo; import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.CourseMedicineMarketService; import com.peanut.modules.master.service.CourseMedicineMarketService;
import com.peanut.modules.master.service.CourseService; import com.peanut.modules.master.service.CourseService;
@@ -44,58 +41,41 @@ public class CourseMedicineMarketController {
return R.ok().put("result", marketsTree); return R.ok().put("result", marketsTree);
} }
/**
* 获取营销标签列表
*/
@RequestMapping(path = "/getMakertListByPid")
public R getMakertListByPid(String pid) {
LambdaQueryWrapper<CourseMedicineMarketEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(CourseMedicineMarketEntity::getPid,pid);
wrapper.orderByAsc(CourseMedicineMarketEntity::getSort);
wrapper.orderByAsc(CourseMedicineMarketEntity::getCreateTime);
List<CourseMedicineMarketEntity> marketTopList = marketService.list(wrapper);
return R.ok().put("result", marketTopList);
}
@RequestMapping(path = "/getMarketById") @RequestMapping(path = "/getMarketById")
public R getMarketById(String id) { public R getMarketById(@RequestBody Map<String,Integer> map) {
int id = map.get("id");
return R.ok().put("result",marketService.getById(id)); return R.ok().put("result",marketService.getById(id));
} }
@RequestMapping(path = "/saveOrUpdateMarket") @RequestMapping("/addSociologyMarket")
public R saveOrUpdateMarket(@RequestBody CourseMedicineMarketEntity market) { public R addSociologyMarket(@RequestBody CourseMedicineMarketEntity courseMedicineMarketEntity){
if (market.getId()==null){ marketService.save(courseMedicineMarketEntity);
if(market.getPid()==0){ return R.ok().put("market",courseMedicineMarketEntity);
marketService.save(market); }
return R.ok().put("result",market);
}else { @RequestMapping("/editSociologyMarket")
CourseMedicineMarketEntity m = marketService.getById(market.getPid()); public R editSociologyMarket(@RequestBody CourseMedicineMarketEntity courseMedicineMarketEntity){
if (m.getIsLast()==1){ CourseMedicineMarketEntity old = marketService.getById(courseMedicineMarketEntity.getId());
return R.error("请将父标签设置为非最后一集"); if(courseMedicineMarketEntity.getIsLast()==1&&old.getIsLast()==0){//非终节点到终结点,要排除是否存在子集
}else { Integer integer = marketService.getBaseMapper().selectCount(new LambdaQueryWrapper<CourseMedicineMarketEntity>().eq(CourseMedicineMarketEntity::getPid, courseMedicineMarketEntity.getId()));
marketService.save(market); if(integer>0){
return R.ok().put("result",market); return R.error("请先清空子集再操作!");
}
}
}else {
if (market.getIsLast() == 1){
List mList = marketService.list(new LambdaQueryWrapper<CourseMedicineMarketEntity>()
.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);
} }
} }
if(courseMedicineMarketEntity.getIsLast()==0&&old.getIsLast()==1){
Integer integer = toMarketService.getBaseMapper().selectCount(new LambdaQueryWrapper<CourseToMedicineMarketEntity>().eq(CourseToMedicineMarketEntity::getMedicineMarketId, courseMedicineMarketEntity.getId()));
if(integer>0){
return R.error("请先清空绑定的课程后,再操作");
}
}
marketService.updateById(courseMedicineMarketEntity);
return R.ok().put("market",courseMedicineMarketEntity);
} }
@RequestMapping(path = "/delMarket") @RequestMapping(path = "/delMarket")
public R delMarket(String id) { public R delMarket(@RequestBody Map<String ,Integer> map) {
int id = map.get("id");
CourseMedicineMarketEntity market = marketService.getById(id); CourseMedicineMarketEntity market = marketService.getById(id);
if (market.getIsLast()==1){ if (market.getIsLast()==1){
MPJLambdaWrapper<CourseToMedicineMarketEntity> wrapper = new MPJLambdaWrapper(); MPJLambdaWrapper<CourseToMedicineMarketEntity> wrapper = new MPJLambdaWrapper();
@@ -118,22 +98,6 @@ public class CourseMedicineMarketController {
} }
} }
/**
* 获取营销标签下课程
*/
// @RequestMapping(path = "/getCourseByMarketId")
// public R getCourseByMarket(@RequestBody Map<String, Object> params) {
// MPJLambdaWrapper<CourseToMedicineMarketEntity> 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") @RequestMapping(path = "/getCourseByMarketId")
public R getCourseByMarketId(@RequestBody Map<String,Integer> map){ public R getCourseByMarketId(@RequestBody Map<String,Integer> map){
int marketId = map.get("marketId"); int marketId = map.get("marketId");
@@ -154,35 +118,27 @@ public class CourseMedicineMarketController {
return R.ok().put("page",page1); return R.ok().put("page",page1);
} }
@RequestMapping(path = "/saveToMarket") @RequestMapping("/bindCourseAndMedicineMarket")
public R saveToMarket(@RequestBody Map params) { public R bindCourseAndMedicineMarket(@RequestBody Map<String,Integer> map){
if (!StringUtils.isEmpty(params.get("courseId").toString())){ int marketId = map.get("marketId");
String[] ids = params.get("courseId").toString().split(","); int courseId = map.get("courseId");
if (ids.length > 0) { Integer integer = toMarketService.getBaseMapper().selectCount(new LambdaQueryWrapper<CourseToMedicineMarketEntity>().eq(CourseToMedicineMarketEntity::getMedicineMarketId, marketId).eq(CourseToMedicineMarketEntity::getCourseId, courseId));
for (String id : ids) { if(integer>0){
CourseToMedicineMarketEntity toMarket = new CourseToMedicineMarketEntity(); return R.error("不可重复绑定");
toMarket.setMedicineMarketId(Integer.parseInt(params.get("marketId").toString()));
toMarket.setCourseId(Integer.parseInt(id));
toMarketService.save(toMarket);
}
}
} }
CourseToMedicineMarketEntity courseToMedicineMarketEntity = new CourseToMedicineMarketEntity();
courseToMedicineMarketEntity.setMedicineMarketId(marketId);
courseToMedicineMarketEntity.setCourseId(courseId);
toMarketService.save(courseToMedicineMarketEntity);
return R.ok(); return R.ok();
} }
@RequestMapping(path = "/delToMarket") @RequestMapping("/unbindCourseAndMedicineMarket")
public R delToMarket(String marketId,String courseId) { public R unbindCourseAndMedicineMarket(@RequestBody Map<String,Integer> map){
if(StringUtils.isNotEmpty(courseId)){ int marketId = map.get("marketId");
String[] productIds = courseId.split(","); int courseId = map.get("courseId");
for(String id : productIds){ toMarketService.getBaseMapper().delete(new LambdaQueryWrapper<CourseToMedicineMarketEntity>().eq(CourseToMedicineMarketEntity::getMedicineMarketId,marketId).eq(CourseToMedicineMarketEntity::getCourseId,courseId));
LambdaQueryWrapper<CourseToMedicineMarketEntity> wrapper = new LambdaQueryWrapper(); return R.ok();
wrapper.eq(CourseToMedicineMarketEntity::getMedicineMarketId,marketId);
wrapper.eq(CourseToMedicineMarketEntity::getCourseId,id);
toMarketService.remove(wrapper);
}
return R.ok();
}
return R.error("参数为空");
} }
} }

View File

@@ -52,8 +52,8 @@ public class CourseMedicineServiceImpl extends ServiceImpl<CourseMedicineDao, Co
} }
} }
if(old.getIsLast()==1&& courseMedicine.getIsLast()==0){ if(old.getIsLast()==1&& courseMedicine.getIsLast()==0){
CourseToMedicine courseToSociologyEntity = toMedicalDao.selectOne(new LambdaQueryWrapper<CourseToMedicine>().eq(CourseToMedicine::getMedicalId, courseMedicine.getId())); Integer integer = toMedicalDao.selectCount(new LambdaQueryWrapper<CourseToMedicine>().eq(CourseToMedicine::getMedicalId, courseMedicine.getId()));
if(courseToSociologyEntity!=null){ if(integer>0){
return R.error(502,"更新失败,请先把此项与课程的关联关系清空后才可把此标签变成普通标签"); return R.error(502,"更新失败,请先把此项与课程的关联关系清空后才可把此标签变成普通标签");
} }
} }