From 4f3b0a6727ecfa555892ebea64bd76e5a07cd6fb Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期二, 17 三月 2026 10:01:38 +0800
Subject: [PATCH] feat: 新增WMS异常上报自动恢复异常按钮

---
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs | 1228 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 971 insertions(+), 257 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 d85473f..deda58a 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"
@@ -15,22 +15,40 @@
  *----------------------------------------------------------------*/
 #endregion << 鐗� 鏈� 娉� 閲� >>
 using AutoMapper;
+using Microsoft.AspNetCore.Mvc;
 using Newtonsoft.Json;
+using NPOI.SS.Formula.Functions;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using RYB_PTL_API;
 using SqlSugar;
+using System.Collections.Generic;
+using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
+using System.DirectoryServices.Protocols;
+using System.Linq;
 using System.Net.Http.Headers;
+using System.Security.Policy;
+using System.Text;
+using System.Threading.Tasks;
 using WIDESEA_DTO.Agv;
+using WIDESEA_External.Model;
+using WIDESEAWCS_BasicInfoService;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.APIEnum;
+using WIDESEAWCS_Common.Helper;
 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;
+using WIDESEAWCS_DTO.Agv;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_IBasicInfoRepository;
+using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
@@ -44,6 +62,7 @@
     public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
     {
         private readonly IMapper _mapper;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
         private readonly ICacheService _cacheService;
         private readonly IRouterService _routerService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
@@ -51,7 +70,10 @@
         private readonly IStationMangerRepository _stationMangerRepository;
         private readonly IRouterRepository _routerRepository;
         private readonly IApiInfoRepository _apiInfoRepository;
-        private List<Dt_ApiInfo> apiInfos;
+        private readonly ILocationInfoRepository _locationInfoRepository;
+        private readonly ILocationInfoService _locationInfoService;
+        private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
+        private readonly IErrorInfoRepository _errorInfoRepository;
 
         private Dictionary<string, OrderByType> _taskOrderBy = new()
             {
@@ -60,7 +82,6 @@
                 {nameof(Dt_Task.CreateDate),OrderByType.Asc},
             };
 
-        private List<Dt_Warehouse>? Warehouses = new List<Dt_Warehouse>();
 
         public Dictionary<string, OrderByType> TaskOrderBy { get { return _taskOrderBy; } set { _taskOrderBy = value; } }
 
@@ -70,7 +91,7 @@
 
         public List<int> TaskRelocationTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 900 && x < 1000).ToList();
 
-        public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository, ILocationInfoRepository locationInfoRepository, IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IErrorInfoRepository errorInfoRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _cacheService = cacheService;
@@ -80,301 +101,418 @@
             _stationMangerRepository = stationMangerRepository;
             _routerRepository = routerRepository;
             _apiInfoRepository = apiInfoRepository;
-
-            string? cacheStr = _cacheService.Get(nameof(Dt_Warehouse));
-            if (!string.IsNullOrEmpty(cacheStr))
-            {
-                Warehouses = JsonConvert.DeserializeObject<List<Dt_Warehouse>>(cacheStr);
-            }
-
-
-            string? apiInfoStr = _cacheService.Get("apiInfos");
-            if (!string.IsNullOrEmpty(apiInfoStr))
-            {
-                List<Dt_ApiInfo>? infos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr);
-                if (infos == null || infos.Count == 0)
-                {
-                    apiInfos = new List<Dt_ApiInfo>();
-                }
-                else
-                {
-                    apiInfos = infos;
-                }
-            }
+            _locationInfoRepository = locationInfoRepository;
+            _unitOfWorkManage = unitOfWorkManage;
+            _locationInfoService = locationInfoService;
+            _locationStatusChangeRecordService = locationStatusChangeRecordService;
+            _errorInfoRepository = errorInfoRepository;
         }
+        static object lock_taskReceive = new object();
         /// <summary>
         /// 鎺ユ敹WMS浠诲姟淇℃伅
         /// </summary>
         /// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
         /// <returns>杩斿洖澶勭悊缁撴灉</returns>
-        public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs)
+        public WMSReceiveTaskContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO)
         {
-            WebResponseContent content = new WebResponseContent();
+            WMSReceiveTaskContent content = new WMSReceiveTaskContent();
+            string errorMsg = "";
             try
             {
-                bool flag = false;
-                List<Dt_Task> tasks = new List<Dt_Task>();
-                foreach (var item in taskDTOs)
+                lock (lock_taskReceive)
                 {
-                    if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum) != null)
+                    WriteLog.Write_Log("鍏ュ簱浠诲姟涓嬪彂", "WMS鍏ュ簱浠诲姟鎺ユ敹鍙傛暟", "鎺ユ敹鍙傛暟", $"鍙傛暟锛歿taskDTO.ToJson()}");
+                    List<Dt_Task> tasks = new List<Dt_Task>();
+                    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());
+                    List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData();
+                    ////涓嬪彂浠诲姟缁�
+                    //string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode;
+                    foreach (var item in taskDTO.Tasks.OrderBy(x => x.TaskDescribe.ToStationCode))
                     {
-                        flag = true;
-                        continue;
+                        if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙颁笉鑳戒负绌�");
+                        //鑾峰彇鎿嶄綔鍙�
+                        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;
+                        task.TargetAddress = stationManger.PickStationCode;
+                        //task.GroupId = taskGroup;
+                        task.TaskType = TaskTypeEnum.Outbound.ObjToInt();
+                        task.Roadway = locationInfo.RoadwayNo;
+                        task.DeviceCode = stationManger.CraneCode;
+                        task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
+                        tasks.Add(task);
+                        content.SucessData.Add(new BinCodeObj() { Bincode = item.TaskDescribe.ContainerCode });
                     }
-                    Dt_Task task = _mapper.Map<Dt_Task>(item);
-                    task.Creater = "WMS";
-                    task.TaskState = (int)TaskStatusEnum.New;
-                    task.CurrentAddress = item.SourceAddress;
 
