From 8655501ffb8dbdaf2508e575933063e6731be714 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 28 八月 2026 17:14:40 +0800
Subject: [PATCH] refactor(mes): 重构MES生产批次和袋码管理功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 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 ca31481..0675ba6 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
@@ -27,6 +27,15 @@
         return selectOne(MesProBagCodeDO::getCode, code);
     }
 
+    default MesProBagCodeDO selectByCodeForUpdate(String code) {
+        return selectOne(new LambdaQueryWrapperX<MesProBagCodeDO>()
+                .eq(MesProBagCodeDO::getCode, code).last("FOR UPDATE"));
+    }
+
+    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_bag_code SET inbound_time = NOW(), inbound_event_id = #{eventId}, inbound_device_code = #{deviceCode}, inbound_line_code = #{lineCode}, update_time = NOW() WHERE id = #{id} AND deleted = 0 AND inbound_event_id IS NULL")
+    int markInbound(@org.apache.ibatis.annotations.Param("id") Long id, @org.apache.ibatis.annotations.Param("eventId") Long eventId,
+                    @org.apache.ibatis.annotations.Param("deviceCode") String deviceCode, @org.apache.ibatis.annotations.Param("lineCode") String lineCode);
+
     default List<MesProBagCodeDO> selectListByUuid(String uuid) {
         return selectList(MesProBagCodeDO::getUuid, uuid);
     }
@@ -95,8 +104,14 @@
      * @param batchId 鎵规缂栧彿
      * @return 鏈�澶ц搴忓彿锛屾棤璁板綍杩斿洖 0
      */
-    @Select("SELECT IFNULL(MAX(bag_no), 0) FROM mes_pro_bag_code WHERE batch_id = #{batchId}")
-    Integer selectMaxBagNo(@Param("batchId") Long batchId);
+    @Select("SELECT IFNULL(MAX(bag_no), 0) FROM mes_pro_bag_code")
+    Integer selectMaxBagNo();
+
+    @Update("<script>UPDATE mes_pro_bag_code SET batch_id = #{batchId}, batch_code = #{batchCode}, update_time = NOW() " +
+            "WHERE deleted = 0 AND batch_id IS NULL AND status = #{status} AND id IN " +
+            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach></script>")
+    int bindBatchByIds(@Param("ids") Collection<Long> ids, @Param("batchId") Long batchId,
+                       @Param("batchCode") String batchCode, @Param("status") Integer status);
 
     default List<MesProBagCodeDO> selectListByIdsForUpdate(Collection<Long> ids) {
         return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
@@ -112,6 +127,15 @@
                    @Param("toStatus") Integer toStatus, @Param("cancelTime") LocalDateTime cancelTime,
                    @Param("cancelReason") String cancelReason);
 
+    @Update("UPDATE mes_pro_bag_code SET sales_id = #{salesId}, outbound_time = #{outboundTime}, update_time = NOW() "
+            + "WHERE id = #{id} AND deleted = 0")
+    void markOutbound(@Param("id") Long id, @Param("salesId") Long salesId,
+                      @Param("outboundTime") LocalDateTime outboundTime);
+
+    @Update("UPDATE mes_pro_bag_code SET sales_id = NULL, outbound_time = NULL, update_time = NOW() "
+            + "WHERE id = #{id} AND deleted = 0")
+    void clearOutbound(@Param("id") Long id);
+
     @Select("SELECT COUNT(*) FROM mes_pro_bag_code WHERE batch_id = #{batchId} " +
             "AND deleted = 0 AND status <> 30")
     int selectEffectiveCountByBatchId(@Param("batchId") Long batchId);

--
Gitblit v1.9.3