From ff24fa06ba2d3a5e271789b8f81f3a3131d19470 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 20 四月 2026 09:29:14 +0800
Subject: [PATCH] 更新代码

---
 项目代码/WIDESEA_WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs |  178 +++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 136 insertions(+), 42 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs"
index f374b24..5907898 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WIDESEA_WCSServer/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -5,19 +5,25 @@
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
 using SqlSugar;
+using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
+using System.Reflection;
+using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.Log;
 using WIDESEAWCS_BasicInfoRepository;
 using WIDESEAWCS_BasicInfoService;
 using WIDESEAWCS_Common;
+using WIDESEAWCS_Common.APIEnum;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
+using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_Core.LogHelper;
 using WIDESEAWCS_DTO.MES;
 using WIDESEAWCS_DTO.TaskInfo;
-using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_ISystemServices;
@@ -43,6 +49,8 @@
         private readonly IDt_StationManagerRepository _stationManagerRepository;
         private readonly IRouterRepository _routerRepository;
         private readonly ITask_HtyRepository _taskHtyRepository;
+        private readonly IApiInfoRepository _apiInfoRepository;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
 
         private Dictionary<string, OrderByType> _taskOrderBy = new()
         {
@@ -56,20 +64,12 @@
 
 
         #region 鑾峰彇鎵�鏈変换鍔$被鍨嬨�佺姸鎬�
-        public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList();
 
-        public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList();
-        public List<int> TaskRelocationboundTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList();
-
-        public List<int> TaskInboundStates => typeof(TaskInStatusEnum).GetEnumIndexList();
-
-        public List<int> TaskOutboundStates => typeof(TaskOutStatusEnum).GetEnumIndexList();
-        public List<int> TaskRelocationboundStates => typeof(TaskRelocationStatusEnum).GetEnumIndexList();
 
         #endregion 鑾峰彇鎵�鏈変换鍔$被鍨嬨�佺姸鎬�
 
 
-        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, IRouterRepository routerRepository, ITask_HtyRepository htyRepository) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, IRouterRepository routerRepository, ITask_HtyRepository htyRepository, IApiInfoRepository apiInfoRepository,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
         {
             _routerService = routerService;
             _taskExecuteDetailService = taskExecuteDetailService;
@@ -80,6 +80,8 @@
             _stationManagerRepository = stationManagerRepository;
             _routerRepository = routerRepository;
             _taskHtyRepository = htyRepository;
+            _apiInfoRepository = apiInfoRepository;
+            _unitOfWorkManage = unitOfWorkManage;
         }
 
         /// <summary>
@@ -139,13 +141,9 @@
             {
                 var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                 if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.CarryGroup)
                 {
-                    task.TaskState = (int)TaskOutStatusEnum.OutPending;
-                }
-                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
-                {
-                    task.TaskState = (int)TaskInStatusEnum.InPending;
+                    task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryException;
                 }
                 task.ExceptionMessage = message;
                 task.ModifyDate = DateTime.Now;
