| | |
| | | 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; |
| | |
| | | { |
| | | try |
| | | { |
| | | var newTasksOut = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType==TaskTypeEnum.Outbound.ObjToInt() && x.DeviceCode == "AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); |
| | | var newTasksIn = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.DeviceCode == "AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); |
| | | var newTasksOut = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType==TaskTypeEnum.Outbound.ObjToInt() && x.DeviceCode == "AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.TaskNum).ToList(); |
| | | var newTasksIn = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.DeviceCode == "AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.TaskNum).ToList(); |
| | | var taskDownOut = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState > TaskStatusEnum.AGV_Execute.ObjToInt()) && x.TaskType == TaskTypeEnum.Outbound.ObjToInt() && x.DeviceCode == "AGV").OrderBy(x => x.TaskNum).ToList(); |
| | | #region åºåºä»»å¡ä¸å |
| | | if (newTasksOut.Count>0) |
| | | { |
| | | List<string> GroupIds = newTasksOut.GroupBy(x => x.GroupId).Select(x => x.Key).ToList(); |
| | | foreach (var GroupId in GroupIds) |
| | | foreach (var GroupTask in newTasksOut.GroupBy(x=>x.NextAddress)) |
| | | { |
| | | var tasks = newTasksOut.Where(x => x.GroupId == GroupId).ToList(); |
| | | try |
| | | int taskCount = 6; |
| | | if (GroupTask.ObjToInt() > 201) |
| | | { |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | taskCount = 4; |
| | | } |
| | | var tasks = GroupTask.Take(taskCount).ToList(); |
| | | TimeSpan span = DateTime.Now - tasks.FirstOrDefault().CreateDate; |
| | | int taskDownCount = taskDownOut.Where(x => x.NextAddress == GroupTask.Key).Count(); |
| | | if (taskDownCount < (GroupTask.ObjToInt() > 201 ? 4 : 6) && (tasks.Count >= 4 || (int)span.TotalSeconds >= 20)) |
| | | { |
| | | try |
| | | { |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | foreach (var task in tasks) |
| | | { |
| | | //è·åç®æ ç¹è´§ä½ |
| | | Dt_LocationInfo locationInfoStart = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress); |
| | | //è·åæ£éåºåºç«å° |
| | | Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.PickStationCode == task.NextAddress); |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | { |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | string taskGroupId = Guid.NewGuid().ToString().Replace("-", ""); |
| | | |
| | | foreach (var task in tasks) |
| | | { |
| | | //è·åç®æ ç¹è´§ä½ |
| | | Dt_LocationInfo locationInfoStart = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.CurrentAddress); |
| | | //è·åæ£éåºåºç«å° |
| | | Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.PickStationCode == task.NextAddress); |
| | | |
| | | if (locationInfoStart == null || stationMangerEnd == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskNum}èµ·å§ç¹{task.CurrentAddress}æç®æ ç¹{task.NextAddress}ä½ç½®ä¿¡æ¯"); |
| | | agvTaskSend.RequestId = GroupId; |
| | | agvTaskSend.MissionCode = GroupId; |
| | | if (task.Grade == 0) |
| | | if (locationInfoStart == null || stationMangerEnd == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskNum}èµ·å§ç¹{task.CurrentAddress}æç®æ ç¹{task.NextAddress}ä½ç½®ä¿¡æ¯"); |
| | | agvTaskSend.RequestId = taskGroupId; |
| | | agvTaskSend.MissionCode = taskGroupId; |
| | | agvTaskSend.ViewBoardType = "W01"; |
| | | //æç®±åæ¬è¿ä»»å¡ |
| | | MissionDataItem missionDataItem = new MissionDataItem() |
| | | { |
| | | Sequence = task.TaskNum, |
| | | BinCode = task.PalletCode, |
| | | StartPosition = locationInfoStart.AgvPoint, |
| | | StartSlotCode = locationInfoStart.LocationCode, |
| | | EndPosition = stationMangerEnd.StationCode, |
| | | EndSlotCode = stationMangerEnd.CraneStationCode, |
| | | TakeActionConfirm = false, |
| | | TakeActionInform = false, |
| | | PutActionConfirm = true, |
| | | PutActionInform = true, |
| | | }; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | } |
| | | if (tasks.OrderByDescending(x => x.Grade).FirstOrDefault()?.Grade == 0) |
| | | { |
| | | agvTaskSend.Priority = 99; |
| | | } |
| | | else |
| | | { |
| | | agvTaskSend.Priority = 99 - task.Grade; |
| | | agvTaskSend.Priority = 99 - tasks.OrderByDescending(x => x.Grade).FirstOrDefault().Grade; |
| | | } |
| | | //æç®±åæ¬è¿ä»»å¡ |
| | | MissionDataItem missionDataItem = new MissionDataItem() |
| | | tasks.ForEach(x => |
| | | { |
| | | Sequence = task.TaskNum, |
| | | BinCode = task.PalletCode, |
| | | StartPosition = locationInfoStart.AgvPoint, |
| | | StartSlotCode = locationInfoStart.LocationCode, |
| | | EndPosition = stationMangerEnd.StationCode, |
| | | EndSlotCode = stationMangerEnd.CraneStationCode, |
| | | TakeActionConfirm = false, |
| | | TakeActionInform = false, |
| | | PutActionConfirm = true, |
| | | PutActionInform = true, |
| | | }; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | x.GroupId = taskGroupId; |
| | | }); |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.Dispatchertime = DateTime.Now; |
| | | x.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); |
| | | }); |
| | | _taskService.UpdateData(tasks); |
| | | Thread.Sleep(500); |
| | | } |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | tasks.ForEach(x => |
| | | catch (Exception ex) |
| | | { |
| | | x.Dispatchertime = DateTime.Now; |
| | | x.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); |
| | | }); |
| | | _taskService.UpdateData(tasks); |
| | | Thread.Sleep(500); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | tasks.ForEach(x => |
| | | { |
| | | x.TaskState = TaskStatusEnum.Exception.ObjToInt(); |
| | | x.ExceptionMessage = ex.Message; |
| | | }); |
| | | _taskService.UpdateData(tasks); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.TaskState = TaskStatusEnum.Exception.ObjToInt(); |
| | | x.ExceptionMessage = ex.Message; |
| | | }); |
| | | _taskService.UpdateData(tasks); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | //è·åç®æ ç¹è´§ä½ |
| | | Dt_LocationInfo locationInfoEnd = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.NextAddress); |
| | | //è·å线ä½å
¥åºç«å° |
| | | Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x => x.PickStationCode == task.CurrentAddress); |
| | | Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x => x.StationCode == task.CurrentAddress); |
| | | if (locationInfoEnd == null || stationMangerStart == null) throw new Exception($"æªæ¾å°ä»»å¡å·${task.TaskNum}èµ·å§ç¹{task.CurrentAddress}æç®æ ç¹{task.NextAddress}ä½ç½®ä¿¡æ¯"); |
| | | agvTaskSend.RequestId = Guid.NewGuid().ToString().Replace("-", ""); |
| | | agvTaskSend.MissionCode = task.TaskNum.ToString(); |
| | | agvTaskSend.ViewBoardType = "W02"; |
| | | if (task.Grade == 0) |
| | | { |
| | | agvTaskSend.Priority = 99; |
| | |
| | | StartSlotCode = stationMangerStart.CraneStationCode, |
| | | EndPosition = locationInfoEnd.AgvPoint, |
| | | EndSlotCode = locationInfoEnd.LocationCode, |
| | | TakeActionConfirm = false, |
| | | TakeActionInform = false, |
| | | PutActionConfirm = true, |
| | | PutActionInform = true, |
| | | TakeActionConfirm = true, |
| | | TakeActionInform = true, |
| | | PutActionConfirm = false, |
| | | PutActionInform = false, |
| | | }; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | //åéAGVä»»å¡ |