From 704265308b1227dbada5a36b2027b588c062ded2 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 12 十月 2026 09:14:37 +0800
Subject: [PATCH] feat(mes): 新增业务码支持并优化追溯查询功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java |   95 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 87 insertions(+), 8 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java
index 0489480..3892fab 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/pallet/MesProPalletController.java
@@ -10,7 +10,11 @@
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.bagcode.vo.MesProBagCodeRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletBatchCreateReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletBindBatchReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletExportQrReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletPageReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletPreGenerateReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletPreGenerateRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletRespVO;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletTraceRespVO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.mdm.MesMdmItemDO;
@@ -69,10 +73,43 @@
     private AdminUserApi adminUserApi;
 
     @PostMapping("/batch-create")
-    @Operation(summary = "鎵归噺鐢熸垚鎵樼洏鐮�")
+    @Operation(summary = "鎵归噺鐢熸垚鎵樼洏鐮侊紙涓�娆″綍鍏ユ壒娆$敓鎴愭寮忔墭鐩樼爜锛�")
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:create')")
     public CommonResult<List<Long>> batchCreatePallet(@Valid @RequestBody MesProPalletBatchCreateReqVO createReqVO) {
         return success(palletService.batchCreatePallet(createReqVO));
+    }
+
+    @PostMapping("/pre-generate")
+    @Operation(summary = "棰勭敓鎴愭墭鐩樼爜浜岀淮鐮侊紙浠呯敓鎴愪复鏃舵墭鐩樼爜锛屼笉缁戝畾鐢熶骇鎵规锛�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:create')")
+    public CommonResult<List<MesProPalletPreGenerateRespVO>> preGeneratePallet(
+            @Valid @RequestBody MesProPalletPreGenerateReqVO preGenerateReqVO) {
+        List<MesProPalletDO> list = palletService.preGeneratePallet(preGenerateReqVO);
+        return success(BeanUtils.toBean(list, MesProPalletPreGenerateRespVO.class));
+    }
+
+    @PutMapping("/bind-batch")
+    @Operation(summary = "鎵樼洏鐮佺粦瀹氱敓浜ф壒娆★紙鐢熸垚姝e紡鎵樼洏鐮侊級")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:update')")
+    public CommonResult<Boolean> bindBatch(@Valid @RequestBody MesProPalletBindBatchReqVO bindReqVO) {
+        palletService.bindBatch(bindReqVO);
+        return success(true);
+    }
+
+    @PostMapping("/export-qr-by-ids")
+    @Operation(summary = "鎸夋墭鐩樼爜缂栧彿鍒楄〃鎵归噺瀵煎嚭浜岀淮鐮佸浘鐗� ZIP锛堟敮鎸佹湭缁戝畾鎵规鐨勪复鏃舵墭鐩橈級")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportPalletQrByIds(@Valid @RequestBody MesProPalletExportQrReqVO exportReqVO,
+                                    HttpServletResponse response) throws IOException {
+        List<MesProPalletDO> list = palletService.getPalletListByIds(exportReqVO.getIds());
+        if (CollUtil.isEmpty(list)) {
+            throw exception(PRO_PALLET_NOT_EXISTS);
+        }
+        if (list.size() > QrCodeImageUtils.MAX_QR_EXPORT) {
+            throw exception(PRO_QR_EXPORT_TOO_MANY);
+        }
+        QrCodeImageUtils.writeZip(response, "鎵樼洏鐮佷簩缁寸爜", buildPalletQrLabels(list));
     }
 
     @DeleteMapping("/delete")
@@ -90,7 +127,7 @@
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
     public CommonResult<MesProPalletRespVO> getPallet(@RequestParam("id") Long id) {
         MesProPalletDO pallet = palletService.getPallet(id);
-        return success(BeanUtils.toBean(pallet, MesProPalletRespVO.class));
+        return success(pallet == null ? null : buildPalletRespVOList(List.of(pallet)).get(0));
     }
 
     @GetMapping("/get-by-code")
