From 770531b9645ed712be426346148387f165d39773 Mon Sep 17 00:00:00 2001 From: 肖洋 <cathay_xy@163.com> Date: 星期一, 23 十二月 2024 17:25:45 +0800 Subject: [PATCH] 添加日志功能,更新SignalR接口,优化前端日志展示逻辑 --- Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 106 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 66 insertions(+), 40 deletions(-) diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs index 71047ab..7e0cec8 100644 --- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs +++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs @@ -1,5 +1,6 @@ 锘縰sing 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 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇 // 鑾峰彇缂撳瓨涓殑鐢ㄦ埛淇℃伅 - var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); - if (tokenInfos != null && tokenInfos.Any()) + if (userTokenIds == null && userIds == null) { - var userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList(); - var userIds = tokenInfos.Select(x => x.UserId).ToList(); + var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); + if (tokenInfos != null && tokenInfos.Any()) + { + 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,20 +211,13 @@ 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) { - // 鑾峰彇澶勭悊鏂规硶 - MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType); - if (method != null) - { - command.InteractiveSignal = writeInteractiveSignal; - // 璋冪敤澶勭悊鏂规硶 - method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, itemValue }); - } + 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鍙e叆搴� + #region 璁惧NG鍙e叆搴� public void NGRequestTaskInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, string TargetAddress) { @@ -706,36 +724,44 @@ WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃繑鍥炲弬鏁般�恵result}銆�"); ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); - var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1).ToList(); - if (serialNosError.Count > 0) + if (result1.Success) { - return; - } - if (result1.SerialNos.Count <= 0) - { - // 绌烘墭鐩樺叆搴撻�昏緫 - Dt_Task dt_Task = new Dt_Task() + var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1).ToList(); + if (serialNosError.Count > 0) { - TargetAddress = TargetAddress, - PalletCode = command.Barcode, - NextAddress = TargetAddress, - TaskNum = 0 - }; + return; + } - var next = dt_Task.NextAddress; - var taskCommand = MapTaskCommand(dt_Task, command); - dt_Task.NextAddress = next; + if (result1.SerialNos.Count <= 0) + { + // 绌烘墭鐩樺叆搴撻�昏緫 + Dt_Task dt_Task = new Dt_Task() + { + TargetAddress = TargetAddress, + PalletCode = command.Barcode, + NextAddress = TargetAddress, + TaskNum = 0 + }; - conveyorLine.SendCommand(taskCommand, childDeviceCode); + var next = dt_Task.NextAddress; + var taskCommand = MapTaskCommand(dt_Task, command); + dt_Task.NextAddress = next; - ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); + conveyorLine.SendCommand(taskCommand, childDeviceCode); + + ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); + } + else + { + conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, 1000, childDeviceCode); + + ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); + } } else { - conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, 1000, childDeviceCode); - ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); } } -- Gitblit v1.9.3