-                    Dt_Router? router;
-                    
+                    locationInfos.ForEach(x =>
+                    {
+                        x.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
+                    });
+                    //娣诲姞浠诲姟鏇存柊璐т綅鏁版嵁
+                    _unitOfWorkManage.BeginTran();
+                    BaseDal.AddData(tasks);
+                    _locationInfoRepository.UpdateData(locationInfos);
+                    _unitOfWorkManage.CommitTran();
+                    _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
+                    if (tasks.Count > 0)
+                    {
+                        _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.InStock, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, tasks);
+                    }
+                    content.OK(errorMsg.IsNullOrEmpty() ? "鎴愬姛" : errorMsg);
                 }
-                BaseDal.AddData(tasks);
-
-                _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
-
-                content = (flag || tasks.Count > 0) ? WebResponseContent.Instance.OK("鎴愬姛") : WebResponseContent.Instance.Error("澶辫触");
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error($"浠诲姟鎺ユ敹閿欒,閿欒淇℃伅:{ex.Message}");
+                content.Error($"浠诲姟鎺ユ敹閿欒,閿欒淇℃伅:{ex.Message}");
             }
             return content;
         }
 
         /// <summary>
-        /// 鏍规嵁鎵樼洏鍙枫�佽捣濮嬪湴鍧�鍚慦MS璇锋眰浠诲姟
+        /// 瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟
         /// </summary>
-        /// <param name="palletCode">鎵樼洏鍙�</param>
-        /// <param name="sourceAddress">璧峰鍦板潃</param>
         /// <returns></returns>
-        public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress, string materielBoxCode = "")
+        public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode, string stationCode, int type = 0)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == sourceAddress);
-                if (stationManger == null)
+                List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData();
+                Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode);
+                if (locationInfo != null) throw new Exception($"搴撲綅鏂欑鍙穥containerFlowDTO.ContainerCode}宸插瓨鍦�");
+                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 WebResponseContent.Instance.Error($"鏈壘鍒扮珯鍙颁俊鎭�");
+                    Thread.Sleep(500);
+                    return content.OK();
                 }
-                string address = AppSettings.Get("WMSApiAddress");
-                if (string.IsNullOrEmpty(address))
+                if (taskOld != null && taskOld.PalletCode == containerFlowDTO.ContainerCode && taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() && taskOld.TaskState == TaskStatusEnum.CL_Executing.ObjToInt() && taskOld.DeviceCode != deviceCode)
                 {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
+                    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();
                 }
-                string responseStr = "";
-                if (!string.IsNullOrEmpty(materielBoxCode))
+                else if (taskOld != null)
                 {
-                    responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}&materielBoxCode={materielBoxCode}");
+                    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($"鍙敤璐т綅涓嶈冻!");
+                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
+                //鍒涘缓浠诲姟
+                Dt_Task task = new Dt_Task();
+                task.PalletCode = containerFlowDTO.ContainerCode;
+                task.SourceAddress = containerFlowDTO.SlotCode;
+                task.CurrentAddress = containerFlowDTO.SlotCode;
+                task.NextAddress = stationManger.StationCode;
+                task.TargetAddress = "";
+                task.WMSId = "";
+                task.TaskType = TaskTypeEnum.Inbound.ObjToInt();
+                task.Roadway = noInLocation.RoadwayNo;
+                task.DeviceCode = stationManger.StationDeviceCode;
+                task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
+
+                //娣诲姞浠诲姟
+                int taskId = BaseDal.AddData(task);
+                if (type > 0)
+                {
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鎵嬪姩鎸夐挳鍏ュ簱");
                 }
                 else
                 {
-                    responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}");
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鍒涘缓鍏ュ簱浠诲姟");
                 }
-                WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-                if (responseContent != null && responseContent.Status && responseContent.Data != null)
-                {
-                    WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString());
-                    if (taskDTO != null)
-                    {
-                        content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
-                    }
-                }
-
+                WriteLog.Write_Log("鍏ュ簱浠诲姟涓嬪彂", "瀹瑰櫒鍏ュ簱浠诲姟娣诲姞浠诲姟", "娣诲姞浠诲姟", $"浠诲姟锛歿task.ToJson()}");
+                content.OK("鎴愬姛");
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error(ex.Message);
+                content.Error($"閿欒淇℃伅:{ex.Message}");
             }
             return content;
         }
-        // <summary>
-        /// 璇锋眰鍏ュ簱浠诲姟
+        /// <summary>
+        /// 鎾澧欏垵濮嬪寲
         /// </summary>
-        /// <param name="palletCode">鎵樼洏鍙�</param>
-        /// <param name="sourceAddress">璧峰鍦板潃</param>
-        /// /// <param name="roadWay">宸烽亾</param>
         /// <returns></returns>
