From 5171d3f59b89389bf75293afd210cfa6de4ccff7 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 10 四月 2026 23:03:49 +0800
Subject: [PATCH] feat: 添加堆垛机相关常量类并重构代码使用常量
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 84 ++++++++++++++++++++++++++++++++----------
1 files changed, 64 insertions(+), 20 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
index 5ee565e..69ec861 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,17 +1,17 @@
+using Microsoft.Extensions.Logging;
using Quartz;
-using System;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-using System.Threading.Tasks;
-using WIDESEAWCS_Common.TaskEnum;
+using WIDESEA_Core;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
-using WIDESEAWCS_QuartzJob.StackerCrane;
-using WIDESEAWCS_Tasks.StackerCraneJob;
-using WIDESEA_Core;
using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_QuartzJob.StackerCrane;
+using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_Common.Constants;
+using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
@@ -79,6 +79,16 @@
private readonly StackerCraneCommandBuilder _commandBuilder;
/// <summary>
+ /// 鏃ュ織璁板綍鍣�
+ /// </summary>
+ private readonly ILogger<CommonStackerCraneJob> _logger;
+
+ /// <summary>
+ /// 鍫嗗灈鏈鸿澶囩紪鐮�
+ /// </summary>
+ private string _deviceCode = string.Empty;
+
+ /// <summary>
/// 鏋勯�犲嚱鏁�
/// </summary>
/// <param name="taskService">浠诲姟鏈嶅姟</param>
@@ -86,25 +96,28 @@
/// <param name="taskRepository">浠诲姟浠撳偍</param>
/// <param name="routerService">璺敱鏈嶅姟</param>
/// <param name="httpClientHelper">HTTP 瀹㈡埛绔府鍔╃被</param>
+ /// <param name="logger">鏃ュ織璁板綍鍣�</param>
public CommonStackerCraneJob(
ITaskService taskService,
ITaskExecuteDetailService taskExecuteDetailService,
ITaskRepository taskRepository,
IRouterService routerService,
- HttpClientHelper httpClientHelper)
+ HttpClientHelper httpClientHelper,
+ ILogger<CommonStackerCraneJob> logger)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
+ _logger = logger;
// 鍔犺浇閰嶇疆鏂囦欢
_config = LoadConfig();
// 鍒濆鍖栦换鍔¢�夋嫨鍣�
- _taskSelector = new StackerCraneTaskSelector(taskService, routerService, httpClientHelper);
+ _taskSelector = new StackerCraneTaskSelector(taskService, routerService, httpClientHelper, _logger);
// 鍒濆鍖栧懡浠ゆ瀯寤哄櫒
- _commandBuilder = new StackerCraneCommandBuilder(taskService, routerService, _config);
+ _commandBuilder = new StackerCraneCommandBuilder(taskService, routerService, _config, _logger);
}
/// <summary>
@@ -158,26 +171,37 @@
{
// 浠� JobDataMap 鑾峰彇鍫嗗灈鏈鸿澶囧弬鏁�
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
- if (!flag || value is not IStackerCrane commonStackerCrane)
+ if (!flag || value is not CommonStackerCrane commonStackerCrane)
{
// 鍙傛暟鏃犳晥锛岀洿鎺ヨ繑鍥�
+ _logger.LogWarning("Execute锛氬弬鏁版棤鏁�");
+ QuartzLogger.Warn("Execute锛氬弬鏁版棤鏁�", "CommonStackerCraneJob");
return Task.CompletedTask;
}
+
+ _deviceCode = commonStackerCrane.DeviceCode;
// ========== 璁㈤槄浠诲姟瀹屾垚浜嬩欢锛堝叏灞�鍙闃呬竴娆★級 ==========
if (!commonStackerCrane.IsEventSubscribed)
{
// 缁戝畾浠诲姟瀹屾垚浜嬩欢澶勭悊鏂规硶
commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;
+ _logger.LogInformation("Execute锛氳闃呬换鍔″畬鎴愪簨浠讹紝璁惧: {DeviceCode}", _deviceCode);
+ QuartzLogger.Info($"璁㈤槄浠诲姟瀹屾垚浜嬩欢", _deviceCode);
}
// ========== 妫�鏌ュ爢鍨涙満浠诲姟瀹屾垚鐘舵�� ==========
commonStackerCrane.CheckStackerCraneTaskCompleted();
+ //_logger.LogDebug("Execute锛氭鏌ヤ换鍔″畬鎴愮姸鎬侊紝璁惧: {DeviceCode}", _deviceCode);
+ //QuartzLogger.Debug($"妫�鏌ヤ换鍔″畬鎴愮姸鎬侊紝璁惧: {_deviceCode}", _deviceCode);
// ========== 妫�鏌ユ槸鍚﹀彲浠ュ彂閫佹柊浠诲姟 ==========
- if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs))
+ //if (!commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs))
+ if (commonStackerCrane.StackerCraneStatusValue != StackerCraneStatus.Normal)
{
// 鍫嗗灈鏈轰笉鍙敤锛堝姝e湪鎵ц涓婁竴浠诲姟锛夛紝鐩存帴杩斿洖
+ _logger.LogDebug("Execute锛氬爢鍨涙満涓嶅彲鐢紝璁惧: {DeviceCode}", _deviceCode);
+ QuartzLogger.Debug($"鍫嗗灈鏈轰笉鍙敤锛岃澶�: {_deviceCode}", _deviceCode);
return Task.CompletedTask;
}
@@ -187,8 +211,13 @@
if (task == null)
{
// 娌℃湁鍙敤浠诲姟
+ //_logger.LogDebug("Execute锛氭病鏈夊彲鐢ㄤ换鍔★紝璁惧: {DeviceCode}", _deviceCode);
+ //QuartzLogger.Debug($"娌℃湁鍙敤浠诲姟锛岃澶�: {_deviceCode}", _deviceCode);
return Task.CompletedTask;
}
+
+ //_logger.LogInformation("Execute锛氶�夋嫨浠诲姟锛岃澶�: {DeviceCode}锛屼换鍔″彿: {TaskNum}", _deviceCode, task.TaskNum);
+ //QuartzLogger.Info($"閫夋嫨浠诲姟锛屼换鍔″彿: {task.TaskNum}", _deviceCode);
// ========== 鏋勫缓鍛戒护 ==========
// 鍛戒护鏋勫缓涓嬫矇鍒颁笓鐢ㄦ瀯寤哄櫒
@@ -196,6 +225,8 @@
if (stackerCraneTaskCommand == null)
{
// 鍛戒护鏋勫缓澶辫触
+ _logger.LogWarning("Execute锛氬懡浠ゆ瀯寤哄け璐ワ紝璁惧: {DeviceCode}锛屼换鍔″彿: {TaskNum}", _deviceCode, task.TaskNum);
+ QuartzLogger.Warn($"鍛戒护鏋勫缓澶辫触锛屼换鍔″彿: {task.TaskNum}", _deviceCode);
return Task.CompletedTask;
}
@@ -203,15 +234,26 @@
bool sendFlag = SendStackerCraneCommand(commonStackerCrane, stackerCraneTaskCommand);
if (sendFlag)
{
+ Task.Delay(1000).Wait();
+ commonStackerCrane.SetValue(StackerCraneDBName.WorkAction, (short)StackerCraneWorkActionEnum.StartTask);
// 鍙戦�佹垚鍔燂紝鏇存柊鐘舵��
commonStackerCrane.LastTaskType = task.TaskType;
_taskService.UpdateTaskStatusToNext(task.TaskNum);
+
+ _logger.LogInformation("Execute锛氬懡浠ゅ彂閫佹垚鍔燂紝璁惧: {DeviceCode}锛屼换鍔″彿: {TaskNum}", _deviceCode, task.TaskNum);
+ QuartzLogger.Info($"鍛戒护鍙戦�佹垚鍔燂紝浠诲姟鍙�: {task.TaskNum}", _deviceCode);
+ }
+ else
+ {
+ _logger.LogError("Execute锛氬懡浠ゅ彂閫佸け璐ワ紝璁惧: {DeviceCode}锛屼换鍔″彿: {TaskNum}", _deviceCode, task.TaskNum);
+ QuartzLogger.Error($"鍛戒护鍙戦�佸け璐�", _deviceCode);
}
}
catch (Exception ex)
{
// 璁板綍寮傚父
- Console.WriteLine($"CommonStackerCraneJob Error: {ex.Message}");
+ _logger.LogError(ex, "Execute锛氭墽琛屽紓甯革紝璁惧: {DeviceCode}", _deviceCode);
+ QuartzLogger.Error($"鎵ц寮傚父: {ex.Message}", _deviceCode, ex);
}
return Task.CompletedTask;
@@ -235,13 +277,15 @@
if (stackerCrane != null)
{
// 璁板綍鏃ュ織
- Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
+ _logger.LogInformation("CommonStackerCrane_StackerCraneTaskCompletedEventHandler锛氫换鍔″畬鎴愶紝浠诲姟鍙�: {TaskNum}", e.TaskNum);
+ QuartzLogger.Info($"浠诲姟瀹屾垚锛屼换鍔″彿: {e.TaskNum}", stackerCrane.DeviceCode);
// 鏇存柊浠诲姟鐘舵�佷负瀹屾垚
- _taskService.StackCraneTaskCompleted(e.TaskNum);
-
- // 娓呴櫎鍫嗗灈鏈虹殑浣滀笟鎸囦护锛堣缃负 2锛岃〃绀虹┖闂诧級
- stackerCrane.SetValue(StackerCraneDBName.WorkAction, 2);
+ if (_taskService.StackCraneTaskCompleted(e.TaskNum).Status)
+ {
+ // 娓呴櫎鍫嗗灈鏈虹殑浣滀笟鎸囦护锛堣缃负绌洪棽锛�
+ stackerCrane.SetValue(StackerCraneDBName.WorkAction, (short)StackerCraneWorkActionEnum.TaskComplete);
+ }
}
}
@@ -268,4 +312,4 @@
};
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3