添加学校
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.yunhai.bschclassmanage.controller.api;
|
||||
|
||||
|
||||
import com.yunhai.bschclassmanage.annotation.OperationLog;
|
||||
import com.yunhai.bschclassmanage.config.Config;
|
||||
import com.yunhai.bschclassmanage.model.constant.LogModule;
|
||||
import com.yunhai.bschclassmanage.model.dto.SchInfoDto;
|
||||
import com.yunhai.bschclassmanage.service.ISchInfoService;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Config.API_PATH+"/school/")
|
||||
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
|
||||
public class SchoolController {
|
||||
|
||||
@Autowired
|
||||
private ISchInfoService schInfoService;
|
||||
|
||||
@PostMapping("addSchool")
|
||||
@OperationLog(module = LogModule.SCHOOL_SYSTEM, description = "添加学校(初始化)成功")
|
||||
public void addSchool(@Valid @RequestBody SchInfoDto dto) {
|
||||
schInfoService.addSchool(UserContext.getCurrentUser(), dto);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public final class LogModule {
|
||||
|
||||
// ==================== 学制 ====================
|
||||
public static final String BASE_SYSTEM = "系统管理";
|
||||
// public static final String SCHOOL_SYSTEM = "学校管理";
|
||||
public static final String SCHOOL_SYSTEM = "学校管理";
|
||||
|
||||
// ==================== 字典管理 ====================
|
||||
public static final String SUBJECT = "学科管理";
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.yunhai.bschclassmanage.service;
|
||||
|
||||
import com.yunhai.bschclassmanage.entity.BaseDicGrade;
|
||||
import com.yunhai.bschclassmanage.entity.SchInfo;
|
||||
import com.yunhai.bschclassmanage.model.dto.SchInfoDto;
|
||||
import com.yunhai.bschclassmanage.model.vo.oa.SchInfoVO;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,4 +19,6 @@ public interface ISchInfoService {
|
||||
SchInfoVO GetSchFirst(String SchID);
|
||||
|
||||
SchInfoVO GetSchFirst(Integer schId);
|
||||
|
||||
void addSchool(UserContext.UserInfo user, SchInfoDto dto);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,18 @@ package com.yunhai.bschclassmanage.service.impl;
|
||||
|
||||
import com.yunhai.bschclassmanage.Repository.SchInfoRepository;
|
||||
import com.yunhai.bschclassmanage.entity.SchInfo;
|
||||
import com.yunhai.bschclassmanage.enums.NodeType;
|
||||
import com.yunhai.bschclassmanage.model.dto.SchInfoDto;
|
||||
import com.yunhai.bschclassmanage.model.vo.SelectIntVO;
|
||||
import com.yunhai.bschclassmanage.model.vo.oa.SchInfoVO;
|
||||
import com.yunhai.bschclassmanage.service.IComSchTreeService;
|
||||
import com.yunhai.bschclassmanage.service.ISchInfoService;
|
||||
import com.yunhai.bschclassmanage.service.ISendUserBaseService;
|
||||
import com.yunhai.bschclassmanage.utils.RedisUtil;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import com.yunhai.platform.openapi.client.YschBaseOpenApi;
|
||||
import com.yunhai.platform.utils.exception.DException;
|
||||
import com.yunhai.platform.utils.model.BoaGroup;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,6 +31,10 @@ public class SchInfoService implements ISchInfoService {
|
||||
@Autowired
|
||||
private IComSchTreeService comSchTreeService;
|
||||
|
||||
@Autowired
|
||||
private ISendUserBaseService sendUserBaseService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@@ -103,4 +114,40 @@ public class SchInfoService implements ISchInfoService {
|
||||
.orElse(null); // 如果不存在返回 null
|
||||
}
|
||||
|
||||
public void addSchool(UserContext.UserInfo user, SchInfoDto dto) {
|
||||
// 操作人所在学校(区)上下文
|
||||
Integer schId = user.getSchId();
|
||||
|
||||
// 获取全区学校列表,根据 name 判断是否存在同名学校组,存在则抛出异常提示学校名称已存在
|
||||
List<SelectIntVO> schoolList = comSchTreeService.getSchoolList();
|
||||
boolean nameExists = schoolList.stream()
|
||||
.anyMatch(s -> s.getName() != null && s.getName().equals(dto.getName()));
|
||||
if (nameExists) {
|
||||
throw new DException("学校名称已存在");
|
||||
}
|
||||
|
||||
// 否则添加学校组(返回新建的学校组,其 id 即新学校的 schId)
|
||||
BoaGroup newSchoolGroup = sendUserBaseService.addGroup(
|
||||
dto.getName(), dto.getGroupId(), null, NodeType.SCHOOL, schId);
|
||||
schId = newSchoolGroup.getId();
|
||||
|
||||
// 添加成功后,判断数据库是否已存在该学校的 sch_info 记录
|
||||
// 存在则更新,否则保存
|
||||
SchInfoVO existSch = GetSchFirst(schId);
|
||||
if (existSch == null) {
|
||||
SchInfo schInfo = new SchInfo();
|
||||
schInfo.setSchId(schId);
|
||||
schInfo.setName(dto.getName());
|
||||
schInfoRepository.save(schInfo);
|
||||
} else {
|
||||
schInfoRepository.findBySchId(schId).ifPresent(schInfo -> {
|
||||
schInfo.setName(dto.getName());
|
||||
schInfoRepository.save(schInfo);
|
||||
});
|
||||
}
|
||||
|
||||
// 调用 ComSchTreeService 清除全区缓存和学校列表缓存
|
||||
comSchTreeService.clearCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+52
-19
@@ -11,6 +11,7 @@ import com.yunhai.bschclassmanage.utils.LogContextHolder;
|
||||
import com.yunhai.bschclassmanage.utils.OtherUtil;
|
||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||
import com.yunhai.platform.utils.exception.DException;
|
||||
import com.yunhai.platform.utils.model.BoaGroup;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -45,6 +46,9 @@ public class SchClassHigherService {
|
||||
@Autowired
|
||||
private SchClassCacheService cacheService;
|
||||
|
||||
@Autowired
|
||||
private ISendUserBaseService sendUserBaseService;
|
||||
|
||||
@Autowired
|
||||
private SchClassLogService logService;
|
||||
|
||||
@@ -64,6 +68,12 @@ public class SchClassHigherService {
|
||||
throw new DException("班级名称不能为空");
|
||||
}
|
||||
|
||||
BoaGroup stuGroup= comSchTreeService.getStuTree(schId,false);
|
||||
if(stuGroup==null){
|
||||
throw new DException("学生组不存在!");
|
||||
}
|
||||
Integer parentId=stuGroup.getId();
|
||||
|
||||
boolean isNew = (entity.getId() == null || entity.getId() == 0);
|
||||
if (isNew) {
|
||||
boolean exists = schClassRepository.existsBySchIdAndGroupIdAndName(schId, entity.getGroupId(), entity.getName());
|
||||
@@ -81,32 +91,55 @@ public class SchClassHigherService {
|
||||
entity.setGradeId(entity.getEnrollYear());
|
||||
|
||||
SchClass oldSchClass = null;
|
||||
if (isNew) {
|
||||
|
||||
{
|
||||
//sync
|
||||
Integer maxSort = schClassRepository.findMaxCodeNumber(entity.getEnrollYear(), schId);
|
||||
int startSort = (maxSort == null) ? 1 : maxSort + 1;
|
||||
|
||||
// 同步组ID
|
||||
List<SelectIntVO> gradeGroupList = comSchTreeService.getSchGroupTypeList(schId, NodeType.GRADE.getId()).get(schsystemId);
|
||||
if (gradeGroupList == null || gradeGroupList.isEmpty()) {
|
||||
throw new DException("该学制下没有年级组,请先同步年级组数据!");
|
||||
}
|
||||
Map<String, Integer> gradeNameToIdMap = gradeGroupList.stream()
|
||||
.collect(Collectors.toMap(SelectIntVO::getName, SelectIntVO::getId, (a, b) -> a));
|
||||
List<SelectIntVO> classGroupList = comSchTreeService.getSchGroupTypeList(schId, NodeType.CLASS.getId()).get(schsystemId);
|
||||
Map<String, Integer> classNameToIdMap = new HashMap<>();
|
||||
if (classGroupList != null && !classGroupList.isEmpty()) {
|
||||
classNameToIdMap = classGroupList.stream()
|
||||
if (gradeGroupList == null || gradeGroupList.size()==0) {
|
||||
BoaGroup academicGroup= sendUserBaseService.addGroup(entity.getEnrollYear().toString(),parentId,entity.getEnrollYear(),NodeType.GRADE,schId);
|
||||
parentId=academicGroup.getId();
|
||||
}else {
|
||||
Map<String, Integer> gradeNameToIdMap = gradeGroupList.stream()
|
||||
.collect(Collectors.toMap(SelectIntVO::getName, SelectIntVO::getId, (a, b) -> a));
|
||||
parentId= gradeNameToIdMap.get(entity.getEnrollYear().toString());
|
||||
if(parentId==null)
|
||||
{
|
||||
BoaGroup academicGroup= sendUserBaseService.addGroup(entity.getEnrollYear().toString(),parentId,entity.getEnrollYear(),NodeType.GRADE,schId);
|
||||
parentId=academicGroup.getId();
|
||||
}
|
||||
}
|
||||
entity.setGroupId(parentId);
|
||||
|
||||
List<SelectIntVO> classGroupList = comSchTreeService.getSchGroupTypeList(schId, NodeType.CLASS.getId()).get(schsystemId);
|
||||
if (classGroupList != null && classGroupList.size()==0){
|
||||
BoaGroup classGroup= sendUserBaseService.addGroup(entity.getName(),parentId,startSort,NodeType.CLASS,schId);
|
||||
parentId=classGroup.getId();
|
||||
}else {
|
||||
Map<String, Integer> classNameToIdMap = new HashMap<>();
|
||||
if (classGroupList != null && !classGroupList.isEmpty()) {
|
||||
classNameToIdMap = classGroupList.stream()
|
||||
.collect(Collectors.toMap(SelectIntVO::getName, SelectIntVO::getId, (a, b) -> a));
|
||||
}
|
||||
parentId = classNameToIdMap.get(entity.getName());
|
||||
if(parentId==null)
|
||||
{
|
||||
BoaGroup classGroup= sendUserBaseService.addGroup(entity.getName(),parentId,startSort,NodeType.CLASS,schId);
|
||||
parentId=classGroup.getId();
|
||||
}
|
||||
}
|
||||
|
||||
Integer groupId = gradeNameToIdMap.get(entity.getEnrollYear().toString());
|
||||
if (groupId == null || groupId < 1) {
|
||||
throw new DException(entity.getEnrollYear() + "该年级组不存在,请检查年级组名称!");
|
||||
}
|
||||
entity.setGroupId(groupId);
|
||||
|
||||
Integer classId = classNameToIdMap.get(entity.getName());
|
||||
if (classId == null || classId < 1) {
|
||||
if (parentId == null || parentId < 1) {
|
||||
throw new DException("同步班级组失败,请检查班级组数据!");
|
||||
}
|
||||
entity.setClassId(classId);
|
||||
entity.setClassId(parentId);
|
||||
}
|
||||
|
||||
|
||||
if (isNew) {
|
||||
entity.setGraduate(false);
|
||||
schClassRepository.save(entity);
|
||||
} else {
|
||||
|
||||
@@ -826,7 +826,6 @@ public class ComSchTreeService implements IComSchTreeService {
|
||||
throw new DException("请创建高校系部和专业!");
|
||||
}
|
||||
|
||||
|
||||
SelectIntVO systemVO=schBinSchsystemService.selectSchBinSchsystem(schId).stream().findFirst()
|
||||
.orElseThrow(() -> new DException("学制未选择!"));
|
||||
|
||||
@@ -852,6 +851,7 @@ public class ComSchTreeService implements IComSchTreeService {
|
||||
node.setType(NodeType.GRADE); // 年级类型为2
|
||||
node.setGradeId(gradeYear);
|
||||
node.setSchsystemId(systemVO.getId());
|
||||
node.setEnrollYear(gradeYear);
|
||||
if (includeClass) {
|
||||
// 查询该年级下的班级列表,并转换为子节点
|
||||
List<SchClass> classList = schClassRepository.findBySchIdAndEnrollYear(schId, gradeYear);
|
||||
|
||||
Reference in New Issue
Block a user