班次编号生成,改为XYD+年度+补零序号
This commit is contained in:
+5
-1
@@ -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<ElectiveCourseVO> 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();
|
||||
}
|
||||
|
||||
+9
-2
@@ -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();
|
||||
|
||||
+16
-2
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 班次(学员队)编号生成器。
|
||||
* <p>
|
||||
* 规则:XYD + 年度(4位) + 四位补零序号,序号在年度内递增,如 XYD20260001。
|
||||
* 所有系统建队入口统一走此生成器;调用方传入手工编号时仍按手工编号落库。
|
||||
* </p>
|
||||
*/
|
||||
@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<XYDB> rows = xydbMapper.selectList(new LambdaQueryWrapper<XYDB>()
|
||||
.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user