@@ -196,29 +194,15 @@
                 int oldState = task.TaskState;
                 if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.OutbondGroup)
                 {
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
+                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskAGVCarryStatusEnum>();
 
                     task.TaskState = nextStatus;
 
-                    if (task.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish)
+                    if (task.TaskState == (int)TaskAGVCarryStatusEnum.AGV_CarryFinish)
                     {
 
-                        task.ModifyDate = DateTime.Now;
-                        task.Modifier = "System";
-
-                        Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task);
-                        task_Hty.TaskId = 0;
-
-                        BaseDal.DeleteData(task);
-                        _taskHtyRepository.AddData(task_Hty);
+                        BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                     }
-                }
-                else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.InboundGroup)
-                {
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
-                    task.TaskState = nextStatus;
-
-                    
                 }
                 else
                 {
@@ -273,7 +257,7 @@
             {
                 var task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                 if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-                if (task.TaskState != (int)TaskInStatusEnum.InPending && task.TaskState != (int)TaskOutStatusEnum.OutPending)
+                if (task.TaskState != (int)TaskAGVCarryStatusEnum.AGV_CarryException && task.TaskState != (int)TaskAGVCarryStatusEnum.AGV_CarryException)
                 {
                     return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙仮澶�,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
                 }
@@ -285,14 +269,7 @@
                 }
                 else
                 {
-                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-                    {
-                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
-                    }
-                    else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
-                    {
-                        task.TaskState = (int)TaskInStatusEnum.InNew;
-                    }
+                    throw new Exception($"鏈壘鍒颁换鍔″彿{taskNum}鎭㈠鐘舵��");
                 }
 
                 task.ExceptionMessage = string.Empty;
@@ -379,5 +356,122 @@
 
 
         #endregion 閲嶅啓鏂规硶
+
+        /// <summary>
+        /// 鏇存柊浠诲姟淇℃伅鍙婃坊鍔犱换鍔℃槑缁嗚褰�
+        /// </summary>
+        /// <param name="task">浠诲姟鍘熷璞″疄渚�(鏈慨鏀圭殑鏁版嵁瀵硅薄)</param>
+        /// <param name="taskStatus">淇敼鍚庣殑浠诲姟鐘舵��</param>
+        /// <param name="deviceCode">淇敼鍚庣殑璁惧缂栧彿</param>
+        /// <param name="sourceAddress">淇敼鍚庣殑璧峰鍦板潃</param>
+        /// <param name="targetAddress">淇敼鍚庣殑鐩爣鍦板潃</param>
+        /// <param name="currentAddress">淇敼鍚庣殑褰撳墠鍦板潃</param>
+        /// <param name="nextAddress">淇敼鍚庣殑涓嬩竴鍦板潃</param>
+        public void UpdateTask(Dt_Task task, TaskAGVCarryStatusEnum taskStatus, string deviceCode = "", string sourceAddress = "", string targetAddress = "", string currentAddress = "", string nextAddress = "", string roadwayNo = "")
+        {
+            StringBuilder stringBuilder = new StringBuilder(App.User?.UserId == 0 ? $"绯荤粺鑷姩娴佺▼" : "浜哄伐鎵嬪姩娴佺▼");
+            if (task.SourceAddress != sourceAddress && !string.IsNullOrEmpty(sourceAddress))
+            {
+                stringBuilder.Append($",璧峰鍦板潃鐢眥task.SourceAddress}鍙樻洿涓簕sourceAddress}");
+                task.SourceAddress = sourceAddress;
+            }
+            if (task.TargetAddress != targetAddress && !string.IsNullOrEmpty(targetAddress))
+            {
+                stringBuilder.Append($",鐩爣鍦板潃鐢眥task.TargetAddress}鍙樻洿涓簕targetAddress}");
+                task.TargetAddress = targetAddress;
+            }
+            if (task.CurrentAddress != currentAddress && !string.IsNullOrEmpty(currentAddress))
+            {
+                stringBuilder.Append($",褰撳墠浣嶇疆鐢眥task.CurrentAddress}鍙樻洿涓簕currentAddress}");
+                task.CurrentAddress = currentAddress;
+            }
+            if (task.NextAddress != nextAddress && !string.IsNullOrEmpty(nextAddress))
+            {
+                stringBuilder.Append($",涓嬩竴浣嶇疆鐢眥task.NextAddress}鍙樻洿涓簕nextAddress}");
+                task.NextAddress = nextAddress;
+            }
+            if (task.Roadway != roadwayNo && !string.IsNullOrEmpty(roadwayNo))
+            {
+                stringBuilder.Append($",宸烽亾鍙风敱{task.Roadway}鍙樻洿涓簕roadwayNo}");
+                task.Roadway = roadwayNo;
+            }
+            if (task.TaskState != taskStatus.ObjToInt())
+            {
+                string newStatus = $"{taskStatus}";
+                try
+                {
+                    List<int> enums = Enum.GetValues(typeof(TaskAGVCarryStatusEnum)).Cast<int>().ToList();
+                    FieldInfo? fieldInfo = typeof(TaskAGVCarryStatusEnum).GetField((taskStatus).ToString());
+                    if (fieldInfo != null)
+                    {
+                        DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
+                        if (description != null)
+                        {
+                            newStatus = $"{description.Description}({taskStatus})";
+                        }
+                    }
+                }
+                catch { }
+                string oldStatus = $"{task.TaskState}";
+                try
+                {
+                    FieldInfo? fieldInfo2 = typeof(RouterInOutType).GetField(((TaskAGVCarryStatusEnum)task.TaskState).ToString());
+                    if (fieldInfo2 != null)
+                    {
+                        DescriptionAttribute? description2 = fieldInfo2.GetCustomAttribute<DescriptionAttribute>();
+                        if (description2 != null)
+                        {
+                            oldStatus = $"{description2.Description}({task.TaskState})";
+                        }
+                    }
+                }
+                catch { }
+                stringBuilder.Append($",浠诲姟鐘舵�佺敱{oldStatus}鍙樻洿涓簕newStatus}");
+
+                task.TaskState = taskStatus.ObjToInt();
+            }
+            BaseDal.UpdateData(task);
+            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, stringBuilder.ToString());
+        }
+
+        // 鍦ㄧ被涓坊鍔犻潤鎬侀攣瀵硅薄
+        private static readonly object _taskCompleteLock = new object();
+
+        /// <summary>
+        /// 浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <returns></returns>
+        public WebResponseContent TaskCompleted(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+
+            // 浣跨敤閿佺‘淇濆悓涓�浠诲姟涓嶄細骞跺彂澶勭悊
+            lock (_taskCompleteLock)
+            {
+                try
+                {
+                    WriteLog.Write_Log("浠诲姟瀹屾垚", "浠诲姟瀹屾垚鎺ュ彛", "浠诲姟鍙�", $"浠诲姟锛歿taskNum}");
+
+                    // 鍐嶆鏌ヨ浠诲姟鐘舵�侊紝闃叉鍦ㄩ攣绛夊緟鏈熼棿浠诲姟鐘舵�佸凡鏀瑰彉
+                    Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                    if (task == null)
+                    {
+                        return content.Error($"浠诲姟{taskNum}涓嶅瓨鍦�");
+                    }
+                    //浠诲姟瀹屾垚閫昏緫
+                    _unitOfWorkManage.BeginTran();
+
+                    _unitOfWorkManage.CommitTran();
+                    content.OK("浠诲姟瀹屾垚");
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    content.Error(ex.Message);
+                }
+                return content;
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3