学期新增的时候校验校历功能点添加,否则会有大量的数据重复生成

This commit is contained in:
2026-09-14 17:24:56 +08:00
parent 52a04dbf60
commit 5187435285
9 changed files with 352 additions and 87 deletions
@@ -0,0 +1,76 @@
package com.roomroot.jwgl.utils;
/**
* 学期代号工具。
*
* <p>系统内学期统一用 6 位学期代号表示,形如 {@code 202601}:前 4 位为年份,后 2 位为学期第次。
*
* <p>但「学员队年度学期基本信息表」的 {@code 年度} 列在历史上出现过两种口径:
* <ul>
* <li>4 位年份 + 学期第次,例如 年度=2026、学期第次=1 → 2026 * 100 + 1 = 202601</li>
* <li>直接存 6 位学期代号,例如 年度=202503</li>
* </ul>
* 把 6 位值再套 {@code nd * 100 + xqdc} 会溢出(202503 * 100 + 1 = 20250301),
* 所以各处都需要先判别口径。本工具把两种口径统一解析为 6 位学期代号,
* 同时提供「写库时统一为 4 位年份」的规范化方法,避免新增数据继续产生双口径。
*/
public final class SemesterCodeUtil {
/** 6 位学期代号的下界(4 位年份最大 9999)。 */
private static final int SEMESTER_CODE_LOWER_BOUND = 100000;
private SemesterCodeUtil() {
}
/**
* 解析为 6 位学期代号,兼容 4 位年份与 6 位学期代号两种历史口径。
*
* @param nd 年度:4 位年份(如 2026)或 6 位学期代号(如 202503)
* @param xqdc 学期第次(1/2/3)。仅当 nd 为 4 位年份时参与计算
* @return 6 位学期代号;nd 为空时返回 null
*/
public static Integer resolve(Integer nd, Integer xqdc) {
if (nd == null) {
return null;
}
if (isSemesterCode(nd)) {
return nd;
}
if (xqdc == null) {
return nd;
}
return nd * 100 + xqdc;
}
/**
* 判断给定年度是否已经是 6 位学期代号。
*/
public static boolean isSemesterCode(Integer nd) {
return nd != null && nd >= SEMESTER_CODE_LOWER_BOUND;
}
/**
* 取 4 位年份部分。传入 6 位学期代号时拆分,传入 4 位年份时原样返回。
*
* @return 4 位年份;nd 为空时返回 null
*/
public static Integer toYear(Integer nd) {
if (nd == null) {
return null;
}
return isSemesterCode(nd) ? nd / 100 : nd;
}
/**
* 取学期第次。传入 6 位学期代号时取末两位,传入 4 位年份时返回传入的兜底值。
*
* @param xqdcFallback 4 位年份口径下的学期第次兜底值
* @return 学期第次;nd 为空时返回 null
*/
public static Integer toPeriod(Integer nd, Integer xqdcFallback) {
if (nd == null) {
return null;
}
return isSemesterCode(nd) ? nd % 100 : xqdcFallback;
}
}