From ba998c70b77180668f295e65e07f3a62bf85e5ee Mon Sep 17 00:00:00 2001
From: HuBingJie <3146306518@qq.com>
Date: 星期三, 17 十二月 2025 10:26:03 +0800
Subject: [PATCH] 最新

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  208 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 183 insertions(+), 25 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index ead1c5c..2461430 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -561,7 +561,7 @@
             try
             {
                 // 鏌ユ壘浠诲姟
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskStatus == TaskOutStatusEnum.OutFinish.ObjToInt());
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum &&(x.TaskStatus == TaskOutStatusEnum.OutNew.ObjToInt()|| x.TaskStatus == TaskRelocationStatusEnum.RelocationNew.ObjToInt()|| x.TaskStatus == TaskInStatusEnum.Line_InExecuting.ObjToInt()));
                 if (task == null)
                 {
                     return webResponse.Error($"鏈壘鍒颁换鍔″彿涓恒�恵taskNum}銆戠殑浠诲姟淇℃伅");
@@ -615,45 +615,69 @@
                 }
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                 //鑾峰彇鎺ュ彛杩涜璋冨彇
-                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.WCSCancelinventory);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSCancelinventory);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
                 string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
                 if (WCSReceiveTaskAPI == null)
                 {
-                    return webResponse.Error($"浠诲姟鍙嶉MES澶辫触锛屾湭閰嶇疆MES浠诲姟瀹屾垚鍙嶉鎺ュ彛");
+                    _unitOfWorkManage.RollbackTran();
+
+                    return webResponse.Error($"浠诲姟鎵嬪姩鍙栨秷澶辫触锛屾湭閰嶇疆WCS浠诲姟鎵嬪姩鍙栨秷鍙嶉鎺ュ彛");
                 }
                 var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
-                if (respon != null)
-                {
-                    var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
-                    //    if (response.Success)
-                    //    {
-                    //        return webResponse.OK();
-                    //    }
-                    //    else
-                    //    {
-                    //        return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
-                    //    }
-                    //}
-                    //else
-                    //{
-                    //    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
-                    //}
-                    if (stockmsseg > 0 && locationmsseg > 0 && taskmsseg)
-                    {
-                        _unitOfWorkManage.CommitTran();
-                        return webResponse.OK("浠诲姟鍙栨秷鎴愬姛");
 
+                if (respon == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                if (!response.Success)
+                {
+                    _unitOfWorkManage.RollbackTran();
+
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                }
+                if (stockmsseg <= 0 && locationmsseg <= 0 && taskmsseg)
+                    {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error("浠诲姟鍙栨秷澶辫触");
                     }
 
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MEScancelTask);      //鑾峰彇鍒癕ES鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string MEScancelTask = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (MEScancelTask == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屾湭閰嶇疆WCS浠诲姟鎵嬪姩瀹屾垚鍙嶉鎺ュ彛");
                 }
+                var MES = new
+                {
+                    businessId = task.MESbusinessId,
+                    taskId = task.MEStaskId,
+                    palletCode = task.PalletCode
+                };
+                var MESrespon = HttpHelper.Post(MEScancelTask, JsonConvert.SerializeObject(MES));
+                if (respon == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+                var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                if (!response.Success)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                }
+                _unitOfWorkManage.CommitTran();
+                return webResponse.OK("浠诲姟鍙栨秷鎴愬姛");
             }
             catch (Exception ex)
             {
                 _unitOfWorkManage.RollbackTran();
                 return webResponse.Error($"鍙栨秷浠诲姟澶辫触锛屽師鍥狅細{ex.Message}");
             }
-            _unitOfWorkManage.RollbackTran();
-            return webResponse.Error("浠诲姟鍙栨秷澶辫触");
         }
 
         /// <summary>
@@ -832,5 +856,139 @@
 
             }
         }
