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 |   46 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 6 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 1aba55e..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
@@ -127,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")
@@ -135,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);
         }
@@ -147,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")
@@ -156,7 +156,7 @@
     @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")
@@ -164,7 +164,7 @@
     @PreAuthorize("@ss.hasPermission('mes:pro-pallet:query')")
     public CommonResult<List<MesProPalletRespVO>> getUnboundPalletList() {
         List<MesProPalletDO> list = palletService.getUnboundPalletList();
-        return success(BeanUtils.toBean(list, MesProPalletRespVO.class));
+        return success(buildPalletRespVOList(list));
     }
 
     @GetMapping("/export-excel")
@@ -175,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);
     }
 
@@ -198,8 +198,42 @@
 
     // ==================== 鎷兼帴 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);
+        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) {

--
Gitblit v1.9.3