From 939cd6b8ac3d28eb1c028a0ce15f7dacd53118ab Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 12 九月 2024 16:20:50 +0800
Subject: [PATCH] 新增入库添加库存

---
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs |   98 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 83 insertions(+), 15 deletions(-)

diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
index 0ef476a..2434b72 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -1,10 +1,4 @@
-锘縰sing WIDESEA_Common;
-using WIDESEA_DTO;
-using WIDESEA_IStorageTaskRepository;
-using WIDESEA_Repository;
-using WIDESEA_StorageTaskRepository;
-
-namespace WIDESEA_StorageOutTaskServices;
+锘縩amespace WIDESEA_StorageOutTaskServices;
 
 public class Dt_TaskService : ServiceBase<Dt_Task, IDt_TaskRepository>, IDt_TaskService
 {
@@ -56,7 +50,7 @@
     #region 澶栭儴鎺ュ彛鏂规硶
 
     /// <summary>
-    /// 鍫嗗灈鏈轰换鍔″畬鎴�
+    /// 鍫嗗灈鏈哄嚭搴撲换鍔″畬鎴�
     /// </summary>
     /// <param name="saveModel">浠诲姟鏁版嵁鍚堥泦</param>
     /// <returns>杩斿洖缁撴灉闆�</returns>
@@ -66,7 +60,9 @@
         try
         {
             // 鏇存柊搴撳瓨鐘舵��
+            // 璁剧疆搴撲綅鐘舵�佷负绌洪棽
             stock.LocationInfo.LocationStatus = LocationEnum.Free.ObjToInt();
+            // 璁剧疆搴撳瓨鐘舵�佷负鍑哄簱
             stock.StockInfoDetails.ForEach(x =>
             {
                 x.Status = 2;
@@ -80,20 +76,30 @@
             LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍫嗗灈鏈哄嚭搴撳畬鎴�", "鏇存柊搴撳瓨鐘舵�佷笌浠诲姟鐘舵��");
 
             // 浜嬪姟澶勭悊
+            // 寮�濮嬩簨鍔�
             _unitOfWorkManage.BeginTran();
+            // 鏇存柊搴撳瓨淇℃伅
             var isStockUpdated = _stockInfoRepository.UpdateData(stock);
+            // 鏇存柊浠诲姟淇℃伅
             var isTaskUpdated = await Update(task);
 
+            // 濡傛灉搴撳瓨淇℃伅鍜屼换鍔′俊鎭兘鏇存柊鎴愬姛
             if (isStockUpdated && isTaskUpdated)
             {
+                // 璁板綍鏃ュ織
                 LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍫嗗灈鏈哄嚭搴撳畬鎴�", $"浜嬪姟澶勭悊瀹屾垚锛屽簱瀛樼姸鎬佹洿鏂帮細{isStockUpdated}锛屼换鍔$姸鎬佹洿鏂�:{isTaskUpdated}");
+                // 鎻愪氦浜嬪姟
                 _unitOfWorkManage.CommitTran();
+                // 杩斿洖鎴愬姛缁撴灉
                 return content.OK("浠诲姟瀹屾垚鎴愬姛");
             }
             else
             {
+                // 璁板綍鏃ュ織
                 LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍫嗗灈鏈哄嚭搴撳畬鎴�", $"浜嬪姟澶勭悊澶辫触锛屽簱瀛樼姸鎬佹洿鏂帮細{isStockUpdated}锛屼换鍔$姸鎬佹洿鏂�:{isTaskUpdated}");
+                // 鍥炴粴浜嬪姟
                 _unitOfWorkManage.RollbackTran();
+                // 杩斿洖澶辫触缁撴灉
                 return content.Error("浠诲姟鎴栧簱瀛樻洿鏂板け璐�");
             }
         }
@@ -106,7 +112,7 @@
     }
 
     /// <summary>
-    /// 鍑哄簱浠诲姟瀹屾垚
+    /// 鎬诲嚭搴撲换鍔″畬鎴�
     /// </summary>
     /// <param name="saveModel">浠诲姟鏁版嵁鍚堥泦</param>
     /// <returns>杩斿洖缁撴灉闆�</returns>
@@ -159,7 +165,7 @@
             // 鏇存柊璐т綅鍜屽簱瀛樹俊鎭�
             (DtStockInfo updateStock, DtLocationInfo locationInf) = UpdateStockLocation(stock, task.NextAddress);
             var taskHty = CreateHistoricalTask(task);
-            LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "绉诲簱浠诲姟瀹屾垚", $"淇敼鍚庡簱瀛樻暟鎹細{JsonConvert.SerializeObject(updateStock)}锛屽師鍏堣揣浣嶆暟鎹細{locationInf}");
+            LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "绉诲簱浠诲姟瀹屾垚", $"璐т綅鍦板潃锛歿task.TargetAddress},淇敼鍚庡簱瀛樻暟鎹細{JsonConvert.SerializeObject(updateStock)}锛屽師鍏堣揣浣嶆暟鎹細{locationInf}");
 
             // 鎵ц鏁版嵁搴撲簨鍔�
             bool isResult = await ExecuteTransaction(updateStock, taskHty, locationInf, task.TaskId);
@@ -167,6 +173,45 @@
                 content.OK("绉诲簱浠诲姟瀹屾垚鎴愬姛");
             else
                 content.Error("绉诲簱浠诲姟瀹屾垚澶辫触");
