|
|
package cn.bronet.admin.demo.service.impl;
|
|
|
|
|
|
import cn.bronet.admin.common.core.domain.AjaxResult;
|
|
|
import cn.bronet.admin.common.utils.ServletUtils;
|
|
|
import cn.bronet.admin.demo.domain.CRelationshipStudentSgc;
|
|
|
import cn.bronet.admin.demo.domain.CTeacher;
|
|
|
import cn.bronet.admin.demo.domain.CUser;
|
|
|
import cn.bronet.admin.demo.domain.vo.TestDemoVo;
|
|
|
import cn.bronet.admin.demo.mapper.CRegisterSchoolMapper;
|
|
|
import cn.bronet.admin.demo.mapper.CUserMapper;
|
|
|
import cn.bronet.admin.demo.domain.vo.ClassInfoVo;
|
|
|
import cn.bronet.admin.demo.domain.vo.GradeInfoVo;
|
|
|
import cn.bronet.admin.demo.mapper.*;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.bronet.admin.common.utils.PageUtils;
|
|
|
import cn.bronet.admin.common.core.page.PagePlus;
|
|
|
import cn.bronet.admin.common.core.page.TableDataInfo;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import javassist.runtime.Desc;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -23,8 +23,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
import cn.bronet.admin.demo.domain.bo.CGradeBo;
|
|
|
import cn.bronet.admin.demo.domain.vo.CGradeVo;
|
|
|
import cn.bronet.admin.demo.domain.CGrade;
|
|
|
import cn.bronet.admin.demo.mapper.CGradeMapper;
|
|
|
import cn.bronet.admin.demo.service.ICGradeService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
...
|
...
|
@@ -51,6 +52,12 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
@Autowired
|
|
|
private CRegisterSchoolMapper cRegisterSchoolMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private CTeacherMapper cTeacherMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private CRelationshipStudentSgcMapper cRelationshipStudentSgcMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public CGradeVo queryById(Long id){
|
...
|
...
|
@@ -60,9 +67,12 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
@Override
|
|
|
public TableDataInfo<CGradeVo> queryPageList(CGradeBo bo) {
|
|
|
|
|
|
// TODO: 2021/9/24 获取当前登录人Id
|
|
|
Long uId=119911L;
|
|
|
Long schoolId = cRegisterSchoolMapper.selectByUserId(uId);
|
|
|
bo.setSchoolId(schoolId);
|
|
|
|
|
|
|
|
|
PagePlus<CGrade, CGradeVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
|
|
PagePlus<CGrade, CGradeVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
|
|
return PageUtils.buildDataInfo(result);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -91,6 +101,7 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
|
|
|
@Override
|
|
|
public Boolean updateByBo(CGradeBo bo) {
|
|
|
|
|
|
CGrade update = BeanUtil.toBean(bo, CGrade.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
return updateById(update);
|
...
|
...
|
@@ -144,7 +155,7 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
public AjaxResult saveGrade(CGradeBo bo) {
|
|
|
|
|
|
//获取登录用户的Id
|
|
|
Long uId=111111L;
|
|
|
Long uId=119911L;
|
|
|
Long schoolId = cRegisterSchoolMapper.selectByUserId(uId);
|
|
|
|
|
|
//创建需要添加到数据库的参数
|
...
|
...
|
@@ -171,7 +182,6 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
|
|
|
//获取登录人的Id
|
|
|
Long uId =119911L;
|
|
|
CUser cUser = cUserMapper.selectById(uId);
|
|
|
Long schoolId = cRegisterSchoolMapper.selectByUserId(uId);
|
|
|
|
|
|
//创建数据库查询条件
|
...
|
...
|
@@ -214,7 +224,8 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
//创建存储信息
|
|
|
CGrade grade = new CGrade();
|
|
|
BeanUtils.copyProperties(bo,grade);
|
|
|
grade.setSchoolId(schoolId);
|
|
|
grade.setSchoolId(schoolId)
|
|
|
.setCreateTime(LocalDateTime.now());
|
|
|
|
|
|
cGradeMapper.insert(grade);
|
|
|
|
...
|
...
|
@@ -251,7 +262,6 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
|
|
|
//获取登录人用户
|
|
|
Long uId=119911L;
|
|
|
CUser cUser = cUserMapper.selectById(uId);
|
|
|
Long schoolId = cRegisterSchoolMapper.selectByUserId(uId);
|
|
|
|
|
|
LambdaQueryWrapper<CGrade> wrapper = new LambdaQueryWrapper<>();
|
...
|
...
|
@@ -275,4 +285,146 @@ public class CGradeServiceImpl extends ServicePlusImpl<CGradeMapper, CGrade, CGr |
|
|
|
|
|
return AjaxResult.success(vos);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询年级的信息信息
|
|
|
* @param gradeId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult getGradeInfo(Long gradeId) {
|
|
|
|
|
|
|
|
|
GradeInfoVo vo = new GradeInfoVo();
|
|
|
CGrade grade = cGradeMapper.selectById(gradeId);
|
|
|
List<CGrade> classes = cGradeMapper.selectByGradeParentId( grade.getId());
|
|
|
List<CGradeVo> classesList = new ArrayList<>();
|
|
|
|
|
|
//判断 classes不为null
|
|
|
if (!classes.isEmpty()){
|
|
|
for (CGrade aClass : classes) {
|
|
|
|
|
|
CGradeVo classVo = new CGradeVo();
|
|
|
BeanUtils.copyProperties(aClass,classVo);
|
|
|
|
|
|
classesList.add(classVo);
|
|
|
}
|
|
|
|
|
|
vo.setClassesList(classesList);
|
|
|
}
|
|
|
//填数据到返回值中
|
|
|
vo.setGradeName(grade.getGradeName());
|
|
|
vo.setId(grade.getId());
|
|
|
vo.setCreateTime(grade.getCreateTime());
|
|
|
|
|
|
return AjaxResult.success(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询班级的详细系信息
|
|
|
* @param gradeId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult getClassInfo(Long gradeId) {
|
|
|
|
|
|
CGrade classVo = cGradeMapper.selectById(gradeId);
|
|
|
|
|
|
CGradeVo vo = new CGradeVo();
|
|
|
BeanUtils.copyProperties(classVo,vo);
|
|
|
|
|
|
return AjaxResult.success(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取需要修改的班级Id
|
|
|
* @param gradeId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult getUpdateClassInfo(Long gradeId) {
|
|
|
|
|
|
ClassInfoVo vo = new ClassInfoVo();
|
|
|
CGrade cClass = cGradeMapper.selectById(gradeId);
|
|
|
CGrade cGrade = cGradeMapper.selectById(cClass.getParentId());
|
|
|
|
|
|
if (cClass != null){
|
|
|
BeanUtils.copyProperties(cClass,vo);
|
|
|
}
|
|
|
|
|
|
if (cGrade != null){
|
|
|
CGradeVo cGradeVo = new CGradeVo();
|
|
|
BeanUtils.copyProperties(cGrade,cGradeVo);
|
|
|
vo.setGradeVo(cGradeVo);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除学校年级
|
|
|
* @param gradeIds
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public AjaxResult deleteGrade(List<Long> gradeIds) {
|
|
|
|
|
|
//想要删除的总数
|
|
|
int count = gradeIds.size();
|
|
|
|
|
|
//成功删除数量
|
|
|
int success = 0;
|
|
|
|
|
|
for (int i = 0; i < gradeIds.size(); i++) {
|
|
|
|
|
|
List<CGrade> cGrades = cGradeMapper.selectByGradeParentId(gradeIds.get(i));
|
|
|
|
|
|
if (cGrades.isEmpty()){
|
|
|
|
|
|
cGradeMapper.deleteById(gradeIds.get(i));
|
|
|
success++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//失败数量
|
|
|
int fail = count-success;
|
|
|
|
|
|
return AjaxResult.success("总共删除:["+count+"],成功删除:["+success+"],失败:["+fail+"]"+"条件:年级下存在班级");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除学校班级(备选)
|
|
|
* @param gradeIds
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public AjaxResult deleteClasses(List<Long> gradeIds) {
|
|
|
|
|
|
//想要删除的总数
|
|
|
int count = gradeIds.size();
|
|
|
|
|
|
//成功删除数量
|
|
|
int success = 0;
|
|
|
|
|
|
for (int i = 0; i < gradeIds.size(); i++) {
|
|
|
|
|
|
List<CTeacher> cTeachers = cTeacherMapper.selectByGradeId(gradeIds.get(i));
|
|
|
List<CRelationshipStudentSgc> cStudent = cRelationshipStudentSgcMapper.selectByGradeId(gradeIds.get(i));
|
|
|
|
|
|
|
|
|
if (cTeachers.isEmpty() && cStudent.isEmpty()){
|
|
|
|
|
|
cGradeMapper.deleteById(gradeIds.get(i));
|
|
|
success++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//失败数量
|
|
|
int fail = count-success;
|
|
|
|
|
|
return AjaxResult.success("总共删除:["+count+"],成功删除:["+success+"],失败:["+fail+"]"+"条件:班级下存在老师或老师");
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|