1
wangxinhui
2025-07-19 334ecd210dbadba93c8ac7cf1c6255db999f226d
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -23,12 +23,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_DTO.Agv;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
@@ -198,7 +200,7 @@
                List<Dt_Task> tasks = new List<Dt_Task>();
                foreach (var item in taskDTOs)
                {
                    if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null)
                    if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum) != null)
                    {
                        flag = true;
                        continue;
@@ -214,28 +216,21 @@
                    if (string.IsNullOrEmpty(item.AGVArea))
                    {
                        Dt_StationManger stationManger;
                        //获取站台信息
                        if (taskTypeGroup == TaskTypeGroup.InboundGroup)
                        {
                            stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == item.SourceAddress || x.StationDeviceCode == item.SourceAddress);
                            if (stationManger==null && task.TaskType==TaskTypeEnum.InProduct.ObjToInt())
                            {
                                stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneCode==task.SourceAddress);
                                //转换成品仓起点站台
                                item.SourceAddress = stationManger.StationCode;
                                task.CurrentAddress = stationManger.StationCode;
                                task.SourceAddress = stationManger.StationCode;
                            }
                        }
                        else
                        {
                            stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneCode == item.RoadWay || x.Remark==item.RoadWay);
                            stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneCode == item.RoadWay && x.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt());
                        }
                        if (stationManger == null)
                        {
                            return WebResponseContent.Instance.Error($"未找到站台配置信息");
                        }
                        List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && (item.SourceAddress == x.StartPosi || item.RoadWay == x.StartPosi /*|| item.RoadWay == x.ChildPosiDeviceCode || item.RoadWay == x.ChildPosi*/));
                        //获取路由信息
                        List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && (item.SourceAddress == x.StartPosi || item.RoadWay == x.StartPosi));
                        router = routers.FirstOrDefault();
                        if (router == null)
                        {
@@ -244,127 +239,28 @@
                        if (routers.Count == 1)
                        {
                            if (taskTypeGroup == TaskTypeGroup.InboundGroup && item.TargetAddress == stationManger.StackerCraneCode)
                            if (taskTypeGroup == TaskTypeGroup.InboundGroup)
                            {
                                task.CurrentAddress = router.StartPosi;
                                task.NextAddress = router.NextPosi;
                                task.DeviceCode = stationManger.StationDeviceCode;
                            }
                            else if (item.TaskType == TaskTypeEnum.MesMatReturn.ObjToInt() && !router.IsEnd)
                            {
                                task.NextAddress = router.NextPosi;
                                task.DeviceCode = router.ChildPosi;
                            }
                            else if ((item.TaskType == TaskTypeEnum.MesPalletLargeReturn.ObjToInt() || item.TaskType == TaskTypeEnum.MesPalletSmallReturn.ObjToInt()) && router.IsEnd)
                            {
                                task.NextAddress = router.NextPosi;
                                task.DeviceCode = router.ChildPosi;
                            }
                            else if (item.TaskType == TaskTypeEnum.MesOutbound.ObjToInt() || item.TaskType == TaskTypeEnum.MesHandOutbound.ObjToInt() || item.TaskType == TaskTypeEnum.MesHandPickOutbound.ObjToInt() || (item.TaskType == TaskTypeEnum.OutAllocate.ObjToInt() && item.RoadWay.Contains("BC")))
                            {
                                task.NextAddress = router.NextPosi;
                                task.DeviceCode = stationManger.StackerCraneCode;
                                if (item.TaskType == TaskTypeEnum.MesOutbound.ObjToInt() && task.TargetAddress== "SCUTL-001")
                                {
                                    task.TaskState = TaskStatusEnum.MesPending.ObjToInt();
                                }
                                else
                                {
                                    task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                                }
                            }
                            else if (item.TaskType == TaskTypeEnum.MesOutbound.ObjToInt() && item.RoadWay.Contains("ZH"))
                            {
                                task.NextAddress = stationManger.StackerCraneStationCode;
                                task.DeviceCode = stationManger.StackerCraneCode;
                                task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                                task.DeviceCode = router.ChildPosiDeviceCode;
                            }
                            else
                            {
                                task.NextAddress = taskTypeGroup == TaskTypeGroup.InboundGroup ? task.TargetAddress : router.NextPosi;
                                if (item.RoadWay.Contains("AGV_FL")|| (item.RoadWay.Contains("AGV_CP") && taskTypeGroup == TaskTypeGroup.OutbondGroup))
                                {
                                    task.DeviceCode = item.RoadWay;
                                    task.AgvTaskNum = item.RoadWay + DateTime.Now.ToString("yyyyMMdd") + item.TaskNum;
                                }
                                else if(item.RoadWay.Contains("AGV_CP") && taskTypeGroup == TaskTypeGroup.InboundGroup)
                                {
                                    task.DeviceCode = stationManger.StationDeviceCode;
                                    task.AgvTaskNum = task.Roadway + DateTime.Now.ToString("yyyyMMdd") + item.TaskNum;
                                }
                                else
                                {
                                    task.DeviceCode = stationManger.StationDeviceCode;
                                }
                                task.DeviceCode = stationManger.StackerCraneCode;
                                task.NextAddress = router.NextPosi;
                            }
                        }
                        else
                        {
                            if (item.RoadWay=="AGV_CP")
                            if (taskTypeGroup == TaskTypeGroup.InboundGroup)
                            {
                                Dt_Router routerSelect = _routerRepository.QueryFirst(x => x.InOutType == item.TaskType && item.RoadWay == x.StartPosi && x.NextPosi==item.TargetAddress);
                                if (routerSelect != null)
                                {
                                    task.NextAddress = routerSelect.NextPosi;
                                    task.DeviceCode = routerSelect.ChildPosi;
                                    task.AgvTaskNum = item.RoadWay + DateTime.Now.ToString("yyyyMMdd") + item.TaskNum;
                                }
                                else
                                {
                                    return content.Error("未找到路由信息");
                                }
                            }
                            else
                            {
                                List<Dt_Router> dt_Routers = _routerService.QueryNextRoutes(item.SourceAddress, item.RoadWay, item.TaskType);
                                if (dt_Routers != null && dt_Routers.Count > 0)
                                {
                                    task.NextAddress = dt_Routers.FirstOrDefault().NextPosi;
                                    task.DeviceCode = dt_Routers.FirstOrDefault().ChildPosi;
                                }
                                else
                                {
                                    task.NextAddress = "";
                                    task.DeviceCode = "";
                                }
                                task.CurrentAddress = router.StartPosi;
                                task.NextAddress = "";
                                task.DeviceCode = router.ChildPosiDeviceCode;
                            }
                        }
                    }
                    else
                    {
                        if (taskTypeGroup == TaskTypeGroup.OutbondGroup)
                        {
                            task.AgvTaskNum = item.AGVArea + DateTime.Now.ToString("yyyyMMdd") + item.TaskNum;
                            List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && item.AGVArea == x.NextPosi);
                            if (routers.FirstOrDefault() == null)
                            {
                                return WebResponseContent.Instance.Error($"未找到路由配置信息");
                            }
                            router = routers.FirstOrDefault();
                            task.NextAddress = router?.StartPosi ?? "";
                            task.DeviceCode = item.RoadWay;
                            task.TaskState = TaskStatusEnum.SC_Execute.ObjToInt();
                        }
                        else
                        {
                            task.AgvTaskNum = item.AGVArea + DateTime.Now.ToString("yyyyMMdd") + item.TaskNum;
                            List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == item.TaskType && item.AGVArea == x.StartPosi);
                            if (routers.FirstOrDefault() == null)
                            {
                                return WebResponseContent.Instance.Error($"未找到路由配置信息");
                            }
                            router = routers.FirstOrDefault();
                            Dt_StationManger? stationManger = _stationMangerRepository.QueryData(x => true).FirstOrDefault(x=>x.StationCode== router?.NextPosi);
                            if (stationManger == null)
                            {
                                return WebResponseContent.Instance.Error($"未找到站台配置信息");
                            }
                            task.NextAddress = stationManger?.AGVStationCode ?? "";
                            task.DeviceCode = stationManger?.Remark ?? "";
                            task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
                        }
                    }
                    tasks.Add(task);
                }
                BaseDal.AddData(tasks);
