Zhang-Hong-Lin
2025-05-27 7924008bfdcfc7a73428826fc10ae475b1f71353
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/OHT/OHTJob.cs
@@ -1,10 +1,12 @@
using Autofac.Core;
using HslCommunication;
using HslCommunication.Core;
using HslCommunication.Enthernet;
using HslCommunication.WebSocket;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualBasic.FileIO;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using SixLabors.ImageSharp.PixelFormats;
using System;
@@ -18,6 +20,7 @@
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
@@ -25,6 +28,7 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.OHT;
namespace WIDESEAWCS_Tasks
@@ -36,12 +40,16 @@
        public static OHTReadData oHTReadData = new OHTReadData();
        private readonly ITaskService _taskService;
        private readonly Idt_ErrormsginfoService _ErrormsginfoService;
        private readonly IRepository<Dt_Task_hty> _taskhtyRepository;
        WebSocketServer _webSocketServer;
        public OHTJob(ITaskService taskService, WebSocketServer webSocketServer, Idt_ErrormsginfoService errormsginfoService)
        OtherDevice devicese;
        OtherDevice deviceses;
        public OHTJob(ITaskService taskService, WebSocketServer webSocketServer, Idt_ErrormsginfoService errormsginfoService, IRepository<Dt_Task_hty> taskhtyRepository)
        {
            _taskService = taskService;//注入
            _webSocketServer = webSocketServer;
            _ErrormsginfoService = errormsginfoService;
            _taskhtyRepository = taskhtyRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
@@ -51,6 +59,12 @@
            {
                //天车PLC对象
                OtherDevice device = (OtherDevice)value;
                OtherDevice zxj = (OtherDevice)Storage.Devices.Find(v => v.DeviceName == "阳极整形机");
                OtherDevice gzj = (OtherDevice)Storage.Devices.Find(v => v.DeviceName == "阳极规整机");
                devicese = zxj;
                deviceses = gzj;
                //整形机PLC对象
                var ZXJdevice = Storage.Devices.Find(v => v.DeviceName == "阳极整形机");
                //规整机PLC对象
@@ -110,6 +124,38 @@
                                device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                            }
                        }
                        //剔除出库
                        else if (nawtask.TaskType == (int)TaskOutboundTypeEnum.TiChuChuKu)
                        {
                            //修改状态
                            WebResponseContent result = _taskService.UpdateTaskStatusToLine_Outgrab(nawtask);
                            if (result.Status)
                            {
                                //gzj.SetValue(DeviceDBName.W_GZJ_LockGZJ, true);
                                device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                            }
                        }
                        //剔除入库
                        else if (nawtask.TaskType == (int)TaskInboundTypeEnum.TiChuRuKu)
                        {
                            //修改状态
                            WebResponseContent result = _taskService.UpdateTaskStatusToLine_Ingrab(nawtask);
                            if (result.Status)
                            {
                                device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                            }
                        }
                        //剔除直接出库
                        else if (nawtask.TaskType == (int)TaskOutboundTypeEnum.TiChuZhiJieChuKu)
                        {
                            //修改状态
                            WebResponseContent result = _taskService.UpdateTaskStatusToLine_Outgrab(nawtask);
                            if (result.Status)
                            {
                                //gzj.SetValue(DeviceDBName.W_GZJ_LockGZJ, true);
                                device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                            }
                        }
                        return Task.CompletedTask;
                    }
                    else if (oHTReadData.R_RunState == (int)RunStateEnum.PutCompleted && oHTReadData.R_TaskState == (int)TaskStateEnum.TaskComplete)
@@ -120,6 +166,17 @@
                        {
                            device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                        }
                        var nawtask = _taskService.QueryTakNnmTask(oHTReadData.R_TaskNumber);
                        if (nawtask == null)
                        {
                            throw new Exception(string.Format("天车取货完成任务未查询到任务号{0}", oHTReadData.R_TaskNumber));
                        }
                        //剔除出库与剔除直接出库
                        //if (nawtask.TaskType == (int)TaskOutboundTypeEnum.TiChuChuKu || nawtask.TaskType == (int)TaskOutboundTypeEnum.TiChuZhiJieChuKu)
                        //{
                        //    gzj.SetValue(DeviceDBName.W_GZJ_LockGZJ, false);
                        //}
                        return Task.CompletedTask;
                    }
                    else if (oHTReadData.R_RunState == (int)RunStateEnum.MoveCompleted && oHTReadData.R_TaskState == (int)TaskStateEnum.TaskComplete)
