zhanghonglin
6 天以前 8f9b9411ca279670bd85fcfa7763987295ed9abf
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/Job/ConveyorLineJob.cs
@@ -3,12 +3,17 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac.Core;
using HslCommunication.WebSocket;
using Microsoft.AspNetCore.Components;
using Quartz;
using SqlSugar;
using WIDESEA_Model.Models.Basic;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO.MES;
using WIDESEAWCS_DTO.Stock;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models.System;
@@ -28,25 +33,31 @@
        private readonly IRepository<Dt_StationManger> _stationMangerRepository;
        private readonly IRepository<Dt_Task> _TaskRepository;
        private readonly IRepository<Dt_FillingOrder> _FillingOrderRepository;
        private readonly ITaskService _ITaskService;
        private static Stock Stock = new Stock();
        private static bool k = true;
        private static int i = 0;
        //判断是否把出库信号发给WMS
        private static bool m = true;
        private static bool n = true;
        //存储信号
        private readonly Commands comm = new Commands();
        public ConveyorLineJob(WebSocketServer webSocketServer, IRepository<Dt_StationManger> stationMangerRepository, IRepository<Dt_Task> TaskRepository, ITaskService ITaskService)
        public ConveyorLineJob(WebSocketServer webSocketServer, IRepository<Dt_StationManger> stationMangerRepository, IRepository<Dt_Task> TaskRepository, IRepository<Dt_FillingOrder> FillingOrderRepository, ITaskService ITaskService)
        {
            _stationMangerRepository = stationMangerRepository;
            _TaskRepository = TaskRepository;
            _ITaskService = ITaskService;
            _FillingOrderRepository = FillingOrderRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
            //堆垛机设备状态
            int sc = comm.GETR_TaskStatus();
            //连接设备
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
@@ -54,29 +65,30 @@
                OtherDevice device = (OtherDevice)value;
                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                //具体设备
                foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                try
                {
                    i++;
                    //读取信号
                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    //DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode ).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    if (deviceProRead != null)
                    //具体设备
                    foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                    {
                        ConveyorLineCommand conveyorLineInfoRead = device.Communicator.ReadCustomer<ConveyorLineCommand>(deviceProRead.DeviceProAddress);
                        //空桶入库任务
                        if (item.StationName == "空桶入")
                        i++;
                        //读取信号
                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                        //DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode ).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                        if (deviceProRead != null)
                        {
                            comm.R_StatusA((short)conveyorLineInfoRead.R_State);
                            comm.R_PickA((short)conveyorLineInfoRead.R_Pick);
                            if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1)
                            ConveyorLineCommand conveyorLineInfoRead = device.Communicator.ReadCustomer<ConveyorLineCommand>(deviceProRead.DeviceProAddress);
                            //空桶入库任务
                            if (item.StationName == "空桶入")
                            {
                                try
                                comm.R_StatusA((short)conveyorLineInfoRead.R_State);
                                comm.R_PickA((short)conveyorLineInfoRead.R_Pick);
                                if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                {
                                    //判断任务是否重复
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.InEmpty);
                                    if (task == null)
                                    {
                                        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"空桶入库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State}" });
                                        //WMS生成任务
                                        string address = AppSettings.Get("WMSApiAddress");
                                        if (!string.IsNullOrEmpty(address))
@@ -85,21 +97,13 @@
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    //写入日志
                                    WriteInfo(device.DeviceCode, $"{ex.Message}");
                                }
                            }
                        }
                        //满桶入库任务
                        if (item.StationName == "满桶入")
                        {
                            comm.R_StatusC((short)conveyorLineInfoRead.R_State);
                            comm.R_PickC((short)conveyorLineInfoRead.R_Pick);
                            if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1)
                            //满桶入库任务
                            if (item.StationName == "满桶入")
                            {
                                try
                                comm.R_StatusC((short)conveyorLineInfoRead.R_State);
                                comm.R_PickC((short)conveyorLineInfoRead.R_Pick);
                                if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                {
                                    //清空物料编号
                                    if (k)
@@ -117,9 +121,10 @@
                                    Stock.MaterialCode4 = conveyorLineInfoRead.R_NumberD;
                                    //判断任务是否重复
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.Infull);
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.Infull || x.TaskType == (int)TaskTypeEnum.OutDirect);
                                    if (task == null)
                                    {
                                        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"满桶入库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State + "//" + conveyorLineInfoRead.R_NumberA + "/" + conveyorLineInfoRead.R_NumberB + "/" + conveyorLineInfoRead.R_NumberC + "/" + conveyorLineInfoRead.R_NumberD}" });
                                        Stock.location = item.location;
                                        //WMS生成任务
                                        string address = AppSettings.Get("WMSApiAddress");
@@ -131,81 +136,48 @@
                                            device.SetValue(ConveyorLineName.W_ReceivedD, 1, item.StationCode);
                                            k = true;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    //写入日志
                                    WriteInfo(device.DeviceCode, $"{ex.Message}");
                                }
                            }
                        }
                        //空桶出
                        if (item.StationName == "空桶出")
                        {
                            comm.R_StatusB((short)conveyorLineInfoRead.R_State);
                            comm.R_PickB((short)conveyorLineInfoRead.R_Pick);
                            if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1)
                            //空桶出
                            if (item.StationName == "空桶出")
                            {
                                try
                                {
                                    //判断任务是否重复
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.OutEmpty);
                                    if (task == null)
                                    {
                                        //WMS生成任务
                                        string address = AppSettings.Get("WMSApiAddress");
                                        if (!string.IsNullOrEmpty(address))
                                        {
                                            HttpHelper.Post($"{address}/api/Task/addOutEmptyTask/?location={item.location}", "");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    //写入日志
                                    WriteInfo(device.DeviceCode, $"{ex.Message}");
                                }
                                comm.R_StatusB((short)conveyorLineInfoRead.R_State);
                                comm.R_PickB((short)conveyorLineInfoRead.R_Pick);
                                //if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                //{
                                //    //判断任务是否重复
                                //    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.OutEmpty);
                                //    if (task == null)
                                //    {
                                //        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"空桶出库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State}" });
                                //        //WMS生成任务
                                //        string address = AppSettings.Get("WMSApiAddress");
                                //        if (!string.IsNullOrEmpty(address))
                                //        {
                                //            HttpHelper.Post($"{address}/api/Task/addOutEmptyTask/?location={item.location}", "");
                                //        }
                                //    }
                                //}
                            }
                        }
                        //满桶出
                        if (item.StationName == "满桶出")
                        {
                            comm.R_StatusD((short)conveyorLineInfoRead.R_State);
                            comm.R_PickD((short)conveyorLineInfoRead.R_Pick);
                            //告诉WMS可以出库
                            if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1)
                            //满桶出
                            if (item.StationName == "满桶出")
                            {
                                if (m)
                                {
                                    //WMS生成任务
                                    string address = AppSettings.Get("WMSApiAddress");
                                    if (!string.IsNullOrEmpty(address))
                                    {
                                        HttpHelper.Post($"{address}/api/Task/WCSSignal/?k=1", "");
                                    }
                                    m = false;
                                    n = true;
                                }
                            }
                            else
                            {
                                if (n)
                                {
                                    //WMS生成任务
                                    string address = AppSettings.Get("WMSApiAddress");
                                    if (!string.IsNullOrEmpty(address))
                                    {
                                        HttpHelper.Post($"{address}/api/Task/WCSSignal/?k=0", "");
                                    }
                                    n = false;
                                    m = true;
                                }
                                comm.R_StatusD((short)conveyorLineInfoRead.R_State);
                                comm.R_PickD((short)conveyorLineInfoRead.R_Pick);
                            }
                        }
                    }
                    i = 0;
                }
                i = 0;
                catch (Exception ex)
                {
                    //写入日志
                    WriteInfo(device.DeviceCode, $"{ex.Message}");
                }
            }
            return Task.CompletedTask;
        }