-        public WebResponseContent RequestYLWMSTaskSimple(string palletCode, string sourceAddress,int taskNum=0)
+        public WebResponseContent InitLight()
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                string address = AppSettings.Get("WMSApiAddress");
-                if (string.IsNullOrEmpty(address))
+                EPLightContent lightContent = INITIALIZATION();
+                if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}");
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 缁撴潫浣滀笟
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent EndLight()
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                EPLightContent lightContent = ENDWORK();
+                if (lightContent.Result != "0") throw new Exception($"{lightContent.Msg}");
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 涓�鏈熸挱绉嶅涓嬪彂
+        /// </summary>
+        /// <returns></returns>
+        public EPLightContent Phase1PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
+        {
+            EPLightContent content = new EPLightContent();
+
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.Phase1PickOrderInfoRequest.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
                 {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
+                    return content.Error("鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛锛岃妫�鏌ユ帴鍙i厤缃�");
                 }
-                string responseStr = HttpHelper.Get($"{address}/api/Task/RequestYLWMSTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}&taskNum{taskNum}");
-                WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-                if (responseContent != null && responseContent.Status && responseContent.Data != null)
+
+                bool allSuccess = true;
+                StringBuilder errorMessages = new StringBuilder();
+
+                foreach (EPLightSendDTO lightSendDTO in lightSendDTOs)
                 {
-                    WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString());
-                    if (taskDTO != null)
+                    try
                     {
-                        content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
+                        bool operationResult;
+
+                        // 澶勭悊鐏厜绫诲瀷杞崲
+                        if (!int.TryParse(lightSendDTO.LIGHTTYPE, out int lightType))
+                        {
+                            allSuccess = false;
+                            errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夌被鍨� '{lightSendDTO.LIGHTTYPE}'");
+                            continue;
+                        }
+
+                        // 澶勭悊鍏抽棴鐏厜璇锋眰
+                        if (lightType == 2)
+                        {
+                            operationResult = RYB_PTL.RYB_PTL_CloseDigit5(url, lightSendDTO.LOCATION);
+                            // TODO: 鍏抽棴鐏厜鍥炶皟澶勭悊
+                            //List<EPLightBackDTO> lightBackDTOs = new List<EPLightBackDTO>();
+                            //List<TaskBackLight> taskBackLights = lightSendDTOs.Select(x => new TaskBackLight()
+                            //{
+                            //    TagNo = "B1",
+                            //    TagCode = x.LOCATION,
+                            //}).ToList();
+                            //content = WMSLightBack(taskBackLights);
+                        }
+                        // 澶勭悊鏄剧ず鐏厜璇锋眰
+                        else
+                        {
+                            // 澶勭悊鐏厜棰滆壊杞崲
+                            if (!int.TryParse(lightSendDTO.LIGHTCOLOR, out int lightColor))
+                            {
+                                allSuccess = false;
+                                errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 閿欒: 鏃犳晥鐨勭伅鍏夐鑹� '{lightSendDTO.LIGHTCOLOR}'");
+                                continue;
+                            }
+
+                            operationResult = RYB_PTL.RYB_PTL_DspDigit5(
+                                url,
+
+                                lightSendDTO.LOCATION,
+                                lightSendDTO.QUANTITY,
+                                lightType,
+                                lightColor);
+                        }
+                        if (!operationResult)
+                        {
+                            allSuccess = false;
+                            errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 鎿嶄綔澶辫触");
+                        }
                     }
+
+                    catch (Exception ex)
+                    {
+                        allSuccess = false;
+                        errorMessages.AppendLine($"浣嶇疆 {lightSendDTO.LOCATION} 澶勭悊寮傚父: {ex.Message}");
+                    }
+                }
+
+                return allSuccess
+                    ? content.OK("鎵�鏈夋挱绉嶅涓嬪彂鎿嶄綔鎴愬姛")
+                    : content.Error(errorMessages.ToString());
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鎾澧欎寒鐏�
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent SendLight(TaskSendLight taskSendLight)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (taskSendLight.TagNo == "B1")
+                {
+                    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" => "4",
+                                "Green" => "2",
+                                "Red" => "1",
+                                _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
+                            },
+                            ORDERTYPE="1",
+                            LIGHTTYPE=taskSendLight.Mode.ToString(),
+                        }
+                    };
+                    EPLightContent pLightContent = Phase1PickOrderInfoRequest(lightSendDTOs);
+                    if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+                    content.OK();
+                }
+                else 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="1",
+                            LIGHTTYPE=taskSendLight.Mode.ToString(),
+                        }
+                    };
+                    EPLightContent pLightContent = PickOrderInfoRequest(lightSendDTOs);
+                    if (pLightContent.Result != "0") throw new Exception($"{pLightContent.Msg}");
+                    content.OK();
                 }
                 else
                 {
-                    content = responseContent ?? content.Error("缁撴灉閿欒");
+                    content.OK();
                 }
 
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error(ex.Message);
+                content.Error(ex.Message);
             }
             return content;
         }
-        // <summary>
-        /// 璇锋眰鍏ュ簱宸烽亾
+        static object lock_requestInTask = new object();
+        /// <summary>
+        /// 鐢宠鍏ュ簱
         /// </summary>
         /// <returns></returns>
-        public WebResponseContent AssignCPRoadwayNo()
+        public WebResponseContent RequestInTask(string stationCode, string barCode)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                string address = AppSettings.Get("WMSApiAddress");
-                if (string.IsNullOrEmpty(address))
+                lock (lock_requestInTask)
                 {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
+                    Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt());
+                    if (task == null) throw new Exception($"{barCode}鏂欑鏈壘鍒颁换鍔�!");
+                    Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation();
+                    if (locationInfo == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
+                    task.NextAddress = locationInfo.LocationCode;
+                    task.TargetAddress = locationInfo.LocationCode;
+                    task.CurrentAddress = stationCode;
+                    task.DeviceCode = "AGV";
+                    task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
+                    locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
+                    //鏇存柊浠诲姟鍜岃揣浣嶆暟鎹�
+                    _unitOfWorkManage.BeginTran();
+                    BaseDal.UpdateData(task);
+                    _locationInfoRepository.UpdateData(locationInfo);
+                    _unitOfWorkManage.CommitTran();
+                    _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, $"鍒嗛厤璐т綅{locationInfo.LocationCode}");
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Free, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation, task.TaskNum);
+                    WriteLog.Write_Log("鍏ュ簱浠诲姟涓嬪彂", "鐢宠鍏ュ簱鎺ュ彛", "鏇存柊浠诲姟", $"浠诲姟锛歿task.ToJson()}");
+                    content.OK("鎴愬姛");
                 }
-                string responseStr = HttpHelper.Get($"{address}/api/Task/AssignCPRoadwayNo");
-                
-                if (!responseStr.IsNullOrEmpty())
-                {
-                    content.OK("鎴愬姛", responseStr);
-                }
-
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error(ex.Message);
+                _unitOfWorkManage.RollbackTran();
+                content.Error($"閿欒淇℃伅:{ex.Message}");
             }
             return content;
         }
 
