From 251be431ad12399fe4ebce599c353d05dcec7888 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 29 十月 2026 12:28:34 +0800
Subject: [PATCH] feat(mes): 支持追溯二维码解析功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/scan/MesProScanEventServiceImpl.java |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/scan/MesProScanEventServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/scan/MesProScanEventServiceImpl.java
index f9412cc..56a5a4e 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/scan/MesProScanEventServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/scan/MesProScanEventServiceImpl.java
@@ -17,6 +17,7 @@
 import cn.iocoder.yudao.module.mes.enums.MesProScanEventStatusEnum;
 import cn.iocoder.yudao.module.mes.enums.wm.MesWmStockStateEnum;
 import cn.iocoder.yudao.module.mes.enums.wm.MesWmTransactionTypeEnum;
+import cn.iocoder.yudao.module.mes.framework.qrcode.MesTraceCodeUtils;
 import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService;
 import cn.iocoder.yudao.module.mes.service.wm.transaction.MesWmTransactionService;
 import cn.iocoder.yudao.module.mes.service.wm.transaction.dto.MesWmTransactionSaveReqDTO;
@@ -61,13 +62,15 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public MesProScanEventDO createInbound(MesProScanEventCreateReqVO req) {
+        // 杩芥函浜岀淮鐮佸唴瀹规槸銆岃拷婧綉鍧�?code=鐮佸�笺�嶏紝鎵爜鏋篃鍙兘鐩翠紶鏁存缃戝潃锛屽厛缁熶竴鎻愬彇鐮佸��
+        String scanCode = MesTraceCodeUtils.extractCode(req.getBagCode());
         String scanType = (req.getScanType() == null || req.getScanType().isBlank()) ? SCAN_TYPE_BAG : req.getScanType();
         if (!List.of(SCAN_TYPE_BAG, SCAN_TYPE_PALLET, SCAN_TYPE_BATCH).contains(scanType)) {
             throw new ServiceException(400, "涓嶆敮鎸佺殑鎵爜绫诲瀷");
         }
         MesProScanEventDO existing = eventMapper.selectByEventIdForUpdate(req.getEventId());
         if (existing != null) {
-            boolean contentMatch = req.getBagCode().equals(existing.getBagCode())
+            boolean contentMatch = scanCode.equals(existing.getBagCode())
                     && Objects.equals(req.getDeviceCode(), existing.getDeviceCode())
                     && Objects.equals(req.getLineCode(), existing.getLineCode())
                     && Objects.equals(scanType, existing.getScanType())
@@ -82,7 +85,7 @@
             return existing;
         }
         MesProScanEventDO event = new MesProScanEventDO();
-        event.setEventId(req.getEventId()).setBagCode(req.getBagCode()).setScanType(scanType)
+        event.setEventId(req.getEventId()).setBagCode(scanCode).setScanType(scanType)
                 .setQuantity(req.getQuantity()).setDeviceCode(req.getDeviceCode()).setLineCode(req.getLineCode())
                 .setRemark(req.getRemark()).setLocationId(req.getLocationId()).setAreaId(req.getAreaId())
                 .setStatus(MesProScanEventStatusEnum.FAILED).setReceivedTime(LocalDateTime.now());
@@ -96,7 +99,7 @@
         Long bagCodeId = null;
         String bagCode = null;
         if (SCAN_TYPE_PALLET.equals(scanType)) {
-            MesProPalletDO pallet = palletMapper.selectByScanCodeForUpdate(req.getBagCode());
+            MesProPalletDO pallet = palletMapper.selectByScanCodeForUpdate(scanCode);
             if (pallet == null) return failed(event, "MES_SCAN_PALLET_NOT_EXISTS", "鎵樼洏鐮佷笉瀛樺湪");
             if (MesProPalletStatusEnum.CANCELED.getStatus().equals(pallet.getStatus()))
                 return failed(event, "MES_SCAN_PALLET_CANCELED", "鎵樼洏宸蹭綔搴燂紝涓嶅彲鍏ュ簱");
@@ -107,13 +110,13 @@
             targetId = pallet.getId();
             quantity = BigDecimal.valueOf(bagCodeMapper.selectPendingInboundCountByPalletId(pallet.getId()));
         } else if (SCAN_TYPE_BATCH.equals(scanType)) {
-            batch = batchMapper.selectByScanCodeForUpdate(req.getBagCode());
+            batch = batchMapper.selectByScanCodeForUpdate(scanCode);
             if (batch == null) return failed(event, "MES_SCAN_BATCH_NOT_EXISTS", "鐢熶骇鎵规涓嶅瓨鍦�");
             batchId = batch.getId();
             targetId = batch.getId();
             quantity = BigDecimal.valueOf(bagCodeMapper.selectPendingInboundCountByBatchId(batch.getId()));
         } else {
-            MesProBagCodeDO bag = bagCodeMapper.selectByScanCodeForUpdate(req.getBagCode());
+            MesProBagCodeDO bag = bagCodeMapper.selectByScanCodeForUpdate(scanCode);
             if (bag == null) return failed(event, "MES_SCAN_BAG_NOT_EXISTS", "琚嬬爜涓嶅瓨鍦�");
             if (MesProBagCodeStatusEnum.CANCELED.getStatus().equals(bag.getStatus()))
                 return failed(event, "MES_SCAN_BAG_CANCELED", "琚嬬爜宸蹭綔搴燂紝涓嶅彲鍏ュ簱");
@@ -167,7 +170,7 @@
             return event;
         } catch (Exception ex) {
             log.error("[createInbound] 搴撳瓨浜嬪姟澶勭悊澶辫触锛宔ventId={}, bagCode={}, batchId={}, itemId={}",
-                    req.getEventId(), req.getBagCode(), batchId, batch.getItemId(), ex);
+                    req.getEventId(), scanCode, batchId, batch.getItemId(), ex);
             throw ex;
         }
     }

--
Gitblit v1.9.3