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/wm/productsales/MesWmProductSalesDetailMapper.java |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/wm/productsales/MesWmProductSalesDetailMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/wm/productsales/MesWmProductSalesDetailMapper.java
index cac3187..dc477d3 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/wm/productsales/MesWmProductSalesDetailMapper.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/wm/productsales/MesWmProductSalesDetailMapper.java
@@ -14,6 +14,23 @@
 @Mapper
 public interface MesWmProductSalesDetailMapper extends BaseMapperX<MesWmProductSalesDetailDO> {
 
+    // 浠呮湭鍙栨秷涓斿皻鏈畬鎴愮殑鍑哄簱鍗曞崰鐢ㄨ鐮併�傛棫鏁存墭鏄庣粏涔熷弬涓庨噸鍙犲垽鏂��
+    @org.apache.ibatis.annotations.Select("""
+        SELECT d.* FROM mes_wm_product_sales_detail d
+        JOIN mes_wm_product_sales s ON s.id = d.sales_id
+        WHERE d.deleted = 0 AND s.deleted = 0 AND s.status IN (2, 10, 3)
+          AND d.batch_code = #{batchCode}
+        """)
+    List<MesWmProductSalesDetailDO> selectPickingByBatchCode(String batchCode);
+
+    @org.apache.ibatis.annotations.Select("""
+        SELECT d.* FROM mes_wm_product_sales_detail d
+        JOIN mes_wm_product_sales s ON s.id = d.sales_id
+        WHERE d.deleted = 0 AND s.deleted = 0 AND s.status IN (2, 10, 3)
+          AND d.batch_code = #{batchCode} FOR UPDATE
+        """)
+    List<MesWmProductSalesDetailDO> selectPickingByBatchCodeForUpdate(String batchCode);
+
     default List<MesWmProductSalesDetailDO> selectListByLineId(Long lineId) {
         return selectList(MesWmProductSalesDetailDO::getLineId, lineId);
     }
@@ -22,6 +39,18 @@
         return selectList(MesWmProductSalesDetailDO::getSalesId, salesId);
     }
 
+    default MesWmProductSalesDetailDO selectBySalesIdAndBagCodeId(Long salesId, Long bagCodeId) {
+        return selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesWmProductSalesDetailDO>()
+                .eq(MesWmProductSalesDetailDO::getSalesId, salesId)
+                .eq(MesWmProductSalesDetailDO::getBagCodeId, bagCodeId));
+    }
+
+    default MesWmProductSalesDetailDO selectBySalesIdAndPalletCodeId(Long salesId, Long palletCodeId) {
+        return selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesWmProductSalesDetailDO>()
+                .eq(MesWmProductSalesDetailDO::getSalesId, salesId)
+                .eq(MesWmProductSalesDetailDO::getPalletCodeId, palletCodeId).orderByAsc(MesWmProductSalesDetailDO::getId).last("LIMIT 1"));
+    }
+
     default void deleteByLineId(Long lineId) {
         delete(MesWmProductSalesDetailDO::getLineId, lineId);
     }
@@ -30,4 +59,24 @@
         delete(MesWmProductSalesDetailDO::getSalesId, salesId);
     }
 
+    /**
+     * 鏍规嵁琚嬬爜缂栧彿鏌ヨ鏈�杩戠殑鍑哄簱鏄庣粏锛堜緵绐滆揣绋芥煡鍙嶆煡鍑哄簱鍘诲悜锛�
+     */
+    default MesWmProductSalesDetailDO selectLatestByBagCodeId(Long bagCodeId) {
+        return selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesWmProductSalesDetailDO>()
+                .eq(MesWmProductSalesDetailDO::getBagCodeId, bagCodeId)
+                .orderByDesc(MesWmProductSalesDetailDO::getId)
+                .last("LIMIT 1"));
+    }
+
+    /**
+     * 鏍规嵁鎵樼洏鐮佺紪鍙锋煡璇㈡渶杩戠殑鍑哄簱鏄庣粏锛堜緵绐滆揣绋芥煡鍙嶆煡鍑哄簱鍘诲悜锛�
+     */
+    default MesWmProductSalesDetailDO selectLatestByPalletCodeId(Long palletCodeId) {
+        return selectOne(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesWmProductSalesDetailDO>()
+                .eq(MesWmProductSalesDetailDO::getPalletCodeId, palletCodeId)
+                .orderByDesc(MesWmProductSalesDetailDO::getId)
+                .last("LIMIT 1"));
+    }
+
 }

--
Gitblit v1.9.3