From 75ef0dfecf2331c0828a1a182b1d3243d3041c51 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 13:19:44 +0800
Subject: [PATCH] refactor: 统一日志组件为Serilog并优化相关功能
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs | 85 +++++++++++++++++++++++++++++++-----------
1 files changed, 62 insertions(+), 23 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
index 0017804..79096d3 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineNewJob/CommonConveyorLineNewJob.cs
@@ -1,14 +1,14 @@
using MapsterMapper;
+using Masuit.Tools;
using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Quartz;
+using Serilog;
using SqlSugar;
using WIDESEA_Core;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
-using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
@@ -40,6 +40,11 @@
/// 浠诲姟鏈嶅姟
/// </summary>
private readonly ITaskService _taskService;
+
+ /// <summary>
+ /// 鏈哄櫒浜轰换鍔℃湇鍔�
+ /// </summary>
+ private readonly IRobotTaskService _robotTaskService;
/// <summary>
/// 浠诲姟鎵ц鏄庣粏鏈嶅姟
@@ -75,7 +80,7 @@
/// <summary>
/// 鏃ュ織璁板綍鍣�
/// </summary>
- private readonly ILogger<CommonConveyorLineNewJob> _logger;
+ private readonly ILogger _logger;
/// <summary>
/// 鐩爣鍦板潃鍒拌澶囩被鍨嬬殑鏄犲皠
@@ -83,6 +88,11 @@
/// <remarks>
/// </remarks>
private static List<string> AddressToDeviceType = new List<string> { "11020", "11028" };
+
+ /// <summary>
+ /// 鎵樼洏妫�鏌ヤ綅缃殑鏈�杩戞墽琛屾椂闂达紙鐢ㄤ簬30绉掗棿闅旈檺鍒讹級
+ /// </summary>
+ private static readonly Dictionary<string, DateTime> _lastPalletCheckTime = new();
/// <summary>
/// 鏋勯�犲嚱鏁�
@@ -93,7 +103,7 @@
/// <param name="mapper">瀵硅薄鏄犲皠鍣�</param>
/// <param name="httpClientHelper">HTTP 瀹㈡埛绔府鍔╃被</param>
/// <param name="logger">鏃ュ織璁板綍鍣�</param>
- public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper, ILogger<CommonConveyorLineNewJob> logger)
+ public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper, ILogger logger, IRobotTaskService robotTaskService)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
@@ -101,6 +111,7 @@
_mapper = mapper;
_httpClientHelper = httpClientHelper;
_logger = logger;
+ _robotTaskService = robotTaskService;
// 鍒濆鍖栬皟搴﹀鐞嗗櫒
_conveyorLineDispatch = new ConveyorLineDispatchHandler(_taskService, _taskExecuteDetailService, _routerService, _mapper, _logger);
@@ -133,8 +144,7 @@
if (childDeviceCodes == null || childDeviceCodes.Count == 0)
{
// 娌℃湁瀛愯澶囷紝鐩存帴杩斿洖
- _logger.LogInformation("杈撻�佺嚎 {DeviceCode} 娌℃湁瀛愯澶�", conveyorLine.DeviceCode);
- QuartzLogger.Info($"杈撻�佺嚎 {conveyorLine.DeviceCode} 娌℃湁瀛愯澶�", conveyorLine.DeviceCode);
+ QuartzLogHelper.LogInfo(_logger, "杈撻�佺嚎 {DeviceCode} 娌℃湁瀛愯澶�", $"杈撻�佺嚎 {conveyorLine.DeviceCode} 娌℃湁瀛愯澶�", conveyorLine.DeviceCode, conveyorLine.DeviceCode);
return Task.CompletedTask;
}
@@ -144,9 +154,6 @@
// // 闄愬埗骞跺彂鏁帮細瀛愯澶囨暟閲忓拰 CPU 鏍稿績鏁�*2 鐨勮緝灏忓��
// MaxDegreeOfParallelism = Math.Min(childDeviceCodes.Count, Environment.ProcessorCount * 2),
//};
-
- //_logger.LogDebug("Execute锛氬紑濮嬪苟琛屽鐞嗚緭閫佺嚎 {DeviceCode}锛屽瓙璁惧鏁伴噺: {Count}", conveyorLine.DeviceCode, childDeviceCodes.Count);
- //QuartzLogger.Debug($"寮�濮嬪苟琛屽鐞嗚緭閫佺嚎锛屽瓙璁惧鏁伴噺: {childDeviceCodes.Count}", conveyorLine.DeviceCode);
// 骞惰澶勭悊姣忎釜瀛愯澶�
//Parallel.For(0, childDeviceCodes.Count, parallelOptions, i =>
@@ -162,11 +169,10 @@
// 濡傛灉鍛戒护涓虹┖锛岃烦杩�
if (command == null)
{
- _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", childDeviceCode);
- QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鍛戒护涓虹┖锛岃烦杩�", conveyorLine.DeviceCode);
continue;
}
+ #region 妫�娴嬫槸鍚﹂渶瑕佺┖鎵樼洏
// ========== 妫�鏌ョ壒瀹氫綅缃槸鍚︽湁鎵樼洏 ==========
// 浠庨厤缃腑璇诲彇闇�瑕佹鏌ユ墭鐩樼殑浣嶇疆鍒楄〃
@@ -176,6 +182,13 @@
// 濡傛灉褰撳墠璁惧鍦ㄦ鏌ュ垪琛ㄤ腑
if (checkPalletPositions.Any(x => x.Code == childDeviceCode))
{
+ // 30绉掗棿闅旈檺鍒�
+ if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) &&
+ (DateTime.Now - lastTime).TotalSeconds < 30)
+ {
+ continue;
+ }
+
// 妫�鏌ヨ緭閫佺嚎鐘舵�侊紙鏄惁鏈夋墭鐩橈級
if (command.CV_State == 2)
{
@@ -185,14 +198,15 @@
{
// 娌℃湁浠诲姟锛屽悜 WMS 璇锋眰鍑哄簱鎵樼洏浠诲姟
var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode);
- _logger.LogInformation("Execute锛氭鏌ユ墭鐩樹綅缃� {ChildDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", childDeviceCode);
- QuartzLogger.Info($"妫�鏌ユ墭鐩樹綅缃� {childDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", conveyorLine.DeviceCode);
+ //QuartzLogHelper.LogInfo(_logger, "Execute锛氭鏌ユ墭鐩樹綅缃� {ChildDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", $"妫�鏌ユ墭鐩樹綅缃� {childDeviceCode}锛岃姹俉MS鍑哄簱鎵樼洏浠诲姟", conveyorLine.DeviceCode, childDeviceCode);
var responseResult = _httpClientHelper.Post<WebResponseContent>("GetOutBoundTrayTaskAsync", new CreateTaskDto()
{
WarehouseId = position.WarehouseId,
TargetAddress = childDeviceCode
}.Serialize());
+
+ _lastPalletCheckTime[childDeviceCode] = DateTime.Now;
// 濡傛灉璇锋眰鎴愬姛锛屾帴鏀� WMS 杩斿洖鐨勪换鍔�
if (responseResult.IsSuccess && responseResult.Data.Status)
@@ -205,6 +219,8 @@
}
}
}
+
+ #endregion 妫�娴嬫槸鍚﹂渶瑕佺┖鎵樼洏
// ========== 妫�鏌� PLC_STB 鏍囧織 ==========
// 鍙湁褰� PLC_STB 涓� 1 鏃舵墠澶勭悊浠诲姟
@@ -226,8 +242,7 @@
}
catch (Exception ex)
{
- _logger.LogError(ex, "澶勭悊鎵嬪姩鍏ュ簱浠诲姟寮傚父");
- QuartzLogger.Error($"澶勭悊鎵嬪姩鍏ュ簱浠诲姟寮傚父: {ex.Message}", "CommonConveyorLineNewJob", ex);
+ QuartzLogHelper.LogError(_logger, ex, "澶勭悊鎵嬪姩鍏ュ簱浠诲姟寮傚父", $"澶勭悊鎵嬪姩鍏ュ簱浠诲姟寮傚父: {ex.Message}", "CommonConveyorLineNewJob");
}
continue;
}
@@ -236,8 +251,6 @@
// 鏃犳墭鐩樻潯鐮佹椂锛岃姹傚嚭搴撲换鍔�
if (command.Barcode.IsNullOrEmpty() || command.Barcode.Replace("\0", "") == "")
{
- _logger.LogDebug("Execute锛氬瓙璁惧 {ChildDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", childDeviceCode);
- QuartzLogger.Debug($"瀛愯澶� {childDeviceCode} 鏃犳墭鐩樻潯鐮侊紝璇锋眰鍑哄簱浠诲姟", conveyorLine.DeviceCode);
_conveyorLineDispatch.RequestOutbound(conveyorLine, command, childDeviceCode);
continue;
}
@@ -249,19 +262,46 @@
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
if (!task.IsNullOrEmpty())
{
- _logger.LogInformation("Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊浠诲姟 {TaskNum}锛岀姸鎬�: {Status}", childDeviceCode, task.TaskNum, task.TaskStatus);
- QuartzLogger.Info($"澶勭悊浠诲姟 {task.TaskNum}锛岀姸鎬�: {task.TaskStatus}", conveyorLine.DeviceCode);
+ QuartzLogHelper.LogInfo(_logger, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊浠诲姟 {TaskNum}锛岀姸鎬�: {Status}", $"澶勭悊浠诲姟 {task.TaskNum}锛岀姸鎬�: {task.TaskStatus}", conveyorLine.DeviceCode, childDeviceCode, task.TaskNum, task.TaskStatus);
// 澶勭悊浠诲姟鐘舵�侊紙鏍规嵁鐘舵�佸垎鍙戝埌涓嶅悓鏂规硶锛�
ProcessTaskState(conveyorLine, command, task, childDeviceCode);
return Task.CompletedTask;
+ }
+ else if (command.TaskNo == 1 && !command.Barcode.IsNullOrEmpty() && childDeviceCode == "11068")
+ {
+ if (_robotTaskService.Db.Queryable<Dt_RobotTask>().Any(x => x.RobotTargetAddressPalletCode == command.Barcode))
+ {
+ return Task.CompletedTask;
+ }
+
+ Random rnd = new Random();
+ int num = rnd.StrictNext();//浜х敓鐪熼殢鏈烘暟
+ // 娌℃湁浠诲姟鍙蜂絾鏈夋潯鐮佸苟涓斿湪11068浣嶇疆锛岀洿鎺ユ坊鍔犳満姊版墜缁勭洏浠诲姟
+ Dt_RobotTask robotTask = new Dt_RobotTask
+ {
+ RobotTargetAddressPalletCode = command.Barcode,
+ RobotSourceAddress = "1",
+ RobotTargetAddress = "2", // 鏈烘鎵嬬洰鏍囧湴鍧�
+ RobotTaskType = (int)RobotTaskTypeEnum.GroupPallet, // 缁勭洏浠诲姟
+ RobotTaskState = (int)TaskRobotStatusEnum.RobotNew, // 寰呮墽琛�
+ RobotTaskTotalNum = 48,
+ RobotGrade = 1,
+ RobotRoadway = "娉ㄦ恫缁勭洏鏈烘鎵�",
+ RobotTargetAddressLineCode = childDeviceCode,
+ RobotTaskNum = num, // 鐢熸垚浠诲姟鍙�
+ RobotDispatchertime = DateTime.Now,
+ };
+ if (_robotTaskService.AddData(robotTask).Status)
+ {
+ conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode);
+ }
}
}
}
catch (Exception innerEx)
{
// 璁板綍寮傚父锛屼絾涓嶅奖鍝嶅叾浠栧瓙璁惧鐨勫鐞�
- _logger.LogError(innerEx, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊寮傚父锛孋orrelationId: {CorrelationId}", childDeviceCode, correlationId);
- QuartzLogger.Error($"瀛愯澶囧鐞嗗紓甯�: {innerEx.Message}", conveyorLine.DeviceCode, innerEx);
+ QuartzLogHelper.LogError(_logger, innerEx, "Execute锛氬瓙璁惧 {ChildDeviceCode} 澶勭悊寮傚父锛孋orrelationId: {CorrelationId}", $"瀛愯澶囧鐞嗗紓甯�: {innerEx.Message}", conveyorLine.DeviceCode, childDeviceCode, correlationId);
}
}
}
@@ -269,8 +309,7 @@
catch (Exception ex)
{
// 璁板綍鏁翠綋寮傚父
- _logger.LogError(ex, "Execute锛氳緭閫佺嚎 {DeviceCode} 鎵ц寮傚父", ex.Message);
- QuartzLogger.Error($"杈撻�佺嚎鎵ц寮傚父: {ex.Message}", "CommonConveyorLineNewJob", ex);
+ QuartzLogHelper.LogError(_logger, ex, "Execute锛氳緭閫佺嚎 {DeviceCode} 鎵ц寮傚父", $"杈撻�佺嚎鎵ц寮傚父: {ex.Message}", "CommonConveyorLineNewJob", ex.Message);
}
return Task.CompletedTask;
}
--
Gitblit v1.9.3