新增教学场地校验编号的重复性

This commit is contained in:
2026-09-17 09:30:04 +08:00
parent abf616a8ee
commit 9af6de6ff3
2 changed files with 14 additions and 2 deletions
@@ -6,6 +6,7 @@ import com.roomroot.common.utils.StringUtils;
import com.roomroot.jwgl.entity.JSB;
import com.roomroot.jwgl.mapper.ClassRoomMapper;
import com.roomroot.jwgl.service.ClassRoomService;
import com.roomroot.jwgl.unit.BusinessException;
import com.roomroot.jwgl.unit.PageQuery;
import com.roomroot.jwgl.unit.PageResult;
import com.roomroot.jwgl.utils.UuidUtil;
@@ -27,11 +28,17 @@ public class ClassRoomServiceImpl implements ClassRoomService {
public void add(JSB jsb) {
jsb.setId(UuidUtil.getUUID());
jsb.setDelFlag(0);
// 教室编号为非空列:留空时按现有最大数字编号 +1 自动生成
// 教室编号为非空列:留空时按现有最大数字编号 +1 自动生成;手填时校验唯一,避免按编号查询出现多行
if (StringUtils.isEmpty(jsb.getJsbh())) {
jsb.setJsbh(nextJsbh());
} else {
jsb.setJsbh(jsb.getJsbh().trim());
Long dup = jsbMapper.selectCount(new LambdaQueryWrapper<JSB>()
.eq(JSB::getJsbh, jsb.getJsbh())
.eq(JSB::getDelFlag, 0));
if (dup != null && dup > 0) {
throw new BusinessException("教室编号已存在:" + jsb.getJsbh());
}
}
jsbMapper.insert(jsb);
}
@@ -407,7 +407,12 @@ public class ElectiveServiceImpl implements ElectiveService {
}
JSB room = classRoomMapper.selectById(zyjsbh);
if (room == null) {
room = classRoomMapper.selectOne(new LambdaQueryWrapper<JSB>().eq(JSB::getJsbh, zyjsbh));
// 教室编号历史上可能出现重复行,取第一条避免 selectOne 多结果异常
List<JSB> rooms = classRoomMapper.selectList(new LambdaQueryWrapper<JSB>()
.eq(JSB::getJsbh, zyjsbh)
.eq(JSB::getDelFlag, 0)
.last("LIMIT 1"));
room = rooms.isEmpty() ? null : rooms.get(0);
}
return room == null ? null : room.getJsmc();
}