| | |
| | | using HslCommunication; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Quartz; |
| | | using Quartz; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IRouterService _routerService; |
| | | |
| | | public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService) |
| | | public CommonStackerCraneJob(ITaskService taskService, ITaskRepository taskRepository, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskRepository = taskRepository; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _routerService = routerService; |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | GetStackerObject getStackerObject = new GetStackerObject(); |
| | | if (speStackerCrane != null) |
| | | { |
| | | if (getStackerObject.StackerCraneTaskCompletedValue(speStackerCrane) == StackerCraneTaskCompleted.WorkCompleted) |
| | | GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane); |
| | | if (!getStackerObject.IsEventSubscribed) |
| | | { |
| | | _taskService.StackCraneTaskCompleted(speStackerCrane.CurrentTaskNum); |
| | | speStackerCrane.SetValue(StackerCraneDBName.WorkType, 2); |
| | | getStackerObject.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订é
ä»»å¡å®æäºä»¶ |
| | | } |
| | | else |
| | | |
| | | getStackerObject.CheckStackerCraneTaskCompleted();//æ£æµå åæºä»»å¡å®æäºä»¶ |
| | | |
| | | if (getStackerObject.StackerCraneStatusValue == StackerCraneStatus.Ready) |
| | | { |
| | | if (getStackerObject.StackerCraneAutoStatusValue(speStackerCrane) == StackerCraneAutoStatus.Automatic && getStackerObject.StackerCraneStatusValue(speStackerCrane) == StackerCraneStatus.Ready) |
| | | Dt_Task? task = GetTask(speStackerCrane); |
| | | if (task != null) |
| | | { |
| | | if (getStackerObject.StackerCraneWorkStatusValue(speStackerCrane) == StackerCraneWorkStatus.Standby) |
| | | bool sendFlag = true; |
| | | //if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt()) |
| | | //{ |
| | | // //åWMSç³è¯·åºå
¥åºå£æ¯å¦æç©ºæç |
| | | // sendFlag = false; |
| | | //} |
| | | if (sendFlag) |
| | | { |
| | | Dt_Task? task = GetTask(speStackerCrane); |
| | | if (task != null) |
| | | StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand != null) |
| | | { |
| | | if (task.TaskType == TaskTypeGroup.OutbondGroup.ObjToInt()) |
| | | sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand); |
| | | if (sendFlag) |
| | | { |
| | | //todoåºåºå¤æè´§æ¶ç¶æ |
| | | StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand != null) |
| | | { |
| | | bool sendFlag = speStackerCrane.SendCommand(stackerCraneTaskCommand); |
| | | if (sendFlag) |
| | | { |
| | | speStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand != null) |
| | | { |
| | | bool sendFlag = speStackerCrane.SendCommand(stackerCraneTaskCommand); |
| | | if (sendFlag) |
| | | { |
| | | speStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | | } |
| | | speStackerCrane.SetValue(StackerCraneDBName.CommandSend, 1);//å¯å¨å½ä»¤ |
| | | speStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString()); |
| | | //WriteLog.GetLog($"å åæºå¼å¸¸").Write($"{nameof(CommonStackerCraneJob)}:{ex.Message}", "å åæºå¼å¸¸"); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e) |
| | | private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, StackerCraneTaskCompletedEventArgs e) |
| | | { |
| | | SpeStackerCrane? speStackerCrane = sender as SpeStackerCrane; |
| | | if (speStackerCrane != null) |
| | | { |
| | | if (speStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) |
| | | if (speStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CommandSend) != 2) |
| | | { |
| | | Console.Out.WriteLine("TaskCompleted" + e.TaskNum); |
| | | _taskService.StackCraneTaskCompleted(e.TaskNum); |
| | | speStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); |
| | | speStackerCrane.SetValue(StackerCraneDBName.CommandSend, 2); |
| | | _taskService.StackCraneTaskCompleted(e.TaskNum, "å åæº"); |
| | | } |
| | | } |
| | | } |
| | |
| | | /// <returns></returns> |
| | | private Dt_Task? GetTask(SpeStackerCrane speStackerCrane) |
| | | { |
| | | Dt_Task task; |
| | | Dt_Task? task; |
| | | string DeviceCode = speStackerCrane.DeviceCode.Contains("CP") ? "CP" : "FL"; |
| | | if (speStackerCrane.LastTaskType == null) |
| | | { |
| | | task = _taskService.QueryStackerCraneTask(speStackerCrane.DeviceCode); |
| | | task = _taskService.QueryStackerCraneTask(DeviceCode); |
| | | } |
| | | else |
| | | { |
| | | if (speStackerCrane.LastTaskType == TaskTypeEnum.Relocation.ObjToInt()) |
| | | { |
| | | task = _taskService.QueryStackerCraneTask(DeviceCode); |
| | | if (task != null) return task; |
| | | } |
| | | bool flag = speStackerCrane.LastTaskType == TaskTypeEnum.Inbound.ObjToInt() || speStackerCrane.LastTaskType == TaskTypeEnum.PalletInbound.ObjToInt(); |
| | | if (flag==false) |
| | | if (flag == false) |
| | | { |
| | | task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode); |
| | | if (task == null) |
| | |
| | | else |
| | | { |
| | | task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode); |
| | | if (task == null) |
| | | { |
| | | task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode); |
| | | } |
| | | } |
| | | } |
| | | return task; |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public bool SendCommands(StackerCraneTaskCommand command,SpeStackerCrane speStackerCrane) |
| | | { |
| | | try |
| | | { |
| | | speStackerCrane.SetValue(StackerCraneDBName.TaskNum, command.TaskNum); |
| | | speStackerCrane.SetValue(StackerCraneDBName.StartRow, command.StartRow); |
| | | speStackerCrane.SetValue(StackerCraneDBName.StartColumn, command.StartColumn); |
| | | speStackerCrane.SetValue(StackerCraneDBName.StartLayer, command.StartLayer); |
| | | speStackerCrane.SetValue(StackerCraneDBName.EndRow, command.EndRow); |
| | | speStackerCrane.SetValue(StackerCraneDBName.EndColumn, command.EndColumn); |
| | | speStackerCrane.SetValue(StackerCraneDBName.EndLayer, command.EndLayer); |
| | | speStackerCrane.SetValue(StackerCraneDBName.Barcode, command.Barcode); |
| | | speStackerCrane.SetValue(StackerCraneDBName.WorkType, command.WorkType); |
| | | speStackerCrane.SetValue(StackerCraneDBName.TrayType, command.TrayType); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// ä»»å¡å®ä½è½¬æ¢æå½ä»¤Model |
| | | /// </summary> |
| | | /// <param name="task">ä»»å¡å®ä½</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task) |
| | | /// <summary> |
| | | /// ä»»å¡å®ä½è½¬æ¢æå½ä»¤Model |
| | | /// </summary> |
| | | /// <param name="task">ä»»å¡å®ä½</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task) |
| | | { |
| | | StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand(); |
| | | |
| | | stackerCraneTaskCommand.Barcode = task.PalletCode; |
| | | stackerCraneTaskCommand.TaskNum = task.TaskNum; |
| | | stackerCraneTaskCommand.WorkType = 1; |
| | | stackerCraneTaskCommand.TrayType = 0; |
| | | if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())//夿æ¯å¦æ¯å
¥åºä»»å¡ |
| | | { |
| | | stackerCraneTaskCommand.WorkType = 1; |
| | | if (task.SourceAddress != null && task.TargetAddress != null) |
| | | { |
| | | string[] sourceCodes = task.SourceAddress.Split("-"); |
| | | if (sourceCodes.Length == 3) |
| | | if (sourceCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); |
| | | stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); |
| | |
| | | return null; |
| | | } |
| | | string[] targetCodes = task.TargetAddress.Split("-"); |
| | | if (targetCodes.Length == 3) |
| | | if (targetCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); |
| | | stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); |
| | |
| | | } |
| | | else if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt()) |
| | | { |
| | | stackerCraneTaskCommand.WorkType = 2; |
| | | if (task.SourceAddress != null && task.TargetAddress != null) |
| | | { |
| | | string[] targetCodes = task.TargetAddress.Split("-"); |
| | | if (targetCodes.Length == 3) |
| | | if (targetCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); |
| | | stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); |
| | |
| | | return null; |
| | | } |
| | | string[] sourceCodes = task.SourceAddress.Split("-"); |
| | | if (sourceCodes.Length == 3) |
| | | if (sourceCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); |
| | | stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); |
| | |
| | | } |
| | | else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt()) |
| | | { |
| | | stackerCraneTaskCommand.WorkType = 3; |
| | | if (task.SourceAddress != null && task.TargetAddress != null) |
| | | { |
| | | string[] targetCodes = task.TargetAddress.Split("-"); |
| | | if (targetCodes.Length == 3) |
| | | if (targetCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]); |
| | | stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]); |
| | |
| | | return null; |
| | | } |
| | | string[] sourceCodes = task.SourceAddress.Split("-"); |
| | | if (sourceCodes.Length == 3) |
| | | if (sourceCodes.Length == 5) |
| | | { |
| | | stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]); |
| | | stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]); |
| | |
| | | } |
| | | return stackerCraneTaskCommand; |
| | | } |
| | | |
| | | } |
| | | } |