From f7273277023f3497ac071bf98f556a569cb4dd25 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 17 九月 2026 16:24:10 +0800
Subject: [PATCH] feat(mes): 重构袋码生成与物料分类功能

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 3 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 0675ba6..effcd75 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
@@ -36,6 +36,30 @@
     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);
 
+    /** 鎵规鏁存壒鍏ュ簱鏃舵壒閲忔爣璁板叾涓嬫湭鍏ュ簱琚嬬爜锛堝箓绛夛級锛屼繚鎸佽鐮佷笌搴撳瓨鐘舵�佷竴鑷� */
+    @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}")
+    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}")
+    int markInboundByPalletId(@Param("palletId") Long palletId, @Param("eventId") Long eventId,
+                              @Param("lineCode") String lineCode);
+
+    /**
+     * 鏇存柊琚嬬爜璐ㄦ鐘舵�侊紙绉嶅瓙璐ㄦ鍚堟牸/涓嶅悎鏍兼椂璁板綍璇ヨ缁撴灉锛�
+     *
+     * @param id       琚嬬爜缂栧彿
+     * @param qcStatus 璐ㄦ鐘舵�侊紙瑙� MesProBagCodeQcStatusEnum锛�
+     */
+    default void updateQcStatus(Long id, Integer qcStatus) {
+        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
+                .eq(MesProBagCodeDO::getId, id)
+                .set(MesProBagCodeDO::getQcStatus, qcStatus));
+    }
+
     default List<MesProBagCodeDO> selectListByUuid(String uuid) {
         return selectList(MesProBagCodeDO::getUuid, uuid);
     }
@@ -67,9 +91,11 @@
                 .likeIfPresent(MesProBagCodeDO::getBatchCode, reqVO.getBatchCode())
                 .eqIfPresent(MesProBagCodeDO::getUuid, reqVO.getUuid())
                 .eqIfPresent(MesProBagCodeDO::getPalletId, reqVO.getPalletId())
+                .eqIfPresent(MesProBagCodeDO::getItemId, reqVO.getItemId())
                 .eqIfPresent(MesProBagCodeDO::getStatus, reqVO.getStatus())
                 .betweenIfPresent(MesProBagCodeDO::getCreateTime, reqVO.getCreateTime())
-                .orderByAsc(MesProBagCodeDO::getBagNo));
+                .orderByDesc(MesProBagCodeDO::getCreateTime)
+                .orderByDesc(MesProBagCodeDO::getId));
     }
 
     /**
@@ -84,6 +110,18 @@
                 .set(MesProBagCodeDO::getPalletId, palletId)
                 .set(MesProBagCodeDO::getPalletCode, palletCode)
                 .in(MesProBagCodeDO::getId, ids));
+    }
+
+    /**
+     * 鎵樼洏姝e紡鐮佺敓鎴愬悗锛屽洖鍐欏叾涓嬫墍鏈夎鐮佺殑鍐椾綑鎵樼洏鐮�
+     *
+     * @param palletId   鎵樼洏缂栧彿
+     * @param palletCode 姝e紡鎵樼洏鐮�
+     */
+    default void updatePalletCodeByPalletId(Long palletId, String palletCode) {
+        update(null, new LambdaUpdateWrapper<MesProBagCodeDO>()
+                .set(MesProBagCodeDO::getPalletCode, palletCode)
+                .eq(MesProBagCodeDO::getPalletId, palletId));
     }
 
     /**
@@ -108,10 +146,24 @@
     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 " +
+            "WHERE deleted = 0 AND batch_id IS NULL AND status IN " +
+            "<foreach collection='statuses' item='st' open='(' separator=',' close=')'>#{st}</foreach> 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);
+                       @Param("batchCode") String batchCode, @Param("statuses") Collection<Integer> statuses);
+
+    /** 鏌ヨ鎵樼洏涓嬪皻鏈粦瀹氭壒娆$殑琚嬬爜锛堟墭鐩樼粦瀹氭壒娆℃椂绾ц仈褰曞叆鐢級 */
+    default List<MesProBagCodeDO> selectUnboundListByPalletIds(Collection<Long> palletIds) {
+        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
+                .in(MesProBagCodeDO::getPalletId, palletIds)
+                .isNull(MesProBagCodeDO::getBatchId)
+                .orderByAsc(MesProBagCodeDO::getId));
+    }
+
+    /** 鎵规鍐呮湁鏁堣鐮佺殑鍝佺缂栧彿闆嗗悎锛堝拷鐣ュ巻鍙茬┖鍝佺琚嬬爜锛夛紝鐢ㄤ簬褰曞叆鎵规鏃剁殑鍝佺涓�鑷存�ф牎楠� */
+    @Select("SELECT DISTINCT item_id FROM mes_pro_bag_code " +
+            "WHERE deleted = 0 AND status <> 30 AND batch_id = #{batchId} AND item_id IS NOT NULL")
+    List<Long> selectDistinctItemIdsByBatchId(@Param("batchId") Long batchId);
 
     default List<MesProBagCodeDO> selectListByIdsForUpdate(Collection<Long> ids) {
         return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()

--
Gitblit v1.9.3