肖洋
2025-01-16 a05bbc36d31b8745fad325aa677c29f03d176718
更新
已修改3个文件
已添加4个文件
303 ■■■■ 文件已修改
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/EmptyTrayStationHandler.cs 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/ExceptionPortStationHandler.cs 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/IStationHandler.cs 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/StationHandlerFactory.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
@@ -17,6 +17,7 @@
using WIDESEAWCS_QuartzJob.QuartzExtensions;
using WIDESEAWCS_QuartzJob.Seed;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks;
using WIDESEAWCS_WCSServer.Filter;
var builder = WebApplication.CreateBuilder(args);
@@ -81,6 +82,7 @@
builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit限流 å¯åŠ¨æœåŠ¡
builder.Services.AddScoped<UseServiceDIAttribute>();
builder.Services.AddScoped<CommonConveyorLineJob>();
builder.Services.AddSession();
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -77,79 +77,115 @@
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    ConsoleHelper.WriteColorLine("开始:" + DateTime.Now, ConsoleColor.Cyan);
                    // æŸ¥è¯¢æ‰€æœ‰å­è®¾å¤‡çš„位置
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    // èŽ·å–æ‰€æœ‰ç«™ç‚¹ç®¡ç†å™¨
                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
                    // å¹¶è¡Œå¤„理每个子设备
                    var tasks = childDeviceCodes.Select(childDeviceCode => ProcessDeviceAsync(conveyorLine, childDeviceCode)).ToList();
                    // å¹¶è¡Œå¤„理每个站点管理器
                    tasks = stationManagers.Select(station => Task.Run(async () =>
                    {
                        var (command, commandWrite) = ReadCommands(station, conveyorLine);
                        if (command == null || commandWrite == null)
                        {
                            return;
                        }
                        IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this);
                        await handler.HandleStationAsync(conveyorLine, station, command, commandWrite);
                    })).ToList();
                    #region
                    //foreach (var station in stationManagers)
                    //{
                    //    #region
                    //    //tasks.Add(Task.Run(async () =>
                    //    //{
                    //    //    if (station.stationType == 11)
                    //    //    {
                    //    //        // è¯»å–任务命令和设备命令
                    //    //        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
                    //    //        ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
                    //    //        if (command != null && commandWrite != null)
                    //    //        {
                    //    //            // å°†äº¤äº’信号转换为布尔数组
                    //    //            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
                    //    //            if (structs[0] == true)
                    //    //            {
                    //    //                // è¾“出警告信息
                    //    //                var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】空托盘请求扫码入库";
                    //    //                ConsoleHelper.WriteWarningLine(log);
                    //    //                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                    //    //                WriteInfo(conveyorLine.DeviceName, log);
                    //    //                // å¤„理入库请求
                    //    //                NGRequestTaskInbound(conveyorLine, command, station, 0);
                    //    //            }
                    //    //            else
                    //    //            {
                    //    //                // å‘送完成信号
                    //    //                ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
                    //    //            }
                    //    //        }
                    //    //    }
                    //    //    else if (station.stationType == 5)
                    //    //    {
                    //    //        // è¯»å–任务命令和设备命令
                    //    //        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
                    //    //        ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
                    //    //        if (command != null && commandWrite != null)
                    //    //        {
                    //    //            // å°†äº¤äº’信号转换为布尔数组
                    //    //            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
                    //    //            if (structs[0] == true)
                    //    //            {
                    //    //                // æ£€æŸ¥æ˜¯å¦å­˜åœ¨ä»»åŠ¡
                    //    //                if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0)
                    //    //                {
                    //    //                    return;
                    //    //                }
                    //    //                // è¾“出警告信息
                    //    //                var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】异常口请求扫码入库";
                    //    //                ConsoleHelper.WriteWarningLine(log);
                    //    //                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                    //    //                WriteInfo(conveyorLine.DeviceName, log);
                    //    //                // å¤„理新任务
                    //    //                await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0);
                    //    //            }
                    //    //            else
                    //    //            {
                    //    //                // å‘送完成信号
                    //    //                ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
                    //    //            }
                    //    //        }
                    //    //    }
                    //    //}));
                    //    #endregion
                    //    tasks.Add(Task.Run(async () =>
                    //    {
                    //        var (command, commandWrite) = ReadCommands(station, conveyorLine);
                    //        if (command == null || commandWrite == null)
                    //        {
                    //            return;
                    //        }
                    //        IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this);
                    //        await handler.HandleStationAsync(conveyorLine, station, command, commandWrite);
                    //    }));
                    //}
                    #endregion
                    await Task.WhenAll(tasks);
                    // èŽ·å–æ‰€æœ‰ç«™ç‚¹ç®¡ç†å™¨
                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
                    foreach (var station in stationManagers)
                    {
                        if (station.stationType == 11)
                        {
                            // è¯»å–任务命令和设备命令
                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
                            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
                            if (command != null && commandWrite != null)
                            {
                                // å°†äº¤äº’信号转换为布尔数组
                                var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
                                if (structs[0] == true)
                                {
                                    // è¾“出警告信息
                                    var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】空托盘请求扫码入库";
                                    ConsoleHelper.WriteWarningLine(log);
                                    await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                                    WriteInfo(conveyorLine.DeviceName, log);
                                    // å¤„理入库请求
                                    NGRequestTaskInbound(conveyorLine, command, station, 0);
                                }
                                else
                                {
                                    // å‘送完成信号
                                    ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
                                }
                            }
                        }
                        else if (station.stationType == 5)
                        {
                            // è¯»å–任务命令和设备命令
                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode);
                            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand");
                            if (command != null && commandWrite != null)
                            {
                                // å°†äº¤äº’信号转换为布尔数组
                                var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
                                if (structs[0] == true)
                                {
                                    // æ£€æŸ¥æ˜¯å¦å­˜åœ¨ä»»åŠ¡
                                    if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0)
                                    {
                                        return;
                                    }
                                    // è¾“出警告信息
                                    var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】异常口请求扫码入库";
                                    ConsoleHelper.WriteWarningLine(log);
                                    await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                                    WriteInfo(conveyorLine.DeviceName, log);
                                    // å¤„理新任务
                                    await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0);
                                }
                                else
                                {
                                    // å‘送完成信号
                                    ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
                                }
                            }
                        }
                    }
                    ConsoleHelper.WriteColorLine("结束:" + DateTime.Now, ConsoleColor.Cyan);
                }
            }
            catch (Exception ex)
