ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -3,6 +3,7 @@
using LogLibrary.Log;
using Mapster;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
@@ -123,28 +124,23 @@
                            task.NextAddress = station.stationChildCode;
                            task.Floor = "1F";
                            task.Floor = item.Floor;
                            task.AGVSign = "";
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.AcrossFloorGroup)
                        {
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.SourceAddress);
                            var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == item.Floor);
                            if (station != null)
                            {
                                var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == station.stationFloor);
                            task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                                task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                            task.CurrentAddress = item.SourceAddress;
                                task.CurrentAddress = item.SourceAddress;
                            task.NextAddress = next.stationChildCode;
                                task.NextAddress = next.stationChildCode;
                            task.Floor = item.Floor;
                                task.Floor = station.stationFloor;
                                task.AGVSign = "";
                            }
                            task.AGVSign = "";
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.CarryGroup)
                        {
@@ -180,22 +176,17 @@
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.AcrossFloorGroup)
                        {
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.SourceAddress);
                            var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == item.Floor);
                            if (station != null)
                            {
                                var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == station.stationFloor);
                            task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                                task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                            task.CurrentAddress = item.SourceAddress;
                                task.CurrentAddress = item.SourceAddress;
                            task.NextAddress = next.stationChildCode;
                                task.NextAddress = next.stationChildCode;
                            task.Floor = item.Floor;
                                task.Floor = station.stationFloor;
                                task.AGVSign = "";
                            }
                            task.AGVSign = "";
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.CarryGroup)
                        {
@@ -218,7 +209,7 @@
                    {
                        if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.RelocationGroup)
                        {
                            task.TaskState = (int)TaskRelocationStatusEnum.RelocationNew;
                            //task.TaskState = (int)TaskRelocationStatusEnum.RelocationNew;
                            task.CurrentAddress = item.SourceAddress;
@@ -230,26 +221,20 @@
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.AcrossFloorGroup)
                        {
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.SourceAddress);
                            var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == item.Floor);
                            if (station != null)
                            {
                                var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == station.stationFloor);
                            task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                                task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                            task.CurrentAddress = item.SourceAddress;
                                task.CurrentAddress = item.SourceAddress;
                            task.NextAddress = next.stationChildCode;
                                task.NextAddress = next.stationChildCode;
                            task.Floor = item.Floor;
                                task.Floor = station.stationFloor;
                                task.AGVSign = "";
                            }
                            task.AGVSign = "";
                        }
                        else if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.CarryGroup)
                        {
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.SourceAddress);
                            task.TaskState = (int)TaskAGVCarryStatusEnum.CarryNew;
@@ -257,7 +242,7 @@
                            task.NextAddress = task.TargetAddress;
                            task.Floor = station.stationFloor;
                            task.Floor = item.Floor;
                            task.AGVSign = "";
                        }
@@ -267,23 +252,19 @@
                    {
                        if (task.TaskState.GetTaskStateGroup() == TaskStateGroup.AcrossFloorGroup)
                        {
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.SourceAddress);
                            var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == item.Floor);
                            if (station != null)
                            {
                                var next = _stationManagerRepository.QueryFirst(x => x.stationType == 5 && x.stationFloor == station.stationFloor);
                            task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                                task.TaskState = (int)TaskAcrossFloorStatusEnum.CarryNew;
                            task.CurrentAddress = item.SourceAddress;
                                task.CurrentAddress = item.SourceAddress;
                            task.NextAddress = next.stationChildCode;
                                task.NextAddress = next.stationChildCode;
                            task.Floor = item.Floor;
                                task.Floor = station.stationFloor;
                                task.AGVSign = "";
                            }
                            task.AGVSign = "";
                        }
                    }
                    // å°†è½¬æ¢åŽçš„任务添加到任务列表中
@@ -387,7 +368,7 @@
        /// <returns></returns>
        public Dt_Task QueryRequestTSJSignalTask()
        {
            return BaseDal.QueryFirst(x => TaskAcrossFloorboundTypes.Contains(x.TaskType) && x.TaskState > (int)TaskAcrossFloorStatusEnum.CarryNew && (x.AGVSign == "RequestPickUp" || x.AGVSign == "RequestPut"));
            return BaseDal.QueryFirst(x =>  x.TaskState > (int)TaskAcrossFloorStatusEnum.CarryNew && (x.AGVSign == "RequestPickUp" || x.AGVSign == "RequestPut"));
        }
        #endregion
@@ -487,8 +468,13 @@
                    }
                    if (task.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting)
                    {
                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress);
                        SendAgvTask(station.stationRemark, task.TaskNum);
                        string TargetAddress = GetLocation(task.PalletCode);
                        if (TargetAddress == "")
                        {
                            return content.Error($"未获取出库终点货位信息");
                        }
                        task.NextAddress = TargetAddress;
                        task.TargetAddress = TargetAddress;
                    }
                }
