From 1482bfd31c0261c67890f97cf9f0ae86f170a46c Mon Sep 17 00:00:00 2001 From: liweijie Date: Mon, 21 Sep 2026 16:36:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8F=AD=E6=AC=A1=E7=BC=96=E5=8F=B7=E7=94=9F?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E6=94=B9=E4=B8=BAXYD+=E5=B9=B4=E5=BA=A6+?= =?UTF-8?q?=E8=A1=A5=E9=9B=B6=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ElectiveCourseServiceImpl.java | 6 +- .../service/impl/ElectiveServiceImpl.java | 11 ++- .../impl/StudentRecordsServiceImpl.java | 18 ++++- .../com/roomroot/jwgl/utils/TeamCodeUtil.java | 69 +++++++++++++++++++ .../src/api/studentRecords/classCalendar.js | 2 +- .../src/views/student/shiftTeam/index.vue | 4 +- .../shiftSemester/ClassCalendarDialog.vue | 10 +-- .../TeachingAllocationDialog.vue | 2 +- .../views/teachOffice/shiftSemester/index.vue | 8 +-- 9 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/utils/TeamCodeUtil.java diff --git a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveCourseServiceImpl.java b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveCourseServiceImpl.java index 1d4b8fcb9..37f0a85e4 100644 --- a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveCourseServiceImpl.java +++ b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveCourseServiceImpl.java @@ -31,6 +31,7 @@ import com.roomroot.jwgl.service.ElectiveCourseService; import com.roomroot.jwgl.unit.PageQuery; import com.roomroot.jwgl.unit.PageResult; import com.roomroot.jwgl.utils.SemesterCodeUtil; +import com.roomroot.jwgl.utils.TeamCodeUtil; import com.roomroot.jwgl.utils.UuidUtil; import com.roomroot.jwgl.vo.jys.ElectiveCourseStudentVO; import com.roomroot.jwgl.vo.jys.ElectiveCourseVO; @@ -93,6 +94,9 @@ public class ElectiveCourseServiceImpl implements ElectiveCourseService { @Resource private ClassSemesterMapper classSemesterMapper; + @Resource + private TeamCodeUtil teamCodeUtil; + @Override public PageResult pageList(PageQuery query, ElectiveCourseQuery cond) { ElectiveCourseQuery filter = normalizeQuery(cond); @@ -379,13 +383,13 @@ public class ElectiveCourseServiceImpl implements ElectiveCourseService { throw new ServiceException("选修班不存在:" + xxbmc, NOT_FOUND); } XYDB created = new XYDB(); - created.setXydbh(UuidUtil.getOriginalUUID()); created.setXydmc(xxbmc.trim()); created.setNj(blankToNull(nj)); created.setXydlx(CLASS_TYPE_ELECTIVE); created.setXslx(0); created.setXydrs(rs != null ? rs : 0); fillTeamRequiredDefaults(created); + created.setXydbh(teamCodeUtil.nextXydbhForNj(created.getNj())); xydbMapper.insert(created); return created.getXydbh(); } diff --git a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveServiceImpl.java b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveServiceImpl.java index 39e825e10..c6a57a3b2 100644 --- a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveServiceImpl.java +++ b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/ElectiveServiceImpl.java @@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.roomroot.jwgl.dto.elective.AddClassDTO; import com.roomroot.jwgl.entity.*; import com.roomroot.jwgl.mapper.*; +import com.roomroot.jwgl.utils.TeamCodeUtil; import com.roomroot.jwgl.vo.elective.*; -import com.roomroot.jwgl.mapper.*; import com.roomroot.jwgl.service.BuildService; import com.roomroot.jwgl.service.ElectiveService; import com.roomroot.jwgl.unit.BusinessException; @@ -14,7 +14,6 @@ import com.roomroot.jwgl.unit.PageQuery; import com.roomroot.jwgl.unit.PageResult; import com.roomroot.jwgl.utils.SemesterCodeUtil; import com.roomroot.jwgl.utils.UuidUtil; -import com.roomroot.jwgl.vo.elective.*; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -56,10 +55,18 @@ public class ElectiveServiceImpl implements ElectiveService { @Resource private ClassSemesterMapper classSemesterMapper; + @Resource + private TeamCodeUtil teamCodeUtil; + @Override @Transactional public void add(AddClassDTO dto) { XYDB entity = dto.getClazz(); + if (entity.getXydbh() == null || entity.getXydbh().isEmpty()) { + entity.setXydbh(teamCodeUtil.nextXydbhForNj(entity.getNj())); + } else if (xydbMapper.selectById(entity.getXydbh()) != null) { + throw new BusinessException("学员队编号已存在:" + entity.getXydbh()); + } xydbMapper.insert(entity); // 同时写入学员队期表(学号规则、注册设置) XYDQB period = dto.getPeriod(); diff --git a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/StudentRecordsServiceImpl.java b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/StudentRecordsServiceImpl.java index bca441b35..31053f895 100644 --- a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/StudentRecordsServiceImpl.java +++ b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/service/impl/StudentRecordsServiceImpl.java @@ -29,6 +29,7 @@ import com.roomroot.jwgl.unit.PageQuery; import com.roomroot.jwgl.unit.PageResult; import com.roomroot.jwgl.utils.ExcelParseUtil; import com.roomroot.jwgl.utils.JwglRoleHelper; +import com.roomroot.jwgl.utils.TeamCodeUtil; import com.roomroot.jwgl.utils.UuidUtil; import com.roomroot.jwgl.vo.StudentListEchoVO; import jakarta.servlet.http.HttpServletResponse; @@ -90,6 +91,9 @@ public class StudentRecordsServiceImpl implements StudentRecordsService { @Resource private JwglRoleHelper jwglRoleHelper; + @Resource + private TeamCodeUtil teamCodeUtil; + @Override @Transactional public void add(XYXX xyxx) { @@ -704,7 +708,9 @@ public class StudentRecordsServiceImpl implements StudentRecordsService { @Transactional public void addTeam(XYDB entity) { if (entity.getXydbh() == null || entity.getXydbh().isEmpty()) { - throw new RuntimeException("学员队编号不能为空"); + entity.setXydbh(teamCodeUtil.nextXydbhForNj(entity.getNj())); + } else if (xydbMapper.selectById(entity.getXydbh()) != null) { + throw new RuntimeException("学员队编号已存在:" + entity.getXydbh()); } xydbMapper.insert(entity); } @@ -748,10 +754,18 @@ public class StudentRecordsServiceImpl implements StudentRecordsService { if (list.isEmpty()) { throw new RuntimeException("Excel中无有效数据"); } + int count = 0; for (XYDB entity : list) { + if (entity.getXydbh() == null || entity.getXydbh().isEmpty()) { + entity.setXydbh(teamCodeUtil.nextXydbhForNj(entity.getNj())); + } else if (xydbMapper.selectById(entity.getXydbh()) != null) { + // 编号已存在的跳过,避免整批导入因主键冲突中断 + continue; + } xydbMapper.insert(entity); + count++; } - return list.size(); + return count; } @Override diff --git a/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/utils/TeamCodeUtil.java b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/utils/TeamCodeUtil.java new file mode 100644 index 000000000..9ac3d9375 --- /dev/null +++ b/backend/roomroot-jwgl/src/main/java/com/roomroot/jwgl/utils/TeamCodeUtil.java @@ -0,0 +1,69 @@ +package com.roomroot.jwgl.utils; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.roomroot.jwgl.entity.XYDB; +import com.roomroot.jwgl.mapper.XYDBMapper; +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.time.LocalDate; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 班次(学员队)编号生成器。 + *

+ * 规则:XYD + 年度(4位) + 四位补零序号,序号在年度内递增,如 XYD20260001。 + * 所有系统建队入口统一走此生成器;调用方传入手工编号时仍按手工编号落库。 + *

+ */ +@Component +public class TeamCodeUtil { + + private static final String PREFIX = "XYD"; + private static final Pattern YEAR_PATTERN = Pattern.compile("\\d{4}"); + + @Resource + private XYDBMapper xydbMapper; + + /** + * 取指定年度下一个班次编号。 + * synchronized 避免单实例内并发取到同一序号;跨实例并发由主键约束兜底。 + */ + public synchronized String nextXydbh(Integer year) { + int y = (year != null && year > 0) ? year : LocalDate.now().getYear(); + String prefix = PREFIX + y; + List rows = xydbMapper.selectList(new LambdaQueryWrapper() + .select(XYDB::getXydbh) + .likeRight(XYDB::getXydbh, prefix)); + int max = 0; + for (XYDB row : rows) { + String code = row.getXydbh(); + if (code == null || code.length() <= prefix.length()) { + continue; + } + String tail = code.substring(prefix.length()); + // 只把 1-4 位纯数字后缀计入序号(兼容 XYD202601 这类两位序号存量数据),其它形态跳过 + if (tail.length() > 4 || !tail.chars().allMatch(Character::isDigit)) { + continue; + } + max = Math.max(max, Integer.parseInt(tail)); + } + return prefix + String.format("%04d", max + 1); + } + + /** + * 按年级文本解析年度后取号(如 "2026级" → 2026),解析不出取当前年度。 + */ + public String nextXydbhForNj(String nj) { + Integer year = null; + if (nj != null) { + Matcher m = YEAR_PATTERN.matcher(nj); + if (m.find()) { + year = Integer.valueOf(m.group()); + } + } + return nextXydbh(year); + } +} diff --git a/frontend/src/api/studentRecords/classCalendar.js b/frontend/src/api/studentRecords/classCalendar.js index ac99989a2..38e5190dd 100644 --- a/frontend/src/api/studentRecords/classCalendar.js +++ b/frontend/src/api/studentRecords/classCalendar.js @@ -1,6 +1,6 @@ import request from '@/utils/request' -// ======================== 班次教学任务(实体 XYDRWB 学员队任务表,不是班历) ======================== +// ======================== 班次课程(实体 XYDRWB 学员队任务表,不是班历) ======================== // 接口依据:api2.txt「班次学期日历(班历)」分组 + StudentTeamTaskController // 每个班次学期(xydxqbh)下挂若干条课程任务记录: // bh 编号、nd 年度、xydbh 学员队编号、kbh 课编号、xqdc 学期第次、jybh 教员编号、kcxh 课次序号、 diff --git a/frontend/src/views/student/shiftTeam/index.vue b/frontend/src/views/student/shiftTeam/index.vue index 7c3c710ff..1aee67fc6 100644 --- a/frontend/src/views/student/shiftTeam/index.vue +++ b/frontend/src/views/student/shiftTeam/index.vue @@ -133,7 +133,7 @@ - + @@ -408,7 +408,7 @@ export default { formSaving: false, form: this.createEmptyForm(), formRules: { - xydbh: [{ required: true, message: '请输入学员队编号', trigger: 'blur' }], + xydbh: [{ required: false }], xydmc: [{ required: true, message: '请输入学员队名称', trigger: 'blur' }], xydrs: [{ required: true, message: '请输入学员队人数', trigger: 'change' }], zydh: [{ required: true, message: '请选择专业', trigger: 'change' }], diff --git a/frontend/src/views/teachOffice/shiftSemester/ClassCalendarDialog.vue b/frontend/src/views/teachOffice/shiftSemester/ClassCalendarDialog.vue index 766c93ef5..078e09c1f 100644 --- a/frontend/src/views/teachOffice/shiftSemester/ClassCalendarDialog.vue +++ b/frontend/src/views/teachOffice/shiftSemester/ClassCalendarDialog.vue @@ -1,7 +1,7 @@