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/pallet/MesProPalletMapper.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java
index b2b6512..045b669 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/pallet/MesProPalletMapper.java
@@ -5,6 +5,7 @@
 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.mes.controller.admin.pro.pallet.vo.MesProPalletPageReqVO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.pallet.MesProPalletDO;
+import cn.iocoder.yudao.module.mes.enums.pro.MesProPalletStatusEnum;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -23,18 +24,51 @@
         return selectOne(MesProPalletDO::getCode, code);
     }
 
+    default MesProPalletDO selectByScanCode(String code) {
+        return selectOne(new LambdaQueryWrapperX<MesProPalletDO>().and(q ->
+                q.eq(MesProPalletDO::getBusinessCode, code).or().eq(MesProPalletDO::getCode, code)
+                        .or().eq(MesProPalletDO::getTempCode, code)));
+    }
+
+    default MesProPalletDO selectByScanCodeForUpdate(String code) {
+        return selectOne(new LambdaQueryWrapperX<MesProPalletDO>().and(q ->
+                q.eq(MesProPalletDO::getBusinessCode, code).or().eq(MesProPalletDO::getCode, code)
+                        .or().eq(MesProPalletDO::getTempCode, code)).last("FOR UPDATE"));
+    }
+
+    default MesProPalletDO selectByTempCode(String tempCode) {
+        return selectOne(MesProPalletDO::getTempCode, tempCode);
+    }
+
+    @Select("SELECT * FROM mes_pro_pallet WHERE id = #{id} AND deleted = 0 FOR UPDATE")
+    MesProPalletDO selectByIdForUpdate(@Param("id") Long id);
+
     default List<MesProPalletDO> selectListByBatchId(Long batchId) {
         return selectList(MesProPalletDO::getBatchId, batchId);
     }
 
+    /** 鏌ヨ鏈粦瀹氱敓浜ф壒娆$殑涓存椂鎵樼洏锛堟棤姝e紡鎵樼洏鐮佷笖鏈綔搴燂級锛屼緵鎵规鏂板/琛ュ綍缁戝畾鎵樼洏涓嬫媺浣跨敤 */
+    default List<MesProPalletDO> selectUnboundList() {
+        return selectList(new LambdaQueryWrapperX<MesProPalletDO>()
+                .isNull(MesProPalletDO::getBatchId)
+                .isNull(MesProPalletDO::getCode)
+                .eq(MesProPalletDO::getStatus, MesProPalletStatusEnum.IN_USE.getStatus())
+                .orderByAsc(MesProPalletDO::getId));
+    }
+
     default PageResult<MesProPalletDO> selectPage(MesProPalletPageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<MesProPalletDO>()
-                .likeIfPresent(MesProPalletDO::getCode, reqVO.getCode())
+                .likeIfPresent(MesProPalletDO::getBusinessCode, reqVO.getBusinessCode())
+                .likeIfPresent(MesProPalletDO::getTempCode, reqVO.getTempCode())
                 .eqIfPresent(MesProPalletDO::getBatchId, reqVO.getBatchId())
                 .likeIfPresent(MesProPalletDO::getBatchCode, reqVO.getBatchCode())
                 .eqIfPresent(MesProPalletDO::getStatus, reqVO.getStatus())
                 .betweenIfPresent(MesProPalletDO::getCreateTime, reqVO.getCreateTime())
-                .orderByDesc(MesProPalletDO::getId));
+                .orderByDesc(MesProPalletDO::getId)
+                .and(cn.hutool.core.util.StrUtil.isNotBlank(reqVO.getCode()), q ->
+                        q.like(MesProPalletDO::getCode, reqVO.getCode()).or()
+                                .like(MesProPalletDO::getBusinessCode, reqVO.getCode()).or()
+                                .like(MesProPalletDO::getTempCode, reqVO.getCode())));
     }
 
     /**
@@ -46,4 +80,25 @@
     @Select("SELECT IFNULL(MAX(pallet_no), 0) FROM mes_pro_pallet WHERE batch_id = #{batchId}")
     Integer selectMaxPalletNo(@Param("batchId") Long batchId);
 
+    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet 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") java.time.LocalDateTime outboundTime);
+
+    /** 鏁存墭鎵爜鍏ュ簱鍥炲啓锛氬箓绛夛紙宸叉湁鍏ュ簱鏍囪鐨勪笉鍐嶆洿鏂帮級锛岀敤浜庨槻閲嶅鍏ュ簱 */
+    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet SET inbound_event_id = #{eventId}, inbound_time = NOW(), update_time = NOW() "
+            + "WHERE id = #{id} AND deleted = 0 AND inbound_event_id IS NULL")
+    int markInbound(@Param("id") Long id, @Param("eventId") Long eventId);
+
+    /** 鍗曡銆佹暣鎵樸�佹暣鎵瑰叆搴撳悗锛屽彧鏈夋湁鏁堣鐮佸叏閮ㄥ叆搴撶殑鎵樼洏鎵嶅悓姝ユ爣璁板凡鍏ュ簱銆� */
+    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet p SET inbound_event_id = #{eventId}, inbound_time = NOW(), update_time = NOW() "
+            + "WHERE p.batch_id = #{batchId} AND p.deleted = 0 AND p.status <> 20 AND p.inbound_event_id IS NULL "
+            + "AND EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.pallet_id = p.id AND b.deleted = 0 AND b.status <> 30) "
+            + "AND NOT EXISTS (SELECT 1 FROM mes_pro_bag_code b WHERE b.pallet_id = p.id AND b.deleted = 0 AND b.status <> 30 AND b.inbound_event_id IS NULL)")
+    int markCompletedInboundByBatchId(@Param("batchId") Long batchId, @Param("eventId") Long eventId);
+
+    @org.apache.ibatis.annotations.Update("UPDATE mes_pro_pallet SET sales_id = NULL, outbound_time = NULL, update_time = NOW() "
+            + "WHERE id = #{id} AND deleted = 0")
+    void clearOutbound(@Param("id") Long id);
+
 }

--
Gitblit v1.9.3