|
|
@@ -1,5 +1,7 @@
|
|
|
package org.dromara.xg.service.impl;
|
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.service.ConfigService;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
@@ -49,12 +51,14 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.Set;
|
|
|
import java.util.HashSet;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
|
/**
|
|
|
* 学生信息Service业务层处理
|
|
|
@@ -67,6 +71,14 @@ import java.util.HashSet;
|
|
|
@Service
|
|
|
public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
|
|
|
|
|
|
+ /** 一年级请假代理学院(人文学院)dept_id,配置于 sys_config */
|
|
|
+ private static final String FRESHMAN_PROXY_COLLEGE_CONFIG_KEY = "xg.studentLeave.freshmanProxyCollegeId";
|
|
|
+
|
|
|
+ /** 请假二级学院审批角色 */
|
|
|
+ private static final String LEAVE_COLLEGE_APPROVER_ROLE_KEY = "xsqj-ejxyspr";
|
|
|
+
|
|
|
+ private static final ZoneId SHANGHAI_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
+
|
|
|
private final XgStudentMsgMapper baseMapper;
|
|
|
private final ISysUserService sysUserService;
|
|
|
private final SysDeptMapper sysDeptMapper;
|
|
|
@@ -76,6 +88,7 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
|
|
|
private final XgClassMsgMapper xgClassMsgMapper;
|
|
|
private final XgDormBedStudentMapper xgDormBedStudentMapper;
|
|
|
private final XgSysDeptMapper xgSysDeptMapper;
|
|
|
+ private final ConfigService configService;
|
|
|
|
|
|
/**
|
|
|
* 查询学生信息
|
|
|
@@ -1088,6 +1101,9 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
|
|
|
|
|
|
/**
|
|
|
* 根据学生ID获取学院请假审批人列表
|
|
|
+ * <p>
|
|
|
+ * 一年级(按入学年、每年9月1日切届)走 sys_config 配置的代理学院(人文学院);
|
|
|
+ * 二年级及以上走学生本学院。入学年缺失时禁止提交。
|
|
|
*
|
|
|
* @param studentId 学生ID
|
|
|
* @return 请假审批人用户ID列表
|
|
|
@@ -1095,34 +1111,16 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
|
|
|
@Override
|
|
|
public List<Long> getCollegeLeaveApproversByStudentId(Long studentId) {
|
|
|
log.info("根据学生ID获取学院请假审批人列表 - 学生ID: {}", studentId);
|
|
|
-
|
|
|
- // 1. 根据学生ID查询学院ID
|
|
|
- String collegeIdStr = baseMapper.selectCollegeIdByStudentId(studentId);
|
|
|
- Long collegeId = null;
|
|
|
- if (StringUtils.isNotBlank(collegeIdStr)) {
|
|
|
- try {
|
|
|
- collegeId = Long.valueOf(collegeIdStr);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- log.warn("学院ID格式错误,无法转换为Long类型 - 学生ID: {}, collegeIdStr: {}", studentId, collegeIdStr);
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
- if (collegeId == null) {
|
|
|
- log.warn("未找到学生对应的学院信息 - 学生ID: {}", studentId);
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- log.info("学生所在学院ID: {}", collegeId);
|
|
|
-
|
|
|
- // 2. 根据学院ID和角色Key查询具备请假审批角色的用户列表
|
|
|
- List<Long> approverUserIds = baseMapper.selectUserIdsByCollegeIdAndRoleKey(collegeId, "xsqj-ejxyspr");
|
|
|
-
|
|
|
- log.info("找到的请假审批人数量: {}", approverUserIds.size());
|
|
|
+ Long collegeId = resolveLeaveCollegeId(studentId);
|
|
|
+ List<Long> approverUserIds = baseMapper.selectUserIdsByCollegeIdAndRoleKey(collegeId, LEAVE_COLLEGE_APPROVER_ROLE_KEY);
|
|
|
+ log.info("找到的请假审批人数量: {}, collegeId: {}", approverUserIds.size(), collegeId);
|
|
|
return approverUserIds;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据学生ID获取二级学院分管领导ID列表
|
|
|
+ * <p>
|
|
|
+ * 一年级走人文学院(配置代理学院),二年级及以上走本学院;入学年缺失禁止提交。
|
|
|
*
|
|
|
* @param studentId 学生ID
|
|
|
* @return 分管领导ID列表
|
|
|
@@ -1130,30 +1128,75 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
|
|
|
@Override
|
|
|
public List<Long> getCollegeLeadersByStudentId(Long studentId) {
|
|
|
log.info("根据学生ID获取二级学院分管领导ID列表 - 学生ID: {}", studentId);
|
|
|
+ Long collegeId = resolveLeaveCollegeId(studentId);
|
|
|
+ List<Long> leaderIds = baseMapper.selectCollegeLeaderIdsByCollegeId(collegeId);
|
|
|
+ log.info("找到的二级学院分管领导数量: {}, collegeId: {}", leaderIds.size(), collegeId);
|
|
|
+ return leaderIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析请假流程使用的学院ID:一年级 → 代理学院;非一年级 → 学生本学院。
|
|
|
+ */
|
|
|
+ private Long resolveLeaveCollegeId(Long studentId) {
|
|
|
+ Long enrollmentYear = baseMapper.selectEnrollmentYearByStudentId(studentId);
|
|
|
+ if (enrollmentYear == null) {
|
|
|
+ throw new ServiceException("学生入学年信息不完整,无法提交请假,请联系管理员维护班级或学生的入学年份");
|
|
|
+ }
|
|
|
|
|
|
- // 1. 根据学生ID查询学院ID
|
|
|
String collegeIdStr = baseMapper.selectCollegeIdByStudentId(studentId);
|
|
|
- Long collegeId = null;
|
|
|
- if (StringUtils.isNotBlank(collegeIdStr)) {
|
|
|
- try {
|
|
|
- collegeId = Long.valueOf(collegeIdStr);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- log.warn("学院ID格式错误,无法转换为Long类型 - 学生ID: {}, collegeIdStr: {}", studentId, collegeIdStr);
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
+ Long ownCollegeId = parseCollegeId(collegeIdStr, studentId);
|
|
|
+ if (ownCollegeId == null) {
|
|
|
+ throw new ServiceException("未找到该学生所在学院信息,无法提交请假");
|
|
|
}
|
|
|
- if (collegeId == null) {
|
|
|
- log.warn("未找到学生对应的学院信息 - 学生ID: {}", studentId);
|
|
|
- return new ArrayList<>();
|
|
|
+
|
|
|
+ if (!isFreshmanByEnrollmentYear(enrollmentYear)) {
|
|
|
+ log.info("非一年级请假,使用学生本学院 - studentId: {}, enrollmentYear: {}, collegeId: {}",
|
|
|
+ studentId, enrollmentYear, ownCollegeId);
|
|
|
+ return ownCollegeId;
|
|
|
}
|
|
|
|
|
|
- log.info("学生所在学院ID: {}", collegeId);
|
|
|
+ Long proxyCollegeId = resolveFreshmanProxyCollegeId();
|
|
|
+ log.info("一年级请假,使用代理学院 - studentId: {}, enrollmentYear: {}, proxyCollegeId: {}, ownCollegeId: {}",
|
|
|
+ studentId, enrollmentYear, proxyCollegeId, ownCollegeId);
|
|
|
+ return proxyCollegeId;
|
|
|
+ }
|
|
|
|
|
|
- // 2. 根据学院ID查询二级学院分管领导ID列表
|
|
|
- List<Long> leaderIds = baseMapper.selectCollegeLeaderIdsByCollegeId(collegeId);
|
|
|
+ /**
|
|
|
+ * 按入学年判断是否一年级。学年切换日:每年 9 月 1 日(Asia/Shanghai)。
|
|
|
+ */
|
|
|
+ private boolean isFreshmanByEnrollmentYear(Long enrollmentYear) {
|
|
|
+ LocalDate today = LocalDate.now(SHANGHAI_ZONE);
|
|
|
+ int currentCohortYear = today.getMonthValue() >= 9 ? today.getYear() : today.getYear() - 1;
|
|
|
+ return enrollmentYear.intValue() == currentCohortYear;
|
|
|
+ }
|
|
|
|
|
|
- log.info("找到的二级学院分管领导数量: {}", leaderIds.size());
|
|
|
- return leaderIds;
|
|
|
+ /**
|
|
|
+ * 从系统参数读取一年级请假代理学院 dept_id。
|
|
|
+ */
|
|
|
+ private Long resolveFreshmanProxyCollegeId() {
|
|
|
+ String configValue = configService.getConfigValue(FRESHMAN_PROXY_COLLEGE_CONFIG_KEY);
|
|
|
+ if (StringUtils.isBlank(configValue)) {
|
|
|
+ throw new ServiceException("一年级请假代理学院未配置,请在系统参数中配置 "
|
|
|
+ + FRESHMAN_PROXY_COLLEGE_CONFIG_KEY);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Long.valueOf(configValue.trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ throw new ServiceException("一年级请假代理学院配置无效(应为部门ID数字),请检查参数 "
|
|
|
+ + FRESHMAN_PROXY_COLLEGE_CONFIG_KEY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long parseCollegeId(String collegeIdStr, Long studentId) {
|
|
|
+ if (StringUtils.isBlank(collegeIdStr)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Long.valueOf(collegeIdStr);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("学院ID格式错误 - 学生ID: {}, collegeIdStr: {}", studentId, collegeIdStr);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|