| | |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar.Extensions; |
| | |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using HslCommunication.WebSocket; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IRouterExtension _routerExtension; |
| | | private readonly WebSocketServer _webSocketServer; |
| | | private readonly List<Dt_WarehouseDevice> warehouseDevices; |
| | | |
| | | public ConveyorLineJob_CPD(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) |
| | | public ConveyorLineJob_CPD(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension, WebSocketServer webSocketServer) |
| | | { |
| | | _cacheService = cacheService; |
| | | _taskService = taskService; |
| | |
| | | _routerRepository = routerRepository; |
| | | _routerService = routerService; |
| | | _routerExtension = routerExtension; |
| | | _webSocketServer = webSocketServer; |
| | | |
| | | string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice)); |
| | | if (!string.IsNullOrEmpty(warehouseDevicesStr)) |
| | |
| | | if (flag && value != null) |
| | | { |
| | | OtherDevice device = (OtherDevice)value; |
| | | //è·åææåè®®çè¾é线ç«å° |
| | | List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList(); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); |
| | | |
| | | // å建è¾éçº¿æ°æ®å¯¹è±¡ï¼ç¨äºWebSocketåé |
| | | var conveyorLineCPData = new Dictionary<string, object>(); |
| | | conveyorLineCPData["设å¤ç¼å·"] = device.DeviceCode; |
| | | conveyorLineCPData["设å¤åç§°"] = "æååºä¸æ¥¼è¾é线"; |
| | | conveyorLineCPData["ConveyorLineCPInfo"] = new Dictionary<string, Dictionary<string, object>>(); |
| | | foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode))) |
| | | { |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && deviceProRead != null && deviceProWrite != null) |
| | | |
| | | // å
è¯»åææç±»åç«å°ç设å¤ä¿¡æ¯å¹¶æ·»å å°WebSocketæ°æ®ä¸ |
| | | if (deviceProRead != null) |
| | | { |
| | | R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress); |
| | | //æå䏿¥¼å
¥åºå£åå
¥å¯¹åºå
¥åºç«å°å°å |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo <= 0) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.AGV_Finish.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //åé
å··é åå
¥æçæ°æ® |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, task.Roadway, task.TaskType); |
| | | Dt_Router? router = routers.FirstOrDefault(); |
| | | if (routers == null || routers.Count == 0 || router == null) |
| | | { |
| | | WriteError(item.StationName, $"æªæ¾å°å¯¹åºè·¯ç±ä¿¡æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); |
| | | continue; |
| | | } |
| | | if (routers.Count > 1) |
| | | { |
| | | WriteError(item.StationName, $"è·¯ç±ä¿¡æ¯é
ç½®é误,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); |
| | | continue; |
| | | } |
| | | //åå
¥å
¥åºçº¿ä½å°å |
| | | device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode); |
| | | //æ´æ°ä»»å¡ä¿¡æ¯ |
| | | task.CurrentAddress = item.StationCode; |
| | | task.NextAddress = router.NextPosi; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·{conveyorLineInfoRead.TaskNo}ä¸ä¸æ¥"); |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 2 && conveyorLineInfoRead.TaskNo > 0)//䏿¥¼åºåºå£å¤æçæAGVåæä»»å¡ |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //åé
å··é åå
¥æçæ°æ® |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.NextAddress == x.StartPosi); |
| | | Dt_Router router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | WriteError(item.StationName, $"ä»»å¡å·:{task.TaskNum}æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | return Task.CompletedTask; |
| | | } |
| | | //æ´æ°ä»»å¡ä¿¡æ¯ |
| | | task.CurrentAddress = router.StartPosi; |
| | | task.NextAddress = task.TargetAddress; |
| | | task.DeviceCode = router.NextPosi; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Execute); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·{conveyorLineInfoRead.TaskNo}ä¸ä¸æ¥"); |
| | | } |
| | | } |
| | | } |
| | | else if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null) |
| | | { |
| | | //å
¥åºç«å°åé
è´§ä½åå¤å åå
¥åº |
| | | R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress); |
| | | |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 2 && conveyorLineInfoRead.TaskNo > 0) |
| | | // ç¶åæ ¹æ®ä¸åçç«å°ç±»åæ§è¡ä¸åçä¸å¡é»è¾ |
| | | if (conveyorLineInfoRead != null) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | // æå䏿¥¼å
¥åºå£åå
¥å¯¹åºå
¥åºç«å°å°å |
| | | if (item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && deviceProRead != null && deviceProWrite != null) |
| | | { |
| | | //åé
è´§ä½ |
| | | string? local = _taskService.RequestAssignLocation(task.TaskNum, task.Roadway); |
| | | if (!string.IsNullOrEmpty(local)) |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo <= 0) |
| | | { |
| | | task.CurrentAddress = item.StackerCraneStationCode; |
| | | task.TargetAddress = local; |
| | | task.NextAddress = local; |
| | | task.DeviceCode = item.StackerCraneCode; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·:{task.TaskNum}è¿è¡å åæºå
¥åº"); |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.AGV_Finish.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //åé
å··é åå
¥æçæ°æ® |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, task.Roadway, task.TaskType); |
| | | Dt_Router? router = routers.FirstOrDefault(); |
| | | if (routers == null || routers.Count == 0 || router == null) |
| | | { |
| | | WriteError(item.StationName, $"æªæ¾å°å¯¹åºè·¯ç±ä¿¡æ¯,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); |
| | | continue; |
| | | } |
| | | if (routers.Count > 1) |
| | | { |
| | | WriteError(item.StationName, $"è·¯ç±ä¿¡æ¯é
ç½®é误,设å¤ç¼å·:{item.StationCode},ä»»å¡å·:{task.TaskNum}"); |
| | | continue; |
| | | } |
| | | //åå
¥å
¥åºçº¿ä½å°å |
| | | device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode); |
| | | //æ´æ°ä»»å¡ä¿¡æ¯ |
| | | task.CurrentAddress = item.StationCode; |
| | | task.NextAddress = router.NextPosi; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·{conveyorLineInfoRead.TaskNo}ä¸ä¸æ¥"); |
| | | } |
| | | } |
| | | // 䏿¥¼åºåºå£å¤æçæAGVåæä»»å¡ |
| | | else if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 2 && conveyorLineInfoRead.TaskNo > 0)//䏿¥¼åºåºå£å¤æçæAGVåæä»»å¡ |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //åé
å··é åå
¥æçæ°æ® |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.NextAddress == x.StartPosi); |
| | | Dt_Router router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | WriteError(item.StationName, $"ä»»å¡å·:{task.TaskNum}æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | return Task.CompletedTask; |
| | | } |
| | | //æ´æ°ä»»å¡ä¿¡æ¯ |
| | | task.CurrentAddress = router.StartPosi; |
| | | task.NextAddress = task.TargetAddress; |
| | | task.DeviceCode = router.NextPosi; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Execute); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·{conveyorLineInfoRead.TaskNo}ä¸ä¸æ¥"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null && deviceProWrite != null) |
| | | { |
| | | //åºåºç«å°åé
åºåºå¯¹åºç®æ åºåºå£å°å |
| | | R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress); |
| | | |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo <= 0) |
| | | { |
| | | //è·ååºåºç«å°æ¯å¦åå¨åºåºå¾
æ§è¡ä»»å¡ |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) |
| | | && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | // å
¥åºç«å°åé
è´§ä½åå¤å åå
¥åº |
| | | else if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null) |
| | | { |
| | | //è·åè·¯ç±é
ç½® |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi); |
| | | Dt_Router router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 2 && conveyorLineInfoRead.TaskNo > 0) |
| | | { |
| | | WriteError(item.StationName, $"ä»»å¡å·:{task.TaskNum}æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | return Task.CompletedTask; |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //åé
è´§ä½ |
| | | string? local = _taskService.RequestAssignLocation(task.TaskNum, task.Roadway); |
| | | if (!string.IsNullOrEmpty(local)) |
| | | { |
| | | task.CurrentAddress = item.StackerCraneStationCode; |
| | | task.TargetAddress = local; |
| | | task.NextAddress = local; |
| | | task.DeviceCode = item.StackerCraneCode; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·:{task.TaskNum}è¿è¡å åæºå
¥åº"); |
| | | } |
| | | } |
| | | } |
| | | //åå
¥åºåºçº¿ä½å°å |
| | | device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·:{task.TaskNum}è¿è¡çº¿ä½åºåº"); |
| | | } |
| | | else if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null && deviceProWrite != null) |
| | | { |
| | | //åºåºç«å°åé
åºåºå¯¹åºç®æ åºåºå£å°å |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo <= 0) |
| | | { |
| | | //è·ååºåºç«å°æ¯å¦åå¨åºåºå¾
æ§è¡ä»»å¡ |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) |
| | | && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //è·åè·¯ç±é
ç½® |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi); |
| | | Dt_Router router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | WriteError(item.StationName, $"ä»»å¡å·:{task.TaskNum}æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | return Task.CompletedTask; |
| | | } |
| | | //åå
¥åºåºçº¿ä½å°å |
| | | device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode); |
| | | device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationName, $"ä»»å¡å·:{task.TaskNum}è¿è¡çº¿ä½åºåº"); |
| | | } |
| | | } |
| | | } |
| | | // å°å½åç«å°çè¾éçº¿ä¿¡æ¯æ·»å å°æ°æ®å¯¹è±¡ï¼åªå
å«éè¦çåæ®µ |
| | | if (conveyorLineInfoRead != null) |
| | | { |
| | | var simplifiedInfo = new Dictionary<string, object>(); |
| | | simplifiedInfo["LineCode"] = device.DeviceCode; |
| | | simplifiedInfo["TaskNum"] = conveyorLineInfoRead.TaskNo; // ä»»å¡å· |
| | | simplifiedInfo["PalletCode"] = conveyorLineInfoRead.PalletCode;// æçæ¡ç |
| | | simplifiedInfo["HasGoods"] = conveyorLineInfoRead.TaskNo > 0; // æ¯å¦æè´§ |
| | | simplifiedInfo["Status"] = conveyorLineInfoRead.StatusPV;// ç¶æ |
| | | simplifiedInfo["Command"] = conveyorLineInfoRead.Command; // å½ä»¤ |
| | | ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineCPInfo"])[item.StationCode] = simplifiedInfo; |
| | | } |
| | | } |
| | | } |
| | |
| | | WriteError(item.StationName, $"æªæ¾å°è®¾å¤åç¼å·{item.StationCode}çå议信æ¯"); |
| | | } |
| | | } |
| | | // éè¿WebSocketåéè¾éçº¿æ°æ®å°å端 |
| | | // åºååæ°æ® |
| | | string jsonData = JsonConvert.SerializeObject(conveyorLineCPData); |
| | | // åéæ°æ®å°ææå®¢æ·ç«¯ |
| | | _webSocketServer.PublishAllClientPayload(jsonData); |
| | | // è®°å½åéæ¥å¿ |
| | | WriteInfo(device.DeviceCode, $"WebSocketåéè¾éçº¿æ°æ®ï¼{jsonData}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |