From 6db89a97e81e6c26bb2d2ccb3db79ed8858462a2 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 17 七月 2025 20:38:16 +0800
Subject: [PATCH] 优化异常库位出库功能

---
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs |   71 +++++++++++++++++++++++++++++++----
 1 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
index 19282f0..22294eb 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -1,4 +1,5 @@
-锘縰sing Masuit.Tools;
+锘縰sing Mapster;
+using Masuit.Tools;
 using SqlSugar;
 using WIDESEA_Common.CustomModels;
 using WIDESEA_Core.Const;
@@ -183,6 +184,12 @@
 
             if (!result.Success)
             {
+                List<string> strings = new List<string>() { "2036","2038","2084","2086"};
+                if (input.Position.Contains(strings))
+                {
+                    Console.WriteLine($"{result.MOMMessage}");
+                    return null;
+                }
                 var taskNG = new Dt_Task
                 {
                     CurrentAddress = input.Position,
@@ -203,6 +210,7 @@
                     ProcessCode = result.ProcessCode,
                 };
                 return taskNG;
+               
             }
 
             if (result.SerialNos.Count <= 0)
@@ -586,17 +594,50 @@
 
     #region 鐩存帴鍑哄簱浠诲姟瀹屾垚
 
-    public async Task<WebResponseContent> CompleteInToOutTaskAsync(Dt_Task task)
+    public async Task<WebResponseContent> CompleteInToOutTaskAsync(Dt_Task task,DtStockInfo stock)
     {
         WebResponseContent content = new WebResponseContent();
         try
         {
-            //娣诲姞鍘嗗彶
-            var taskHty = CreateHistoricalTask(task);
-            // 娣诲姞鍘嗗彶浠诲姟
-            var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0;
-            //鍒犻櫎浠诲姟
-            BaseDal.DeleteData(task);
+            DtStockInfo_Hty stockInfo_Hty = null;
+            if (stock != null)
+            {
+                stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
+                stockInfo_Hty.ModifyDate = DateTime.Now;
+            }
+            var taskHty = task.Adapt<Dt_Task_Hty>();
+            taskHty.FinishTime = DateTime.Now;
+            taskHty.OperateType = App.User.UserName != null ? (int)OperateTypeEnum.浜哄伐瀹屾垚 : (int)OperateTypeEnum.鑷姩瀹屾垚;
+            taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
+
+            var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway);
+
+            if(location != null)
+            {
+                int lastStatus = location.LocationStatus;
+                location.LocationStatus = (int)LocationEnum.Free; 
+                _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(location, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum);
+            }
+
+            task.TaskState = (int)TaskOutStatusEnum.OutFinish;
+
+            
+            // 浜嬪姟澶勭悊
+            await _unitOfWorkManage.UseTranAsync(async () =>
+            {
+                if (stockInfo_Hty != null)
+                {
+                    await DeleteStockInfoAsync(stock.Id);
+                    await DeleteStockInfoDetailsAsync(stock.StockInfoDetails);
+                    await AddStockInfoHtyAsync(stockInfo_Hty);
+                }
+                if (location != null)
+                {
+                    await UpdateLocationAsync(location);
+                }
+                await DeleteTaskAsync(task.TaskId);
+                await AddTaskHtyAsync(taskHty);
+            });
 
             return content.OK();
         }
@@ -1637,6 +1678,20 @@
             return content.Error(ex.Message);
         }
     }
+    public WebResponseContent GetLocationStatus()
+    {
+        WebResponseContent content = new WebResponseContent();
+        try
+        {
+            List<DtLocationInfo> LocationList = _locationRepository.Db.Queryable<DtLocationInfo>().Where(x => x.LocationStatus != 2 && x.LocationStatus != 0).ToList();
+            return content.OK1(total1: LocationList.Count, data: LocationList);
+        }
+        catch (Exception ex)
+        {
+            return content.Error(ex.Message);
+        }
+
+    }
 }
 
 internal class TaskHourData

--
Gitblit v1.9.3