From 37051424de7c4a97132fbb06e45df594790aabf9 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期二, 16 十二月 2025 18:40:38 +0800
Subject: [PATCH] 优化功能

---
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs |  148 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 118 insertions(+), 30 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
index c3526ee..4dc25f7 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -104,22 +104,17 @@
         /// </summary>
         /// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
         /// <returns>杩斿洖澶勭悊缁撴灉</returns>
-        public WebResponseContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO)
+        public WMSReceiveTaskContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO)
         {
-            WebResponseContent content = new WebResponseContent();
+            WMSReceiveTaskContent content = new WMSReceiveTaskContent();
             string errorMsg = "";
             try
             {
                 lock (lock_taskReceive)
                 {
                     List<Dt_Task> tasks = new List<Dt_Task>();
-                    Dt_Task taskOld = BaseDal.QueryFirst(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode));
-                    if (taskOld != null) throw new Exception($"鏂欑{taskOld.PalletCode}"+(taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱浠诲姟宸插瓨鍦�" : "鍑哄簱浠诲姟宸插瓨鍦�"));
+                    List<Dt_Task> taskOlds = BaseDal.QueryData(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode));
                     List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.TaskDescribe.ContainerCode).ToList());
-                    
-                    Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x=>x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt());
-
-                    if (noOutLocation != null) throw new Exception($"鏂欑{noOutLocation.PalletCode}璐т綅{noOutLocation.LocationCode}鐘舵�佷笉鍙嚭搴�");
                     List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData();
                     //涓嬪彂浠诲姟缁�
                     string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode;
@@ -129,16 +124,28 @@
                         //鑾峰彇鎿嶄綔鍙�
                         Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.TaskDescribe.ToStationCode);
                         if (stationManger == null) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙皗item.TaskDescribe.ToStationCode}涓嶅瓨鍦�");
-
+                        Dt_Task? taskOld = taskOlds.FirstOrDefault(x=>x.PalletCode==item.TaskDescribe.ContainerCode);
+                        if (taskOld != null)
+                        {
+                            errorMsg += $"鏂欑{taskOld.PalletCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱浠诲姟宸插瓨鍦�;" : "鍑哄簱浠诲姟宸插瓨鍦�;");
+                            content.FailData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
+                            continue;
+                        }
                         Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == item.TaskDescribe.ContainerCode);
                         if (locationInfo == null)
                         {
                             errorMsg += $"鏂欑{item.TaskDescribe.ContainerCode}涓嶅瓨鍦�;";
+                            content.FailData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
                             continue;
                         };
-
+                        Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x => (x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) && x.PalletCode == item.TaskDescribe.ContainerCode);
+                        if (noOutLocation != null)
+                        {
+                            errorMsg += $"鏂欑{noOutLocation.PalletCode}璐т綅{noOutLocation.LocationCode}鐘舵�佷笉鍙嚭搴�";
+                            content.FailData.Add(new BinCodeObj() { Bincode = noOutLocation.PalletCode });
+                            continue;
+                        }
                         Dt_Task task = _mapper.Map<Dt_Task>(item);
-                        
                         task.SourceAddress = locationInfo.LocationCode;
                         task.CurrentAddress = locationInfo.LocationCode;
                         task.NextAddress = stationManger.PickStationCode;
@@ -149,6 +156,7 @@
                         task.DeviceCode = stationManger.CraneCode;
                         task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
                         tasks.Add(task);
+                        content.SucessData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
                     }
 
                     locationInfos.ForEach(x =>
@@ -161,8 +169,11 @@
                     _locationInfoRepository.UpdateData(locationInfos);
                     _unitOfWorkManage.CommitTran();
                     _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
-                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks.Select(x => x.TaskNum).ToList());
-                    content = tasks.Count > 0 ? content.OK("鎴愬姛!"+(errorMsg.IsNullOrEmpty()? "": errorMsg)) : content.Error("澶辫触");
+                    if (tasks.Count>0)
+                    {
+                        _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks);
+                    }
+                    content.OK(errorMsg.IsNullOrEmpty()? "鎴愬姛": errorMsg);
                 }
             }
             catch (Exception ex)
@@ -176,7 +187,7 @@
         /// 瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟
         /// </summary>
         /// <returns></returns>
-        public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode, string stationCode)
+        public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode, string stationCode, int type = 0)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -184,13 +195,27 @@
                 List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData();
                 Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode);
                 if (locationInfo != null) throw new Exception($"搴撲綅鏂欑鍙穥containerFlowDTO.ContainerCode}宸插瓨鍦�");
-                if (BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && x.DeviceCode== deviceCode) != null)
+                Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode);
+                if (taskOld !=null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode == deviceCode)
                 {
                     return content.OK();
                 }
