wanshenmean
2025-03-27 0d9fb6555efa42e27de4d57d3fb7b8d82a78ef45
CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,14 +1,9 @@
using AutoMapper;
using HslCommunication;
using Microsoft.AspNetCore.Components.Routing;
using NetTaste;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.Drawing;
using System.Reflection;
using System.Security.Policy;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
@@ -31,7 +26,6 @@
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
namespace WIDESEAWCS_Tasks
@@ -281,7 +275,8 @@
                                    command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                    // 调用处理方法
                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                                };
                                }
                                ;
                            }
                        }
                    }
@@ -296,6 +291,7 @@
            }
            return Task.CompletedTask;
        }
        #region 入库
        /// <summary>
@@ -351,15 +347,23 @@
                }
                else
                {
                    // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务
                    if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
                    task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                    if (task != null)
                    {
                        // 查询条码对应的任务
                        task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
                        if (task == null)
                        RequestInNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    }
                    else
                    {
                        // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务
                        if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull())
                        {
                            // 异步处理新任务
                            await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                            // 查询条码对应的任务
                            task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode);
                            if (task == null)
                            {
                                // 异步处理新任务
                                await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                            }
                        }
                    }
                }
@@ -371,7 +375,7 @@
            }
        }
        public string RequestInboundPlatform(string childDeviceCode,string productLine,bool IsTrayBarcode)
        public string RequestInboundPlatform(string childDeviceCode, string productLine, bool IsTrayBarcode)
        {
            try
            {
@@ -398,11 +402,11 @@
                                }
                                else
                                {
                                    var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                                    if (Hastask != null && Hastask.Count > 0)
                                    {
                                        //doto处理陈化未执行的空托出库任务
                                    }
                                    //var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew);
                                    //if (Hastask != null && Hastask.Count > 0)
                                    //{
                                    //    //doto处理陈化未执行的空托出库任务
                                    //}
                                    return null;
                                }
                            }
@@ -420,7 +424,7 @@
            {
                ConsoleHelper.WriteErrorLine($"方法RequestInboundPlatform:{ex.Message}");
            }
            return null;
        }
@@ -432,20 +436,19 @@
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode,int ProtocalDetailValue)
        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求入库下一地址";
            ConsoleHelper.WriteWarningLine(log);
            _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
            WriteInfo(conveyorLine.DeviceName, log);
            if (childDeviceCode == "1279")
            {
                var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
                CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue, stationManager);
            }
            //if (childDeviceCode == "1279")
            //{
            //    var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
            //    CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue, stationManager);
            //}
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null)
            {
@@ -467,6 +470,8 @@
                        WriteInfo(conveyorLine.DeviceName, logs);
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    }
                }
            }
@@ -744,8 +749,8 @@
        #endregion 出库
        #region 输送线交互完成
        /// <summary>
        /// 输送线交互完成
        /// </summary>
@@ -776,8 +781,8 @@
                conveyorLine.Communicator.Write(DeviceProAddress, value);
            }
        }
        #endregion
        #endregion
        #region 检测空盘实盘任务
@@ -851,6 +856,7 @@
                // 解析任务数据
                taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                WriteInfo("出库", $"【{JsonConvert.SerializeObject(taskDTO)}】");
                #endregion 调用WMS获取出库任务
@@ -865,6 +871,7 @@
        public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
        {
            var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
            WriteInfo("出库", $"【{JsonConvert.SerializeObject(content)}】");
            if (content.Status)
            {
                Console.WriteLine($"{taskDTO.TargetAddress}呼叫成功");
@@ -959,8 +966,8 @@
        #endregion 设备NG口入库
        #region 输出日志
        public async Task LogAndWarn(string deviceName, string log, string color = "red")
        {
            ConsoleHelper.WriteWarningLine(log);
@@ -970,13 +977,11 @@
        #endregion
        private (ConveyorLineTaskCommand, ConveyorLineTaskCommandWrite) ReadCommands(Dt_StationManager station, CommonConveyorLine conveyorLine)
        {
            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
            return (command, commandWrite);
        }
    }
}