131 lines
5.3 KiB
Java
131 lines
5.3 KiB
Java
package com.yunhai.bschclassmanage.controller.api;
|
||
|
||
|
||
import com.yunhai.bschclassmanage.annotation.OperationLog;
|
||
import com.yunhai.bschclassmanage.config.Config;
|
||
import com.yunhai.bschclassmanage.entity.SchBinSchsystem;
|
||
import com.yunhai.bschclassmanage.enums.UserRole;
|
||
import com.yunhai.bschclassmanage.enums.UserType;
|
||
import com.yunhai.bschclassmanage.model.vo.AcademicStageSchsystemVO;
|
||
import com.yunhai.bschclassmanage.model.vo.SelectIntVO;
|
||
import com.yunhai.bschclassmanage.service.IComSchTreeService;
|
||
import com.yunhai.bschclassmanage.service.ISchBinSchsystemService;
|
||
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 org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
|
||
@RestController
|
||
@RequestMapping(Config.API_PATH+"/schsystem/")
|
||
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
|
||
public class SchsystemController {
|
||
|
||
@Autowired
|
||
private ISchBinSchsystemService schBinSchsystemService; // 使用接口
|
||
|
||
@Autowired
|
||
private IComSchTreeService comSchTreeService; // 使用接口
|
||
/**
|
||
* 获取学段枚举 + 学制列表
|
||
* @return 学段分组后的学制列表
|
||
*/
|
||
@GetMapping("list")
|
||
public List<AcademicStageSchsystemVO> getAcademicStageSchsystemList(@RequestParam(required = false) Integer schId) {
|
||
|
||
Integer roleId = UserContext.getRoleId();
|
||
boolean isSuperAdmin = UserType.SUPER_ADMINISTRATOR.getId().equals(UserContext.getType());
|
||
boolean isAreaAdmin = !isSuperAdmin && UserRole.AREAADMIN.getValue().equals(roleId);
|
||
|
||
if (!isSuperAdmin && !isAreaAdmin) {
|
||
throw new DException("无权操作,仅超级管理员或学校管理员可设置学制");
|
||
}
|
||
|
||
// 3. 确定最终操作的学校ID,并校验
|
||
Integer targetSchId;
|
||
if (isAreaAdmin) {
|
||
// 区域管理员:强制使用自己所属的学校,忽略前端传入的schId
|
||
targetSchId = UserContext.getSchId();
|
||
if (targetSchId == null || targetSchId <= 0) {
|
||
throw new DException("当前学校管理员未关联有效的学校");
|
||
}
|
||
} else { // 超管
|
||
if (schId == null || schId < 0) {
|
||
throw new DException("学校ID不能为空且必须为正整数");
|
||
}
|
||
targetSchId = schId;
|
||
}
|
||
|
||
return schBinSchsystemService.getAcademicStageSchsystemList(targetSchId);
|
||
}
|
||
|
||
@GetMapping("getType")
|
||
public Integer getSchType() {
|
||
return schBinSchsystemService.getSchType(UserContext.getSchId());
|
||
}
|
||
|
||
/**
|
||
* 学校选择学制
|
||
* @return 学段分组后的学制列表
|
||
*/
|
||
@PostMapping("save")
|
||
@OperationLog(module = "绑定学制")
|
||
public void saveSchBinSchsystem(@RequestParam(required = false) Integer schId,
|
||
@RequestParam("schsystemIds") String schsystemIdsStr) {
|
||
|
||
UserContext.UserInfo user= UserContext.getCurrentUser();
|
||
// 2. 角色权限校验
|
||
Integer roleId = user.getRoleId();
|
||
boolean isSuperAdmin = UserType.SUPER_ADMINISTRATOR.getId().equals(UserContext.getType());
|
||
boolean isAreaAdmin =!isSuperAdmin && UserRole.AREAADMIN.getValue().equals(roleId);
|
||
|
||
if (!isSuperAdmin && !isAreaAdmin) {
|
||
throw new DException("无权操作,仅超级管理员或学校管理员可设置学制");
|
||
}
|
||
|
||
// 3. 确定最终操作的学校ID,并校验
|
||
Integer targetSchId;
|
||
if (isAreaAdmin) {
|
||
// 区域管理员:强制使用自己所属的学校,忽略前端传入的schId
|
||
targetSchId = UserContext.getSchId();
|
||
if (targetSchId == null || targetSchId <= 0) {
|
||
throw new DException("当前学校管理员未关联有效的学校");
|
||
}
|
||
} else { // 超管
|
||
if (schId == null || schId <= 0) {
|
||
throw new DException("学校ID不能为空且必须为正整数");
|
||
}
|
||
targetSchId = schId;
|
||
}
|
||
String schName= comSchTreeService.getSchoolName(targetSchId);
|
||
// 4. 转换学制ID数组
|
||
Integer[] schsystemIds = OtherUtil.convertToArray(schsystemIdsStr);
|
||
|
||
List<String> schsystemNames= schBinSchsystemService.selectSchBinSchsystem(targetSchId)
|
||
.stream().filter(s-> Arrays.asList(schsystemIds).contains(s.getId()))
|
||
.map(s->s.getName()).collect(Collectors.toList());
|
||
|
||
LogContextHolder.setDescription(String.format("为学校 %s 绑定学制:%s", schName,String.join(",",schsystemNames) ));
|
||
if (schsystemIds == null || schsystemIds.length == 0) {
|
||
throw new DException("学制ID列表无效");
|
||
}
|
||
SchBinSchsystem entity=new SchBinSchsystem();
|
||
OtherUtil.setBaseEntityValue(user, entity);
|
||
entity.setSchId(targetSchId);
|
||
// 5. 调用服务
|
||
schBinSchsystemService.saveSchBinSchsystem(entity, schsystemIds);
|
||
}
|
||
|
||
@GetMapping("select")
|
||
public List<SelectIntVO> selectSchBinSchsystem() {
|
||
return schBinSchsystemService.selectSchBinSchsystem(UserContext.getSchId());
|
||
}
|
||
|
||
|
||
}
|