-        // <summary>
-        /// 璇锋眰鍘熸枡鍏ュ簱宸烽亾
-        /// </summary>
-        /// <returns></returns>
-        public WebResponseContent AssignYLRoadwayNo(string palletCode)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                string address = AppSettings.Get("WMSApiAddress");
-                if (string.IsNullOrEmpty(address))
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
-                }
-                string responseStr = HttpHelper.Get($"{address}/api/Task/AssignYLRoadwayNo?palletCode={palletCode}");
-                WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-                if (responseContent != null && responseContent.Status && responseContent.Data != null)
-                {
-                    content = responseContent;
-                }
-
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-        // <summary>
-        /// 璇锋眰鍏ュ簱浠诲姟
-        /// </summary>
-        /// <param name="palletCode">鎵樼洏鍙�</param>
-        /// <param name="sourceAddress">璧峰鍦板潃</param>
-        /// /// <param name="roadWay">宸烽亾</param>
-        /// <returns></returns>
-        public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress,string roadWay="", int taskType=630, int taskNum = 0, string targetAddress = "")
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                //string address = AppSettings.Get("WMSApiAddress");
-                //if (string.IsNullOrEmpty(address))
-                //{
-                //    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
-                //}
-                //string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}");
-                //WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-                //if (responseContent != null && responseContent.Status && responseContent.Data != null)
-                //{
-                //    WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString());
-                //    if (taskDTO != null)
-                //    {
-                WMSTaskDTO? taskDTO = new WMSTaskDTO()
-                {
-                    TaskNum = taskNum ==0 ? DateTime.Now.ToString("mmss").ObjToInt(): taskNum,
-                    PalletCode= palletCode,
-                    RoadWay= roadWay,
-                    TaskType= taskType,
-                    PalletType=1,
-                    TaskStatus= TaskStatusEnum.New.ObjToInt(),
-                    SourceAddress= sourceAddress,
-                    TargetAddress= targetAddress,
-                    WarehouseId=2,
-                    Grade=0,
-                };
-                content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
-                //    }
-                //}
-
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-        public WebResponseContent MESBoxCodeNotice(string boxCode)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                string address = AppSettings.Get("WMSApiAddress");
-                if (string.IsNullOrEmpty(address))
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒癢MSApi鍦板潃");
-                }
-                string responseStr = HttpHelper.Get($"{address}/api/Mes/MESBoxCodeNotice?boxCode={boxCode}");
-                return content.OK(responseStr);
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
         public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null)
         {
             string result = string.Empty;
             DateTime beginDate = DateTime.Now;
             try
             {
-                using (HttpContent httpContent = new StringContent(requestJson))
+                using (HttpContent httpContent = new StringContent(string.Empty))
                 {
                     httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
-
                     using HttpClient httpClient = new HttpClient();
                     httpClient.Timeout = new TimeSpan(0, 0, 30);
-                    string LoginToken = AppSettings.Get("MESLoginToken");
-                    headers = new Dictionary<string, string>
-                    {
-                        //姝e紡
-                        { "LoginToken", LoginToken }
-                    };
-                    if (headers != null)
-                    {
-                        foreach (var header in headers)
-                            httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
-                    }
                     HttpResponseMessage responseMessage = httpClient.PostAsync(serviceAddress, httpContent).Result;
                     result = responseMessage.Content.ReadAsStringAsync().Result;
                 }
@@ -388,47 +526,6 @@
             {
                 Logger.Add(serviceAddress, requestJson == null ? "" : requestJson, result, beginDate);
             }
-        }
-
-        /// <summary>
-        /// 鍚慦MS鐢宠鍒嗛厤璐т綅
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="roadwayNo">宸烽亾鍙�</param>
-        /// <returns></returns>
-        public string? RequestAssignLocation(int taskNum, string roadwayNo)
-        {
-            string address = AppSettings.Get("WMSApiAddress");
-            if (string.IsNullOrEmpty(address)) throw new Exception("鏈壘鍒癢MSApi鍦板潃");
-            string responseStr = HttpHelper.Get($"{address}/api/Task/AssignInboundTaskLocation?taskNum={taskNum}&roadwayNo={roadwayNo}");
-
-            WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-            if (responseContent != null && responseContent.Status && responseContent.Data != null)
-            {
-                return responseContent.Data.ToString();
-            }
-
-            return "";
-        }
-        /// <summary>
-        /// 鍚慦MS鐢宠鍑哄簱AGV缁堢偣
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <returns></returns>
-        /// <exception cref="Exception"></exception>
-        public string? RequestTargetAddress(int taskNum)
-        {
-            string address = AppSettings.Get("WMSApiAddress");
-            if (string.IsNullOrEmpty(address)) throw new Exception("鏈壘鍒癢MSApi鍦板潃");
-            string responseStr = HttpHelper.Get($"{address}/api/Task/AssignOutTargetAddress?taskNum={taskNum}");
-
-            WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr);
-            if (responseContent != null && responseContent.Status && responseContent.Data != null)
-            {
-                return responseContent.Data.ToString();
-            }
-
-            return "";
         }
 
         /// <summary>
@@ -448,8 +545,8 @@
                 task.ModifyDate = DateTime.Now;
                 BaseDal.UpdateData(task);
 
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, task.ExceptionMessage);
-
+                _taskExecuteDetailService.AddTaskExecuteDetail(task, task.ExceptionMessage);
+                WriteLog.Write_Log("鏇存柊浠诲姟寮傚父淇℃伅", "鏇存柊浠诲姟鎺ュ彛", "鏇存柊浠诲姟", $"浠诲姟锛歿task.ToJson()}");
                 content = WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -490,7 +587,7 @@
 
                 BaseDal.UpdateData(task);
 
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"浜哄伐鎭㈠鎸傝捣浠诲姟,鎭㈠鎸傝捣鏃朵换鍔$姸鎬併�恵task.TaskState}銆�");
+                _taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐鎭㈠鎸傝捣浠诲姟,鎭㈠鎸傝捣鏃朵换鍔$姸鎬併�恵task.TaskState}銆�");
 
                 content = WebResponseContent.Instance.OK();
             }
