数据编码服务中新增序列号生成逻辑

新增序列号生成服务,支持三种不同的编码规则:
1. 日期+递增数字(年月日或年月)。
2. 随机生成的8位序列号,包含大写字母和数字。
3. 默认规则,自增序列号。

实现具有不同前缀和后缀的序列号生成,包括年月日或年月作为前缀,校验位作为后缀。
This commit is contained in:
lijiaqi 2024-09-12 15:34:10 +08:00
parent c06d295092
commit da9145e29c
5 changed files with 14 additions and 4 deletions

View File

@ -42,7 +42,7 @@ public class BatchesController extends _BaseController {
@PostMapping("/add")
@Operation(summary = "增加")
public Result add(@RequestBody BatchesVo vo) {
public Result add(@RequestBody @Validated BatchesVo vo) {
return batchesService.addBatches(vo);
}
@ -51,7 +51,7 @@ public class BatchesController extends _BaseController {
@Parameters({
@Parameter(name = "batchId", description = "批次ID", required = true)
})
public Result edit(@RequestBody BatchesVo vo, @PathVariable String batchId) {
public Result edit(@RequestBody @Validated BatchesVo vo, @PathVariable String batchId) {
return batchesService.editBatches(batchId, vo);
}

View File

@ -253,7 +253,13 @@ public class BatchesService extends BaseService<BatchesMapper, Batches> {
return Result.fail("批次不存在");
}
Mfc mfc = mfcService.getById(batches.getMfcId());
if (ObjUtil.isNull(mfc)) {
return Result.fail("所属MFC不存在");
}
Rule rule = ruleService.getById(batches.getRuleId());
if (ObjUtil.isNull(rule)) {
return Result.fail("规则不存在");
}
codeService.generateCode(batchesId, batches.getBatchesCode(), mfc.getId(), mfc.getMfcCode(), rule.getId(), rule.getRuleCode(), count);
return Result.success("操作成功");
}

View File

@ -137,7 +137,7 @@ public class CodeService extends BaseService<CodeMapper, Code>{
code.setRuleCode(ruleCode);
code.setSnCode(snCode);
code.setSnPrefix(dateLong);
code.setSnSuffix(one.getSnSuffix() + 1);
code.setSnSuffix(ObjUtil.isNotNull(one) ?one.getSnSuffix() + 1 : maxCode);
code.setSnLength("E");
code.setCode(mfcCode + "E" + snCode);
boolean flag = save(code);
@ -190,7 +190,7 @@ public class CodeService extends BaseService<CodeMapper, Code>{
code.setRuleCode(ruleCode);
code.setSnCode(snCode);
code.setSnPrefix(dateLong);
code.setSnSuffix(one.getSnSuffix() + 1);
code.setSnSuffix(ObjUtil.isNotNull(one) ?one.getSnSuffix() + 1 : maxCode);
code.setSnLength("C");
code.setCode(mfcCode + "C" + snCode);
boolean flag = save(code);

View File

@ -1,5 +1,6 @@
package cn.workde.module.drone.coding.wrapper;
import cn.hutool.core.bean.BeanUtil;
import cn.workde.core.base.BaseWrapper;
import cn.workde.core.util.SpringUtil;
import cn.workde.module.drone.coding.dto.BatchesDto;
@ -19,6 +20,7 @@ public interface BatchesWrapper extends BaseWrapper<Batches, BatchesDto> {
@AfterMapping
default void setOtherField(@Param("obj") Batches obj, @MappingTarget @Param("dto") BatchesDto dto) {
BeanUtil.copyProperties(obj, dto);
MfcService mfcService = SpringUtil.getBean(MfcService.class);
dto.setMfc(mfcService.getById(obj.getMfcId()));
RuleService ruleService = SpringUtil.getBean(RuleService.class);

View File

@ -1,5 +1,6 @@
package cn.workde.module.drone.coding.wrapper;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.workde.core.base.BaseWrapper;
import cn.workde.module.drone.coding.dto.CodeDto;
@ -19,6 +20,7 @@ public interface CodeWrapper extends BaseWrapper<Code, CodeDto> {
@AfterMapping
default void setOtherField(@Param("obj") Code obj, @MappingTarget @Param("dto") CodeDto dto) {
BeanUtil.copyProperties(obj, dto);
BatchesService batchesService = SpringUtil.getBean(BatchesService.class);
dto.setBatches(batchesService.getById(obj.getBatchesId()));
MfcService mfcService = SpringUtil.getBean(MfcService.class);