-                else if(BaseDal.QueryFirst(x => x.PalletCode == containerFlowDTO.ContainerCode) != null)
+                if (taskOld != null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode != deviceCode)
                 {
-                    throw new Exception($"鏂欑鍙穥containerFlowDTO.ContainerCode}浠诲姟宸插瓨鍦�");
+                    Dt_StationManger stationOld = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
+                    string oldSlotCode = taskOld.SourceAddress;
+                    taskOld.SourceAddress = containerFlowDTO.SlotCode;
+                    taskOld.CurrentAddress = containerFlowDTO.SlotCode;
+                    taskOld.NextAddress = stationOld.StationCode;
+                    taskOld.DeviceCode = stationOld.StationDeviceCode;
+                    //鏇存柊浠诲姟
+                    BaseDal.UpdateData(taskOld);
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { taskOld.TaskNum }, $"{oldSlotCode}鎹㈣嚦{containerFlowDTO.SlotCode}鍏ュ簱");
+                    return content.OK();
+                }
+                else if(taskOld != null)
+                {
+                    throw new Exception($"鏂欑鍙穥containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱AGV鎵ц涓�": "鍑哄簱AGV鎵ц涓�"));
                 }
                 Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt());
                 if (noInLocation == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
@@ -207,9 +232,17 @@
                 task.Roadway = noInLocation.RoadwayNo;
                 task.DeviceCode = stationManger.StationDeviceCode;
                 task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
+                
                 //娣诲姞浠诲姟
                 BaseDal.AddData(task);
-                _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鍒涘缓鍏ュ簱浠诲姟");
+                if (type > 0)
+                {
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鎵嬪姩鎸夐挳鍏ュ簱");
+                }
+                else
+                {
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鍒涘缓鍏ュ簱浠诲姟");
+                }
                 content.OK("鎴愬姛");
             }
             catch (Exception ex)
@@ -265,7 +298,36 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                EPLightContent pLightContent = new EPLightContent();
+                if (taskSendLight.TagNo=="B2")
+                {
+                    List<EPLightSendDTO> lightSendDTOs = new List<EPLightSendDTO>()
+                    {
+                        new EPLightSendDTO
+                        {
+                            DOCNO = taskSendLight.DocNo,
+                            TASKNO= taskSendLight.TaskNo,
+                            LOCATION=taskSendLight.TagCode,
+                            QUANTITY=taskSendLight.TagQunity,
+                            LIGHTCOLOR=taskSendLight.Color switch
+                            {
+                                "Blue" => "1",
+                                "Green" => "2",
+                                "Red" => "4",
+                                _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
+                            },
+                            ORDERTYPE=taskSendLight.Mode.ToString(),
+                            LIGHTTYPE="1",
+                        }
+                    };
+                    EPLightContent pLightContent = PickOrderInfoRequest(lightSendDTOs);
+                    if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+                    content.OK();
+                }
+                else
+                {
+                    content.OK();
+                }
+                
             }
             catch (Exception ex)
             {
@@ -567,15 +629,16 @@
                         CompleteType = 1
                     };
                     string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
-                    //璋冪敤鎺ュ彛
-                    string response = HttpHelper.Post(url, request);
-                    WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍑哄簱涓婃姤杩斿洖鍊�");
-                    if (wMSResponse.Code != "0") throw new Exception($"鍑哄簱浠诲姟{task.TaskNum}WMS鍑哄簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}");
+                    
                     _unitOfWorkManage.BeginTran();
                     _locationInfoRepository.UpdateData(locationInfo);
                     BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
                     _unitOfWorkManage.CommitTran();
                     _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.Free, LocationChangeType.OutboundCompleted, task.TaskNum);
+                    //璋冪敤鎺ュ彛
+                    string response = HttpHelper.Post(url, request);
+                    WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍑哄簱涓婃姤杩斿洖鍊�");
+                    if (wMSResponse.Code != "0") content.Message=$"鍑哄簱浠诲姟{task.TaskNum}WMS鍑哄簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
                 }
                 else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍏ュ簱浠诲姟瀹屾垚閫昏緫
                 {
@@ -595,10 +658,7 @@
                         CompleteType = 2
                     };
                     string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
-                    //璋冪敤鎺ュ彛
-                    string response = HttpHelper.Post(url, request);
-                    WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍏ュ簱涓婃姤杩斿洖鍊�");
-                    if (wMSResponse.Code != "0") throw new Exception($"鍏ュ簱浠诲姟{task.TaskNum}WMS鍏ュ簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}");
+                    
                     Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                     if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
                     {
@@ -612,6 +672,10 @@
                     BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
                     _unitOfWorkManage.CommitTran();
                     _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted, task.TaskNum);
+                    //璋冪敤鎺ュ彛
+                    string response = HttpHelper.Post(url, request);
+                    WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍏ュ簱涓婃姤杩斿洖鍊�");
+                    if (wMSResponse.Code != "0") content.Message = $"鍏ュ簱浠诲姟{task.TaskNum}WMS鍏ュ簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
                 }
                 content.OK("浠诲姟瀹屾垚");
             }
@@ -622,11 +686,35 @@
             }
             return content;
         }
-
+        /// <summary>
+        /// 浜屾湡鎾澧欏洖浼�
+        /// </summary>
+        /// <returns></returns>
+        public EPLightContent WMSLightBack(List<TaskBackLight> taskBackLights)
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSLightBack.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
+                {
+                    return content.Error($"鏈壘鍒版挱绉嶅涓婃姤,璇锋鏌ユ帴鍙i厤缃�");
+                }
+                string request = JsonConvert.SerializeObject(taskBackLights, settings);
+                string response = HttpHelper.Post(url, request);
+                WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欎笂鎶ヨ繑鍥炲��");
+                if (wMSResponse.Code != "0") throw new Exception($"鎾澧欎笂鎶ラ敊璇�,淇℃伅:{wMSResponse.Msg}");
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
         /// <summary>
         /// 浜屾湡鎾澧欎笅鍙�
         /// </summary>
-        /// <param name="taskNum"></param>
         /// <returns></returns>
         public EPLightContent PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
         {
@@ -638,7 +726,7 @@
                 {
                     return content.Error($"鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
                 }
-                string request = JsonConvert.SerializeObject(lightSendDTOs, settings);
+                string request = JsonConvert.SerializeObject(lightSendDTOs, settings).ToUpper();
                 //璋冪敤鎺ュ彛
                 string response = HttpHelper.Post(url, request);
                 EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欎笅鍙戜笂鎶ヨ繑鍥炲��");

--
Gitblit v1.9.3