|  |  |  | 
|---|
|  |  |  | using WIDESEAWCS_Tasks.HoisterJob; | 
|---|
|  |  |  | using WIDESEAWCS_Tasks.StackerCraneJob; | 
|---|
|  |  |  | using WIDESEAWCS_Core.Caches; | 
|---|
|  |  |  | using WIDESEAWCS_Tasks.ConveyorLineJob; | 
|---|
|  |  |  | using WIDESEAWCS_QuartzJob.Repository; | 
|---|
|  |  |  | using WIDESEAWCS_DTO.TaskInfo; | 
|---|
|  |  |  | using AutoMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEAWCS_Tasks | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly ITaskRepository _taskRepository; | 
|---|
|  |  |  | private readonly IRouterService _routerService; | 
|---|
|  |  |  | private readonly IStationMangerRepository _stationMangerRepository; | 
|---|
|  |  |  | private readonly IRouterRepository _routerRepository; | 
|---|
|  |  |  | private readonly IMapper _mapper; | 
|---|
|  |  |  | private List<Dt_ApiInfo> apiInfos; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository) | 
|---|
|  |  |  | public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IMapper mapper) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskService = taskService; | 
|---|
|  |  |  | _taskExecuteDetailService = taskExecuteDetailService; | 
|---|
|  |  |  | 
|---|
|  |  |  | _routerService = routerService; | 
|---|
|  |  |  | _stationMangerRepository = stationMangerRepository; | 
|---|
|  |  |  | _cacheService = cacheService; | 
|---|
|  |  |  | _routerRepository = routerRepository; | 
|---|
|  |  |  | _mapper = mapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string? apiInfoStr = _cacheService.Get("apiInfos"); | 
|---|
|  |  |  | if (!string.IsNullOrEmpty(apiInfoStr)) | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Thread.Sleep(2200); | 
|---|
|  |  |  | CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); | 
|---|
|  |  |  | if (commonStackerCrane != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (sendFlag) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | commonStackerCrane.LastTaskType = task.TaskType; | 
|---|
|  |  |  | int oldState = task.TaskState; | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.SC_Executing.ObjToInt(); | 
|---|
|  |  |  | task.Dispatchertime = DateTime.Now; | 
|---|
|  |  |  | task.ExceptionMessage = ""; | 
|---|
|  |  |  | _taskRepository.UpdateData(task); | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"ç³»ç»èªå¨æµç¨ï¼ä»»å¡ç¶æä»ã{oldState}ã转å°ã{task.TaskState}ã"); | 
|---|
|  |  |  | if (task.TaskLength<=0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | WriteInfo(commonStackerCrane.DeviceCode, $"ç©æé¿åº¦é误{task.TaskLength}"); | 
|---|
|  |  |  | return Task.CompletedTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | commonStackerCrane.Communicator.Write("DB105.58", (short)task.TaskLength); | 
|---|
|  |  |  | _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing); | 
|---|
|  |  |  | commonStackerCrane.Communicator.Write("DB105.54", (short)1); | 
|---|
|  |  |  | //å»¶æ¶1s | 
|---|
|  |  |  | Thread.Sleep(1000); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneStationCode == task.NextAddress); | 
|---|
|  |  |  | if (stationManger == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"AGVç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(taskNum, $"AGVç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"AGVç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"è¾é线åºåºç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | _taskService.UpdateTaskExceptionMessage(taskNum, $"è¾é线åºåºç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | return WebResponseContent.Instance.Error($"è¾é线åºåºç«ç¹æªé
ç½®,{task.NextAddress}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int oldStatus = task.TaskState; | 
|---|
|  |  |  | task.DeviceCode = "AGV_CSJ"; | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt(); | 
|---|
|  |  |  | task.CurrentAddress = stationManger.AGVStationCode; | 
|---|
|  |  |  | task.NextAddress = task.TargetAddress; | 
|---|
|  |  |  | task.DeviceCode = stationManger.StationDeviceCode; | 
|---|
|  |  |  | task.TaskState = TaskStatusEnum.Line_Execute.ObjToInt(); | 
|---|
|  |  |  | task.CurrentAddress = stationManger.StationCode; | 
|---|
|  |  |  | _taskRepository.UpdateData(task); | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"ç³»ç»èªå¨æµç¨,ï¼ä»»å¡ç¶æä»ã{oldStatus}ã转å°ã{task.TaskState}ã"); | 
|---|
|  |  |  | _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"ç³»ç»èªå¨æµç¨,ä»»å¡ç¶æä»ã{oldStatus}ã转å°ã{task.TaskState}ã"); | 
|---|
|  |  |  | //todo å®æ | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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ç§»åºå¤ææ¥å£"); | 
|---|
|  |  |  | WriteInfo(commonStackerCrane.DeviceCode, $"æªæ¾å°WMSç§»åºå¤ææ¥å£"); | 
|---|
|  |  |  | WriteError(commonStackerCrane.DeviceCode, $"æªæ¾å°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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => (x.StationCode == task.NextAddress || x.StackerCraneStationCode == task.NextAddress) && x.StackerCraneCode == task.DeviceCode); | 
|---|
|  |  |  | existTask.NextAddress = stationManger.StackerCraneStationCode; | 
|---|
|  |  |  | _taskRepository.UpdateData(existTask); | 
|---|
|  |  |  | return existTask; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (existTask != null && existTask.TaskState != (int)TaskStatusEnum.SC_Execute) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | if (device != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | OtherDevice client = (OtherDevice)device; | 
|---|
|  |  |  | if (client.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode))//åºåºç«å°æªè¢«å ç¨ | 
|---|
|  |  |  | bool ReadGood = client.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Goods, stationManger.StationCode); | 
|---|
|  |  |  | if (!ReadGood)//åºåºç«å°æªè¢«å ç¨ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | task.NextAddress = stationManger.StackerCraneStationCode; | 
|---|
|  |  |  | _taskRepository.UpdateData(task); | 
|---|
|  |  |  | client.SetValue(GroundStationDBName.R_IsCanPut, true, stationManger.StationCode); | 
|---|
|  |  |  | return task; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | stackerCraneTaskCommand.Barcode = task.PalletCode; | 
|---|
|  |  |  | stackerCraneTaskCommand.TaskNum = task.TaskNum; | 
|---|
|  |  |  | stackerCraneTaskCommand.WorkType = 1; | 
|---|
|  |  |  | stackerCraneTaskCommand.TrayType = (Int16)task.PalletType; | 
|---|
|  |  |  | stackerCraneTaskCommand.TrayType = 0; | 
|---|
|  |  |  | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//夿æ¯å¦æ¯å
¥åºä»»å¡ | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string[] startCodes = task.CurrentAddress.Split("-"); | 
|---|