From bb56b2b6f21acb7c69c02585e5bc534d2f67715f Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 27 三月 2025 17:13:35 +0800
Subject: [PATCH] WMS首页优化,WCS优化AGV和产线、输送线交互逻辑

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs |   65 +++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 18 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 d3bc955..6b49947 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"
@@ -37,6 +37,7 @@
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_QuartzJob.Repository;
 using WIDESEAWCS_QuartzJob.Service;
 
 namespace WIDESEAWCS_TaskInfoService
@@ -44,6 +45,7 @@
     public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
     {
         private readonly IRouterService _routerService;
+        private readonly IRouterRepository _routerRepository;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
         private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository;
         private readonly ITaskHtyService _taskHtyService;
@@ -63,9 +65,10 @@
 
         public List<int> TaskRelocationTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList();
 
-        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, ITaskHtyService taskHtyService, IMapper mapper) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IRouterService routerService, IRouterRepository routerRepository, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, ITaskHtyService taskHtyService, IMapper mapper) : base(BaseDal)
         {
             _routerService = routerService;
+            _routerRepository = routerRepository;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskExecuteDetailRepository = taskExecuteDetailRepository;
             _taskHtyService = taskHtyService;
@@ -86,7 +89,7 @@
                 {
                     if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null)
                     {
-                        continue;
+                        throw new Exception($"浠诲姟鍙枫�恵item.TaskNum}宸插瓨鍦ㄤ换鍔°��");
                     }
                     Dt_Task task = _mapper.Map<Dt_Task>(item);
                     task.Creater = "WMS";
@@ -96,7 +99,8 @@
                         //鏆備笉鑰冭檻澶氳矾寰�
                         if (routers.Count > 0)
                         {
-                            task.TaskState = (int)TaskOutStatusEnum.OutNew;
+
+                            task.TaskState = item.SourceIsPickPlace ? TaskOutStatusEnum.Car_OutFinish.ObjToInt() : TaskOutStatusEnum.OutNew.ObjToInt();
                             task.CurrentAddress = item.SourceAddress;
                             task.NextAddress = routers.FirstOrDefault().ChildPosi;
                         }
@@ -107,7 +111,8 @@
                         //鏆備笉鑰冭檻澶氳矾寰�
                         if (routers.Count > 0)
                         {
-                            task.TaskState = (int)TaskInStatusEnum.InNew;
+                            if (task.TaskType != TaskInboundTypeEnum.PalletInbound.ObjToInt())
+                                task.TaskState = (int)TaskInStatusEnum.InNew;
                             task.CurrentAddress = item.SourceAddress;
                             task.NextAddress = routers.FirstOrDefault().ChildPosi;
                         }
@@ -156,7 +161,7 @@
         /// <returns></returns>
         public Dt_Task QueryExecutingConveyorLineTask(int taskNum, string nextAddress)
         {
-            return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy);
+            return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish), TaskOrderBy);
         }
 
         /// <summary>
@@ -213,16 +218,14 @@
         public Dt_Task QueryStackerCraneRelocationTask(string deviceNo, string currentAddress = "")
         {
             Dt_Task task = null;
+            List<Dt_Task> tasks = new List<Dt_Task>();
             if (string.IsNullOrEmpty(currentAddress))
-                task = BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskRelocationTypes.Contains(x.TaskType), TaskOrderBy);
+                tasks = BaseDal.QueryData(x => x.Roadway == deviceNo && TaskRelocationTypes.Contains(x.TaskType) && x.TaskState < TaskRelocationStatusEnum.SC_RelocationFinish.ObjToInt()).OrderBy(x => x.TaskNum).ToList();
             else
-                task = BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && TaskRelocationTypes.Contains(x.TaskType), TaskOrderBy);
-            if (task != null)
+                tasks = BaseDal.QueryData(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && TaskRelocationTypes.Contains(x.TaskType) && x.TaskState < TaskRelocationStatusEnum.SC_RelocationFinish.ObjToInt()).OrderBy(x => x.TaskNum).ToList();
+            if (tasks != null && tasks.Count > 0)
             {
-                if (task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.RelocationNew || !task.SourceIsPickPlace && task.TaskState == (int)TaskRelocationStatusEnum.CarSource_Finish)
-                    return task;
-                else
-                    return null;
+                task = tasks.First();
             }
             return task;
         }
@@ -367,8 +370,9 @@
                     }
 
                     int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
-
                     task.TaskState = nextStatus;
+                    if (task.SourceIsPickPlace && task.TaskState == TaskOutStatusEnum.OutNew.ObjToInt())
+                        task.TaskState = TaskOutStatusEnum.SC_OutExecuting.ObjToInt();
                 }
                 else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
                 {
@@ -395,16 +399,31 @@
                         return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
                     }
                     int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskRelocationStatusEnum>();
-                    task.TaskState = nextStatus;
+                    if (task.SourceIsPickPlace && task.TaskState == TaskRelocationStatusEnum.RelocationNew.ObjToInt())
+                        task.TaskState = TaskRelocationStatusEnum.SC_RelocationExecuting.ObjToInt();
+                    else
+                        task.TaskState = nextStatus;
                 }
                 else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup)//搴撳唴绉昏溅
                 {
-                    if (task.TaskState >= (int)TaskCarStatusEnum.RelocationCarFinish)
+                    if (task.TaskType == TaskOtherTypeEnum.RelocationCar.ObjToInt())
                     {
-                        return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
+                        if (task.TaskState >= (int)TaskCarStatusEnum.RelocationCarFinish)
+                        {
+                            return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
+                        }
+                        int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskCarStatusEnum>();
+                        task.TaskState = nextStatus;
                     }
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskCarStatusEnum>();
-                    task.TaskState = nextStatus;
+                    else if (task.TaskType == TaskOtherTypeEnum.RelocationCarCharging.ObjToInt())
+                    {
+                        if (task.TaskState >= (int)CarChargingTaskEnum.RelocationCarFinish)
+                        {
+                            return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
+                        }
+                        int nextStatus = task.TaskState.GetNextNotCompletedStatus<CarChargingTaskEnum>();
+                        task.TaskState = nextStatus;
+                    }
                 }
                 else
                 {
@@ -598,6 +617,16 @@
         /// <exception cref="NotImplementedException"></exception>
         public WebResponseContent AddRelocationCarTask(string SourceAddress, string TargetAddress, string ShuttleCarCode = "", string remark = "")
         {
+            if (!string.IsNullOrEmpty(SourceAddress) && SourceAddress != "")
+            {
+                Dt_Task? task = BaseDal.QueryFirst(x => x.SourceAddress == SourceAddress && x.TaskType == TaskOtherTypeEnum.RelocationCar.ObjToInt());
+                if (task != null) return WebResponseContent.Instance.Error();
+            }
+            if (!string.IsNullOrEmpty(TargetAddress) && TargetAddress != "")
+            {
+                Dt_Task? task = BaseDal.QueryFirst(x => x.SourceAddress == TargetAddress && x.TaskType == TaskOtherTypeEnum.RelocationCar.ObjToInt());
+                if (task != null) return WebResponseContent.Instance.Error();
+            }
             #region 鍒涘缓鍫嗗灈鏈虹Щ杞︿换鍔�
             Dt_Task dt_Task = new Dt_Task()
             {

--
Gitblit v1.9.3