@@ -434,26 +330,40 @@
        /// <param name="palletCode"></param>
        /// <param name="sourceAddress"></param>
        /// <returns></returns>
        public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress)
        public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress, string roadWay="", int taskType=630)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string address = AppSettings.Get("WMSApiAddress");
                if (string.IsNullOrEmpty(address))
                //string address = AppSettings.Get("WMSApiAddress");
                //if (string.IsNullOrEmpty(address))
                //{
                //    return WebResponseContent.Instance.Error($"未找到WMSApi地址");
                //}
                //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()
                {
                    return WebResponseContent.Instance.Error($"未找到WMSApi地址");
                }
                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)
                    {
                        content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
                    }
                }
                    Id = 1,
                    TaskNum = DateTime.Now.ToString("mmss").ObjToInt(),
                    PalletCode="",
                    RoadWay= roadWay ?? "",
                    TaskType= taskType,
                    PalletType=1,
                    TaskStatus=TaskStatusEnum.New.ObjToInt(),
                    SourceAddress= sourceAddress,
                    TargetAddress="",
                    WarehouseId=1,
                    Grade=0,
                };
                content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
                //    }
                //}
            }
            catch (Exception ex)
@@ -730,6 +640,7 @@
        /// <returns>返回任务实体对象,可能为null</returns>
        public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "")
        {
            //判断是否为空
            if (string.IsNullOrEmpty(currentAddress))
                return BaseDal.QueryFirst(x => x.DeviceCode == deviceNo && x.TaskState == (int)TaskStatusEnum.SC_Execute, TaskOrderBy);
            else