From c9a1df9c19a64844d05d120ff171f523d77e7823 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 25 四月 2026 22:15:36 +0800
Subject: [PATCH] Merge branch 'xiaoyang' into dev

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index 4e7212c..2a154b9 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -247,6 +247,14 @@
                     var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
                     if (!result) return content.Error("鎹㈢洏澶辫触");
 
+                    // 妫�鏌ユ簮鎵樼洏鏄惁杩樻湁鍓╀綑搴撳瓨鏄庣粏锛岃嫢鏃犲垯鍒犻櫎婧愭墭鐩樺簱瀛樺ご
+                    var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id);
+                    if (!remainingSourceDetails.Any())
+                    {
+                        if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0)
+                            return content.Error("鍒犻櫎婧愭墭鐩樺簱瀛樺け璐�");
+                    }
+
                     return content.OK("鎹㈢洏鎴愬姛");
                 });
             }
@@ -314,6 +322,19 @@
 
                     if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
                         return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+                    // 鍒犻櫎宸叉媶鍑虹殑搴撳瓨鏄庣粏
+                    var detailIds = detailEntities.Select(d => d.Id).ToList();
+                    if (await StockInfoDetailService.Repository.Db.Deleteable<Dt_StockInfoDetail>().In(detailIds).ExecuteCommandAsync() <= 0)
+                        return content.Error("鍒犻櫎搴撳瓨鏄庣粏澶辫触");
+
+                    // 妫�鏌ユ簮鎵樼洏鏄惁杩樻湁鍓╀綑搴撳瓨鏄庣粏锛岃嫢鏃犲垯鍒犻櫎婧愭墭鐩樺簱瀛樺ご
+                    var remainingSourceDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStock.Id);
+                    if (!remainingSourceDetails.Any())
+                    {
+                        if (await StockInfoService.Repository.Db.Deleteable<Dt_StockInfo>().Where(s => s.Id == sourceStock.Id).ExecuteCommandAsync() <= 0)
+                            return content.Error("鍒犻櫎婧愭墭鐩樺簱瀛樺け璐�");
+                    }
 
                     return content.OK("鎷嗙洏鎴愬姛");
                 });
@@ -563,6 +584,26 @@
         }
 
         /// <summary>
+        /// 鏍规嵁鎵樼洏鍙锋煡璇㈠簱瀛樻槑缁嗘暟閲�
+        /// </summary>
+        /// <param name="palletCode">鎵樼洏鍙�</param>
+        /// <returns>搴撳瓨鏄庣粏鏁伴噺</returns>
+        public async Task<WebResponseContent> GetStockDetailCountByPalletCodeAsync(string palletCode)
+        {
+            WebResponseContent content = new WebResponseContent();
+            if (string.IsNullOrWhiteSpace(palletCode))
+                return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+            var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode);
+            if (stockInfo == null)
+                return content.Error("鎵樼洏涓嶅瓨鍦�");
+
+            var count = await StockInfoDetailService.Repository.Db.Queryable<Dt_StockInfoDetail>()
+                .CountAsync(d => d.StockId == stockInfo.Id);
+            return content.OK("鏌ヨ鎴愬姛", new { PalletCode = palletCode, DetailCount = count });
+        }
+
+        /// <summary>
         /// 鏍规嵁璁惧鍚嶇О鍜屾墭鐩樺彿瑙f瀽MES璁惧閰嶇疆
         /// </summary>
         /// <param name="deviceName">璁惧鍚嶇О</param>

--
Gitblit v1.9.3