huangxiaoqiang
2025-07-28 ff2bab902d535a6c3fb5027cf1154115f51b59f6
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -20,6 +20,7 @@
using Newtonsoft.Json;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common;
@@ -41,6 +42,7 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_TaskInfoRepository;
@@ -55,6 +57,7 @@
        private readonly ITask_HtyRepository _taskHtyRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly IMapper _mapper;
        private readonly IDeviceInfoRepository _deviceInfoRepository;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
@@ -71,7 +74,8 @@
        public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList();
        public List<int> TaskRelocationboundTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList();
        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService taskHtyService, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository taskHtyRepository) : base(BaseDal)
        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService taskHtyService, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository taskHtyRepository,
        IDeviceInfoRepository deviceInfoRepository) : base(BaseDal)
        {
            _routerService = routerService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -82,6 +86,7 @@
            _taskHtyRepository = taskHtyRepository;
            _mapper = mapper;
            _sys_ConfigService = sys_ConfigService;
            _deviceInfoRepository = deviceInfoRepository;
        }
        /// <summary>
@@ -98,20 +103,48 @@
                // éåŽ†ä¼ å…¥çš„WMSTaskDTO列表
                foreach (var item in taskDTOs)
                {
                    var task = BaseDal.QueryFirst(x => x.WMSTaskNum == item.TaskId || x.PalletCode == item.TPbarcode);
                    if (task != null)
                    {
                        task.Creater = "WMS";
                        task.Grade = 1;
                        task.PalletCode = item.TPbarcode;
                    }
                    // åˆ¤æ–­ä»»åŠ¡ç±»åž‹æ˜¯å¦ä¸ºå‡ºåº“ä»»åŠ¡
                    if (item.TaskType == "2")
                    {
                        string[] targetCodes = item.BeginPoint.Split("-");
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == GetScCode(Convert.ToInt32(targetCodes[0])) && x.stationType == 2);
                        Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationChildCode==item.EndPoint);
                        if (stationManagerEnd == null)
                        {
                            return content.Error("未找到出库站台信息");
                        }
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == GetScCode(Convert.ToInt32(targetCodes[0])) && x.stationType == 2 && x.stationFloor == stationManagerEnd.stationFloor);
                        var RGVName = string.Empty;
                        if (stationManager.stationFloor == "1F")
                        {
                            var deviceCode = _deviceInfoRepository.Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == "1" && x.DeviceRemark == "OneFloor").Where(x => x.DeviceCode.Contains("RGV")).ToList().Select(x => x.DeviceCode).ToList();
                            if (deviceCode != null && deviceCode.Count() > 0)
                            {
                                if (deviceCode.Contains("RGV01")&& deviceCode.Contains("RGV02"))
                                {
                                    var RGVOne = BaseDal.QueryData(x => x.RGVName == "RGV01").ToList();
                                    var RGVTwo = BaseDal.QueryData(x => x.RGVName == "RGV02").ToList();
                                    if (RGVOne.Count > RGVTwo.Count)
                                    {
                                        RGVName = "RGV01";
                                    }
                                    else
                                    {
                                        RGVName = "RGV02";
                                    }
                                }
                                else
                                {
                                    RGVName = deviceCode[0];
                                }
                            }
                            else
                            {
                                RGVName = "RGV01";
                            }
                        }
                        Dt_Task taskOut = new Dt_Task()
                        {
                            TaskNum = BaseDal.GetTaskNo().Result,
@@ -126,13 +159,21 @@
                            Roadway = GetScCode(Convert.ToInt32(targetCodes[0])),
                            NextAddress = stationManager.stationChildCode,
                            TargetAddress = item.EndPoint,
                            RGVName = "RGV01"
                            RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
                            Floor= stationManager.stationFloor,
                        };
                        BaseDal.AddData(taskOut);
                    }
                    // åˆ¤æ–­ä»»åŠ¡ç±»åž‹æ˜¯å¦ä¸ºå…¥åº“ä»»åŠ¡
                    else if (item.TaskType == "1")
                    {
                        var task = BaseDal.QueryFirst(x => x.PalletCode == item.TPbarcode);
                        if (task != null)
                        {
                            task.Creater = "WMS";
                            task.Grade = 1;
                            task.PalletCode = item.TPbarcode;
                        task.TaskType = (int)TaskInboundTypeEnum.Inbound;
                        task.TaskState = (int)TaskInStatusEnum.RGV_IndispatchFinish;
@@ -151,24 +192,32 @@
                        task.NextAddress = stationManager.stationChildCode;
                        BaseDal.UpdateData(task);
                        }
                        else
                        {
                            return content.Error($"未找到该托盘【{item.TPbarcode}】任务");
                        }
                    }
                    else if (item.TaskType == "3")
                    {
                        task.TaskType = (int)TaskRelocationTypeEnum.Relocation;
                        Dt_Task taskRelocation = new Dt_Task()
                        {
                            TaskType = (int)TaskRelocationTypeEnum.Relocation,
                        task.TaskState = (int)TaskRelocationStatusEnum.RelocationNew;
                            TaskState = (int)TaskRelocationStatusEnum.RelocationNew,
                        task.SourceAddress = item.BeginPoint;
                            SourceAddress = item.BeginPoint,
                        task.CurrentAddress = item.BeginPoint;
                            CurrentAddress = item.BeginPoint,
                        task.NextAddress = item.EndPoint;
                            NextAddress = item.EndPoint,
                        task.TargetAddress = item.EndPoint;
                            TargetAddress = item.EndPoint,
                        task.Grade = 3;
                            Grade = 3,
                        BaseDal.AddData(tasks);
                        };
                        BaseDal.AddData(taskRelocation);
                    }
                    else
                    {
@@ -317,7 +366,7 @@
        /// <param name="deviceNo">设备编号</param>
        /// <param name="currentAddress">当前地址</param>
        /// <returns></returns>
        public Dt_Task QueryConveyorLineTask(string currentAddress)
        public Dt_Task QueryConveyorLineTask(string currentAddress,int taskNum)
        {
            Dt_Task task= BaseDal.QueryFirst(x => TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.RGV_InExecutingFinish && x.CurrentAddress == currentAddress, TaskOrderBy);
            if (task == null)
@@ -333,12 +382,12 @@
        /// <param name="deviceNo">设备编号</param>
        /// <param name="currentAddress">当前地址</param>
        /// <returns></returns>
        public Dt_Task QueryConveyorLineFinishTask(string currentAddress)
        public Dt_Task QueryConveyorLineFinishTask(string currentAddress,int taskNum)
        {
            Dt_Task task = BaseDal.QueryFirst(x => TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InExecuting && x.NextAddress == currentAddress, TaskOrderBy);
            Dt_Task task = BaseDal.QueryFirst(x => TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InExecuting && x.NextAddress == currentAddress && x.TaskNum == taskNum, TaskOrderBy);
            if (task == null)
            {
                task = BaseDal.QueryFirst(x => TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && x.NextAddress == currentAddress, TaskOrderBy);
                task = BaseDal.QueryFirst(x => TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && x.CurrentAddress == currentAddress && x.TaskNum == taskNum, TaskOrderBy);
            }
            return task;
        }
@@ -540,6 +589,12 @@
                        BaseDal.DeleteData(task);
                        _taskHtyRepository.AddData(task_Hty);
                    }
                    if (task.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting)
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationChildCode == task.NextAddress);
                        task.CurrentAddress = task.NextAddress;
                        task.NextAddress = task.TargetAddress;
                    }
                    if (task.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)
                    {
@@ -551,13 +606,8 @@
                {
                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                    task.TaskState = nextStatus;
                    if (task.TaskState == (int)TaskInStatusEnum.Line_InExecuting)
                    {
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationChildCode== task.NextAddress);
                        task.CurrentAddress = task.NextAddress;
                        task.NextAddress = stationManager.stationNextChildCode;
                    }
                    else if (task.TaskState == (int)TaskInStatusEnum.Line_InFinish)
                    if (task.TaskState == (int)TaskInStatusEnum.Line_InFinish)
                    {
                        task.CurrentAddress = task.NextAddress;
                        task.NextAddress = task.TargetAddress;
@@ -644,10 +694,10 @@
                }
                else if (task.TaskState == (int)TaskInStatusEnum.RGV_InExecuting)
                {
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress && x.stationFloor == task.Floor);
                    task.TaskState = (int)TaskInStatusEnum.RGV_InExecutingFinish;
                    task.NextAddress = stationManager.stationNextChildCode;
                    task.CurrentAddress = task.NextAddress;
                    task.NextAddress = stationManager.stationNextChildCode;
                    task.ModifyDate = DateTime.Now;
                    BaseDal.UpdateData(task);
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"RGV入库完成");
@@ -661,7 +711,7 @@
                }
                else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting)
                {
                    task.TaskState = (int)TaskOutStatusEnum.RGV_OutFinish;
                    task.TaskState = (int)TaskOutStatusEnum.OutFinish;
                    task.ModifyDate = DateTime.Now;
                    task.Modifier = "System";
@@ -722,7 +772,7 @@
                {
                    task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 2);
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 2 && x.stationFloor == task.Floor);
                    task.CurrentAddress = task.NextAddress;
@@ -734,9 +784,7 @@
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
                {
                    //todo åŒæ­¥åˆ°WMS
                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                    task.TaskState = nextStatus;
                    task.TaskState = (int)TaskInStatusEnum.InFinish; ;
                    task.ModifyDate = DateTime.Now;
                    task.Modifier = "System";