From 3460ffdc967b65ea67c959212c2505a19008401e Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期四, 16 四月 2026 13:39:56 +0800
Subject: [PATCH] 盘点优化,智仓调智仓防呆

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  144 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 137 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 09e3cf5..c49e8af 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -308,7 +308,7 @@
                 }
             }
             stockInfo.LocationCode = task.TargetAddress;
-            stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+            stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
             stockInfo.Details.ForEach(x =>
             {
                 x.Status = StockStatusEmun.鍏ュ簱纭.ObjToInt();
@@ -391,7 +391,7 @@
                             allocatefeedmodel.Details = groupedData;
 
                             var response = responseModel(inboundOrder, 3, null, allocatefeedmodel);
-                            if (response != null && response.IsSuccess)
+                            if (response != null && response.IsSuccess && response.Data.Code =="200")
                             {
                                 var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
                                 .Where(it => it.OrderId == inboundOrder.Id)
@@ -496,7 +496,7 @@
 
                             var response= responseModel(inboundOrder,2, feedmodel);
 
-                            if (response != null && response.IsSuccess)
+                            if (response != null && response.IsSuccess && response.Data.Code == "200")
                             {
                                 var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>()
                                 .Where(it => it.OrderId == inboundOrder.Id)
@@ -1091,6 +1091,7 @@
                 stockInfo.LocationCode = locationInfo.LocationCode;
                 stockInfo.PalletCode = task.PalletCode;
                 stockInfo.LocationCode = task.TargetAddress;
+                stockInfo.Remark ="";
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                 _stockRepository.UpdateData(stockInfo);
 
@@ -1346,6 +1347,7 @@
                 // 鏇存柊搴撳瓨淇℃伅
                 stockInfo.LocationCode = task.TargetAddress;
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                stockInfo.Remark = "";
 
                 // 鏇存柊搴撳瓨鏄庣粏鐘舵��
                 if (stockInfo.Details != null && stockInfo.Details.Any())
@@ -2234,7 +2236,7 @@
         /// <summary>
         /// 鐩樼偣鍑哄簱瀹屾垚
         /// </summary>
-        public WebResponseContent OutInventoryTaskCompleted(Dt_Task task)
+        public async Task<WebResponseContent> OutInventoryTaskCompleted(Dt_Task task)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -2259,7 +2261,7 @@
                 {
                     return content.Error($"鐩樼偣鍗晎task.OrderNo}鐩樼偣宸插畬鎴愭垨鏈紑濮�");
                 }
-                if (stockInfo.StockStatus != StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
+                if (stockInfo.StockStatus != StockStatusEmun.鐩樼偣鍑哄簱閿佸畾.ObjToInt())
                 {
                     return content.Error($"{stockInfo.PalletCode}搴撳瓨鐘舵�佷笉姝g‘");
                 }
@@ -2285,7 +2287,7 @@
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
-                content.Error(ex.Message);
+                return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message));
             }
             return content;
         }
@@ -2351,7 +2353,7 @@
                 {
                     _logger.LogInformation($"InEmptyTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
                 }
-                return content;
+                return content.OK();
             }
             catch (Exception ex)
             {
@@ -2583,6 +2585,134 @@
                 return WebResponseContent.Instance.Error($"浠诲姟鍙栨秷澶辫触锛歿ex.Message}");
             }
         }
