| | |
| | | { |
| | | try |
| | | { |
| | | var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.DeviceCode=="AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList(); |
| | | |
| | | if (newTasks.Count>0) |
| | | 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(); |
| | | #region åºåºä»»å¡ä¸å |
| | | if (newTasksOut.Count>0) |
| | | { |
| | | foreach (var task in newTasks) |
| | | List<string> GroupIds = newTasksOut.GroupBy(x => x.GroupId).Select(x => x.Key).ToList(); |
| | | foreach (var GroupId in GroupIds) |
| | | { |
| | | var tasks = newTasksOut.Where(x => x.GroupId == GroupId).ToList(); |
| | | try |
| | | { |
| | | Guid guid = Guid.NewGuid(); |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | { |
| | | SysToken=guid.ToString().Replace("-",""), |
| | | ReceiveTaskID=task.TaskNum.ToString(), |
| | | MapCode="01", |
| | | Variables=new List<PointDetail>() |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | if (task.NextAddress== "䏿¥¼æå°ç 头") |
| | | foreach (var task in tasks) |
| | | { |
| | | string? address =_taskService.RequestTargetAddress(task.TaskNum); |
| | | if (address.IsNullOrEmpty()) |
| | | //è·åç®æ ç¹è´§ä½ |
| | | 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) |
| | | { |
| | | task.ExceptionMessage = "æªæ¾å°AGVç«ç¹"; |
| | | continue; |
| | | } |
| | | task.NextAddress = address; |
| | | } |
| | | Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x=>x.StationCode==task.CurrentAddress); |
| | | Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress); |
| | | //æ·»å ä»»å¡è·¯å¾åé«åº¦ |
| | | if (stationMangerStart !=null && stationMangerEnd != null) |
| | | { |
| | | PointDetail pointDetail1 = new PointDetail() |
| | | { |
| | | Code= "GoodPoint", |
| | | Value=stationMangerStart.AGVStationCode |
| | | }; |
| | | //夿æ¯å¦æåç½®ç¹ |
| | | if (!string.IsNullOrEmpty(stationMangerStart.AGVFrontCode)) |
| | | { |
| | | PointDetail pointDetail2 = new PointDetail() |
| | | { |
| | | Code = "CostPoint", |
| | | Value = stationMangerStart.AGVFrontCode |
| | | }; |
| | | agvTaskSend.Variables.Add(pointDetail2); |
| | | } |
| | | PointDetail pointDetail3 = new PointDetail() |
| | | { |
| | | Code = "PointB", |
| | | Value = stationMangerEnd.AGVStationCode |
| | | }; |
| | | //夿æ¯å¦æåç½®ç¹ |
| | | if (!string.IsNullOrEmpty(stationMangerEnd.AGVFrontCode)) |
| | | { |
| | | PointDetail pointDetail4 = new PointDetail() |
| | | { |
| | | Code = "PointA", |
| | | Value = stationMangerEnd.AGVFrontCode |
| | | }; |
| | | agvTaskSend.Variables.Add(pointDetail4); |
| | | } |
| | | PointDetail pointDetail5 = new PointDetail() |
| | | { |
| | | Code = "QUQTH", |
| | | Value = stationMangerStart.AGVStationHeight.ToString() |
| | | }; |
| | | PointDetail pointDetail6 = new PointDetail() |
| | | { |
| | | Code = "FHMH", |
| | | Value = stationMangerEnd.AGVStationHeight.ToString() |
| | | }; |
| | | agvTaskSend.Variables.Add(pointDetail1); |
| | | agvTaskSend.Variables.Add(pointDetail3); |
| | | agvTaskSend.Variables.Add(pointDetail5); |
| | | agvTaskSend.Variables.Add(pointDetail6); |
| | | agvTaskSend.Priority = 99; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æªæ¾å°AGVç«ç¹"); |
| | | agvTaskSend.Priority = 99 - task.Grade; |
| | | } |
| | | //忾任塿¨¡ç |
| | | if (stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT") && stationMangerEnd.IsManual==0)//è¯·æ±æ¾ |
| | | //æç®±åæ¬è¿ä»»å¡ |
| | | MissionDataItem missionDataItem = new MissionDataItem() |
| | | { |
| | | agvTaskSend.TaskCode = "DUIGAO1"; |
| | | if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//æ½ä¼é¡¶å车 |
| | | { |
| | | agvTaskSend.TaskCode = "DUOLUN1"; |
| | | } |
| | | } |
| | | else if (!stationMangerStart.StationCode.Contains("PNT") && stationMangerEnd.StationCode.Contains("PNT") && stationMangerStart.IsManual == 0)//请æ±å |
| | | { |
| | | agvTaskSend.TaskCode = "DUIGAO2"; |
| | | if (stationMangerStart.StationType==998 || stationMangerEnd.StationType == 998)//æ½ä¼é¡¶å车 |
| | | { |
| | | agvTaskSend.TaskCode = "DUOLUN2"; |
| | | } |
| | | } |
| | | else if (!stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT") && stationMangerStart.IsManual == 0 && stationMangerStart.IsManual == 0)//请æ±åæ¾ |
| | | { |
| | | agvTaskSend.TaskCode = "DUIGAO3"; |
| | | if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//æ½ä¼é¡¶å车 |
| | | { |
| | | agvTaskSend.TaskCode = "DUOLUN3"; |
| | | } |
| | | } |
| | | else//æ è¯·æ± |
| | | { |
| | | agvTaskSend.TaskCode = "DUIGAO4"; |
| | | if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//æ½ä¼é¡¶å车 |
| | | { |
| | | agvTaskSend.TaskCode = "DUOLUN4"; |
| | | } |
| | | } |
| | | if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//æ½ä¼é¡¶å车 |
| | | { |
| | | agvTaskSend.Variables.FirstOrDefault(x => x.Code == "FHMH").Value = "0"; |
| | | agvTaskSend.Variables.FirstOrDefault(x => x.Code == "GoodPoint").Value = ""; |
| | | //å¤æäººå·¥æå¨ |
| | | PointDetail complete = new(); |
| | | if (stationMangerStart.IsManual==1 && stationMangerEnd.IsManual==0) |
| | | { |
| | | complete = new() |
| | | { |
| | | Code = "Complete", |
| | | Value = "1" |
| | | 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, |
| | | }; |
| | | } |
| | | else if (stationMangerStart.IsManual == 0 && stationMangerEnd.IsManual == 1) |
| | | { |
| | | complete = new() |
| | | { |
| | | Code = "Complete", |
| | | Value = "2" |
| | | }; |
| | | } |
| | | else if (stationMangerStart.IsManual == 1 && stationMangerEnd.IsManual == 1) |
| | | { |
| | | complete = new() |
| | | { |
| | | Code = "Complete", |
| | | Value = "3" |
| | | }; |
| | | } |
| | | else |
| | | { |
| | | complete = new() |
| | | { |
| | | Code = "Complete", |
| | | Value = "0" |
| | | }; |
| | | } |
| | | //ä¸åä»»å¡AGVä»»å¡é群 |
| | | agvTaskSend.AgvGroupCode = "QianF"; |
| | | PointDetail pointDetail2 = new PointDetail() |
| | | { |
| | | Code = "CostPoint", |
| | | Value = stationMangerStart.AGVStationCode |
| | | }; |
| | | agvTaskSend.Variables.Add(pointDetail2); |
| | | agvTaskSend.Variables.Add(complete); |
| | | } |
| | | if (task.TaskType==TaskTypeEnum.OutCarton.ObjToInt()) |
| | | { |
| | | agvTaskSend.AgvGroupCode = "GAOc"; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | } |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | task.Dispatchertime = DateTime.Now; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing); |
| | | tasks.ForEach(x => |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | #region å
¥åºä»»å¡ä¸å |
| | | if (newTasksIn.Count > 0) |
| | | { |
| | | foreach (var task in newTasksIn) |
| | | { |
| | | try |
| | | { |
| | | AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO() |
| | | { |
| | | MissionData = new List<MissionDataItem>() |
| | | }; |
| | | //è·åç®æ ç¹è´§ä½ |
| | | Dt_LocationInfo locationInfoEnd = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.NextAddress); |
| | | //è·å线ä½å
¥åºç«å° |
| | | Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x => x.PickStationCode == 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(); |
| | | if (task.Grade == 0) |
| | | { |
| | | agvTaskSend.Priority = 99; |
| | | } |
| | | else |
| | | { |
| | | agvTaskSend.Priority = 99 - task.Grade; |
| | | } |
| | | //æç®±åæ¬è¿ä»»å¡ |
| | | MissionDataItem missionDataItem = new MissionDataItem() |
| | | { |
| | | Sequence = task.TaskNum, |
| | | BinCode = task.PalletCode, |
| | | StartPosition = stationMangerStart.StationCode, |
| | | StartSlotCode = stationMangerStart.CraneStationCode, |
| | | EndPosition = locationInfoEnd.AgvPoint, |
| | | EndSlotCode = locationInfoEnd.LocationCode, |
| | | TakeActionConfirm = false, |
| | | TakeActionInform = false, |
| | | PutActionConfirm = true, |
| | | PutActionInform = true, |
| | | }; |
| | | agvTaskSend.MissionData.Add(missionDataItem); |
| | | //åéAGVä»»å¡ |
| | | WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask); |
| | | if (!content.Status) |
| | | throw new Exception(content.Message); |
| | | task.Dispatchertime = DateTime.Now; task.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt(); |
| | | _taskService.UpdateData(task); |
| | | Thread.Sleep(500); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | task.TaskState = TaskStatusEnum.Exception.ObjToInt(); |
| | | task.ExceptionMessage = ex.Message; |
| | | _taskService.UpdateData(task); |
| | | } |
| | | } |
| | | //æ´æ°ä»»å¡ |
| | | if (newTasks.Count > 0) |
| | | { |
| | | _taskService.UpdateData(newTasks); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | catch (Exception ex) |
| | | { |