This commit is contained in:
wangjinlei
2024-05-20 18:06:57 +08:00
parent 4be1541818
commit 40c0d0e862
3 changed files with 134 additions and 90 deletions

View File

@@ -3,8 +3,10 @@ package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.R; import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.*; import com.peanut.modules.master.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -15,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@RestController("masterCourseSociologyMarket") @RestController("masterCourseSociologyMarket")
@@ -37,58 +40,41 @@ public class CourseSociologyMarketController {
return R.ok().put("result", courseSociologyMarketEntities); return R.ok().put("result", courseSociologyMarketEntities);
} }
/**
* 获取营销标签列表
*/
@RequestMapping(path = "/getMakertListByPid")
public R getMakertListByPid(String pid) {
LambdaQueryWrapper<CourseSociologyMarketEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(CourseSociologyMarketEntity::getPid,pid);
wrapper.orderByAsc(CourseSociologyMarketEntity::getSort);
wrapper.orderByAsc(CourseSociologyMarketEntity::getCreateTime);
List<CourseSociologyMarketEntity> 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 CourseSociologyMarketEntity market) { public R addSociologyMarket(@RequestBody CourseSociologyMarketEntity courseSociologyMarketEntity){
if (market.getId()==null){ marketService.save(courseSociologyMarketEntity);
if(market.getPid()==0){ return R.ok();
marketService.save(market);
return R.ok().put("result",market);
}else {
CourseSociologyMarketEntity 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<CourseSociologyMarketEntity>()
.eq(CourseSociologyMarketEntity::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("/editSociologyMarket")
public R editSociologyMarket(@RequestBody CourseSociologyMarketEntity courseSociologyMarketEntity){
CourseSociologyMarketEntity old = marketService.getById(courseSociologyMarketEntity.getId());
if(courseSociologyMarketEntity.getIsLast()==1&&old.getIsLast()==0){//非终节点到终结点,要排除是否存在子集
Integer integer = marketService.getBaseMapper().selectCount(new LambdaQueryWrapper<CourseSociologyMarketEntity>().eq(CourseSociologyMarketEntity::getPid, courseSociologyMarketEntity.getId()));
if(integer>0){
return R.error("请先清空子集再操作!");
} }
} }
if(courseSociologyMarketEntity.getIsLast()==0&&old.getIsLast()==1){
Integer integer = toMarketService.getBaseMapper().selectCount(new LambdaQueryWrapper<CourseToSociologyMarketEntity>().eq(CourseToSociologyMarketEntity::getSociologyMarketId, courseSociologyMarketEntity.getId()));
if(integer>0){
return R.error("请先清空绑定的课程后,再操作");
}
}
marketService.save(courseSociologyMarketEntity);
return R.ok();
}
@RequestMapping(path = "/delMarket") @RequestMapping(path = "/delMarket")
public R delMarket(String id) { public R delMarket(@RequestBody Map<String ,Integer> map) {
int id = map.get("id");
CourseSociologyMarketEntity market = marketService.getById(id); CourseSociologyMarketEntity market = marketService.getById(id);
if (market.getIsLast()==1){ if (market.getIsLast()==1){
MPJLambdaWrapper<CourseToSociologyMarketEntity> wrapper = new MPJLambdaWrapper(); MPJLambdaWrapper<CourseToSociologyMarketEntity> wrapper = new MPJLambdaWrapper();
@@ -111,66 +97,105 @@ public class CourseSociologyMarketController {
} }
} }
@RequestMapping("/getCourseListByMarketId")
public R getCourseListByMarketId(@RequestBody Map<String,Integer> map){
List<CourseEntity> marketId = toMarketService.getCourseListByMarketId(map.get("marketId"));
return R.ok().put("courseList",marketId);
}
/** /**
* 获取营销标签下课程 * 获取营销标签下课程
*/ */
@RequestMapping(path = "/getCourseByMarketId") // @RequestMapping(path = "/getCourseByMarketId")
public R getCourseByMarket(@RequestBody Map<String, Object> params) { // public R getCourseByMarket(@RequestBody Map<String, Object> params) {
MPJLambdaWrapper<CourseToSociologyMarketEntity> wrapper = new MPJLambdaWrapper(); // MPJLambdaWrapper<CourseToSociologyMarketEntity> wrapper = new MPJLambdaWrapper();
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId, CourseToSociologyMarketEntity::getCourseId); // wrapper.leftJoin(CourseEntity.class,CourseEntity::getId, CourseToSociologyMarketEntity::getCourseId);
wrapper.selectAll(CourseEntity.class); // wrapper.selectAll(CourseEntity.class);
wrapper.like(CourseEntity::getTitle,params.get("title")); // wrapper.like(CourseEntity::getTitle,params.get("title"));
wrapper.eq(CourseToSociologyMarketEntity::getSociologyMarketId,params.get("marketId")); // wrapper.eq(CourseToSociologyMarketEntity::getSociologyMarketId,params.get("marketId"));
Page res = toMarketService.pageMaps(new Page<>( // Page res = toMarketService.pageMaps(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper); // Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
return R.ok().put("result", res); // return R.ok().put("result", res);
// }
@RequestMapping("/getNotToMarketList")
public R getNotToMarketList(@RequestBody ParamTo param){
List<Integer> collect = toMarketService.getBaseMapper().selectList(new LambdaQueryWrapper<CourseToSociologyMarketEntity>().eq(CourseToSociologyMarketEntity::getSociologyMarketId, param.getId())).stream().map(CourseToSociologyMarketEntity::getCourseId).collect(Collectors.toList());
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.notIn(collect.size()>0,CourseEntity::getId,collect);
wrapper.like(StringUtils.isNotBlank(param.getKeywords()),CourseEntity::getTitle,param.getKeywords());
Page<CourseEntity> page = courseService.page(new Page<>(param.getPage(), param.getLimit()), wrapper);
return R.ok().put("page",page);
} }
/** /**
* 获取未关联课程列表 * 获取未关联课程列表
*/ */
@RequestMapping("/getNotToMarketList") // @RequestMapping("/getNotToMarketList")
public R getNotToMarketList(@RequestBody Map params){ // public R getNotToMarketList(@RequestBody Map params){
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper(); // LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper();
wrapper.like(CourseEntity::getTitle,params.get("title")); // wrapper.like(CourseEntity::getTitle,params.get("title"));
if (params.containsKey("marketId")&&!"".equals(params.get("marketId").toString())){ // if (params.containsKey("marketId")&&!"".equals(params.get("marketId").toString())){
String sql = "select course_id from course_to_market where del_flag = 0 and market_id = "+params.get("marketId"); // String sql = "select course_id from course_to_market where del_flag = 0 and market_id = "+params.get("marketId");
wrapper.notInSql(CourseEntity::getId,sql); // wrapper.notInSql(CourseEntity::getId,sql);
} // }
Page<CourseEntity> page = courseService.page(new Page<>( // Page<CourseEntity> page = courseService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper); // Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
return R.ok().put("result", page); // return R.ok().put("result", page);
} // }
@RequestMapping(path = "/saveToMarket") @RequestMapping("/bindCourseAndSociologyMarket")
public R saveToMarket(@RequestBody Map params) { public R bindCourseAndSociologyMarket(@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<CourseToSociologyMarketEntity>().eq(CourseToSociologyMarketEntity::getSociologyMarketId, marketId).eq(CourseToSociologyMarketEntity::getCourseId, courseId));
for (String id : ids) { if(integer>0){
CourseToSociologyMarketEntity toMarket = new CourseToSociologyMarketEntity(); return R.error("不可重复绑定");
toMarket.setSociologyMarketId(Integer.parseInt(params.get("marketId").toString()));
toMarket.setCourseId(Integer.parseInt(id));
toMarketService.save(toMarket);
}
}
} }
CourseToSociologyMarketEntity courseToSociologyMarketEntity = new CourseToSociologyMarketEntity();
courseToSociologyMarketEntity.setSociologyMarketId(marketId);
courseToSociologyMarketEntity.setCourseId(courseId);
toMarketService.save(courseToSociologyMarketEntity);
return R.ok(); return R.ok();
} }
@RequestMapping(path = "/delToMarket") @RequestMapping("/unbindCourseAndSociologyMarket")
public R delToMarket(String marketId,String courseId) { public R unbindCourseAndSociologyMarket(@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<CourseToSociologyMarketEntity>().eq(CourseToSociologyMarketEntity::getSociologyMarketId,marketId).eq(CourseToSociologyMarketEntity::getCourseId,courseId));
LambdaQueryWrapper<CourseToSociologyMarketEntity> wrapper = new LambdaQueryWrapper();
wrapper.eq(CourseToSociologyMarketEntity::getSociologyMarketId,marketId);
wrapper.eq(CourseToSociologyMarketEntity::getCourseId,id);
toMarketService.remove(wrapper);
}
return R.ok(); return R.ok();
} }
return R.error("参数为空");
} // @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) {
// CourseToSociologyMarketEntity toMarket = new CourseToSociologyMarketEntity();
// toMarket.setSociologyMarketId(Integer.parseInt(params.get("marketId").toString()));
// toMarket.setCourseId(Integer.parseInt(id));
// toMarketService.save(toMarket);
// }
// }
// }
// 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<CourseToSociologyMarketEntity> wrapper = new LambdaQueryWrapper();
// wrapper.eq(CourseToSociologyMarketEntity::getSociologyMarketId,marketId);
// wrapper.eq(CourseToSociologyMarketEntity::getCourseId,id);
// toMarketService.remove(wrapper);
// }
// return R.ok();
// }
// return R.error("参数为空");
// }
} }

