From 46908c0f79e7aab8a3fa41bfdcd8390bbc3659f2 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期日, 04 一月 2026 11:48:15 +0800
Subject: [PATCH] 完善前端二期播种墙初始化和任务完成按钮,后端定期删除日志

---
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs |  190 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 181 insertions(+), 9 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 4dc25f7..fe591f7 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"
@@ -18,18 +18,23 @@
 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.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;
@@ -66,6 +71,7 @@
         private readonly ILocationInfoRepository _locationInfoRepository;
         private readonly ILocationInfoService _locationInfoService;
         private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
+        private readonly IErrorInfoRepository _errorInfoRepository;
 
         private Dictionary<string, OrderByType> _taskOrderBy = new()
             {
@@ -83,7 +89,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,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService,ILocationStatusChangeRecordService locationStatusChangeRecordService) : 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;
@@ -97,6 +103,7 @@
             _unitOfWorkManage = unitOfWorkManage;
             _locationInfoService = locationInfoService;
             _locationStatusChangeRecordService=locationStatusChangeRecordService;
+            _errorInfoRepository = errorInfoRepository;
         }
         static object lock_taskReceive = new object();
         /// <summary>
@@ -116,8 +123,8 @@
                     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;
+                    ////涓嬪彂浠诲姟缁�
+                    //string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode;
                     foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode))
                     {
                         if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"浠诲姟{item.TaskCode}鍑哄簱鐩爣鎿嶄綔鍙颁笉鑳戒负绌�");
@@ -150,7 +157,7 @@
                         task.CurrentAddress = locationInfo.LocationCode;
                         task.NextAddress = stationManger.PickStationCode;
                         task.TargetAddress = stationManger.PickStationCode;
-                        task.GroupId = taskGroup;
+                        //task.GroupId = taskGroup;
                         task.TaskType = TaskTypeEnum.Outbound.ObjToInt();
                         task.Roadway = locationInfo.RoadwayNo;
                         task.DeviceCode = stationManger.CraneCode;
@@ -290,6 +297,95 @@
             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 content.Error("鏈壘鍒版挱绉嶅涓嬪彂鎺ュ彛锛岃妫�鏌ユ帴鍙i厤缃�");
+                }
+
+                bool allSuccess = true;
+                StringBuilder errorMessages = new StringBuilder();
+
+                foreach (EPLightSendDTO lightSendDTO in lightSendDTOs)
+                {
+                    try
+                    {
+                        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>
@@ -298,7 +394,32 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                if (taskSendLight.TagNo=="B2")
+                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>()
                     {
@@ -315,8 +436,8 @@
                                 "Red" => "4",
                                 _ => throw new Exception($"鏈壘鍒伴鑹插畾涔�")
                             },
-                            ORDERTYPE=taskSendLight.Mode.ToString(),
-                            LIGHTTYPE="1",
+                            ORDERTYPE="1",
+                            LIGHTTYPE=taskSendLight.Mode.ToString(),
                         }
                     };
                     EPLightContent pLightContent = PickOrderInfoRequest(lightSendDTOs);
@@ -327,7 +448,7 @@
                 {
                     content.OK();
                 }
-                
+
             }
             catch (Exception ex)
             {
@@ -727,7 +848,7 @@
                     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}");
@@ -793,5 +914,56 @@
             }
             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;
+        }
     }
 }

--
Gitblit v1.9.3