Commit ff676ee9bdee11cd67cfb383ef2a6c63807766a4
1 parent
138b5d3f
✨ feat(mes): 添加条码内容生成接口及相关逻辑
新增条码内容生成接口,支持根据业务类型和编码生成条码内容。 同时更新相关服务和前端组件,确保条码内容的自动生成和验证逻辑。
Showing
4 changed files
with
64 additions
and
7 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/barcode/MesWmBarcodeController.java
| @@ -17,6 +17,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; | @@ -17,6 +17,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 17 | import jakarta.annotation.Resource; | 17 | import jakarta.annotation.Resource; |
| 18 | import jakarta.servlet.http.HttpServletResponse; | 18 | import jakarta.servlet.http.HttpServletResponse; |
| 19 | import jakarta.validation.Valid; | 19 | import jakarta.validation.Valid; |
| 20 | +import jakarta.validation.constraints.NotBlank; | ||
| 21 | +import jakarta.validation.constraints.NotNull; | ||
| 20 | import org.springframework.security.access.prepost.PreAuthorize; | 22 | import org.springframework.security.access.prepost.PreAuthorize; |
| 21 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| 22 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| @@ -88,6 +90,17 @@ public class MesWmBarcodeController { | @@ -88,6 +90,17 @@ public class MesWmBarcodeController { | ||
| 88 | return success(BeanUtils.toBean(barcode, MesWmBarcodeRespVO.class)); | 90 | return success(BeanUtils.toBean(barcode, MesWmBarcodeRespVO.class)); |
| 89 | } | 91 | } |
| 90 | 92 | ||
| 93 | + @GetMapping("/generate-content") | ||
| 94 | + @Operation(summary = "生成条码内容") | ||
| 95 | + @Parameter(name = "bizType", description = "业务类型", required = true, example = "1") | ||
| 96 | + @Parameter(name = "bizCode", description = "业务编码", required = true, example = "WO202403070001") | ||
| 97 | + @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')") | ||
| 98 | + public CommonResult<String> generateBarcodeContent(@RequestParam("bizType") @NotNull(message = "业务类型不能为空") Integer bizType, | ||
| 99 | + @RequestParam("bizCode") @NotBlank(message = "业务编码不能为空") String bizCode) { | ||
| 100 | + String content = barcodeService.generateBarcodeContent(bizType, bizCode); | ||
| 101 | + return success(content); | ||
| 102 | + } | ||
| 103 | + | ||
| 91 | @GetMapping("/export-excel") | 104 | @GetMapping("/export-excel") |
| 92 | @Operation(summary = "导出条码清单 Excel") | 105 | @Operation(summary = "导出条码清单 Excel") |
| 93 | @PreAuthorize("@ss.hasPermission('mes:wm-barcode:export')") | 106 | @PreAuthorize("@ss.hasPermission('mes:wm-barcode:export')") |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| @@ -505,5 +505,8 @@ public interface ErrorCodeConstants { | @@ -505,5 +505,8 @@ public interface ErrorCodeConstants { | ||
| 505 | ErrorCode WM_BARCODE_NOT_EXISTS = new ErrorCode(1_040_731_000, "条码不存在"); | 505 | ErrorCode WM_BARCODE_NOT_EXISTS = new ErrorCode(1_040_731_000, "条码不存在"); |
| 506 | ErrorCode WM_BARCODE_ALREADY_EXISTS = new ErrorCode(1_040_731_001, "该业务对象的条码已存在"); | 506 | ErrorCode WM_BARCODE_ALREADY_EXISTS = new ErrorCode(1_040_731_001, "该业务对象的条码已存在"); |
| 507 | ErrorCode WM_BARCODE_CONTENT_DUPLICATE = new ErrorCode(1_040_731_002, "条码内容已存在"); | 507 | ErrorCode WM_BARCODE_CONTENT_DUPLICATE = new ErrorCode(1_040_731_002, "条码内容已存在"); |
| 508 | + ErrorCode BARCODE_BIZ_TYPE_NOT_EXISTS = new ErrorCode(1_040_731_003, "业务类型不能为空"); | ||
| 509 | + ErrorCode BARCODE_BIZ_CODE_NOT_EXISTS = new ErrorCode(1_040_731_004, "业务编码不能为空"); | ||
| 510 | + ErrorCode BARCODE_CONFIG_NOT_EXISTS = new ErrorCode(1_040_731_005, "条码配置不存在"); | ||
| 508 | 511 | ||
| 509 | } | 512 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/barcode/MesWmBarcodeService.java
| @@ -70,4 +70,13 @@ public interface MesWmBarcodeService { | @@ -70,4 +70,13 @@ public interface MesWmBarcodeService { | ||
| 70 | */ | 70 | */ |
| 71 | void autoGenerateBarcode(Integer bizType, Long bizId, String bizCode, String bizName); | 71 | void autoGenerateBarcode(Integer bizType, Long bizId, String bizCode, String bizName); |
| 72 | 72 | ||
| 73 | + /** | ||
| 74 | + * 生成条码内容(供前端预览使用) | ||
| 75 | + * | ||
| 76 | + * @param bizType 业务类型 | ||
| 77 | + * @param bizCode 业务编码 | ||
| 78 | + * @return 生成的条码内容 | ||
| 79 | + */ | ||
| 80 | + String generateBarcodeContent(Integer bizType, String bizCode); | ||
| 81 | + | ||
| 73 | } | 82 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/barcode/MesWmBarcodeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mes.service.wm.barcode; | 1 | package cn.iocoder.yudao.module.mes.service.wm.barcode; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjUtil; | ||
| 3 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -42,9 +43,11 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | @@ -42,9 +43,11 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | ||
| 42 | throw exception(WM_BARCODE_ALREADY_EXISTS); | 43 | throw exception(WM_BARCODE_ALREADY_EXISTS); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | - // 2.1 生成条码内容(根据配置模板) | ||
| 46 | - // TODO @AI:MesWmBarcodeSaveReqVO 增加一个 content 字段;如果为空,才进行生成; | ||
| 47 | - String content = generateBarcodeContent(config.getContentFormat(), createReqVO.getBizCode()); | 46 | + // 2.1 生成条码内容(如果前端未传递,则自动生成) |
| 47 | + String content = createReqVO.getContent(); | ||
| 48 | + if (StrUtil.isBlank(content)) { | ||
| 49 | + content = generateBarcodeContent(config.getContentFormat(), createReqVO.getBizCode()); | ||
| 50 | + } | ||
| 48 | // 2.2 校验条码内容唯一性 | 51 | // 2.2 校验条码内容唯一性 |
| 49 | MesWmBarcodeDO contentBarcode = barcodeMapper.selectByContent(content); | 52 | MesWmBarcodeDO contentBarcode = barcodeMapper.selectByContent(content); |
| 50 | if (contentBarcode != null) { | 53 | if (contentBarcode != null) { |
| @@ -58,7 +61,21 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | @@ -58,7 +61,21 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | ||
| 58 | return barcode.getId(); | 61 | return barcode.getId(); |
| 59 | } | 62 | } |
| 60 | 63 | ||
| 61 | - // TODO @AI:后端提供一个接口,用于 generateBarcodeContent 的生成;前端需要调用这个接口; | 64 | + @Override |
| 65 | + public String generateBarcodeContent(Integer bizType, String bizCode) { | ||
| 66 | + // 1.1 校验参数 | ||
| 67 | + if (bizType == null) { | ||
| 68 | + throw exception(BARCODE_BIZ_TYPE_NOT_EXISTS); | ||
| 69 | + } | ||
| 70 | + if (StrUtil.isBlank(bizCode)) { | ||
| 71 | + throw exception(BARCODE_BIZ_CODE_NOT_EXISTS); | ||
| 72 | + } | ||
| 73 | + // 1.2 查询条码配置 | ||
| 74 | + MesWmBarcodeConfigDO config = barcodeConfigService.validateBarcodeConfigByBizType(bizType); | ||
| 75 | + | ||
| 76 | + // 2. 生成条码内容 | ||
| 77 | + return generateBarcodeContent(config.getContentFormat(), bizCode); | ||
| 78 | + } | ||
| 62 | 79 | ||
| 63 | /** | 80 | /** |
| 64 | * 生成条码内容 | 81 | * 生成条码内容 |
| @@ -76,13 +93,28 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | @@ -76,13 +93,28 @@ public class MesWmBarcodeServiceImpl implements MesWmBarcodeService { | ||
| 76 | 93 | ||
| 77 | @Override | 94 | @Override |
| 78 | public void updateBarcode(MesWmBarcodeSaveReqVO updateReqVO) { | 95 | public void updateBarcode(MesWmBarcodeSaveReqVO updateReqVO) { |
| 79 | - // 校验存在 | 96 | + // 1. 校验存在 |
| 80 | validateBarcodeExists(updateReqVO.getId()); | 97 | validateBarcodeExists(updateReqVO.getId()); |
| 81 | 98 | ||
| 82 | - // TODO @AI:content 可以更新;更新需要校验唯一; | 99 | + // 2.1 生成条码内容(如果前端未传递,则自动生成) |
| 100 | + String content = updateReqVO.getContent(); | ||
| 101 | + if (StrUtil.isBlank(content)) { | ||
| 102 | + MesWmBarcodeConfigDO config = barcodeConfigService.validateBarcodeConfigByBizType(updateReqVO.getBizType()); | ||
| 103 | + content = generateBarcodeContent(config.getContentFormat(), updateReqVO.getBizCode()); | ||
| 104 | + } | ||
| 105 | + // 2.2 校验条码内容唯一性(排除自己) | ||
| 106 | + if (StrUtil.isNotBlank(content)) { | ||
| 107 | + MesWmBarcodeDO contentBarcode = barcodeMapper.selectByContent(content); | ||
| 108 | + if (contentBarcode != null && ObjUtil.notEqual(contentBarcode.getId(), updateReqVO.getId())) { | ||
| 109 | + throw exception(WM_BARCODE_CONTENT_DUPLICATE); | ||
| 110 | + } | ||
| 111 | + } | ||
| 83 | 112 | ||
| 84 | - // 更新 | 113 | + // 3. 更新 |
| 85 | MesWmBarcodeDO updateObj = BeanUtils.toBean(updateReqVO, MesWmBarcodeDO.class); | 114 | MesWmBarcodeDO updateObj = BeanUtils.toBean(updateReqVO, MesWmBarcodeDO.class); |
| 115 | + if (StrUtil.isNotBlank(content)) { | ||
| 116 | + updateObj.setContent(content); | ||
| 117 | + } | ||
| 86 | barcodeMapper.updateById(updateObj); | 118 | barcodeMapper.updateById(updateObj); |
| 87 | } | 119 | } |
| 88 | 120 |