+
+        /// <summary>
+        /// 鎵嬪姩瀹屾垚鎺ュ彛
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public WebResponseContent ManualTaskCompleted(int taskNum)
+        {
+            WebResponseContent webResponse = new WebResponseContent();
+            try
+            {
+                // 鏌ユ壘浠诲姟
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null)
+                {
+                    return webResponse.Error($"鏈壘鍒颁换鍔″彿涓恒�恵taskNum}銆戠殑浠诲姟淇℃伅");
+                }
+
+
+                Dt_StockInfo stockInfo = _stockRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+
+                _unitOfWorkManage.BeginTran();
+
+                Dt_StockInfo stockmsseg;
+                Dt_LocationInfo locationmsseg1 = null;
+                Dt_LocationInfo locationmsseg2 = null;
+                bool taskmsseg;
+                bool task_htymsseg;
+
+                bool location1;
+                bool location2 = false;
+
+                bool resstock;
+                if (task.TaskType == TaskInboundTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+                {
+                    stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                    if (stockmsseg == null) { return webResponse.Error("鏈壘鍒板簱瀛樹俊鎭�"); };
+                    stockmsseg.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                     resstock = _stockRepository.UpdateData(stockmsseg);
+                    if (task.TaskType == TaskRelocationTypeEnum.Relocation.ObjToInt())
+                    {
+                        locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                        locationmsseg2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+                        if (locationmsseg1 == null || locationmsseg2 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                        locationmsseg2.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+                        location2 = _locationInfoRepository.UpdateData(locationmsseg2);
+                    }
+                    else
+                    {
+                        locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                        if (locationmsseg1 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+                        locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                        location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+                        
+                    }
+                }
+                else
+                {
+                    stockmsseg = _stockRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+                    if (stockmsseg == null) { return webResponse.Error("鏈壘鍒板簱瀛樹俊鎭�"); }
+                    resstock = _stockRepository.DeleteData(stockmsseg);
+                    locationmsseg1 = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress);
+                    if (locationmsseg1 == null) { webResponse.Error("鏈壘鍒拌揣浣嶄俊鎭�"); }
+                    locationmsseg1.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                    location1 = _locationInfoRepository.UpdateData(locationmsseg1);
+                }
+
+                taskmsseg = BaseDal.DeleteData(task);
+
+                task_htymsseg = BaseDal.DeleteAndMoveIntoHty(task,OperateTypeEnum.浜哄伐瀹屾垚);
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var ConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_WCS_IPAddress, SysConfigConst.WCSManualTaskCompleted);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string WCSReceiveTaskAPI = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (WCSReceiveTaskAPI == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屾湭閰嶇疆WCS浠诲姟鎵嬪姩瀹屾垚鍙嶉鎺ュ彛");
+                }
+                var respon = HttpHelper.Get(WCSReceiveTaskAPI, JsonConvert.SerializeObject(task.TaskNum));
+                if (respon == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+                var response = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                if (!response.Success)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                }
+                if (!(resstock && task_htymsseg && taskmsseg && task.TaskType ==TaskOutboundTypeEnum.Outbound.ObjToInt() ? location1 : (location1 && location2)))
+                    {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触");
+                }
+
+                //鑾峰彇鎺ュ彛杩涜璋冨彇
+                var MESConfigsAPIInfo = _dt_ApiInfoService.GetConfigsByAPIInfo(CateGoryConst.CONFIG_MES_IPAddress, SysConfigConst.MESmockComplete);      //鑾峰彇鍒皐cs鍏ㄩ儴绫诲瀷鐨勬帴鍙�
+                string MESmockComplete = ConfigsAPIInfo.ApiAddress + ConfigsAPIInfo.ApiName;
+                if (MESConfigsAPIInfo == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屾湭閰嶇疆WCS浠诲姟鎵嬪姩瀹屾垚鍙嶉鎺ュ彛");
+                }
+                var MES = new
+                {
+                    businessId = task.MESbusinessId,
+                    taskId = task.MEStaskId,
+                    palletCode = task.PalletCode
+            };
+                var MESrespon = HttpHelper.Post(MESmockComplete, JsonConvert.SerializeObject(MES));
+                if (respon == null)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁颁负绌�");
+                }
+                var MESresponse = JsonConvert.DeserializeObject<ApiResponse<object>>(respon);
+                if (!response.Success)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return webResponse.Error($"璋冨彇鎺ュ彛澶辫触锛屽弽棣堝弬鏁板師鍥狅細{response.Message}");
+                }
+                _unitOfWorkManage.CommitTran();
+                return webResponse.OK("浠诲姟鎵嬪姩瀹屾垚鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return webResponse.Error($"浠诲姟鎵嬪姩瀹屾垚澶辫触锛屽師鍥狅細{ex.Message}");
+            }
+        }
     }
 }

--
Gitblit v1.9.3