1
xiazhengtongxue
2025-12-26 a2f06e43a6f4ed3c613aefbb8bc0ccf3dd30ff8f
ÏîÄ¿´úÂë/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("未找到播种墙下发接口,请检查接口配置");
                }
                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($"未找到播种墙下发接口,请检查接口配置");
                }
                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,30 @@
            }
            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;
        }
    }
}