@@ -853,5 +889,20 @@
        }
        #endregion è®¾å¤‡NG口入库
        public async Task LogAndWarn(string deviceName, string log, string color = "red")
        {
            ConsoleHelper.WriteWarningLine(log);
            await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color });
            WriteInfo(deviceName, log);
        }
        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);
        }
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/EmptyTrayStationHandler.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,33 @@
using HslCommunication;
using MoYu;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks.ConveyorLineJob
{
    public class EmptyTrayStationHandler : IStationHandler
    {
        private readonly CommonConveyorLineJob _commonConveyorLineJob;
        public EmptyTrayStationHandler(CommonConveyorLineJob commonConveyorLineJob)
        {
            _commonConveyorLineJob = commonConveyorLineJob;
        }
        public async Task HandleStationAsync(CommonConveyorLine conveyorLine, Dt_StationManager station, ConveyorLineTaskCommand command, ConveyorLineTaskCommandWrite commandWrite)
        {
            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
            if (structs[0])
            {
                var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】空托盘请求扫码入库";
                await _commonConveyorLineJob.LogAndWarn(conveyorLine.DeviceName, log);
                _commonConveyorLineJob.NGRequestTaskInbound(conveyorLine, command, station, 0);
            }
            else
            {
                _commonConveyorLineJob.ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
            }
        }
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/ExceptionPortStationHandler.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
using HslCommunication;
using MoYu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks.ConveyorLineJob.StationHandler
{
    public class ExceptionPortStationHandler : IStationHandler
    {
        private readonly CommonConveyorLineJob _commonConveyorLineJob;
        private readonly ITaskRepository _taskRepository = App.GetService<ITaskRepository>();
        public ExceptionPortStationHandler(CommonConveyorLineJob commonConveyorLineJob)
        {
            _commonConveyorLineJob = commonConveyorLineJob;
        }
        public async Task HandleStationAsync(CommonConveyorLine conveyorLine, Dt_StationManager station, ConveyorLineTaskCommand command, ConveyorLineTaskCommandWrite commandWrite)
        {
            var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray();
            if (structs[0])
            {
                if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0)
                {
                    return;
                }
                var log = $"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】异常口请求扫码入库";
                await _commonConveyorLineJob.LogAndWarn(conveyorLine.DeviceName, log);
                await _commonConveyorLineJob.HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0);
            }
            else
            {
                _commonConveyorLineJob.ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false);
            }
        }
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/IStationHandler.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks.ConveyorLineJob
{
    public interface IStationHandler
    {
        Task HandleStationAsync(CommonConveyorLine conveyorLine, Dt_StationManager station, ConveyorLineTaskCommand command, ConveyorLineTaskCommandWrite commandWrite);
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/StationHandler/StationHandlerFactory.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
using MoYu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Tasks.ConveyorLineJob.StationHandler;
namespace WIDESEAWCS_Tasks.ConveyorLineJob
{
    public class StationHandlerFactory
    {
        public static IStationHandler GetHandler(int stationType, CommonConveyorLineJob commonConveyorLineJob)
        {
            switch (stationType)
            {
                case 11:
                    return new EmptyTrayStationHandler(commonConveyorLineJob);
                case 5:
                    return new ExceptionPortStationHandler(commonConveyorLineJob);
                default:
                    throw new ArgumentException($"Unsupported station type: {stationType}");
            }
        }
    }
}
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs
@@ -55,7 +55,7 @@
        /// <summary>
        /// å¤„理新任务
        /// </summary>
        private async Task HandleNewTaskAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        public async Task HandleNewTaskAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);