@@ -98,7 +135,7 @@
     @Parameter(name = "code", description = "鎵樼洏鐮侊紙浜岀淮鐮佸唴瀹癸級", required = true, example = "PC20260818L01001-P01")
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
     public CommonResult<MesProPalletTraceRespVO> getPalletByCode(@RequestParam("code") String code) {
-        MesProPalletDO pallet = palletService.getPalletByCode(code);
+        MesProPalletDO pallet = palletService.getPalletByScanCode(code);
         if (pallet == null) {
             throw exception(PRO_PALLET_NOT_EXISTS);
         }
@@ -110,7 +147,7 @@
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
     public CommonResult<PageResult<MesProPalletRespVO>> getPalletPage(@Valid MesProPalletPageReqVO pageReqVO) {
         PageResult<MesProPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
-        return success(BeanUtils.toBean(pageResult, MesProPalletRespVO.class));
+        return success(new PageResult<>(buildPalletRespVOList(pageResult.getList()), pageResult.getTotal()));
     }
 
     @GetMapping("/simple-list")
@@ -119,7 +156,15 @@
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
     public CommonResult<List<MesProPalletRespVO>> getPalletSimpleList(@RequestParam("batchId") Long batchId) {
         List<MesProPalletDO> list = palletService.getPalletListByBatchId(batchId);
-        return success(BeanUtils.toBean(list, MesProPalletRespVO.class));
+        return success(buildPalletRespVOList(list));
+    }
+
+    @GetMapping("/unbound-list")
+    @Operation(summary = "鑾峰緱鏈粦瀹氭壒娆$殑涓存椂鎵樼洏鍒楄〃锛堜緵鎵规鏂板/琛ュ綍缁戝畾鎵樼洏涓嬫媺浣跨敤锛�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
+    public CommonResult<List<MesProPalletRespVO>> getUnboundPalletList() {
+        List<MesProPalletDO> list = palletService.getUnboundPalletList();
+        return success(buildPalletRespVOList(list));
     }
 
     @GetMapping("/export-excel")
@@ -130,7 +175,7 @@
                                   HttpServletResponse response) throws IOException {
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
         List<MesProPalletDO> list = palletService.getPalletPage(pageReqVO).getList();
-        List<MesProPalletRespVO> voList = BeanUtils.toBean(list, MesProPalletRespVO.class);
+        List<MesProPalletRespVO> voList = buildPalletRespVOList(list);
         ExcelUtils.write(response, "鎵樼洏鐮�.xls", "鏁版嵁", MesProPalletRespVO.class, voList);
     }
 
@@ -153,10 +198,44 @@
 
     // ==================== 鎷兼帴 VO ====================
 
+    @PostMapping("/generate-business-code")
+    @Operation(summary = "琛ョ敓鎴愬凡鏈夋墭鐩樹笟鍔$爜锛屽凡鏈夌爜鍊间笉鍙�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:create')")
+    public CommonResult<Integer> generateBusinessCodes(@Valid @RequestBody
+            cn.iocoder.yudao.module.mes.controller.admin.pro.vo.MesProBusinessCodeGenerateReqVO reqVO) {
+        return success(palletService.generateBusinessCodes(reqVO.getIds()));
+    }
+
+    @PostMapping("/export-business-qr-by-ids")
+    @Operation(summary = "鎸夌紪鍙峰鍑烘墭鐩樹笟鍔$爜浜岀淮鐮侊紝鍐呭涓虹函涓氬姟鐮佸��")
+    @PreAuthorize("@ss.hasPermission('mes:pro-pallet:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportBusinessQrByIds(@Valid @RequestBody MesProPalletExportQrReqVO reqVO,
+                                      HttpServletResponse response) throws IOException {
+        List<MesProPalletDO> list = palletService.getPalletListByIds(reqVO.getIds()).stream()
+                .filter(record -> !cn.iocoder.yudao.module.mes.enums.pro.MesProPalletStatusEnum.CANCELED.getStatus().equals(record.getStatus())).toList();
+        if (CollUtil.isEmpty(list)) throw exception(PRO_PALLET_NOT_EXISTS);
+        if (list.size() > QrCodeImageUtils.MAX_QR_EXPORT) throw exception(PRO_QR_EXPORT_TOO_MANY);
+        QrCodeImageUtils.writeZip(response, "鎵樼洏涓氬姟浜岀淮鐮�", list.stream()
+                .map(MesProQrLabelBuilder::buildPalletBusinessCodeLabel).toList());
+    }
+
+    private List<MesProPalletRespVO> buildPalletRespVOList(List<MesProPalletDO> list) {
+        Map<Long, MesMdmItemDO> items = mdmItemService.getItemMap(convertSet(list, MesProPalletDO::getItemId));
+        return BeanUtils.toBean(list, MesProPalletRespVO.class, vo ->
+                MapUtils.findAndThen(items, vo.getItemId(), item -> { vo.setItemCode(item.getCode()); vo.setItemName(item.getName()); }));
+    }
+
     private MesProPalletTraceRespVO buildPalletTraceRespVO(MesProPalletDO pallet) {
         MesProPalletTraceRespVO respVO = BeanUtils.toBean(pallet, MesProPalletTraceRespVO.class);
-        // 鎵规淇℃伅
-        MesProBatchDO batch = batchService.getBatch(pallet.getBatchId());
+        respVO.setPendingBagQuantity((int) bagCodeService.getBagCodeListByPalletId(pallet.getId()).stream()
+                .filter(b -> !Integer.valueOf(30).equals(b.getStatus()) && b.getInboundEventId() == null).count());
+        if (pallet.getItemId() != null) {
+            MesMdmItemDO item = mdmItemService.getItem(pallet.getItemId());
+            if (item != null) respVO.setItemCode(item.getCode()).setItemName(item.getName()).setItemSpecification(item.getSpecification());
+        }
+        // 鎵规淇℃伅锛堜复鏃舵墭鐩樻湭缁戝畾鎵规鏃朵负绌烘壒娆★級
+        MesProBatchDO batch = pallet.getBatchId() == null ? null : batchService.getBatch(pallet.getBatchId());
         if (batch != null) {
             respVO.setBatchStatus(batch.getStatus())
                     .setProduceDate(batch.getProduceDate())

--
Gitblit v1.9.3