+        }
+        catch (Exception err)
+        {
+            Console.WriteLine(err.Message.ToString());
+        }
+        return content;
+    }
+
+    /// <summary>
+    /// 鍏ュ簱浠诲姟瀹屾垚
+    /// </summary>
+    /// <param name="task">浠诲姟鏁版嵁鍚堥泦</param>
+    /// <returns>杩斿洖缁撴灉闆�</returns>
+    public async Task<WebResponseContent> CompleteInboundTaskAsync(Dt_Task task)
+    {
+        WebResponseContent content = new WebResponseContent();
+        try
+        {
+            // 鍒涘缓搴撳瓨瀹炰緥妯″瀷
+            DtStockInfo stock = new DtStockInfo()
+            {
+
+            };
+
+            // 鍒涘缓鍘嗗彶浠诲姟瀹炰緥妯″瀷
+            var taskHty = CreateHistoricalTask(task);
+
+            // 淇敼璐т綅淇℃伅涓烘湁璐�
+            var locationInf = await _locationRepository.QueryFirstAsync(x => x.LocationCode == task.TargetAddress);
+            locationInf.LocationStatus = (int)LocationEnum.Lock;
+
+            LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍏ュ簱浠诲姟瀹屾垚", $"璐т綅鍦板潃锛歿task.TargetAddress},淇敼鍚庤揣浣嶆暟鎹細{locationInf}");
+
+            // 鎵ц鏁版嵁搴撲簨鍔�
+            bool isResult = await ExecuteTransaction(stock, taskHty, locationInf, task.TaskId);
+            if (isResult)
+                content.OK("鍏ュ簱浠诲姟瀹屾垚鎴愬姛");
+            else
+                content.Error("鍏ュ簱浠诲姟瀹屾垚澶辫触");
         }
         catch (Exception err)
         {
@@ -198,7 +243,17 @@
         var stock = await _stockInfoRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode);
         if (stock == null)
         {
-            return content.Error("搴撳瓨涓嶅瓨鍦�");
+            LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "搴撳瓨涓嶅瓨鍦ㄥ瓨鍦紝鍒ゆ柇鏄惁鏄叆搴撲换鍔�", $"{task.TaskType}");
+            if (task.TaskType == (int)TaskTypeEnum.Inbound)
+            {
+                LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "鍏ュ簱浠诲姟", "");
+                return await CompleteInboundTaskAsync(task);
+            }
+            else
+            {
+                LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "搴撳瓨涓嶅瓨鍦ㄤ篃涓嶆槸鍏ュ簱浠诲姟", "");
+                return content.Error("搴撳瓨涓嶅瓨鍦�");
+            }
         }
         LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "楠岃瘉搴撳瓨鏄惁瀛樺湪", JsonConvert.SerializeObject(stock));
 
@@ -250,7 +305,6 @@
 
             if (task != null)
             {
-
                 // 鏇存柊鐜版湁浠诲姟
                 content = await UpdateExistingTask(input, areaInfo.AreaID, task);
             }
@@ -571,6 +625,11 @@
         return stockHty;
     }
 
+    /// <summary>
+    /// 鍒涘缓鍘嗗彶浠诲姟璁板綍
+    /// </summary>
+    /// <param name="task"></param>
+    /// <returns></returns>
     private Dt_Task_Hty CreateHistoricalTask(Dt_Task task)
     {
         // 鏇存柊浠诲姟鐘舵��
@@ -615,8 +674,17 @@
         _unitOfWorkManage.BeginTran();
         try
         {
-            // 鏇存柊搴撳瓨
-            var isUpdateStock = await _stockInfoRepository.UpdateDataAsync(stock);
+            var isUpdateStock = true;
+            if (taskHty.TaskType == (int)TaskTypeEnum.Outbound)
+            {
+                // 鏇存柊搴撳瓨
+                isUpdateStock = await _stockInfoRepository.UpdateDataAsync(stock);
+            }
+            else
+            {
+                // 娣诲姞搴撳瓨
+                isUpdateStock = await _stockInfoRepository.AddDataAsync(stock) > 0;
+            }
 
             // 娣诲姞鍘嗗彶浠诲姟
             var isTaskHtyAdd = await _task_HtyRepository.AddDataAsync(taskHty) > 0;
@@ -630,7 +698,7 @@
             // 鎻愪氦鎴栧洖婊氫簨鍔�
             if (isUpdateStock && isTaskHtyAdd && isTaskDelete && isUpdateLoc)
             {
-                LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "绉诲簱浠诲姟瀹屾垚", $"浜嬪姟澶勭悊瀹屾垚,鎻愪氦浜嬪姟銆傛坊鍔犲巻鍙蹭换鍔★細{isTaskHtyAdd},鍒犻櫎浠诲姟鏁版嵁锛歿isTaskDelete},鏇存柊搴撳瓨锛歿isUpdateStock},淇敼绉诲簱鍓嶈揣浣嶇姸鎬侊細{isUpdateLoc}");
+                LogFactory.GetLog("浠诲姟瀹屾垚").InfoFormat(true, "绉诲簱浠诲姟瀹屾垚", $"浜嬪姟澶勭悊瀹屾垚,鎻愪氦浜嬪姟銆傛坊鍔犲巻鍙蹭换鍔★細{isTaskHtyAdd},鍒犻櫎浠诲姟鏁版嵁锛歿isTaskDelete},鏇存柊鎴栨坊鍔犲簱瀛橈細{isUpdateStock},淇敼绉诲簱鍓嶈揣浣嶇姸鎬侊細{isUpdateLoc}");
                 _unitOfWorkManage.CommitTran();
                 return true;
             }

--
Gitblit v1.9.3