This commit is contained in:
wuchunlei
2024-03-26 18:01:13 +08:00
6 changed files with 173 additions and 0 deletions

View File

@@ -1,11 +1,13 @@
package com.peanut.modules.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@TableName("course_sociology")
@@ -20,8 +22,13 @@ public class CourseSociologyEntity {
private String title;
private Integer sort;
private Date createTime;
@TableLogic
private Integer delFlag;
@TableField(exist = false)
private List<CourseSociologyEntity> children;
}

View File

@@ -0,0 +1,48 @@
package com.peanut.modules.master.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CourseSociologyEntity;
import com.peanut.modules.common.to.ParamTo;
import com.peanut.modules.master.service.CourseSociologyService;
import com.peanut.modules.master.service.CourseToSociologyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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;
@Slf4j
@RestController("masterCourseSociology")
@RequestMapping("master/courseSociology")
public class CourseSociologyController {
@Autowired
private CourseSociologyService courseSociologyService;
@Autowired
private CourseToSociologyService courseToSociologyService;
@RequestMapping("/getCourseSociologyList")
public R getCourseSociologyList(){
List<CourseSociologyEntity> courseSociologyList = courseSociologyService.getCourseSociologyList();
return R.ok().put("sociologys",courseSociologyList);
}
@RequestMapping("/addCourseSociology")
public R addCourseSociology(@RequestBody CourseSociologyEntity courseSociologyEntity){
courseSociologyService.save(courseSociologyEntity);
return R.ok();
}
@RequestMapping("/delCourseSociology")
public R delCourseSociology(@RequestBody ParamTo param){
return courseSociologyService.delCourseSociology(param.getId());
}
@RequestMapping("/editCourseSociology")
public R editCourseSociology(@RequestBody CourseSociologyEntity courseSociologyEntity){
courseSociologyService.editCourseSociology(courseSociologyEntity);
return R.ok();
}
}

View File

@@ -0,0 +1,18 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.CourseSociologyEntity;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
import com.peanut.modules.common.to.ParamTo;
import java.util.List;
public interface CourseSociologyService extends IService<CourseSociologyEntity> {
List<CourseSociologyEntity> getCourseSociologyList();
R delCourseSociology(int id);
R editCourseSociology(CourseSociologyEntity courseSociologyEntity);
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.master.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
public interface CourseToSociologyService extends IService<CourseToSociologyEntity> {
}

View File

@@ -0,0 +1,77 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.common.utils.R;
import com.peanut.modules.common.dao.CourseSociologyDao;
import com.peanut.modules.common.dao.CourseToSociologyDao;
import com.peanut.modules.common.entity.CourseSociologyEntity;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
import com.peanut.modules.master.service.CourseSociologyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service("masterCourseSociologyService")
public class CourseSociologyServiceImpl extends ServiceImpl<CourseSociologyDao, CourseSociologyEntity> implements CourseSociologyService {
@Autowired
private CourseToSociologyDao courseToSociologyDao;
@Override
public List<CourseSociologyEntity> getCourseSociologyList() {
return this.sociologys(0);
}
@Override
public R delCourseSociology(int id) {
//查看下一级是否存在
CourseSociologyEntity one = this.getOne(new LambdaQueryWrapper<CourseSociologyEntity>().eq(CourseSociologyEntity::getPid, id));
if(one!=null){
return R.error(501,"删除失败,请先删除子项目后再尝试");
}
//查看绑定关系是否存在
CourseToSociologyEntity courseToSociologyEntity = courseToSociologyDao.selectOne(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getSociologyId, id));
if(courseToSociologyEntity!=null){
return R.error(502,"删除失败,请先解绑课程与国学标签的绑定关系");
}
this.removeById(id);
return R.ok();
}
@Override
public R editCourseSociology(CourseSociologyEntity courseSociologyEntity) {
CourseSociologyEntity old = this.getById(courseSociologyEntity.getId());
if(old.getIsLast()==0&&courseSociologyEntity.getIsLast()==1){
CourseSociologyEntity one = this.getOne(new LambdaQueryWrapper<CourseSociologyEntity>().eq(CourseSociologyEntity::getPid, courseSociologyEntity.getId()));
if(one!=null){
return R.error(501,"更新失败,请先清空此项的下级标签,才能将此标签变成终极标签");
}
}
if(old.getIsLast()==1&&courseSociologyEntity.getIsLast()==0){
CourseToSociologyEntity courseToSociologyEntity = courseToSociologyDao.selectOne(new LambdaQueryWrapper<CourseToSociologyEntity>().eq(CourseToSociologyEntity::getSociologyId, courseSociologyEntity.getId()));
if(courseToSociologyEntity!=null){
return R.error(502,"更新失败,请先把此项与课程的关联关系清空后才可把此标签变成普通标签");
}
}
this.updateById(courseSociologyEntity);
return R.ok();
}
private List<CourseSociologyEntity> sociologys(int id){
List<CourseSociologyEntity> list = this.list(new LambdaQueryWrapper<CourseSociologyEntity>().eq(CourseSociologyEntity::getPid, id));
for (CourseSociologyEntity c : list){
if(c.getIsLast()!=1){
List<CourseSociologyEntity> so = this.sociologys(c.getId());
c.setChildren(so);
}
}
return list;
}
}

View File

@@ -0,0 +1,16 @@
package com.peanut.modules.master.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.CourseToSociologyDao;
import com.peanut.modules.common.entity.CourseToSociologyEntity;
import com.peanut.modules.master.service.CourseToSociologyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service("masterCourseToSociologyService")
public class CourseToSociologyServiceImpl extends ServiceImpl<CourseToSociologyDao, CourseToSociologyEntity> implements CourseToSociologyService {
}