forked from liweijie/education
教室编号生成调整
This commit is contained in:
@@ -20,4 +20,11 @@ public interface ClassRoomMapper extends BaseMapper<JSB> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<JSB> selectPageList(Page<JSB> page, @Param("jsb") JSB jsb);
|
||||
|
||||
/**
|
||||
* 获取最大教室编号(仅统计纯数字编号)
|
||||
*
|
||||
* @return 最大教室编号
|
||||
*/
|
||||
String selectMaxJsbh();
|
||||
}
|
||||
@@ -54,4 +54,8 @@
|
||||
ORDER BY 序号
|
||||
</select>
|
||||
|
||||
<select id="selectMaxJsbh" resultType="java.lang.String">
|
||||
SELECT MAX(CAST(教室编号 AS INT)) FROM 教室表 WHERE DEL_FLAG = 0 AND REGEXP_LIKE(教室编号, '^[0-9]+$')
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+22
@@ -2,6 +2,7 @@ package com.roomroot.jwgl.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.roomroot.common.utils.StringUtils;
|
||||
import com.roomroot.jwgl.entity.JSB;
|
||||
import com.roomroot.jwgl.mapper.ClassRoomMapper;
|
||||
import com.roomroot.jwgl.service.ClassRoomService;
|
||||
@@ -26,9 +27,30 @@ public class ClassRoomServiceImpl implements ClassRoomService {
|
||||
public void add(JSB jsb) {
|
||||
jsb.setId(UuidUtil.getUUID());
|
||||
jsb.setDelFlag(0);
|
||||
// 教室编号为非空列:留空时按现有最大数字编号 +1 自动生成
|
||||
if (StringUtils.isEmpty(jsb.getJsbh())) {
|
||||
jsb.setJsbh(nextJsbh());
|
||||
} else {
|
||||
jsb.setJsbh(jsb.getJsbh().trim());
|
||||
}
|
||||
jsbMapper.insert(jsb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一个教室编号(纯数字编号中取最大值 +1)
|
||||
*/
|
||||
private String nextJsbh() {
|
||||
String maxJsbh = jsbMapper.selectMaxJsbh();
|
||||
if (StringUtils.isEmpty(maxJsbh)) {
|
||||
return "1";
|
||||
}
|
||||
try {
|
||||
return String.valueOf(Integer.parseInt(maxJsbh.trim()) + 1);
|
||||
} catch (NumberFormatException e) {
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
JSB jsb = getById(id);
|
||||
|
||||
Reference in New Issue
Block a user