|  |  |  | 
|---|
|  |  |  | using Microsoft.AspNetCore.Components.Routing; | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  | using Microsoft.AspNetCore.Components.Routing; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using Quartz; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | 
|---|
|  |  |  | using WIDESEAWCS_Core.Caches; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Enums; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Helper; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.TaskInfo; | 
|---|
|  |  |  | using WIDESEAWCS_IBasicInfoRepository; | 
|---|
|  |  |  | using WIDESEAWCS_ITaskInfoRepository; | 
|---|
|  |  |  | using WIDESEAWCS_ITaskInfoService; | 
|---|
|  |  |  | 
|---|
|  |  |  | [DisallowConcurrentExecution] | 
|---|
|  |  |  | public class StackerCraneJob_CSJ : JobBase, IJob | 
|---|
|  |  |  | { | 
|---|
|  |  |  | private readonly IMapper _mapper; | 
|---|
|  |  |  | private readonly ICacheService _cacheService; | 
|---|
|  |  |  | private readonly ITaskService _taskService; | 
|---|
|  |  |  | private readonly ITaskExecuteDetailService _taskExecuteDetailService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly IStationMangerRepository _stationMangerRepository; | 
|---|
|  |  |  | private List<Dt_ApiInfo> apiInfos; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public StackerCraneJob_CSJ(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository) | 
|---|
|  |  |  | public StackerCraneJob_CSJ(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IMapper mapper) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService = taskService; | 
|---|
|  |  |  | _taskExecuteDetailService = taskExecuteDetailService; | 
|---|
|  |  |  | 
|---|
|  |  |  | _routerService = routerService; | 
|---|
|  |  |  | _stationMangerRepository = stationMangerRepository; | 
|---|
|  |  |  | _cacheService = cacheService; | 
|---|
|  |  |  | _mapper = mapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string? apiInfoStr = _cacheService.Get("apiInfos"); | 
|---|
|  |  |  | if (!string.IsNullOrEmpty(apiInfoStr)) | 
|---|
|  |  |  | 
|---|
|  |  |  | commonStackerCrane.CheckStackerCraneTaskCompleted();//鲿¢ä»»å¡å®æäºä»¶çæµè¶
æ¶ï¼åæå¨è§¦å䏿¬¡ | 
|---|
|  |  |  | if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Thread.Sleep(1000); | 
|---|
|  |  |  | Dt_Task? task = GetTask(commonStackerCrane); | 
|---|
|  |  |  | if (task != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | task.ExceptionMessage = ""; | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing); | 
|---|
|  |  |  | //å»¶æ¶1s | 
|---|
|  |  |  | Thread.Sleep(1000); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; | 
|---|
|  |  |  | if (commonStackerCrane != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) | 
|---|
|  |  |  | if (e.TaskNum != 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteDebug(commonStackerCrane.DeviceCode, $"读åå°ä»»å¡å®æ,ä»»å¡å·:{e.TaskNum}"); | 
|---|
|  |  |  | StackerCraneTaskCompleted(e.TaskNum, commonStackerCrane.DeviceCode); | 
|---|
|  |  |  | commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //å¤æç§»åº | 
|---|
|  |  |  | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (OutTaskStationIsOccupied(task) == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | bool flag = false; | 
|---|
|  |  |  | List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList(); | 
|---|
|  |  |  | List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress,task.TaskType).Select(x => x.ChildPosi).ToList(); | 
|---|
|  |  |  | List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes); | 
|---|
|  |  |  | foreach (var item in tasks) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.FeedBackWMSTaskCompleted.ToString())?.ApiAddress; | 
|---|
|  |  |  | string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.WMSIsReloaction.ToString())?.ApiAddress; | 
|---|
|  |  |  | if (string.IsNullOrEmpty(url)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"æªæ¾å°WMSç§»åºå¤ææ¥å£"); | 
|---|
|  |  |  | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°WMSç§»åºå¤ææ¥å£"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.NextAddress}", "");//todo è°ç¨WMSä»»å¡å®ææ¹æ³ | 
|---|
|  |  |  | string response = HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.CurrentAddress}", "");//todo è°ç¨WMSä»»å¡å®ææ¹æ³ | 
|---|
|  |  |  | if (string.IsNullOrEmpty(response)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | WriteError(commonStackerCrane.DeviceCode, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(response); | 
|---|
|  |  |  | if (responseContent == null || !responseContent.Status) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | WriteError(commonStackerCrane.DeviceCode, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.Serialize()); | 
|---|
|  |  |  | if (taskDTO == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | WriteError(commonStackerCrane.DeviceCode, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ç§»åºæ¥å£è°ç¨é误"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (task.TaskNum == taskDTO.TaskNum) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return task; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_Task reloTask = _mapper.Map<Dt_Task>(taskDTO); | 
|---|
|  |  |  | //å¤æç§»åºè´§ä½ä»»å¡æ¯å¦å·²åå¨ï¼å¦åå¨å
æ§è¡ | 
|---|
|  |  |  | Dt_Task existTask = _taskService.QueryStackerExistTask(reloTask.PalletCode, reloTask.SourceAddress); | 
|---|
|  |  |  | if (existTask != null && existTask.TaskState == (int)TaskStatusEnum.SC_Execute) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return existTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (existTask != null && existTask.TaskState != (int)TaskStatusEnum.SC_Execute) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteError(commonStackerCrane.DeviceCode, $"ä»»å¡{task.TaskNum}æµ
è´§ä½ä»»å¡{existTask.TaskNum}ä»»å¡ç¶æä¸ä¸ºå åå¾
æ§è¡"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ä»»å¡{task.TaskNum}æµ
è´§ä½ä»»å¡{existTask.TaskNum}ä»»å¡ç¶æä¸ä¸ºå åå¾
æ§è¡"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | reloTask.TaskState = TaskStatusEnum.SC_Execute.ObjToInt(); | 
|---|
|  |  |  | reloTask.CurrentAddress = taskDTO.SourceAddress; | 
|---|
|  |  |  | reloTask.NextAddress = taskDTO.TargetAddress; | 
|---|
|  |  |  | reloTask.DeviceCode = task.DeviceCode; | 
|---|
|  |  |  | reloTask.TaskType = TaskTypeEnum.Relocation.ObjToInt(); | 
|---|
|  |  |  | int taskId = _taskRepository.AddData(reloTask); | 
|---|
|  |  |  | reloTask.TaskId = taskId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return reloTask; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return task; | 
|---|
|  |  |  | 
|---|
|  |  |  | /// <returns>妿æªè¢«å ç¨ï¼è¿åä¼ å
¥çä»»å¡ä¿¡æ¯ï¼å¦åï¼è¿ånull</returns> | 
|---|
|  |  |  | private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == task.DeviceCode); | 
|---|
|  |  |  | Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => (x.StationCode == task.NextAddress || x.StackerCraneStationCode == task.NextAddress) && x.StackerCraneCode == task.DeviceCode); | 
|---|
|  |  |  | if (stationManger != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); | 
|---|