huangxiaoqiang
2025-06-12 a407d85032a312cd93513d24e1bd34219e3aa3c9
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerStationJob/CommonStackerStationCraneJob.cs
@@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Quartz;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common.TaskEnum;
@@ -21,6 +22,7 @@
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.StackerCraneJob;
using WIDESEAWCS_Common;
namespace WIDESEAWCS_Tasks
{
@@ -50,10 +52,6 @@
        {
            try
            {
                // speStackerCrane.GetStackerCraneStatus<StackerCraneAutoStatus>();
                // speStackerCrane.GetStackerCraneStatus<StackerCraneWorkStatus>();
                // speStackerCrane.GetStackerCraneStatus<StackerCraneStatus>();
                CommonStackerStationCrane commonStackerCrane = (CommonStackerStationCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
@@ -70,15 +68,30 @@
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                        {
                            Dt_Task? task = GetTask(commonStackerCrane);
                            Dt_Task? task = null;
                            if (StaticVariable.isLineRun)
                            {
                                StaticVariable.isStackerRun = false;
                                task = GetTask(commonStackerCrane);
                            }
                            if (task != null)
                            {
                                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                if (stackerCraneTaskCommand != null)
                                {
                                    Thread.Sleep(1000);
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        StringBuilder builder = new StringBuilder();
                                        builder.AppendLine();
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】");
                                        builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】");
                                        builder.AppendLine($"时间:【{DateTime.Now}】");
                                        builder.AppendLine();
                                        ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue);
                                        commonStackerCrane.LastTaskType = task.TaskType;
                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                    }
@@ -118,6 +131,10 @@
                WriteError("CommonStackerStationCraneJob", "test", ex);
                //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
            }
            finally
            {
                StaticVariable.isStackerRun = true;
            }
            //WriteDebug("CommonStackerStationCraneJob", "test");
            return Task.CompletedTask;
        }
@@ -134,7 +151,9 @@
            {
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                {
                    string str = $"【{commonStackerCrane.DeviceName}】任务完成,任务号:【{e.TaskNum}】";
                    ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】堆垛机作业状态:【{(int)commonStackerCrane.StackerCraneWorkStatusValue}】时间【{DateTime.Now}】", ConsoleColor.Magenta);
                    string str = $"【{commonStackerCrane.DeviceName}】任务完成,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
                    WriteInfo(commonStackerCrane.DeviceName, str);
                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
@@ -142,7 +161,7 @@
                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    str = $"WMS|WCS任务完成:【{content.Status}】,堆垛机完成信号写入:【{isWorkType}】,任务号:【{e.TaskNum}】";
                    str = $"{commonStackerCrane.DeviceName}】WMS|WCS任务完成:【{content.Status}】,堆垛机完成信号写入:【{isWorkType}】,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
                    WriteInfo(commonStackerCrane.DeviceName, str);
                    ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
                }
@@ -157,6 +176,11 @@
        private Dt_Task? GetTask(CommonStackerStationCrane commonStackerCrane)
        {
            Dt_Task task;
            task = _taskService.QueryOutFireAlarmTask(commonStackerCrane.DeviceCode);
            if (task != null)
            {
                return task;
            }
            task = _taskService.QueryRelocationTask(commonStackerCrane.DeviceCode);
            if (task != null)
@@ -197,6 +221,11 @@
                else
                {
                    return task;
                }
                if (task == null)
                {
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                }
            }
            else if (task == null)
@@ -280,6 +309,7 @@
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            stackerCraneTaskCommand.StartCommand = 1;
            stackerCraneTaskCommand.FireCommand = Convert.ToInt16(task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm ? 2 : 0);
            string[] sourceCodes = task.SourceAddress.Split("-");
            if (sourceCodes.Length == 3)