From 7a0fbe3ec8b5ec5e54cb8ee1b3ba5aadea1d1ecd Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 06 三月 2026 17:25:39 +0800
Subject: [PATCH] feat: 添加自动出库任务后台服务

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index e02e62f..b0cbc13 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -405,7 +405,7 @@
             {
                 // 1. 鏌ヨ鍒版湡搴撳瓨
                 var expiredStocks = await _stockInfoService.Repository
-                    .QueryAsync(s => s.OutboundDate <= DateTime.Now
+                    .QueryDataAsync(s => s.OutboundDate <= DateTime.Now
                         && s.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode());
 
                 if (expiredStocks == null || !expiredStocks.Any())
@@ -413,13 +413,29 @@
                     return WebResponseContent.Instance.OK("鏃犲埌鏈熷簱瀛橀渶瑕佸鐞�");
                 }
 
-                // 鍔犺浇浣嶇疆璇︽儏
-                foreach (var stock in expiredStocks)
+                // 鎵归噺鍔犺浇浣嶇疆璇︽儏锛堜紭鍖� N+1 鏌ヨ闂锛�
+                var locationIds = expiredStocks
+                    .Where(s => s.LocationId > 0)
+                    .Select(s => s.LocationId)
+                    .Distinct()
+                    .Cast<object>()
+                    .ToList();
+
+                if (locationIds.Any())
                 {
-                    if (stock.LocationId > 0)
+                    var locations = await _locationInfoService.Repository
+                        .QureyDataByIdsAsync(locationIds);
+
+                    // 鍒涘缓浣嶇疆瀛楀吀浠ヤ究蹇�熸煡鎵�
+                    var locationDict = locations.ToDictionary(l => l.Id, l => l);
+
+                    // 涓烘瘡涓簱瀛樺叧鑱斾綅缃鎯�
+                    foreach (var stock in expiredStocks)
                     {
-                        stock.LocationDetails = await _locationInfoService.Repository
-                            .GetFirstAsync(s => s.Id == stock.LocationId);
+                        if (stock.LocationId > 0 && locationDict.ContainsKey(stock.LocationId))
+                        {
+                            stock.LocationDetails = locationDict[stock.LocationId];
+                        }
                     }
                 }
 
@@ -436,11 +452,11 @@
 
                 // 2. 妫�鏌ュ凡瀛樺湪鐨勪换鍔�
                 var palletCodes = expiredStocks.Select(s => s.PalletCode).ToList();
-                var existingTasks = await Repository.QueryAsync(t =>
+                var existingTasks = await Repository.QueryDataAsync(t =>
                     palletCodes.Contains(t.PalletCode)
                     && (t.TaskStatus == TaskStatusEnum.New.GetHashCode()
-                        || t.TaskStatus == TaskStatusEnum.Executing.GetHashCode()
-                        || t.TaskInStatus == TaskInStatusEnum.InNew.GetHashCode()));
+                        || t.TaskStatus == TaskStatusEnum.SC_Executing.GetHashCode()
+                        || t.TaskStatus == TaskInStatusEnum.InNew.GetHashCode()));
 
                 var processedPallets = existingTasks.Select(t => t.PalletCode).ToHashSet();
 
@@ -481,7 +497,7 @@
                         TaskType = TaskTypeEnum.Outbound.GetHashCode(),
                         TaskStatus = TaskStatusEnum.New.GetHashCode(),
                         Grade = 1,
-                        TaskNum = await Repository.GetTaskNo(),
+                        TaskNum = 0,  // 浣跨敤 0 璁╂暟鎹簱鑷姩鐢熸垚浠诲姟鍙�
                         Creater = "system_auto"
                     };
                     taskList.Add(task);
@@ -494,14 +510,14 @@
                 }
 
                 // 6. 閫氱煡 WCS锛堝紓姝ワ紝涓嶅奖鍝嶄富娴佺▼锛�
-                _ = Task.Run(async () =>
+                _ = Task.Run(() =>
                 {
                     foreach (var task in taskList)
                     {
                         try
                         {
                             var wmstaskDto = _mapper.Map<WMSTaskDTO>(task);
-                            await _httpClientHelper.Post<WebResponseContent>(
+                            _httpClientHelper.Post<WebResponseContent>(
                                 "http://logistics-service/api/logistics/notifyoutbound",
                                 JsonSerializer.Serialize(wmstaskDto));
                         }

--
Gitblit v1.9.3