@@ -128,6 +185,15 @@
                        WebResponseContent result = _taskService.StackCraneTaskCompleted(oHTReadData.R_TaskNumber, oHTReadData.weight);
                        if (result.Status)
                        {
                            //剔除出库、直接出库给完成信号
                            //List<Dt_Task_hty> Task_hty = _taskhtyRepository.QueryData();
                            //int shu = Task_hty.Count - 1;
                            //int zhi = Task_hty[shu].TaskId;
                            //Dt_Task_hty lishi = _taskhtyRepository.QueryFirst(x => x.TaskId == zhi);
                            //if (lishi.TargetAddress == "40-2-1")
                            //{
                            //    gzj.SetValue(DeviceDBName.W_GZJ_LockGZJ, false);
                            //}
                            device.SetValue(DeviceDBName.W_ConfirmSignal, 3);
                        }
                        return Task.CompletedTask;
@@ -180,7 +246,7 @@
                    #endregion
                }
                catch (Exception ex)
                {
                {
                    _ErrormsginfoService.UpdateErrorMsg(ex.Message, 1);
                }
            }
@@ -197,7 +263,7 @@
        public OHTTaskCommand? ConvertToOHTTaskCommand([NotNull] Dt_Task task)
        {
            OHTTaskCommand oHtTaskCommand = new OHTTaskCommand();
            if (task.TaskState == (int)TaskInStatusEnum.InNew || task.TaskState == (int)TaskOutStatusEnum.OutNew)
            {
                oHtTaskCommand.W_Task_Type = 2;
@@ -207,7 +273,19 @@
                    oHtTaskCommand.W_Pick_Line = Convert.ToInt16(SourceCodes[0]);
                    oHtTaskCommand.W_Pick_Column = Convert.ToInt16(SourceCodes[1]);
                    oHtTaskCommand.W_Put_Line = 0;
                    oHtTaskCommand.W_Put_Column = 0;
                    oHtTaskCommand.W_Put_Column = 0;
                    //剔除出库(不需要发送信号)
                    //剔除入库
                    if (task.TaskType == (int)TaskInboundTypeEnum.TiChuRuKu)
                    {
                        devicese.SetValue(DeviceDBName.W_ZXJ_LockLocation, true);
                    }
                    //剔除直接出库
                    else if (task.TaskType == (int)TaskOutboundTypeEnum.TiChuZhiJieChuKu)
                    {
                        devicese.SetValue(DeviceDBName.W_ZXJ_LockLocation, true);
                    }
                }
                else
                {
@@ -227,6 +305,25 @@
                    oHtTaskCommand.W_Pick_Column =0;
                    oHtTaskCommand.W_Put_Line = Convert.ToInt16(SourceCodes[0]);
                    oHtTaskCommand.W_Put_Column = Convert.ToInt16(SourceCodes[1]);
                    //剔除出库
                    //if (task.TaskType == (int)TaskOutboundTypeEnum.TiChuChuKu)
                    //{
                    //    deviceses.SetValue(DeviceDBName.W_GZJ_LockGZJ, true);
                    //}
                    //剔除入库
                    if (task.TaskType == (int)TaskInboundTypeEnum.TiChuRuKu)
                    {
                        devicese.SetValue(DeviceDBName.W_ZXJ_LockLocation, false);
                    }
                    //剔除直接出库
                    else if (task.TaskType == (int)TaskOutboundTypeEnum.TiChuZhiJieChuKu)
                    {
                        //deviceses.SetValue(DeviceDBName.W_GZJ_LockGZJ, true);
                        devicese.SetValue(DeviceDBName.W_ZXJ_LockLocation, false);
                    }
                }
                else
                {