View File

@@ -1,8 +1,13 @@
package com.peanut.modules.master.service; package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.CourseEntity;
import com.peanut.modules.common.entity.CourseToMedicineMarketEntity; import com.peanut.modules.common.entity.CourseToMedicineMarketEntity;
import com.peanut.modules.common.entity.CourseToSociologyMarketEntity; import com.peanut.modules.common.entity.CourseToSociologyMarketEntity;
import java.util.List;
public interface CourseToSociologyMarketService extends IService<CourseToSociologyMarketEntity> { public interface CourseToSociologyMarketService extends IService<CourseToSociologyMarketEntity> {
List<CourseEntity> getCourseListByMarketId(int marketId);
} }

View File

@@ -1,8 +1,10 @@
package com.peanut.modules.master.service.impl; package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.modules.common.dao.CourseToMedicineMarketDao; import com.peanut.modules.common.dao.CourseToMedicineMarketDao;
import com.peanut.modules.common.dao.CourseToSociologyMarketDao; import com.peanut.modules.common.dao.CourseToSociologyMarketDao;
import com.peanut.modules.common.entity.CourseEntity;
import com.peanut.modules.common.entity.CourseToMedicineMarketEntity; import com.peanut.modules.common.entity.CourseToMedicineMarketEntity;
import com.peanut.modules.common.entity.CourseToSociologyMarketEntity; import com.peanut.modules.common.entity.CourseToSociologyMarketEntity;
import com.peanut.modules.master.service.CourseToMedicineMarketService; import com.peanut.modules.master.service.CourseToMedicineMarketService;
@@ -10,7 +12,19 @@ import com.peanut.modules.master.service.CourseToSociologyMarketService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j @Slf4j
@Service("masterCourseToSociologyMarketService") @Service("masterCourseToSociologyMarketService")
public class CourseToSociologyMarketServiceImpl extends ServiceImpl<CourseToSociologyMarketDao, CourseToSociologyMarketEntity> implements CourseToSociologyMarketService { public class CourseToSociologyMarketServiceImpl extends ServiceImpl<CourseToSociologyMarketDao, CourseToSociologyMarketEntity> implements CourseToSociologyMarketService {
@Override
public List<CourseEntity> getCourseListByMarketId(int marketId) {
MPJLambdaWrapper<CourseToSociologyMarketEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(CourseEntity.class);
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,CourseToSociologyMarketEntity::getCourseId);
wrapper.eq(CourseToSociologyMarketEntity::getSociologyMarketId,marketId);
List<CourseEntity> courseEntities = this.getBaseMapper().selectJoinList(CourseEntity.class, wrapper);
return courseEntities;
}
} }