wangxinhui
昨天 c6e8b600398de38b6684f5fa1eaaaade8562859b
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/³ÉÆ·²Ö/ConveyorLineJob_CPH.cs
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using Org.BouncyCastle.Tls;
using Quartz;
using SqlSugar.Extensions;
using System;
@@ -38,6 +40,7 @@
        private readonly IRouterService _routerService;
        private readonly IRouterExtension _routerExtension;
        private readonly List<Dt_WarehouseDevice> warehouseDevices;
        private static object lockObj = 0;//
        public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
        {
@@ -63,54 +66,87 @@
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            lock (lockObj)
            {
                //获取当前设备
                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)))
                if (lockObj.ToString()=="0")
                {
                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null)
                    lockObj = 1;
                    Task task = Task.Run(() =>
                    {
                        R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
                        //码垛环线请求任务
                        if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request==1)
                        try
                        {
                            WebResponseContent content = _taskService.RequestWMSTaskSimple(conveyorLineInfoRead.R_BoxCode, item.StationCode);
                            //向WMS请求任务
                            if (true)
                            while (true)
                            {
                                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
                                if (flag && value != null)
                                {
                                    //获取当前设备
                                    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)))
                                    {
                                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                                        DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                                        if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null)
                                        {
                                            R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
                                            //码垛环线请求任务
                                            if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1)
                                            {
                                                //WebResponseContent content = _taskService.RequestWMSTaskSimple(conveyorLineInfoRead.R_BoxCode, item.StationCode);
                                                ////向WMS请求任务
                                                //if (true)
                                                //{
                                                //}
                                                //写入执行数据
                                                device.SetValue(W_CLineCPHDB.W_TaskNo, 1002, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_Channel, 5, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_Long, 400, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_Wide, 370, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_High, 300, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode, item.StationCode);
                                                device.SetValue(W_CLineCPHDB.W_Request, 1, item.StationCode);
                                            }
                                        }
                                        else if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null)
                                        {
                                            R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
                                            //获取码垛口任务更新任务状态
                                            if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0)
                                            {
                                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
                                                if (task != null)
                                                {
                                                    task.CurrentAddress = item.StationCode;
                                                    task.NextAddress = task.TargetAddress;
                                                    task.DeviceCode = item.StackerCraneCode;
                                                    _taskService.UpdateTask(task, TaskStatusEnum.MD_Executing);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息");
                                        }
                                    }
                                }
                                Thread.Sleep(100);
                            }
                        }
                    }
                    else if(item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null)
                    {
                        R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
                        //获取码垛口任务更新任务状态
                        if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0)
                        catch (Exception ex)
                        {
                            lockObj = 0;
                            WriteError(nameof(ConveyorLineJob_CPH), $"错误信息:{ex.Message}");
                        }
                    }
                    else if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && deviceProRead != null)
                    {
                        R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
                        //码垛环线排出口请求取消任务
                        if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0 && conveyorLineInfoRead.R_Request == 2)
                        {
                        }
                    }
                    else
                    {
                        WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息");
                    }
                    });
                }
            }
            return Task.CompletedTask;
        }