@@ -501,45 +487,21 @@
                    {
                        #region å…¥åº“调用接口获取货位地址
                        //var taskDto = new RequestTaskDto()
                        //{
                        //    Position = task.NextAddress,
                        //    PalletCode = task.PalletCode,
                        //};
                        //// èŽ·å–WMSip地址
                        //var configz = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                        //var wmsBasez = configz.Where(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE).FirstOrDefault()?.ConfigValue;
                        //var requestLocation = configz.Where(x => x.ConfigKey == SysConfigKeyConst.RequestLocation).FirstOrDefault()?.ConfigValue;
                        //if (wmsBasez == null || requestLocation == null)
                        //{
                        //    throw new InvalidOperationException("WMS IP æœªé…ç½®");
                        //}
                        //var wmsIpAddrss = wmsBasez + requestLocation;
                        //// å‘送请求并等待响应
                        //var abc = HttpHelper.PostAsync(wmsIpAddrss, taskDto.ToJsonString()).Result;
                        //if (abc == null)
                        //    return content.Error();
                        //// ååºåˆ—化响应内容
                        //content = JsonConvert.DeserializeObject<WebResponseContent>(abc);
                        //LogFactory.WriteError($"获取货位", $"获取货位,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】返回参数【{JsonConvert.SerializeObject(content)}】");
                        //// æ£€æŸ¥çŠ¶æ€å¹¶è¿”å›ž
                        //if (!content.Status)
                        //{
                        //    return content;
                        //}
                        //// ååºåˆ—化任务数据
                        //var taskResult = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                        string TargetAddress= GetLocation(task.PalletCode);
                        if (TargetAddress == null)
                        {
                            return content.Error($"未获取入库终点货位信息");
                        }
                        task.CurrentAddress = task.NextAddress;
                        task.NextAddress = task.TargetAddress;
                        task.TargetAddress = task.NextAddress;
                        task.NextAddress = TargetAddress;
                        task.TargetAddress = TargetAddress;
                        #endregion å…¥åº“调用接口获取货位地址
                    }
                    else if (task.TaskState == (int)TaskInStatusEnum.Line_InExecuting)
                    {
                        UpdateStartLocationInfo(task);
                    }
                    else if (task.TaskState == (int)TaskInStatusEnum.SC_InFinish)
                    {
@@ -566,6 +528,8 @@
                    if (task.TaskState == (int)TaskAGVCarryStatusEnum.AGV_CarryFinish)
                    {
                        CompletedTask(task.TaskNum);
                        task.ModifyDate = DateTime.Now;
                        task.Modifier = "System";
@@ -647,7 +611,7 @@
                        taskNew.CurrentAddress = stationManager.stationChildCode;
                        taskNew.NextAddress = task.TargetAddress;
                        taskNew.NextAddress = taskDTO.TargetAddress;
                        taskNew.Floor = stationManager.stationFloor;
@@ -710,6 +674,46 @@
            return content;
        }
        public string GetLocation(string palletCode)
        {
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
            var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestLocation)?.ConfigValue;
            if (wmsBase == null || updateTask == null)
            {
                throw new InvalidOperationException("WMS IP æœªé…ç½®");
            }
            var wmsIpAddress = wmsBase + updateTask;
            var keys = new Dictionary<string, object>()
            {
                {"palletCode", palletCode}
            };
            var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result;
            WebResponseContent? content = JsonConvert.DeserializeObject<WebResponseContent>(result);
            if (content.Status)
            {
                return content.Data.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        public void UpdateStartLocationInfo(Dt_Task task)
        {
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
            var updateTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.UpdateStartLocationInfo)?.ConfigValue;
            if (wmsBase == null || updateTask == null)
            {
                throw new InvalidOperationException("WMS IP æœªé…ç½®");
            }
            var wmsIpAddress = wmsBase + updateTask;
            var result = HttpHelper.PostAsync(wmsIpAddress, task.ToJsonString()).Result;
        }
        public void CompletedTask(int taskNum)
        {
            #region WMS同步任务完成
@@ -757,6 +761,8 @@
                    task.ModifyDate = DateTime.Now;
                    task.Modifier = "System";
                    BaseDal.UpdateData(task);
                    UpdateStartLocationInfo(task);
                    content.OK(data: task);
@@ -906,6 +912,11 @@
            return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskType == (int)TaskRelocationTypeEnum.Relocation && x.TaskState == (int)TaskRelocationStatusEnum.RelocationNew);
        }
        public Dt_Task QueryExecutingTask(string deviceNo)
        {
            return BaseDal.QueryFirst(x => x.Roadway == deviceNo &&( x.TaskState == (int)TaskRelocationStatusEnum.SC_RelocationExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting));
        }
        private string GetIpAddress(string baseIp, string name)
        {