|  |  |  | 
|---|
|  |  |  | using System.Diagnostics.CodeAnalysis; | 
|---|
|  |  |  | using WIDESEAWCS_BasicInfoRepository; | 
|---|
|  |  |  | using WIDESEAWCS_Common.TaskEnum; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Caches; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Helper; | 
|---|
|  |  |  | using WIDESEAWCS_Core.HttpContextUser; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.MOM; | 
|---|
|  |  |  | using WIDESEAWCS_IProcessRepository; | 
|---|
|  |  |  | using WIDESEAWCS_ITaskInfoRepository; | 
|---|
|  |  |  | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Models; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Service; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; | 
|---|
|  |  |  | using WIDESEAWCS_SignalR; | 
|---|
|  |  |  | using WIDESEAWCS_Tasks.StackerCraneJob; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEAWCS_Tasks | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly ITaskRepository _taskRepository; | 
|---|
|  |  |  | private readonly IProcessRepository _processRepository; | 
|---|
|  |  |  | private readonly IDt_StationManagerRepository _stationManagerRepository; | 
|---|
|  |  |  | private readonly ICacheService _cacheService; | 
|---|
|  |  |  | private readonly INoticeService _noticeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public CommonStackerStationCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, IDt_StationManagerRepository stationManagerRepository) | 
|---|
|  |  |  | public CommonStackerStationCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService = taskService; | 
|---|
|  |  |  | _taskExecuteDetailService = taskExecuteDetailService; | 
|---|
|  |  |  | _taskRepository = taskRepository; | 
|---|
|  |  |  | _processRepository = processRepository; | 
|---|
|  |  |  | _stationManagerRepository = stationManagerRepository; | 
|---|
|  |  |  | _cacheService = cacheService; | 
|---|
|  |  |  | _noticeService = noticeService; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Task Execute(IJobExecutionContext context) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 调用事件总线通知前端 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); | 
|---|
|  |  |  | if (tokenInfos == null || !tokenInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //throw new Exception(commonStackerCrane.DeviceName + "缓存中未找到Token缓存"); | 
|---|
|  |  |  | return Task.CompletedTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList(); | 
|---|
|  |  |  | var userIds = tokenInfos?.Select(x => x.UserId).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | object obj = new | 
|---|
|  |  |  | { | 
|---|
|  |  |  | commonStackerCrane.StackerCraneStatusDes, | 
|---|
|  |  |  | commonStackerCrane.StackerCraneAutoStatusDes, | 
|---|
|  |  |  | commonStackerCrane.StackerCraneWorkStatusDes, | 
|---|
|  |  |  | commonStackerCrane.DeviceCode, | 
|---|
|  |  |  | commonStackerCrane.DeviceName, | 
|---|
|  |  |  | commonStackerCrane.CurrentTaskNum, | 
|---|
|  |  |  | commonStackerCrane.LastTaskNum, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #endregion 调用事件总线通知前端 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | 
|---|
|  |  |  | private Dt_Task? GetTask(CommonStackerStationCrane commonStackerCrane) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task task; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | task = _taskService.QueryRelocationTask(commonStackerCrane.DeviceCode); | 
|---|
|  |  |  | if (task != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return task; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (commonStackerCrane.LastTaskType == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); | 
|---|
|  |  |  | 
|---|
|  |  |  | string[] sourceCodes = task.SourceAddress.Split("-"); | 
|---|
|  |  |  | if (sourceCodes.Length == 3) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stackerCraneTaskCommand.StartRow = (short)(Convert.ToInt16(sourceCodes[0]) % 2 == 0 ? 2:1); | 
|---|
|  |  |  | stackerCraneTaskCommand.StartRow = (short)(Convert.ToInt16(sourceCodes[0]) % 2 == 0 ? 2 : 1); | 
|---|
|  |  |  | stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); | 
|---|
|  |  |  | stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | string[] targetCodes = task.TargetAddress.Split("-"); | 
|---|
|  |  |  | if (targetCodes.Length == 3) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //if (task.Roadway.Contains("FR")) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    if(task.Roadway.EndsWith("03")|| task.Roadway.EndsWith("01")) | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 1 : 2); | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //    else | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 2 : 1); | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); | 
|---|
|  |  |  | //        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //else | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | stackerCraneTaskCommand.EndRow = (short)(Convert.ToInt16(targetCodes[0]) % 2 == 0 ? 2 : 1); | 
|---|
|  |  |  | stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); | 
|---|
|  |  |  | stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return stackerCraneTaskCommand; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 设备心跳 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="commonStackerCrane"></param> | 
|---|
|  |  |  | public async void EqptAlive(CommonStackerCrane commonStackerCrane) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (commonStackerCrane.StackerOnline) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | BasicDto dto = new BasicDto | 
|---|
|  |  |  | { | 
|---|
|  |  |  | EmployeeNo = "T00001", | 
|---|
|  |  |  | EquipmentCode = commonStackerCrane.DeviceCode, | 
|---|
|  |  |  | RequestTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), | 
|---|
|  |  |  | SessionId = Guid.NewGuid().ToString(), | 
|---|
|  |  |  | Software = commonStackerCrane.DeviceName, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | var respone = await HttpHelper.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/EqptAlive", dto.ToJsonString()); | 
|---|
|  |  |  | if (respone != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var result = JsonConvert.DeserializeObject<ResponseEqptAliveDto>(respone); | 
|---|
|  |  |  | if (result != null && result.Success) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (result.KeyFlag == "99") | 
|---|
|  |  |  | commonStackerCrane.StackerOnline = true; | 
|---|
|  |  |  | else if (result.KeyFlag == "98") | 
|---|
|  |  |  | commonStackerCrane.StackerOnline = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|