From 4ca4444ad33a2a1a51f5c06e78ee9365dfb1eed6 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期四, 08 十月 2026 17:11:11 +0800
Subject: [PATCH] feat(mes): 种子二维码标签国标四要素合规改造

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/bagcode/MesProBagCodeMapper.java |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 103 insertions(+), 10 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 2e12a2b..7024430 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,39 @@
         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);
+
+    /** 鎵规鏁存壒鍏ュ簱鏃舵壒閲忔爣璁板叾涓嬫湭鍏ュ簱琚嬬爜锛堝箓绛夛級锛屼繚鎸佽鐮佷笌搴撳瓨鐘舵�佷竴鑷� */
+    @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);
     }
@@ -40,13 +73,27 @@
         return selectList(MesProBagCodeDO::getBatchId, batchId);
     }
 
-    default List<MesProBagCodeDO> selectUnboundEffectiveListByBatchId(Long batchId) {
+    /**
+     * 鏌ヨ鐢熸垚缁勪笅鍙嵃鍒风殑琚嬬爜锛堟帓闄ゅ凡浣滃簾锛夛紝鐢ㄤ簬浜岀淮鐮佹爣绛惧鍑�
+     * <p>
+     * 宸蹭綔搴熻鐮佺殑鏍囩涓嶅緱鍐嶅嵃鍒凤細鍏舵爣绛捐嫢璐村埌浜у搧涓婏紝娑堣垂鑰呮壂鐮佷細琚彁绀恒�岃杩芥函鐮佸凡浣滃簾銆嶏紝
+     * 瀵艰嚧鐪熷搧琚鍒や负鍋囪揣銆�
+     */
+    default List<MesProBagCodeDO> selectPrintableListByUuid(String uuid) {
+        return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
+                .eq(MesProBagCodeDO::getUuid, uuid)
+                .ne(MesProBagCodeDO::getStatus, MesProBagCodeStatusEnum.CANCELED.getStatus())
+                .orderByAsc(MesProBagCodeDO::getBagNo));
+    }
+
+    /**
+     * 鏌ヨ鎵规涓嬪彲鍗板埛鐨勮鐮侊紙鎺掗櫎宸蹭綔搴燂級锛岀敤浜庝簩缁寸爜鏍囩瀵煎嚭
+     */
+    default List<MesProBagCodeDO> selectPrintableListByBatchId(Long batchId) {
         return selectList(new LambdaQueryWrapperX<MesProBagCodeDO>()
                 .eq(MesProBagCodeDO::getBatchId, batchId)
-                .isNull(MesProBagCodeDO::getPalletId)
                 .ne(MesProBagCodeDO::getStatus, MesProBagCodeStatusEnum.CANCELED.getStatus())
-                .orderByAsc(MesProBagCodeDO::getBagNo)
-                .last("FOR UPDATE"));
+                .orderByAsc(MesProBagCodeDO::getBagNo));
     }
 
     default Long selectCountByBatchId(Long batchId) {
@@ -68,9 +115,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));
     }
 
     /**
@@ -88,6 +137,18 @@
     }
 
     /**
+     * 鎵樼洏姝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));
+    }
+
+    /**
      * 鎵归噺瑙g粦鎵樼洏锛堢疆绌烘墭鐩樼紪鍙蜂笌鎵樼洏鐮侊級
      *
      * @param ids 琚嬬爜缂栧彿鍒楄〃
@@ -100,13 +161,36 @@
     }
 
     /**
-     * 鏌ヨ鎵规鍐呰鐮佹渶澶у簭鍙凤紙鍖呭惈宸查�昏緫鍒犻櫎璁板綍锛屼繚璇佸簭鍙蜂笉鍥為��銆佺爜鍊煎敮涓�锛�
+     * 鏌ヨ鍏ㄥ眬鏈�澶ц搴忓彿锛堣搴忓彿涓哄叏灞�搴忓彿锛屼笉鍖哄垎鎵规锛涘寘鍚凡閫昏緫鍒犻櫎璁板綍锛屼繚璇佸簭鍙蜂笉鍥為��锛�
+     * <p>
+     * 浠呯敤浜庝负 Redis 搴忓彿鍒嗛厤鎻愪緵鍩哄噯鍊硷紝涓嶈鍦ㄤ笟鍔′腑鐩存帴鐢ㄣ�岃繑鍥炲�� + 1銆嶄綔涓鸿捣濮嬪簭鍙封�斺��
+     * 閭f槸鍏堣鍚庡啓锛屽苟鍙戠敓鎴愪細浜х敓閲嶅搴忓彿銆傝浣跨敤
+     * {@code MesCodeRedisDAO#allocateBagNoStart(int, Integer)} 鍘熷瓙鍒嗛厤銆�
      *
-     * @param batchId 鎵规缂栧彿
-     * @return 鏈�澶ц搴忓彿锛屾棤璁板綍杩斿洖 0
+     * @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 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("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>()
@@ -122,6 +206,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