@@ -531,7 +628,7 @@
 
                 BaseDal.UpdateData(task);
 
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"浜哄伐灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戝洖婊氬埌銆恵task.TaskState}銆�");
+                _taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戝洖婊氬埌銆恵task.TaskState}銆�");
 
                 content = WebResponseContent.Instance.OK();
             }
@@ -542,7 +639,7 @@
             return content;
         }
 
-        
+
         /// <summary>
         /// 鎺ュ彈WMS鎵嬪姩瀹屾垚浠诲姟
         /// </summary>
@@ -552,6 +649,7 @@
         {
             try
             {
+                WriteLog.Write_Log("鎺ュ彈WMS鎵嬪姩瀹屾垚浠诲姟", "鎺ュ彈WMS鎵嬪姩瀹屾垚浠诲姟鎺ュ彛", "浠诲姟鍙�", $"浠诲姟鍙凤細{taskNum}");
                 Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                 if (task != null)
                 {
@@ -565,10 +663,626 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
-
-        public Dt_Task QueryBarCodeAGVFinishTask(int TaskNum, string currentAddress)
+        /// <summary>
+        /// AGV浠诲姟鏀捐
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent AgvTaskFlow(string code)
         {
-            return BaseDal.QueryFirst(x => TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.AGV_Finish && x.CurrentAddress == currentAddress && x.TaskNum == TaskNum, TaskOrderBy);
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                WriteLog.Write_Log("AGV浠诲姟鏀捐", "AGV浠诲姟鏀捐鎺ュ彛", "鏂欑鍙�", $"鏂欑锛歿code}");
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.AgvTaskFlow.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url)) throw new Exception($"{code},鏈壘鍒癆GV浠诲姟鏀捐鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                AgvTaskFlowDTO agvTaskFlowDTO = new AgvTaskFlowDTO()
+                {
+                    RequestId = Guid.NewGuid().ToString().Replace("-", ""),
+                    MissionCode = code
+                };
+                string request = JsonConvert.SerializeObject(agvTaskFlowDTO, settings);
+                string response = HttpHelper.Post(url, request);
+                WriteLog.Write_Log("AGV浠诲姟鏀捐鎺ュ彛璇锋眰AGV", "AGV浠诲姟鏀捐鎺ュ彛", $"璇锋眰锛歿request}锛屽洖浼狅細{response}");
+                AgvResponseContent agvResponse = JsonConvert.DeserializeObject<AgvResponseContent>(response) ?? throw new Exception($"{code},鏈帴鏀跺埌AGV浠诲姟鏀捐杩斿洖鍊�");
+                if (!agvResponse.Success) throw new Exception($"鏂欑{code},AGV浠诲姟鏀捐閿欒,淇℃伅:{agvResponse.Message}");
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// WMS鏂欑鍒拌揪鎷i�変綅涓婃姤
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent WMSPickUp(string stationCode, string pickCode)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                WriteLog.Write_Log("WMS鏂欑鍒拌揪鎷i�変綅涓婃姤", "WMS鏂欑鍒拌揪鎷i�変綅涓婃姤鎴愭帴鍙�", "淇℃伅", $"鎷i�変綅锛歿stationCode}锛屾枡绠憋細{pickCode}");
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSPickArrivedUp.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url)) throw new Exception($"鏈壘鍒癢MS鏂欑鍒拌揪鎷i�変綅涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                ContainerArriveDTO containerArriveDTO = new ContainerArriveDTO()
+                {
+                    SlotCode = stationCode,
+                    ContainerCode = pickCode
+                };
+                string request = JsonConvert.SerializeObject(containerArriveDTO, settings);
+                string response = HttpHelper.Post(url, request);
+                WriteLog.Write_Log("涓婃姤WMS鏂欑鍒拌揪", "涓婃姤WMS鏂欑鍒拌揪", "淇℃伅", $"璇锋眰锛歿request}锛屽洖浼狅細{response}");
+                WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{pickCode},鏈帴鏀跺埌WMS鏂欑鍒拌揪鎷i�変綅涓婃姤杩斿洖鍊�");
+                if (wMSResponse.Code != "0") throw new Exception($"鏂欑{pickCode}WMS鏂欑鍒拌揪鎷i�変綅涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}");
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <returns></returns>
+        public WebResponseContent TaskCompleted(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                WriteLog.Write_Log("浠诲姟瀹屾垚", "浠诲姟瀹屾垚鎺ュ彛", "浠诲姟鍙�", $"浠诲姟锛歿taskNum}");
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//鍑哄簱浠诲姟瀹屾垚閫昏緫
+                {
+                    Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                    if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+                    {
+                        return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
+                    }
+                    task.TaskState = TaskStatusEnum.Finish.ObjToInt();
+                    locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                    locationInfo.PalletCode = "";
+                    //鏂欑鍑哄簱瀹屾垚涓婃姤缁橶MS
+                    string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress;
+                    if (string.IsNullOrEmpty(url))
+                    {
+                        _taskExecuteDetailService.AddTaskExecuteDetail(task, $"鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                        UpdateTaskExceptionMessage(taskNum, $"鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                        return content.Error($"{taskNum},鏈壘鍒癢MS鍑哄簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                    }
+                    ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO()
+                    {
+                        TaskCode = task.TaskNum.ToString(),
+                        ContainerCode = task.PalletCode,
+                        StationCode = task.TargetAddress,
+                        LocationCode = task.SourceAddress,
+                        CompleteType = 1
+                    };
+                    string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
+
+                    _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);
+                    WriteLog.Write_Log("WMS鍑哄簱浠诲姟瀹屾垚鍥炰紶", "浠诲姟瀹屾垚鎺ュ彛", "浠诲姟淇℃伅", $"璇锋眰锛歿request}锛屽洖浼狅細{response}");
+                    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)//鍏ュ簱浠诲姟瀹屾垚閫昏緫
+                {
+                    string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress;
+                    if (string.IsNullOrEmpty(url))
+                    {
+                        _taskExecuteDetailService.AddTaskExecuteDetail(task, $"鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                        UpdateTaskExceptionMessage(taskNum, $"鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                        return content.Error($"{taskNum},鏈壘鍒癢MS鍏ュ簱涓婃姤鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                    }
+                    ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO()
+                    {
+                        TaskCode = task.TaskNum.ToString(),
+                        ContainerCode = task.PalletCode,
+                        StationCode = task.SourceAddress,
+                        LocationCode = task.TargetAddress,
+                        CompleteType = 2
+                    };
+                    string request = JsonConvert.SerializeObject(containerInFinishDTO, settings);
+
+                    Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                    if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+                    {
+                        return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
+                    }
+                    task.TaskState = TaskStatusEnum.Finish.ObjToInt();
+                    locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                    locationInfo.PalletCode = task.PalletCode;
+                    _unitOfWorkManage.BeginTran();
+                    _locationInfoRepository.UpdateData(locationInfo);
+                    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);
+                    WriteLog.Write_Log("WMS鍏ュ簱浠诲姟瀹屾垚鍥炰紶", "浠诲姟瀹屾垚鎺ュ彛", "浠诲姟淇℃伅", $"璇锋眰锛歿request}锛屽洖浼狅細{response}");
+                    WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},鏈帴鏀跺埌WMS鍏ュ簱涓婃姤杩斿洖鍊�");
+                    if (wMSResponse.Code != "0") content.Message = $"鍏ュ簱浠诲姟{task.TaskNum}WMS鍏ュ簱涓婃姤閿欒,淇℃伅:{wMSResponse.Msg}";
+                }
+                content.OK("浠诲姟瀹屾垚");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浜哄伐鎵嬪姩鍙栨秷鎸囧畾浠诲姟
+        /// </summary>
+        /// <param name="taskNum">浠诲姟缂栧彿</param>
+        /// <returns>鎿嶄綔缁撴灉</returns>
+        public WebResponseContent ManualTaskCancellation(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浜哄伐鎵嬪姩鍙栨秷鎸囧畾浠诲姟", "浠诲姟鍙�", $"浠诲姟锛歿taskNum}");
+                // 1. 鑾峰彇浠诲姟淇℃伅
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null) return content.Error($"浠诲姟{taskNum}涓嶅瓨鍦�");
+
+                TaskTypeGroup group = task.TaskType.GetTaskTypeGroup();
+                if (group == TaskTypeGroup.InboundGroup)// 鍏ュ簱浠诲姟鍙栨秷
+                {
+                    // 鑾峰彇鐩爣璐т綅
+                    Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                    if (locationInfo == null) return content.Error($"鐩爣璐т綅{task.TargetAddress}涓嶅瓨鍦�");
+                    // 楠岃瘉璐т綅鐘舵��
+                    if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+                        return content.Error($"{task.TargetAddress}璐т綅鐘舵�佸紓甯革紝鏃犳硶鍙栨秷");
+
+                    // 鎭㈠璐т綅鐘舵��
+                    locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); // 鎭㈠涓虹┖闂茬姸鎬�
+                    locationInfo.PalletCode = ""; // 娓呯┖鎵樼洏鍙�
+                    // 鏇存柊鏁版嵁搴�
+                    _unitOfWorkManage.BeginTran();
+                    _locationInfoRepository.UpdateData(locationInfo);
+                    BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.浜哄伐鍒犻櫎);
+                    _unitOfWorkManage.CommitTran();
+                    // 璁板綍鐘舵�佸彉鏇�
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
+                        locationInfo,
+                        LocationStatusEnum.Lock,
+                        LocationStatusEnum.Free,
+                        LocationChangeType.InboundCancelled,
+                        task.TaskNum
+                    );
+                    content.OK("浠诲姟鍙栨秷鎴愬姛");
+                }
+                else
+                {
+                    content.Error("鍙兘鍏ュ簱浠诲姟鍙栨秷锛�");
+                }
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error($"鍙栨秷澶辫触: {ex.Message}");
+                // 璁板綍璇︾粏閿欒
+                _taskExecuteDetailService.AddTaskExecuteDetail(
+                    new Dt_Task { TaskNum = taskNum },
+                    $"浠诲姟鍙栨秷寮傚父: {ex.Message}"
+                );
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浠诲姟鍙栨秷
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent TaskCancelCompleted(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浠诲姟鍙栨秷鎺ュ彛", "浠诲姟鍙�", $"浠诲姟锛歿taskNum}");
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//鍑哄簱浠诲姟瀹屾垚閫昏緫
+                {
+                    Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                    if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt())
+                    {
+                        return content.Error($"{locationInfo.LocationCode}璐т綅鐘舵�佷笉姝g‘");
+                    }
+                    task.TaskState = TaskStatusEnum.Cancel.ObjToInt();
+                    locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                    _unitOfWorkManage.BeginTran();
+                    _locationInfoRepository.UpdateData(locationInfo);
+                    BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+                    _unitOfWorkManage.CommitTran();
+                    _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, LocationStatusEnum.Lock, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted, task.TaskNum);
+                    content.OK();
+                }
+                else
+                {
+                    content.Error($"鏈壘鍒板嚭搴撲换鍔taskNum}");
+                }
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浠诲姟鍙栨秷
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent TaskCancel(List<TaskCancel> taskCancels)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                // 鍙傛暟楠岃瘉
+                if (taskCancels == null || taskCancels.Count == 0)
+                {
+                    return content.Error("浼犲叆鍙傛暟涓嶈兘涓虹┖");
+                }
+
+                WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浠诲姟鍙栨秷鎺ュ彛", "浠诲姟鍙栨秷", $"浠诲姟锛歿taskCancels.ToJson()}");
+
+                // 鑾峰彇鎵�鏈夊嚭搴撲换鍔★紙鍙煡璇竴娆★級
+                List<Dt_Task> outTasks = BaseDal.QueryData(x =>
+                    x.TaskType == TaskTypeEnum.Outbound.ObjToInt());
+
+                if (outTasks.Count == 0)
+                {
+                    return content.Error("鏈壘鍒板搴旂殑浠诲姟");
+                }
+
+                // 鎸塆roupId鍒嗙粍澶勭悊
+                var tasksByGroup = outTasks.GroupBy(x => x.GroupId)
+                                           .Where(g => !string.IsNullOrEmpty(g.Key))
+                                           .ToDictionary(g => g.Key, g => g.ToList());
+
+                List<Dt_Task> cancelTasks = new List<Dt_Task>();
+                List<Dt_Task> cancelTasksCompleted = new List<Dt_Task>();
+                // 鏀堕泦鎵�鏈夐渶瑕佹鏌ョ殑浠诲姟缁�
+                var groupsToCheck = new List<List<Dt_Task>>();
+
+                foreach (var taskCancel in taskCancels)
+                {
+                    // 鎵惧埌璇ヤ换鍔℃墍鍦ㄧ殑缁�
+                    var group = tasksByGroup.Values.FirstOrDefault(g =>
+                        g.Any(t => t.PalletCode == taskCancel.ContainerCode));
+
+                    if (group != null && !groupsToCheck.Contains(group))
+                    {
+                        groupsToCheck.Add(group);
+                    }
+                }
+                // 楠岃瘉浠诲姟鐘舵��
+                foreach (var group in groupsToCheck)
+                {
+                    var firstTask = group.FirstOrDefault();
+                    if (firstTask == null) continue;
+
+                    // 妫�鏌ョ粍鍐呮墍鏈変换鍔$姸鎬�
+                    foreach (var task in group)
+                    {
+                        if (task.TaskState == TaskStatusEnum.AGV_TakeFinish.ObjToInt())
+                        {
+                            task.IsCancel = 1;
+                            cancelTasks.Add(task);
+                        }
+                        else if (task.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt())
+                        {
+                            cancelTasksCompleted.Add(task);
+                        }
+                        else
+                        {
+                            return content.Error($"浠诲姟鍙栨秷澶辫触{task.PalletCode}浠诲姟鐘舵�佷笉鍙彇娑堬紒");
+                        }
+                    }
+                }
+                //WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浠诲姟鍙栨秷鎺ュ彛", "浠诲姟鍙栨秷", $"浠诲姟锛歿taskCancels.ToJson()}");
+                //if (taskCancels==null || taskCancels.Count<=0)
+                //{
+                //    return content.Error("浼犲叆涓嶈兘涓虹┖");
+                //}
+                ////鑾峰彇鎵�鏈夋枡绠�
+                //List<Dt_Task> outTasks = BaseDal.QueryData(x=>x.TaskType==TaskTypeEnum.Outbound.ObjToInt());
+                //List<Dt_Task> cancelTasks = new List<Dt_Task>();
+                //List<Dt_Task> cancelTasksCompleted = new List<Dt_Task>();
+                //HashSet<string> processedGroups = new HashSet<string>();
+                ////鍒ゆ柇鏄惁鏈変换鍔″瓨鍦�
+                //foreach (var item in taskCancels)
+                //{
+                //    Dt_Task? taskExist = outTasks.FirstOrDefault(x=>x.PalletCode == item.ContainerCode);
+                //    if (taskExist==null)
+                //    {
+                //        content.Message += $"{item.ContainerCode}浠诲姟涓嶅瓨鍦�";
+                //        WriteLog.Write_Log("浠诲姟鍙栨秷鎺ユ敹", "浠诲姟鍙栨秷鎺ュ彛", "浠诲姟涓嶅瓨鍦�", $"浠诲姟锛歿item.ContainerCode}");
+                //        continue;
+                //    }
+                //    if (string.IsNullOrEmpty(taskExist.GroupId))
+                //    {
+                //        continue;
+                //    }
+                //    processedGroups.Add(taskExist.GroupId);
+                //    //if (taskExist.TaskState == TaskStatusEnum.AGV_TakeFinish.ObjToInt())
+                //    //{
+                //    //    taskExist.IsCancel = 1;
+                //    //    cancelTasks.Add(taskExist);
+                //    //}
+                //    //else if(taskExist.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt())
+                //    //{
+                //    //    cancelTasksCompleted.Add(taskExist);
+                //    //}
+                //    //else
+                //    //{
+                //    //    return content.Error($"浠诲姟鍙栨秷澶辫触{item.TaskCode}浠诲姟鐘舵�佷笉鍙彇娑堬紒");
+                //    //}
+                //}
+                //// 鍙栨秷鏁翠釜缁�
+                //foreach(var processed in processedGroups)
+                //{
+                //    List<Dt_Task> groupTask = BaseDal.QueryData(x => x.TaskType == TaskTypeEnum.Outbound.ObjToInt() && x.GroupId == processed);
+                //    foreach (var group in groupTask)
+                //    {
+                //        if (group.TaskState == TaskStatusEnum.AGV_TakeFinish.ObjToInt())
+                //        {
+                //            group.IsCancel = 1;
+                //            cancelTasks.Add(group);
+                //        }
+                //        else if (group.TaskState == TaskStatusEnum.AGV_Executing.ObjToInt())
+                //        {
+                //            cancelTasksCompleted.Add(group);
+                //        }
+                //        else
+                //        {
+                //            return content.Error($"浠诲姟鍙栨秷澶辫触{group.PalletCode}浠诲姟鐘舵�佷笉鍙彇娑堬紒");
+                //        }
+                //    }
+                //}
+
+                _unitOfWorkManage.BeginTran();
+                BaseDal.UpdateData(cancelTasks);
+                foreach (var item in cancelTasksCompleted)
+                {
+                    WebResponseContent responseContent = TaskCancelCompleted(item.TaskNum);
+                    if (!responseContent.Status)
+                    {
+                        throw new Exception(responseContent.Message);
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+                cancelTasks.AddRange(cancelTasksCompleted);
+                foreach (var item in cancelTasks)
+                {
+                    AgvTaskCancelDTO agvTaskCancel = new AgvTaskCancelDTO()
+                    {
+                        RequestId = DateTime.Now.ToString("yyMMddHHmmssfff"),
+                        MissionCode = item.GroupId,
+                        ContainerCode = item.PalletCode,
+                        Position = "",
+                        CancelMode = "CTU_REDIRECT_START",
+                        Reason = ""
+                    };
+                    AgvCancelTask(agvTaskCancel);
+                }
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            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>
+        /// <returns></returns>
+        public EPLightContent PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs)
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.PickOrderInfoRequest.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
+                {
+                    return content.Error($"鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                }
+                string request = JsonConvert.SerializeObject(lightSendDTOs, settings).ToUpper();
+                // 璋冪敤鎺ュ彛
+                string response = HttpHelper.Post(url, request);
+                EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欎笅鍙戜笂鎶ヨ繑鍥炲��");
+                if (lightContent.Result != "0") throw new Exception($"鎾澧欎笅鍙戦敊璇�,淇℃伅:{lightContent.Msg}");
+                content.OK("鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浜屾湡鎾澧欏垵濮嬪寲
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <returns></returns>
+        public EPLightContent INITIALIZATION()
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.INITIALIZATION.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
+                {
+                    return content.Error($"鏈壘鍒版挱绉嶅鍒濆鍖栨帴鍙�,璇锋鏌ユ帴鍙i厤缃�");
+                }
+                //璋冪敤鎺ュ彛
+                string response = Post(url);
+                EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欏垵濮嬪寲涓婃姤杩斿洖鍊�");
+                if (lightContent.Result != "0") throw new Exception($"鎾澧欏垵濮嬪寲閿欒,淇℃伅:{lightContent.Msg}");
+                content.OK("鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 浜屾湡鎾澧欑粨鏉熶綔涓�
+        /// </summary>
+        /// <param name="taskNum"></param>
+        /// <returns></returns>
+        public EPLightContent ENDWORK()
+        {
+            EPLightContent content = new EPLightContent();
+            try
+            {
+                string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.ENDWORK.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(url))
+                {
+                    return content.Error($"鏈壘鍒版挱绉嶅缁撴潫浣滀笟鎺ュ彛,璇锋鏌ユ帴鍙i厤缃�");
+                }
+                //璋冪敤鎺ュ彛
+                string response = Post(url);
+                EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"鏈帴鏀跺埌鎾澧欑粨鏉熶綔涓氫笂鎶ヨ繑鍥炲��");
+                if (lightContent.Result != "0") throw new Exception($"鎾澧欑粨鏉熶綔涓氶敊璇�,淇℃伅:{lightContent.Msg}");
+                content.OK("鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        public override WebResponseContent Export(PageDataOptions options)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string savePath = AppDomain.CurrentDomain.BaseDirectory + "ExcelExport";
+
+                // 纭繚鐩綍瀛樺湪
+                if (!Directory.Exists(savePath))
+                    Directory.CreateDirectory(savePath);
+
+                // 鑾峰彇鏁版嵁
+                ISugarQueryable<Dt_Task> query = BaseDal.Db.Queryable<Dt_Task>();
+                var dataList = query.ToList();
+                var properties = typeof(Dt_Task).GetProperties();
+
+                string filePath = TExportHelper.GetExport(savePath, properties, dataList);
+                return WebResponseContent.Instance.OK(data: filePath);
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 閲嶇疆鎵�鏈夊紓甯镐换鍔�
+        /// </summary>
+        public WebResponseContent ResetAllExceptionTask(int taskNum)
+        {
+            // 鑾峰彇寮傚父浠诲姟990淇敼涓篈GV寰呮墽琛�300
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
+                if (task.TaskState != (int)TaskStatusEnum.Exception)
+                {
+                    return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙噸缃�,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
+                }
+                task.TaskState = (int)TaskStatusEnum.AGV_Execute;
+                BaseDal.UpdateData(task);
+                //_taskExecuteDetailService.AddTaskExecuteDetail(task, $"浜哄伐閲嶇疆寮傚父浠诲姟,閲嶇疆鍚庝换鍔$姸鎬併�恵task.TaskState}銆�");
+                content = WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+
+        public WebResponseContent WmsRecovery()
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                // 鍒犻櫎绗竴涓紓甯�
+                // 鎸夊垱寤烘椂闂村崌搴忚幏鍙栫涓�鏉¤褰�
+                var orderBy = new Dictionary<string, OrderByType>
+                {
+                    { "CreateDate", OrderByType.Asc }
+                };
+                Dt_ErrorInfo errorInfo = _errorInfoRepository.QueryFirst(x => true, orderBy);
+                if (errorInfo == null)
+                {
+                    return content.Error("褰撳墠娌℃湁寮傚父浠诲姟");
+                }
+                // 鑾峰彇绗竴涓紓甯革紙鎸夊垱寤烘椂闂存帓搴忥級
+                _unitOfWorkManage.BeginTran();
+                _errorInfoRepository.DeleteData(errorInfo);
+                _unitOfWorkManage.CommitTran();
+                // 涓婃姤鎭㈠
+                string? apiErrorBack = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSErrorBack.ToString())?.ApiAddress;
+                if (string.IsNullOrEmpty(apiErrorBack)) throw new Exception($"鏈壘鍒癢MS鏁呴殰涓婃姤,璇锋鏌ユ帴鍙i厤缃�");
+                TaskError taskError = new TaskError()
+                {
+                    MsgID = errorInfo.Id,
+                    StationCode = errorInfo.StationCode,
+                    MsgCode = 0,
+                    Msg = "鎭㈠"
+                };
+                string reqErrorBack = JsonConvert.SerializeObject(taskError, settings);
+                HttpHelper.Post(apiErrorBack, reqErrorBack);
+                return content.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return content.Error(ex.Message);
+                throw new Exception(ex.Message);
+            }
         }
     }
 }

--
Gitblit v1.9.3