肖洋
2024-12-23 770531b9645ed712be426346148387f165d39773
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,5 +1,6 @@
using AutoMapper;
using HslCommunication;
using NetTaste;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
@@ -42,6 +43,10 @@
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService)
        {
@@ -157,15 +162,30 @@
            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(childDeviceCode, "DeviceCommand");
            if (command != null && commandWrite != null)
            {
                #region 调用事件总线通知前端
                // 获取缓存中的用户信息
                if (userTokenIds == null && userIds == null)
                {
                var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                if (tokenInfos != null && tokenInfos.Any())
                {
                    var userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList();
                    var userIds = tokenInfos.Select(x => x.UserId).ToList();
                        userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList();
                        userIds = tokenInfos.Select(x => x.UserId).ToList();
                        // 构造通知数据
                        object obj = new
                        {
                            command,
                            commandWrite
                        };
                        // 发送通知
                        _noticeService.LineData(userIds.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, childDeviceCode, data = obj });
                    }
                }
                else
                {
                    // 构造通知数据
                    object obj = new
                    {
@@ -191,12 +211,6 @@
                        int itemValue = item.ProtocalDetailValue.ObjToInt();
                        if (structs[itemValue] == true)
                        {
                            var numRead = itemValue;
                            var numWrite = itemValue + 1;
                            // 输出警告信息
                            ConsoleHelper.WriteWarningLine($"【{conveyorLine.DeviceName}】【{childDeviceCode}】【{numRead.ToString()}】位输送线读取信号:【{structs[itemValue]}】 【{numWrite}】位WCS写入信号:【{structs[itemValue + 1]}】");
                            if (structs[itemValue + 1] != structs[itemValue])
                            {
                                // 获取处理方法
                                MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType);
                                if (method != null)
@@ -204,7 +218,6 @@
                                    command.InteractiveSignal = writeInteractiveSignal;
                                    // 调用处理方法
                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, itemValue });
                                }
                            }
                        }
                        else
@@ -239,6 +252,7 @@
                        }
                    }
                }
            }
            return Task.CompletedTask;
        }
@@ -252,12 +266,16 @@
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public async Task RequestInboundAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        public async Task RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            try
            {
                // 输出警告信息,表示任务已到达子设备并请求扫码入库
                ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库");
                var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库";
                ConsoleHelper.WriteWarningLine(log);
                // 发送通知
                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                WriteInfo(conveyorLine.DeviceName, log);
                // 查询条码对应的任务
                var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode);
@@ -675,7 +693,7 @@
        #endregion 检测空盘实盘任务
        #region 化成NG口入库
        #region 设备NG口入库
        public void NGRequestTaskInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, string TargetAddress)
        {
@@ -705,6 +723,9 @@
            WriteInfo("入站校验", "");
            WriteInfo("入站校验", $"【{childDeviceCode}】入站校验返回参数【{result}】");
            ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result);
            if (result1.Success)
            {
            var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
            if (serialNosError.Count > 0)
@@ -738,6 +759,11 @@
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
            }
        }
            else
            {
            }
        }
        #endregion 化成NG口入库
    }