| | |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using HslCommunication.WebSocket; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using System; |
| | |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using HslCommunication.WebSocket; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IRouterExtension _routerExtension; |
| | | private readonly WebSocketServer _webSocketServer; |
| | | private readonly List<Dt_WarehouseDevice> warehouseDevices; |
| | | |
| | | public ConveyorLineJob_YL1ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) |
| | | public ConveyorLineJob_YL1ndFloor(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).ToList(); |
| | | //è·åæåè®®çè¾é线-z |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); |
| | | //让æ¯ä¸ªè¾é线å¯å¨-z |
| | | |
| | | // å建è¾éçº¿æ°æ®å¯¹è±¡ï¼ç¨äºWebSocketåé |
| | | var conveyorLineCPData = new Dictionary<string, object>(); |
| | | conveyorLineCPData["设å¤ç¼å·"] = device.DeviceCode; |
| | | conveyorLineCPData["设å¤åç§°"] = "åæåºä¸æ¥¼è¾é线"; |
| | | conveyorLineCPData["ConveyorLineInfo"] = 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(WR_CLineYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceErrRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ErrorYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | R_ConveyorLineYLInfo conveyorLineInfoRead = new R_ConveyorLineYLInfo(); |
| | | R_ErrorYLDB errorYLDB = new R_ErrorYLDB(); |
| | | var simplifiedInfo = new Dictionary<string, object>(); |
| | | if (deviceProRead != null) |
| | | { |
| | | R_ConveyorLineYLInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress); |
| | | conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress); |
| | | |
| | | if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //䏿¥¼æ¥æç§°éç«å°å
许å
¥åºç³è¯· |
| | | { |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode); |
| | | WriteInfo(item.StationCode, $"请æ±å
¥åºæ¡ç :{conveyorLineInfoRead.WR_TMID}"); |
| | | WebResponseContent content = _taskService.YLPurchaseBoxing(conveyorLineInfoRead.WR_TMID, weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width); |
| | | if (content.Status) |
| | | { |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode); |
| | | WriteInfo(item.StationCode, $"请æ±å
¥åºæ¡ç :{conveyorLineInfoRead.WR_TMID}"); |
| | | } |
| | | else |
| | | { |
| | | WriteError(item.StationCode, $"请æ±å
¥åºå¤±è´¥ï¼{content.Message}"); |
| | | } |
| | | |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //䏿¥¼åé
ç«å°å
¥åºåé
ç®æ ç¹ |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //䏿¥¼åé
ç«å°å
¥åºåé
ç®æ ç¹(å¹³å°) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.WR_TMID && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.RfidCode == conveyorLineInfoRead.WR_TMID && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task == null) |
| | | { |
| | | WebResponseContent content = _taskService.RequestYLWMSTaskSimple(conveyorLineInfoRead.WR_TMID, item.StationCode); |
| | |
| | | { |
| | | device.SetValue(WR_CLineYLDB.WR_Task, task.TaskNum, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_ToHode, task.NextAddress, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Width, task.TaskLength, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationCode, conveyorLineInfoRead.Serialize()); |
| | | WriteInfo(item.StationCode, $"{conveyorLineInfoRead.Serialize()}"); |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && conveyorLineInfoRead.WR_Task > 0) //䏿¥¼åé
ç«å°å
¥åºåé
ç®æ ç¹(åºå
) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.WR_Task && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.AGV_Finish.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | //åéä»»å¡ |
| | | if (task != null) |
| | | { |
| | | if (string.IsNullOrEmpty(task.Roadway) && string.IsNullOrEmpty(task.NextAddress)) |
| | | { |
| | | WebResponseContent content = _taskService.AssignYLRoadwayNo(task.PalletCode,weight: conveyorLineInfoRead.WR_Weight, thickness: conveyorLineInfoRead.WR_Height, wide: conveyorLineInfoRead.WR_Width); |
| | | if (content.Status) |
| | | { |
| | | string roadWay = content.Data.ToString(); |
| | | //è·åè·¯ç±é
ç½® |
| | | List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi && x.ChildPosiDeviceCode == roadWay); |
| | | Dt_Router router = routers.FirstOrDefault(); |
| | | if (router == null) |
| | | { |
| | | WriteError(item.StationName, $"ä»»å¡å·:{task.TaskNum}æªæ¾å°è·¯ç±é
置信æ¯"); |
| | | return Task.CompletedTask; |
| | | } |
| | | task.Roadway = roadWay; |
| | | task.NextAddress = router.NextPosi; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.AGV_Finish); |
| | | } |
| | | else |
| | | { |
| | | WriteError(item.StationCode, $"请æ±å
¥åºå¤±è´¥ï¼{content.Message}"); |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | device.SetValue(WR_CLineYLDB.WR_Task, task.TaskNum, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_ToHode, task.NextAddress, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Width, task.TaskLength, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_TMID, task.PalletCode, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationCode, $"请æ±å
¥åºæå:{conveyorLineInfoRead.Serialize()}"); |
| | | } |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode > 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID) && conveyorLineInfoRead.WR_Task>0) //å
¥åºç«å°ç³è¯· |
| | |
| | | |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 99 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID) && conveyorLineInfoRead.WR_Task <= 0) //åºç«å°åé
ç®æ ç¹ |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 99 && conveyorLineInfoRead.WR_Task > 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); |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskNum == conveyorLineInfoRead.WR_Task && _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 (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(WR_CLineYLDB.WR_Task, task.TaskNum, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Width, task.TaskLength, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_TMID, task.PalletCode, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_ToHode, router.NextPosi, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_ToHode, task.NextAddress, item.StationCode); |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode); |
| | | _taskService.UpdateTask(task,TaskStatusEnum.Line_Executing,nextAddress: router.NextPosi); |
| | | if (task.TaskType==TaskTypeEnum.OutPick.ObjToInt()) |
| | | { |
| | | task.Roadway = task.TargetAddress; |
| | | task.TargetAddress = ""; |
| | | task.TaskType=TaskTypeEnum.InPick.ObjToInt(); |
| | | } |
| | | _taskService.UpdateTask(task,TaskStatusEnum.Line_Executing); |
| | | WriteInfo(item.StationCode, $"ä»»å¡å·:{task.TaskNum}åºåºè³{task.NextAddress}"); |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_Task > 0 && conveyorLineInfoRead.WR_Request == 98) //䏿¥¼èååºåºå£å®æ |
| | |
| | | { |
| | | //ä»»å¡åå¤ |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 98, item.StationCode); |
| | | _taskService.TaskCompleted(task.TaskNum); |
| | | WriteInfo(item.StationCode, $"ä»»å¡å·:{task.TaskNum}䏿¥¼åºåºè³èåæ¿å®æ"); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, deviceCode: "CL3_YL"); |
| | | WriteInfo(item.StationCode, $"ä»»å¡å·:{task.TaskNum}ï¼RIFD{task.RfidCode}䏿¥¼åºåºè³èåæ¿å®æ"); |
| | | } |
| | | } |
| | | else if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && conveyorLineInfoRead.WR_Task <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID) && conveyorLineInfoRead.WR_Request == 98) //䏿¥¼èååºåºå£å®æ |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => (x.RfidCode == conveyorLineInfoRead.WR_TMID || x.PalletCode== conveyorLineInfoRead.WR_TMID) && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == device.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | //ä»»å¡åå¤ |
| | | device.SetValue(WR_CLineYLDB.WR_Reresult, 98, item.StationCode); |
| | | _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing, deviceCode: "CL3_YL"); |
| | | WriteInfo(item.StationCode, $"ä»»å¡å·:{task.TaskNum}ï¼RIFD{task.RfidCode}䏿¥¼åºåºè³èåæ¿å®æ"); |
| | | } |
| | | } |
| | | // å°å½åç«å°çè¾éçº¿ä¿¡æ¯æ·»å å°æ°æ®å¯¹è±¡ï¼åªå
å«éè¦çåæ®µ |
| | | if (conveyorLineInfoRead != null) |
| | | { |
| | | simplifiedInfo["LineCode"] = device.DeviceCode; |
| | | simplifiedInfo["TaskNum"] = conveyorLineInfoRead.WR_Task; // ä»»å¡å· |
| | | simplifiedInfo["RFID"] = conveyorLineInfoRead.WR_TMID;//RFID |
| | | simplifiedInfo["Width"] = conveyorLineInfoRead.WR_Width;//纸å·å¹
宽 |
| | | simplifiedInfo["Request"] = conveyorLineInfoRead.WR_Request;//ç³è¯· |
| | | simplifiedInfo["Reresult"] = conveyorLineInfoRead.WR_Reresult;//ç³è¯·åé¦ |
| | | simplifiedInfo["HasGoods"] = conveyorLineInfoRead.WR_ToHode > 0; // æ¯å¦æè´§ |
| | | ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo; |
| | | } |
| | | } |
| | | else if (deviceErrRead!=null) |
| | | { |
| | | |
| | | errorYLDB = device.Communicator.ReadCustomer<R_ErrorYLDB>(deviceErrRead.DeviceProAddress); |
| | | if (errorYLDB != null && errorYLDB.R_Error==2) |
| | | { |
| | | ErrorDeviceInfo? errorDeviceInfo = RoadwayError.Roadways.FirstOrDefault(x=>x.Code==item.StationCode); |
| | | if (errorDeviceInfo==null) |
| | | { |
| | | RoadwayError.Roadways.Add(new ErrorDeviceInfo() { Code = item.StationCode, Roadway = item.StackerCraneCode }); |
| | | } |
| | | } |
| | | else if(errorYLDB != null && errorYLDB.R_Error == 1) |
| | | { |
| | | ErrorDeviceInfo? deviceInfo = RoadwayError.Roadways.FirstOrDefault(x => x.Code == item.StationCode); |
| | | if (deviceInfo != null) |
| | | { |
| | | RoadwayError.Roadways.Remove(deviceInfo); |
| | | } |
| | | } |
| | | if (errorYLDB != null) |
| | | { |
| | | simplifiedInfo["Error"] = errorYLDB.R_Error; |
| | | ((Dictionary<string, Dictionary<string, object>>)conveyorLineCPData["ConveyorLineInfo"])[item.StationCode] = simplifiedInfo; |
| | | } |
| | | } |
| | | else |
| | |
| | | WriteError(item.StationName, $"æªæ¾å°è®¾å¤åç¼å·{item.StationCode}çå议信æ¯"); |
| | | } |
| | | } |
| | | |
| | | // éè¿WebSocketåéè¾éçº¿æ°æ®å°å端 |
| | | // åºååæ°æ® |
| | | string jsonData = JsonConvert.SerializeObject(conveyorLineCPData); |
| | | // åéæ°æ®å°ææå®¢æ·ç«¯ |
| | | _webSocketServer.PublishAllClientPayload(jsonData); |
| | | // è®°å½åéæ¥å¿ |
| | | WriteInfo(device.DeviceCode, $"WebSocketåéè¾éçº¿æ°æ®ï¼{jsonData}"); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |