huangxiaoqiang
2025-07-28 b31d961a3f0bcd2e555ea12b76c30c453826deba
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -106,96 +106,155 @@
                    // åˆ¤æ–­ä»»åŠ¡ç±»åž‹æ˜¯å¦ä¸ºå‡ºåº“ä»»åŠ¡
                    if (item.TaskType == "2")
                    {
                        string[] targetCodes = item.BeginPoint.Split("-");
                        Dt_StationManager stationManagerEnd = _stationManagerRepository.QueryFirst(x => x.stationChildCode==item.EndPoint);
                        if (stationManagerEnd == null)
                        if (Convert.ToInt32(item.EndPoint) > 1999 && Convert.ToInt32(item.EndPoint) < 3000)
                        {
                            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)
                            Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.EndPoint);
                            if (stationManagerStart == null)
                            {
                                if (deviceCode.Contains("RGV01")&& deviceCode.Contains("RGV02"))
                                return content.Error("未找到出库站台信息");
                            }
                            Dt_Task taskIn = new Dt_Task()
                            {
                                TaskNum = BaseDal.GetTaskNo().Result,
                                Creater = "WMS",
                                WMSTaskNum = item.TaskId,
                                Grade = 1,
                                PalletCode = item.TPbarcode,
                                TaskType = (int)TaskOutboundTypeEnum.Outbound,
                                TaskState = (int)TaskOutStatusEnum.OutNew,
                                SourceAddress = item.BeginPoint,
                                CurrentAddress = item.BeginPoint,
                                Roadway = stationManagerStart.Roadway,
                                NextAddress = item.EndPoint,
                                TargetAddress = item.EndPoint,
                                Floor = stationManagerStart.stationFloor,
                                RGVName = ""
                            };
                            BaseDal.AddData(taskIn);
                        }
                        else
                        {
                            string[] targetCodes = item.BeginPoint.Split("-");
                            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 == "1F").Where(x => x.DeviceCode.Contains("RGV")).ToList().Select(x => x.DeviceCode).ToList();
                                if (deviceCode != null && deviceCode.Count() > 0)
                                {
                                    var RGVOne = BaseDal.QueryData(x => x.RGVName == "RGV01").ToList();
                                    var RGVTwo = BaseDal.QueryData(x => x.RGVName == "RGV02").ToList();
                                    if (RGVOne.Count > RGVTwo.Count)
                                    if (deviceCode.Contains("RGV01") && deviceCode.Contains("RGV02"))
                                    {
                                        RGVName = "RGV01";
                                        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 = "RGV02";
                                        RGVName = deviceCode[0];
                                    }
                                }
                                else
                                {
                                    RGVName = deviceCode[0];
                                    RGVName = "RGV01";
                                }
                            }
                            else
                            Dt_Task taskOut = new Dt_Task()
                            {
                                RGVName = "RGV01";
                            }
                                TaskNum = BaseDal.GetTaskNo().Result,
                                Creater = "WMS",
                                WMSTaskNum = item.TaskId,
                                Grade = 1,
                                PalletCode = item.TPbarcode,
                                TaskType = (int)TaskOutboundTypeEnum.Outbound,
                                TaskState = (int)TaskOutStatusEnum.OutNew,
                                SourceAddress = item.BeginPoint,
                                CurrentAddress = item.BeginPoint,
                                Roadway = GetScCode(Convert.ToInt32(targetCodes[0])),
                                NextAddress = stationManager.stationChildCode,
                                TargetAddress = item.EndPoint,
                                RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
                                Floor = stationManager.stationFloor,
                            };
                            BaseDal.AddData(taskOut);
                        }
                        Dt_Task taskOut = new Dt_Task()
                        {
                            TaskNum = BaseDal.GetTaskNo().Result,
                            Creater = "WMS",
                            WMSTaskNum=item.TaskId,
                            Grade = 1,
                            PalletCode = item.TPbarcode,
                            TaskType = (int)TaskOutboundTypeEnum.Outbound,
                            TaskState = (int)TaskOutStatusEnum.OutNew,
                            SourceAddress = item.BeginPoint,
                            CurrentAddress = item.BeginPoint,
                            Roadway = GetScCode(Convert.ToInt32(targetCodes[0])),
                            NextAddress = stationManager.stationChildCode,
                            TargetAddress = item.EndPoint,
                            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)
                        if (Convert.ToInt32(item.BeginPoint) > 1999 && Convert.ToInt32(item.BeginPoint) < 3000)
                        {
                            task.Creater = "WMS";
                            task.Grade = 1;
                            task.PalletCode = item.TPbarcode;
                        task.TaskType = (int)TaskInboundTypeEnum.Inbound;
                        task.TaskState = (int)TaskInStatusEnum.RGV_IndispatchFinish;
                        task.CurrentAddress = item.BeginPoint;
                        task.WMSTaskNum = item.TaskId;
                        task.TargetAddress = item.EndPoint;
                        string[] targetCodes = item.EndPoint.Split("-");
                        task.Roadway = GetScCode(Convert.ToInt32(targetCodes[0]));
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 3);
                        task.NextAddress = stationManager.stationChildCode;
                        BaseDal.UpdateData(task);
                            Dt_StationManager stationManagerStart = _stationManagerRepository.QueryFirst(x => x.stationChildCode == item.BeginPoint);
                            if (stationManagerStart == null)
                            {
                                return content.Error("未找到出库站台信息");
                            }
                            Dt_Task taskIn = new Dt_Task()
                            {
                                TaskNum = BaseDal.GetTaskNo().Result,
                                Creater = "WMS",
                                WMSTaskNum = item.TaskId,
                                Grade = 1,
                                PalletCode = item.TPbarcode,
                                TaskType = (int)TaskInboundTypeEnum.Inbound,
                                TaskState = (int)TaskInStatusEnum.Line_InFinish,
                                SourceAddress = item.BeginPoint,
                                CurrentAddress = stationManagerStart.stationChildCode,
                                Roadway = stationManagerStart.Roadway,
                                NextAddress = item.EndPoint,
                                TargetAddress = item.EndPoint,
                                Floor = stationManagerStart.stationFloor,
                                RGVName = ""
                            };
                            BaseDal.AddData(taskIn);
                        }
                        else
                        {
                            return content.Error($"未找到该托盘【{item.TPbarcode}】任务");
                            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;
                                task.CurrentAddress = item.BeginPoint;
                                task.WMSTaskNum = item.TaskId;
                                task.TargetAddress = item.EndPoint;
                                string[] targetCodes = item.EndPoint.Split("-");
                                task.Roadway = GetScCode(Convert.ToInt32(targetCodes[0]));
                                Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 3 && x.stationFloor == task.Floor);
                                task.NextAddress = stationManager.stationChildCode;
                                BaseDal.UpdateData(task);
                            }
                            else
                            {
                                return content.Error($"未找到该托盘【{item.TPbarcode}】任务");
                            }
                        }
                    }
                    else if (item.TaskType == "3")
@@ -770,17 +829,37 @@
                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
                {
                    task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                    if (Convert.ToInt32(task.TargetAddress) > 1999 && Convert.ToInt32(task.TargetAddress) < 3000)
                    {
                        task.TaskState = (int)TaskOutStatusEnum.OutFinish; ;
                        task.ModifyDate = DateTime.Now;
                        task.Modifier = "System";
                    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 2 && x.stationFloor == task.Floor);
                        Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task);
                        task_Hty.TaskId = 0;
                    task.CurrentAddress = task.NextAddress;
                        BaseDal.DeleteData(task);
                        _taskHtyRepository.AddData(task_Hty);
                        _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成");
                    }
                    else
                    {
                        task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
                    task.NextAddress = stationManager.stationNextChildCode;
                        Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationType == 2 && x.stationFloor == task.Floor);
                    BaseDal.UpdateData(task);
                        task.CurrentAddress = task.NextAddress;
                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成");
                        task.NextAddress = stationManager.stationNextChildCode;
                        BaseDal.UpdateData(task);
                        _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成");
                    }
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutFinish)
                {
                }
                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
                {
@@ -1002,5 +1081,14 @@
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent text(int taskNum)
        {
            WebResponseContent content = new WebResponseContent();
            var result = _stationManagerRepository.Db.Queryable<Dt_StationManager>()
                .Where(t => SqlFunc.Abs(t.LevelPointFist - taskNum) <= 10)
                .ToList();
            return content.OK(data: result);
        }
    }
}