| | |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Net.Http.Json; |
| | | using System.Net.NetworkInformation; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Reflection.PortableExecutable; |
| | | using System.Text; |
| | | using System.Text.Json.Nodes; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.StackerCraneEnum; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Common.WMSInfo; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_IShuttleCar; |
| | | 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.Enum; |
| | | using WIDESEAWCS_TaskInfoService; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | using static WIDESEAWCS_Common.WMSInfo.RequestWMS; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public class CommonStackerCraneJob : IJob |
| | | public partial class CommonStackerCraneJob : IJob |
| | | { |
| | | private readonly ITaskService _taskService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IShuttleCarService _shuttleCarService; |
| | | |
| | | public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService) |
| | | public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IShuttleCarService shuttleCarService) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskRepository = taskRepository; |
| | | _routerService = routerService; |
| | | _shuttleCarService = shuttleCarService; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | try |
| | | { |
| | | SpeStackerCrane commonStackerCrane1 = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (commonStackerCrane1.GetStackerCraneStatus<StackerCraneAutoStatus>() == StackerCraneAutoStatus.Automatic && commonStackerCrane1.GetStackerCraneStatus<Onlinestate>() == Onlinestate.online) |
| | | SpeStackerCrane commonStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (commonStackerCrane != null) |
| | | { |
| | | #region ä¿¡å·äº¤äºå¤ç |
| | | Heartbeat(commonStackerCrane); |
| | | ShuttleCarSignal(commonStackerCrane); |
| | | #endregion |
| | | |
| | | #region ä»»å¡é»è¾å¤ç |
| | | if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Onlinestate) == (short)Onlinestate.online |
| | | && commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WriteStatus) == (short)WriteStatus.Permit) |
| | | { |
| | | #region ä»»å¡å®æ |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = commonStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CompleteStatus).ToString() && x.DeviceProParamName == nameof(StackerCraneTaskCommandR.CompleteStatus)); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType); |
| | | if (method != null) method.Invoke(this, new object[] { commonStackerCrane }); |
| | | } |
| | | #endregion |
| | | |
| | | #region æ¥è¯¢ä»»å¡,é»è¾å¤ç |
| | | if (Enum.Parse<RunStatus>(commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.RunStatus).ToString()) == RunStatus.Standby) |
| | | { |
| | | var Task = _taskService.GetTaskState(TaskType: (int)TaskOtherTypeEnum.RelocationCar);//è·åç§»è½¦ä»»å¡ |
| | | if (Task != null) |
| | | { |
| | | if (Task.TaskState == (int)TaskCarStatusEnum.ShuttleCar_Finish) SendTask(commonStackerCrane, Task); |
| | | } |
| | | else |
| | | { |
| | | Dt_Task? task = GetTask(commonStackerCrane);//è·åå åæºåºå
¥åºä»»å¡ |
| | | if (task != null) |
| | | { |
| | | if (task.TaskType == (int)TaskInboundTypeEnum.Inbound) |
| | | { |
| | | var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//å
¥åºä»»å¡å¤ææ¯å¦åå¨ç©¿æ¢è½¦ |
| | | if (task.IsPickPlace && ShuttleCar != null)//移走 |
| | | { |
| | | _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode); |
| | | } |
| | | else if (!task.IsPickPlace && ShuttleCar == null) |
| | | { |
| | | _taskService.AddRelocationCarTask("", task.TargetAddress); |
| | | } |
| | | else |
| | | { |
| | | SendTask(commonStackerCrane, task);//ä¸åå åæºä»»å¡ |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | #region ä»»å¡ä¸åç»å åæº |
| | | private void SendTask(SpeStackerCrane commonStackerCrane, Dt_Task task) |
| | | { |
| | | |
| | | StackerCraneTaskCommandW? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand != null) |
| | | { |
| | | bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); |
| | | bool worktype = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, task.TaskType == (int)TaskOtherTypeEnum.RelocationCar ? 2 : 1); |
| | | if (sendFlag && worktype) |
| | | { |
| | | if (commonStackerCrane.SetValue(StackerCraneDBName.CommandSend, sendFlag)) |
| | | { |
| | | commonStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡å®æäºä»¶è®¢é
çæ¹æ³ |
| | |
| | | private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e) |
| | | { |
| | | CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; |
| | | SpeStackerCrane? commonStackerCrane1 = sender as SpeStackerCrane; |
| | | commonStackerCrane1.GetStackerCraneStatus<StackerCraneDBName>(); |
| | | if (commonStackerCrane != null) |
| | | { |
| | | if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任塿£å¸¸å®æ |
| | | /// </summary> |
| | | /// <param name="commonStackerCrane"></param> |
| | | public void NormalCompleted(SpeStackerCrane commonStackerCrane) |
| | | { |
| | | if (commonStackerCrane != null) |
| | | { |
| | | Console.Out.WriteLine($"å åæºä»»å¡å®æï¼[{commonStackerCrane.CurrentTaskNum}]ï¼{DateTime.Now}"); |
| | | var Status = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum).Status;///éä¿®æ¹ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ |
| | | commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, Status); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è·åä»»å¡ |
| | | /// </summary> |
| | | /// <param name="commonStackerCrane">å åæºå¯¹è±¡</param> |
| | | /// <returns></returns> |
| | | private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane) |
| | | private Dt_Task? GetTask(SpeStackerCrane commonStackerCrane) |
| | | { |
| | | Dt_Task task; |
| | | if (commonStackerCrane.LastTaskType == null) |
| | |
| | | else |
| | | { |
| | | task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); |
| | | if (task == null) |
| | | { |
| | | task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes); |
| | | foreach (var item in tasks) |
| | | { |
| | | if (OutTaskStationIsOccupied(task) != null) |
| | | if (OutTaskStationIsOccupied(item) != null) |
| | | { |
| | | return task; |
| | | return item; |
| | | } |
| | | } |
| | | task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); |
| | | } |
| | | } |
| | | |
| | | if (task != null && task.TargetAddress != "SC01") return task;//å
¥åºä»»å¡å¤ææ¯å¦å·²åé
è´§ä½ï¼WMSå¤æè´§ä½ç¶ææ¯å¦å
许æ¾è´§ |
| | | return task; |
| | | } |
| | | |
| | |
| | | /// <param name="task">ä»»å¡å®ä½</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task) |
| | | public StackerCraneTaskCommandW? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task) |
| | | { |
| | | StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand(); |
| | | StackerCraneTaskCommandW stackerCraneTaskCommand = new StackerCraneTaskCommandW(); |
| | | |
| | | stackerCraneTaskCommand.Barcode = task.PalletCode; |
| | | stackerCraneTaskCommand.TaskNum = task.TaskNum; |
| | | stackerCraneTaskCommand.WorkType = 1; |
| | | stackerCraneTaskCommand.WorkType = (short)WorkType.Cargo; |
| | | stackerCraneTaskCommand.TrayType = 0; |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//夿æ¯å¦æ¯å
¥åºä»»å¡ |
| | | { |