+
+        public async Task<WebResponseContent> AreaRelocationTaskCompleted(Dt_Task task)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress))
+                {
+                    return WebResponseContent.Instance.Error("绉诲簱浠诲姟淇℃伅涓嶅畬鏁达紙鎵樼洏鍙�/鐩爣璐т綅涓虹┖锛�");
+                }
+
+                // 2. 鏌ヨ鎵樼洏搴撳瓨淇℃伅
+                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(x => x.Details)
+                    .Where(x => x.PalletCode == task.PalletCode)
+                    .FirstAsync();
+
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩榌{task.PalletCode}]瀵瑰簲鐨勭粍鐩樹俊鎭�");
+                }
+
+                // 闈炵┖鎵樼洏蹇呴』鏈夋槑缁�
+                if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt())
+                {
+                    _logger.LogInformation($"TaskService RelocationTaskCompleted: 鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅.{task.TaskNum}");
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏[{task.PalletCode}]搴撳瓨鏄庣粏淇℃伅");
+                }
+
+                // 3. 鏌ヨ鐩爣璐т綅+鍘熻揣浣嶄俊鎭�
+                Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                if (targetLocationInfo == null)
+                {
+                    return content.Error($"鏈壘鍒板搴旂殑缁堢偣璐т綅[{task.TargetAddress}]淇℃伅");
+                }
+
+                // 鍘熻揣浣嶄俊鎭�
+                Dt_LocationInfo oldLocationInfo = null;
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+                    if (oldLocationInfo == null)
+                    {
+                        return content.Error($"鏈壘鍒板師璐т綅[{stockInfo.LocationCode}]淇℃伅");
+                    }
+                }
+
+                // 4. 璐т綅鐘舵�佹牎楠�
+                if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"鐩爣璐т綅[{task.TargetAddress}]鐘舵�佷笉姝g‘锛堝綋鍓嶄负宸插崰鐢級");
+                }
+
+                // 5. 寮�鍚簨鍔″鐞嗘牳蹇冮�昏緫
+                _unitOfWorkManage.BeginTran();
+
+                // 5.1 璁板綍鐩爣璐т綅鍘熺姸鎬侊紝鏇存柊涓哄崰鐢�
+                var beforeTargetLocationStatus = targetLocationInfo.LocationStatus;
+                targetLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()
+                        ? LocationStatusEnum.Pallet.ObjToInt()
+                        : LocationStatusEnum.InStock.ObjToInt();
+                _locationInfoService.Repository.UpdateData(targetLocationInfo);
+
+                // 5.2 閲婃斁鍘熻揣浣�
+                int beforeOldLocationStatus = 0;
+                if (oldLocationInfo != null)
+                {
+                    beforeOldLocationStatus = oldLocationInfo.LocationStatus;
+                    // 鍘熻揣浣嶆仮澶嶄负绌洪棽
+                    oldLocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                    _locationInfoService.Repository.UpdateData(oldLocationInfo);
+                }
+                // 5.4 鏇存柊搴撳瓨涓讳俊鎭紙缁戝畾鏂拌揣浣嶏級
+                string oldLocationCode = stockInfo.LocationCode; // 璁板綍鍘熻揣浣�
+                stockInfo.LocationCode = targetLocationInfo.LocationCode; // 缁戝畾鐩爣璐т綅
+                stockInfo.PalletCode = task.PalletCode;
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+
+                _stockRepository.UpdateData(stockInfo);
+
+                // 5.5 鏇存柊浠诲姟鐘舵�佷负瀹屾垚
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+
+                // 鎻愪氦浜嬪姟
+                _unitOfWorkManage.CommitTran();
+
+                // 浠诲姟褰掓。澶辫触鍒欑洿鎺ュ垹闄�
+                if (!result)
+                {
+                    await Db.Deleteable(task).ExecuteCommandAsync();
+                }
+                try
+                {
+                    // 璁板綍鐩爣璐т綅鐘舵�佸彉鏇�
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+                        targetLocationInfo,
+                        beforeTargetLocationStatus,
+                        StockChangeType.Inbound.ObjToInt(),
+                        $"绉诲簱鍏ュ簱锛堝師璐т綅锛歿oldLocationCode}锛�",
+                        task.TaskNum);
+
+                    // 璁板綍鍘熻揣浣嶇姸鎬佸彉鏇达紙鑻ユ湁锛�
+                    if (oldLocationInfo != null)
+                    {
+                        _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+                            oldLocationInfo,
+                            beforeOldLocationStatus,
+                            StockChangeType.Outbound.ObjToInt(),
+                            $"绉诲簱鍑哄簱锛堢洰鏍囪揣浣嶏細{targetLocationInfo.LocationCode}锛�",
+                            task.TaskNum);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    _logger.LogInformation($"RelocationTaskCompleted AddLocationStatusChangeRecord : {ex.Message} ");
+                }
+
+                return content.OK();
+            }
+            catch (Exception ex)
+            {
+                // 浜嬪姟鍥炴粴
+                _unitOfWorkManage.RollbackTran();
+                _logger.LogError($"RelocationTaskCompleted 澶勭悊澶辫触锛歿ex.Message}", ex);
+                return await Task.FromResult(WebResponseContent.Instance.Error($"绉诲簱浠诲姟澶勭悊澶辫触锛歿ex.Message}"));
+            }
+        }
     }
 }
 

--
Gitblit v1.9.3