This commit is contained in:
wangjinlei
2024-03-26 17:23:15 +08:00
parent 158fdd8ee2
commit d4f30ed903
4 changed files with 104 additions and 2 deletions

View File

@@ -1,13 +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("masterCourseSociology")
@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;
}
}