| | |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AngleSharp.Dom; |
| | | using Autofac.Core; |
| | | using AutoMapper; |
| | | using HslCommunication; |
| | | using Microsoft.CodeAnalysis.CSharp.Syntax; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using Quartz; |
| | | using System.Reflection; |
| | | using WIDESEA_Common.Log; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core.Caches; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_DTO.Enum; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | using WIDESEAWCS_Model.Models.BasicInfo; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_SignalR; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public class CommonConveyorLineJob : IJob |
| | | public class CommonConveyorLineJob :JobBase, IJob |
| | | { |
| | | private readonly ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IAgvStationService _agvStationService; |
| | | private readonly IDt_StationManagerService _stationManagerService; |
| | | private readonly IMapper _mapper; |
| | | private readonly ICacheService _cacheService; |
| | | private readonly INoticeService _noticeService; |
| | | private static List<string>? userTokenIds; |
| | | private static List<int>? userIds; |
| | | |
| | | public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IAgvStationService agvStation, IMapper mapper) |
| | | public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _routerService = routerService; |
| | | _agvStationService = agvStation; |
| | | _stationManagerService = stationManagerService; |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | | _noticeService = noticeService; |
| | | _taskRepository = taskRepository; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | public async Task Execute(IJobExecutionContext context) |
| | | { |
| | | try |
| | | { |
| | | wcsWriteLog("LineJob", "è¿è¡ç¶æ", $"å¼å§æ¶é´ï¼{DateTime.Now}"); |
| | | CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (conveyorLine != null) |
| | | { |
| | | //çæåè´§ä»»å¡ï¼æ¾è³ä¸æä½ |
| | | RequestInbound(conveyorLine); |
| | | //æ ¹æ®agv䏿任å¡ï¼æææ¾è³ä¸æå£æç¼åä½ |
| | | RequestOutbound(conveyorLine); //䏿å£éè¦æ¾ä»»å¡ï¼æ¾ç¼ååº |
| | | // è·åææç«ç¹ç®¡çå¨ |
| | | List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); |
| | | |
| | | // å¹¶è¡å¤çæ¯ä¸ªåè®¾å¤ |
| | | var tasks = stationManagers.Select(station => ProcessDeviceAsync(conveyorLine, station)).ToList(); |
| | | |
| | | await Task.WhenAll(tasks); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); |
| | | wcsWriteLog("LineJobé误信æ¯", "å¼å¸¸ä¿¡æ¯", ex.ToString()); |
| | | Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); |
| | | } |
| | | wcsWriteLog("LineJob", "è¿è¡ç¶æ", $"ç»ææ¶é´ï¼{DateTime.Now}"); |
| | | return; |
| | | } |
| | | private Task ProcessDeviceAsync(CommonConveyorLine conveyorLine, Dt_StationManager station) |
| | | { |
| | | try |
| | | { |
| | | ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationName); |
| | | if (command != null) |
| | | { |
| | | #region è°ç¨äºä»¶æ»çº¿éç¥å端 |
| | | |
| | | // è·åç¼åä¸çç¨æ·ä¿¡æ¯ |
| | | var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); |
| | | if (tokenInfos != null && tokenInfos.Any()) |
| | | { |
| | | userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList(); |
| | | userIds = tokenInfos.Select(x => x.UserId).ToList(); |
| | | } |
| | | |
| | | #endregion è°ç¨äºä»¶æ»çº¿éç¥å端 |
| | | |
| | | // å°äº¤äºä¿¡å·è½¬æ¢ä¸ºå¸å°æ°ç» |
| | | var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray(); |
| | | // è·å设å¤å议详æ
|
| | | List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList(); |
| | | |
| | | if (deviceProtocolDetails != null) |
| | | { |
| | | foreach (var item in deviceProtocolDetails) |
| | | { |
| | | int itemValue = Convert.ToInt32(item.ProtocalDetailValue); |
| | | if (structs[itemValue] == true) |
| | | { |
| | | // è·åå¤çæ¹æ³ |
| | | |
| | | MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType); |
| | | if (method != null) |
| | | { |
| | | method.Invoke(this, new object[] { conveyorLine, station }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteInfo(conveyorLine.DeviceName, ex.Message); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线请æ±å
¥åº |
| | | /// çæåè´§ä»»å¡ï¼æ¾è³ä¸æä½ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param>Request outbound |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | public void RequestInbound(CommonConveyorLine conveyorLine) |
| | | public async Task RequestInbound(CommonConveyorLine conveyorLine, Dt_StationManager station) |
| | | { |
| | | List<string> _Task = _taskService.QueryConveyorLineTaskSourceAddress(); |
| | | List<AGVStation> childDeviceCodes = _agvStationService.QuerypLatform(conveyorLine.DeviceCode, _Task); //å¯¹åºæ¯ä¸ªipæ¾å
¨é¨ç䏿ç«ç¹ä¸å«æ¿åæ¶ç¹ç«å°ç¹ |
| | | foreach (var childDeviceCode in childDeviceCodes) |
| | | try |
| | | { |
| | | ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(childDeviceCode.Station_name); |
| | | if (command != null) |
| | | { |
| | | if (command.R_Releasespermitted == 1) |
| | | { |
| | | if (childDeviceCode.Station_material==(int)AgvStationEnum.PadRecycle) |
| | | { |
| | | RequestHcdbst(conveyorLine, childDeviceCode.Station_Area, childDeviceCode.Station_name, childDeviceCode.Station_remark); |
| | | } |
| | | else |
| | | { |
| | | Dt_Task taskDTO = new Dt_Task() |
| | | { |
| | | TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + childDeviceCode.Station_code, |
| | | Grade = 1, |
| | | Roadway = childDeviceCode.Station_Area.ToString(), |
| | | SourceAddress = childDeviceCode.Station_name, |
| | | CurrentAddress = childDeviceCode.Station_name, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = (int)childDeviceCode.Station_material, |
| | | }; |
| | | _taskService.ReceiveWMSTask(taskDTO); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | wcsWriteLog(childDeviceCode.Station_name, "读åä¿¡æ¯", $"æªæ¾å°è¯¥è¯»å模å"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | wcsWriteLog(childDeviceCode.Station_name, "读åä¿¡æ¯", $"éè®¯è¿æ¥éè¯¯ï¼æªæ¾å°è¯»å模åå°å"); |
| | | } |
| | | } |
| | | } |
| | | // è¾åºä¿¡æ¯ï¼è¡¨ç¤ºç«å°è¯·æ±åè´§ |
| | | var log = $"ã{conveyorLine._deviceName}ãç«å°ã{station.stationName}ã请æ±åè´§"; |
| | | await LogAndWarn(conveyorLine.DeviceName, log); |
| | | |
| | | /// <summary> |
| | | /// è¾é线请æ±åºç« |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | public void RequestOutbound(CommonConveyorLine conveyorLine) |
| | | { |
| | | List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformarer(conveyorLine.DeviceCode); |
| | | foreach (var AGVStationitem in AGVStationListdata) |
| | | { |
| | | ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name); |
| | | if (command != null) |
| | | // è·åææä»»å¡æºå°å |
| | | List<string> taskSourceAddress = _taskService.QueryConveyorLineTask(); |
| | | if (_taskService.QueryConveyorLineTask(station.stationName) != null) |
| | | { |
| | | if (command.R_Pickuppermitted == 1) |
| | | ConveyorLineSendFinish(conveyorLine, station.stationName); |
| | | await LogAndWarn(conveyorLine.DeviceName, $"ã{conveyorLine._deviceName}ãç«å°ã{station.stationName}ãåå¨ä»»å¡"); |
| | | return; |
| | | } |
| | | |
| | | // æ ¹æ®è®¾å¤ç¼å·å任塿ºå°åæ¥è¯¢æææªæ§è¡çä»»å¡ |
| | | List<Dt_StationManager> childDeviceCodes = _stationManagerService.QueryPlatform(station, taskSourceAddress); //å¯¹åºæ¯ä¸ªipæ¾å
¨é¨ç䏿ç«ç¹ä¸å«æ¿åæ¶ç¹ç«å°ç¹ |
| | | |
| | | if(childDeviceCodes.Count()==0|| childDeviceCodes == null) |
| | | { |
| | | ConveyorLineSendFinish(conveyorLine, station.stationName); |
| | | await LogAndWarn(conveyorLine.DeviceName, $"ã{conveyorLine._deviceName}ãç«å°ã{station.stationName}ãæªæ¾å°å¯åå¾ç«å°"); |
| | | return; |
| | | } |
| | | |
| | | foreach (var item in childDeviceCodes) |
| | | { |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == item.DeviceCode); |
| | | if (device != null) |
| | | { |
| | | if (AGVStationitem.Station_material == (int)AgvStationEnum.BoardLoad) |
| | | CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device; |
| | | ConveyorLineTaskCommand command = commonConveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName); |
| | | if (command != null) |
| | | { |
| | | Dt_Task agvstack= _taskService.QueryConveyorLineTaskRoadway(AGVStationitem.Station_Area); |
| | | if(agvstack != null) |
| | | var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray(); |
| | | if (structs[2]) |
| | | { |
| | | _taskService.UpdateTargetAddress(agvstack.TaskId, AGVStationitem.Station_name); |
| | | Dt_Task taskDTO = new Dt_Task() |
| | | { |
| | | TaskNum = _taskRepository.GetTaskNo().Result, |
| | | Grade = 1, |
| | | Roadway = item.stationArea.ToString(), |
| | | SourceAddress = station.stationName, |
| | | CurrentAddress= station.stationName, |
| | | TargetAddress = item.stationName, |
| | | NextAddress = item.stationName, |
| | | TaskState = (int)AGVTaskStatusEnum.AGVNew, |
| | | TaskType = (int)AGVTaskTypeEnum.AGVCarry, |
| | | AGVName = item.stationArea switch |
| | | { |
| | | 1 => "AGV01", |
| | | 4 => "AGV03", |
| | | _ => "AGV02", |
| | | } |
| | | }; |
| | | _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO }); |
| | | ConveyorLineSendFinish(conveyorLine,station.stationName); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | //廿¾ç¼ååºåºå |
| | | RequestHcst(conveyorLine, AGVStationitem.Station_Area, AGVStationitem.Station_name, AGVStationitem.Station_remark); |
| | | await LogAndWarn(conveyorLine.DeviceName, $"ç«å°{item.stationName}ç¶æä¸å¯ç¨{structs[2]}"); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | wcsWriteLog(AGVStationitem.Station_name, "读åä¿¡æ¯", $"éè®¯è¿æ¥éè¯¯ï¼æªæ¾å°è¯»å模åå°å"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void RequestHcst(CommonConveyorLine conveyorLine,int Station_Area,string Station_names,string Station_remark) |
| | | { |
| | | List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformmaterial(Station_Area); //æ¥åºç¼åä½ |
| | | if (Station_remark != null) //æ¾å¯»å¯¹åºçæ¾è´§ç«å° |
| | | { |
| | | AGVStationListdata = _agvStationService.QuerypStation_Area2(Station_remark); |
| | | } |
| | | foreach (var AGVStationitem in AGVStationListdata) |
| | | { |
| | | ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name); |
| | | if (command != null) |
| | | { |
| | | if (command.R_Releasespermitted == 1) |
| | | { |
| | | if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name)) |
| | | else |
| | | { |
| | | Dt_Task taskDTO = new Dt_Task() |
| | | { |
| | | TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code, |
| | | Grade = 1, |
| | | Roadway = AGVStationitem.Station_Area.ToString(), |
| | | SourceAddress = AGVStationitem.Station_name, |
| | | CurrentAddress = AGVStationitem.Station_name, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = (int)AGVStationitem.Station_material, |
| | | TargetAddress = Station_names, |
| | | NextAddress = Station_names, |
| | | }; |
| | | _taskService.ReceiveWMSTask(taskDTO); |
| | | WriteInfo(conveyorLine.DeviceName, $"éè®¯è¿æ¥é误ï¼{item.stationName}æªæ¾å°è¯»å模åå°å"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | wcsWriteLog(AGVStationitem.Station_name, "读åä¿¡æ¯", $"éè®¯è¿æ¥éè¯¯ï¼æªæ¾å°è¯»å模åå°å"); |
| | | var logerror = $"ã{conveyorLine.DeviceName}ãç«å°ï¼ã{item.stationName}ãæªé
置设å¤è¡¨å¤´"; |
| | | await LogAndWarn(conveyorLine.DeviceName, logerror); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void RequestHcdbst(CommonConveyorLine conveyorLine, int Station_Area, string Station_names,string Station_remark) |
| | | { |
| | | List<AGVStation> AGVStationListdata = _agvStationService.QuerypStation_Area(Station_Area); //æ¥åºç¼åä½ |
| | | if(Station_remark !=null) //æ¾å¯»å¯¹åºçæ¾è´§ç«å° |
| | | catch (Exception ex) |
| | | { |
| | | AGVStationListdata= _agvStationService.QuerypStation_Area2(Station_remark); |
| | | } |
| | | |
| | | foreach (var AGVStationitem in AGVStationListdata) |
| | | { |
| | | ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name); |
| | | if (command != null) |
| | | { |
| | | if (command.R_Releasespermitted == 1) |
| | | { |
| | | if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name)) |
| | | { |
| | | Dt_Task taskDTO = new Dt_Task() |
| | | { |
| | | TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code, |
| | | Grade = 1, |
| | | Roadway = AGVStationitem.Station_Area.ToString(), |
| | | SourceAddress = Station_names, |
| | | CurrentAddress = Station_names, |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | TaskType = (int)AGVStationitem.Station_material, |
| | | TargetAddress = AGVStationitem.Station_name, |
| | | NextAddress = AGVStationitem.Station_name, |
| | | }; |
| | | _taskService.ReceiveWMSTask(taskDTO); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | wcsWriteLog(AGVStationitem.Station_name, "读åä¿¡æ¯", $"è¯»åæ¾è´§ä¿¡å·ä¸ºï¼{command.R_Releasespermitted}"); |
| | | } |
| | | } |
| | | WriteInfo(conveyorLine.DeviceName, ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 读åä¿¡æ¯è®°å½ |
| | | /// è¾é线交äºå®æ |
| | | /// </summary> |
| | | /// <param name="SCLLinStack"></param> |
| | | /// <param name="Logtype"></param> |
| | | /// <param name="Magessadd"></param> |
| | | public void wcsWriteLog(string SCLLinStack,string Logtype,string Magessadd) |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | /// <param name="value">å¼</param> |
| | | public void ConveyorLineSendFinish(CommonConveyorLine conveyorLine, string childDeviceCode) |
| | | { |
| | | WriteLog.Write_Log("ç«å°è¯»åä¿¡æ¯è®°å½", SCLLinStack+"ç«å°", Logtype, new{ä¿¡æ¯ = Magessadd }); |
| | | DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == childDeviceCode && x.DeviceProParamName == "WriteInteractiveSignal").OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | conveyorLine.Communicator.Write(devicePro.DeviceProAddress, true); |
| | | } |
| | | |
| | | public async Task LogAndWarn(string deviceName, string log, string color = "red") |
| | | { |
| | | ConsoleHelper.WriteWarningLine(log); |
| | | await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color }); |
| | | WriteInfo(deviceName, log); |
| | | } |
| | | } |
| | | } |