From c6265b1f32a6c6c4e4dd478efe27d23e7d825859 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 12 十一月 2025 16:40:25 +0800
Subject: [PATCH] 优化任务逻辑,新增API支持动态货位更新重构任务处理逻辑,支持基于区域的任务分配,优化货位状态更新,减少重复代码 更新项目路径和文档路径,反映文件结构调整。  新增 UpdateStartLocationInfo和RequestLocationAPI 方法,支持动态更新货位信息。

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs |  104 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 66 insertions(+), 38 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
index e5c00a9..eee8cd3 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -468,8 +468,13 @@
                     }
                     if (task.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting)
                     {
-                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
-                        SendAgvTask(station.stationRemark, task.TaskNum);
+                        string TargetAddress = GetLocation(task.PalletCode);
+                        if (TargetAddress == "")
+                        {
+                            return content.Error($"鏈幏鍙栧嚭搴撶粓鐐硅揣浣嶄俊鎭�");
+                        }
+                        task.NextAddress = TargetAddress;
+                        task.TargetAddress = TargetAddress;
                     }
 
                 }
@@ -482,45 +487,21 @@
                     {
                         #region 鍏ュ簱璋冪敤鎺ュ彛鑾峰彇璐т綅鍦板潃
 
-                        //var taskDto = new RequestTaskDto()
-                        //{
-                        //    Position = task.NextAddress,
-                        //    PalletCode = task.PalletCode,
-                        //};
-
-                        //// 鑾峰彇WMSip鍦板潃
-                        //var configz = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
-                        //var wmsBasez = configz.Where(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE).FirstOrDefault()?.ConfigValue;
-                        //var requestLocation = configz.Where(x => x.ConfigKey == SysConfigKeyConst.RequestLocation).FirstOrDefault()?.ConfigValue;
-                        //if (wmsBasez == null || requestLocation == null)
-                        //{
-                        //    throw new InvalidOperationException("WMS IP 鏈厤缃�");
-                        //}
-                        //var wmsIpAddrss = wmsBasez + requestLocation;
-
-                        //// 鍙戦�佽姹傚苟绛夊緟鍝嶅簲
-                        //var abc = HttpHelper.PostAsync(wmsIpAddrss, taskDto.ToJsonString()).Result;
-                        //if (abc == null)
-                        //    return content.Error();
-                        //// 鍙嶅簭鍒楀寲鍝嶅簲鍐呭
-                        //content = JsonConvert.DeserializeObject<WebResponseContent>(abc);
-
-                        //LogFactory.WriteError($"鑾峰彇璐т綅", $"鑾峰彇璐т綅,浠诲姟鍙�:銆恵task.TaskNum}銆�,鎵樼洏鍙凤細銆恵task.PalletCode}銆戣繑鍥炲弬鏁般�恵JsonConvert.SerializeObject(content)}銆�");
-
-                        //// 妫�鏌ョ姸鎬佸苟杩斿洖
-                        //if (!content.Status)
-                        //{
-                        //    return content;
-                        //}
-
-                        //// 鍙嶅簭鍒楀寲浠诲姟鏁版嵁
-                        //var taskResult = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
+                        string TargetAddress= GetLocation(task.PalletCode);
+                        if (TargetAddress == null)
+                        {
+                            return content.Error($"鏈幏鍙栧叆搴撶粓鐐硅揣浣嶄俊鎭�");
+                        }
 
                         task.CurrentAddress = task.NextAddress;
-                        task.NextAddress = task.TargetAddress;
-                        task.TargetAddress = task.NextAddress;
+                        task.NextAddress = TargetAddress;
+                        task.TargetAddress = TargetAddress;
 
                         #endregion 鍏ュ簱璋冪敤鎺ュ彛鑾峰彇璐т綅鍦板潃
+                    }
+                    else if (task.TaskState == (int)TaskInStatusEnum.Line_InExecuting)
+                    {
+                        UpdateStartLocationInfo(task);
                     }
                     else if (task.TaskState == (int)TaskInStatusEnum.SC_InFinish)
                     {
@@ -630,7 +611,7 @@
 
                         taskNew.CurrentAddress = stationManager.stationChildCode;
 
-                        taskNew.NextAddress = task.TargetAddress;
+                        taskNew.NextAddress = taskDTO.TargetAddress;
 
                         taskNew.Floor = stationManager.stationFloor;
 
@@ -693,6 +674,46 @@
             return content;
         }
 
+        public string GetLocation(string palletCode)
+        {
+            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+            var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestLocation)?.ConfigValue;
+            if (wmsBase == null || updateTask == null)
+            {
+                throw new InvalidOperationException("WMS IP 鏈厤缃�");
+            }
+            var wmsIpAddress = wmsBase + updateTask;
+            var keys = new Dictionary<string, object>()
+            {
+                {"palletCode", palletCode}
+            };
+            var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result;
+            WebResponseContent? content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+            if (content.Status)
+            {
+                return content.Data.ToString();
+            }
+            else
+            {
+                return string.Empty;
+            }
+        }
+
+        public void UpdateStartLocationInfo(Dt_Task task)
+        {
+            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+            var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateStartLocationInfo)?.ConfigValue;
+            if (wmsBase == null || updateTask == null)
+            {
+                throw new InvalidOperationException("WMS IP 鏈厤缃�");
+            }
+            var wmsIpAddress = wmsBase + updateTask;
+
+            var result = HttpHelper.PostAsync(wmsIpAddress, task.ToJsonString()).Result;
+        }
+
         public void CompletedTask(int taskNum)
         {
             #region WMS鍚屾浠诲姟瀹屾垚
@@ -740,6 +761,8 @@
                     task.ModifyDate = DateTime.Now;
                     task.Modifier = "System";
                     BaseDal.UpdateData(task);
+
+                    UpdateStartLocationInfo(task);
 
                     content.OK(data: task);
 
@@ -889,6 +912,11 @@
             return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskType == (int)TaskRelocationTypeEnum.Relocation && x.TaskState == (int)TaskRelocationStatusEnum.RelocationNew);
         }
 
+        public Dt_Task QueryExecutingTask(string deviceNo)
+        {
+            return BaseDal.QueryFirst(x => x.Roadway == deviceNo &&( x.TaskState == (int)TaskRelocationStatusEnum.SC_RelocationExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting));
+        }
+
 
         private string GetIpAddress(string baseIp, string name)
         {

--
Gitblit v1.9.3