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/dal/mysql/pro/bagcode/MesProBagCodeMapper.java |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
index 7024430..6830e19 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java
@@ -28,6 +28,18 @@
         return selectOne(MesProBagCodeDO::getCode, code);
     }
 
+    /** 鍐呴儴鎵爜鍏煎涓氬姟鐮佷笌鍘嗗彶杩芥函鐮侊紱鍏紬杩芥函缁х画鍙寜 code 鏌ヨ銆� */
+    default MesProBagCodeDO selectByScanCode(String code) {
+        return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
+                .and(q -> q.eq(MesProBagCodeDO::getBusinessCode, code).or().eq(MesProBagCodeDO::getCode, code)));
+    }
+
+    default MesProBagCodeDO selectByScanCodeForUpdate(String code) {
+        return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
+                .and(q -> q.eq(MesProBagCodeDO::getBusinessCode, code).or().eq(MesProBagCodeDO::getCode, code))
+                .last("FOR UPDATE"));
+    }
+
     default MesProBagCodeDO selectByCodeForUpdate(String code) {
         return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
                 .eq(MesProBagCodeDO::getCode, code).last("FOR UPDATE"));
@@ -39,13 +51,13 @@
 
     /** 鎵规鏁存壒鍏ュ簱鏃舵壒閲忔爣璁板叾涓嬫湭鍏ュ簱琚嬬爜锛堝箓绛夛級锛屼繚鎸佽鐮佷笌搴撳瓨鐘舵�佷竴鑷� */
     @Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
-            + "WHERE deleted = 0 AND inbound_event_id IS NULL AND batch_id = #{batchId}")
+            + "WHERE deleted = 0 AND status <> 30 AND inbound_event_id IS NULL AND batch_id = #{batchId}")
     int markInboundByBatchId(@Param("batchId") Long batchId, @Param("eventId") Long eventId,
                              @Param("lineCode") String lineCode);
 
     /** 鏁存墭鍏ュ簱鏃舵壒閲忔爣璁版墭鐩樹笅鏈叆搴撹鐮侊紙骞傜瓑锛� */
     @Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_line_code = #{lineCode}, update_time = NOW() "
-            + "WHERE deleted = 0 AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
+            + "WHERE deleted = 0 AND status <> 30 AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
     int markInboundByPalletId(@Param("palletId") Long palletId, @Param("eventId") Long eventId,
                               @Param("lineCode") String lineCode);
 
@@ -107,10 +119,16 @@
     default List<MesProBagCodeDO> selectListByPalletId(Long palletId) {
         return selectList(MesProBagCodeDO::getPalletId, palletId);
     }
+    default List<MesProBagCodeDO> selectListByPalletIdForUpdate(Long palletId) {
+        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>().eq(MesProBagCodeDO::getPalletId, palletId).orderByAsc(MesProBagCodeDO::getId).last("FOR UPDATE"));
+    }
+    default List<MesProBagCodeDO> selectListByBatchIdForUpdate(Long batchId) {
+        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>().eq(MesProBagCodeDO::getBatchId, batchId).orderByAsc(MesProBagCodeDO::getId).last("FOR UPDATE"));
+    }
 
     default PageResult<MesProBagCodeDO> selectPage(MesProBagCodePageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<MesProBagCodeDO>()
-                .likeIfPresent(MesProBagCodeDO::getCode, reqVO.getCode())
+                .likeIfPresent(MesProBagCodeDO::getBusinessCode, reqVO.getBusinessCode())
                 .eqIfPresent(MesProBagCodeDO::getBatchId, reqVO.getBatchId())
                 .likeIfPresent(MesProBagCodeDO::getBatchCode, reqVO.getBatchCode())
                 .eqIfPresent(MesProBagCodeDO::getUuid, reqVO.getUuid())
@@ -119,7 +137,10 @@
                 .eqIfPresent(MesProBagCodeDO::getStatus, reqVO.getStatus())
                 .betweenIfPresent(MesProBagCodeDO::getCreateTime, reqVO.getCreateTime())
                 .orderByDesc(MesProBagCodeDO::getCreateTime)
-                .orderByDesc(MesProBagCodeDO::getId));
+                .orderByDesc(MesProBagCodeDO::getId)
+                .and(cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getCode()), q ->
+                        q.like(MesProBagCodeDO::getCode, reqVO.getCode()).or()
+                                .like(MesProBagCodeDO::getBusinessCode, reqVO.getCode())));
     }
 
     /**
@@ -219,6 +240,14 @@
             "AND deleted = 0 AND status <> 30")
     int selectEffectiveCountByBatchId(@Param("batchId") Long batchId);
 
+    @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE deleted = 0 AND status <> 30 "
+            + "AND inbound_event_id IS NULL AND batch_id = #{batchId}")
+    int selectPendingInboundCountByBatchId(@Param("batchId") Long batchId);
+
+    @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE deleted = 0 AND status <> 30 "
+            + "AND inbound_event_id IS NULL AND pallet_id = #{palletId}")
+    int selectPendingInboundCountByPalletId(@Param("palletId") Long palletId);
+
     /**
      * 鎵归噺鏍囪涓哄凡瀵煎嚭鍗板埛锛堜粎鏇存柊澶勪簬鐩爣鍘熺姸鎬佺殑璁板綍锛�
      *

--
Gitblit v1.9.3