From c3de7bb2097aa347a1f92c2f640d18753aff633a Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期六, 28 二月 2026 13:41:26 +0800
Subject: [PATCH] 添加HTTP客户端助手、枚举、DTO;更新URL
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 207 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 148 insertions(+), 59 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
index ee38b1e..132566c 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -30,6 +30,7 @@
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly ITaskRepository _taskRepository;
private readonly IRouterService _routerService;
+ private readonly StackerCraneCommandConfig _config;
public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService)
{
@@ -37,6 +38,28 @@
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
_routerService = routerService;
+ _config = LoadConfig();
+ }
+
+ /// <summary>
+ /// 鍔犺浇閰嶇疆锛堜紭鍏堢骇锛氶厤缃枃浠� > 榛樿閰嶇疆锛�
+ /// </summary>
+ private static StackerCraneCommandConfig LoadConfig()
+ {
+ try
+ {
+ string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StackerCraneJob", "stackercrane-command-config.json");
+ if (File.Exists(configPath))
+ {
+ string json = File.ReadAllText(configPath);
+ return System.Text.Json.JsonSerializer.Deserialize<StackerCraneCommandConfig>(json) ?? new StackerCraneCommandConfig();
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"閰嶇疆鍔犺浇澶辫触: {ex.Message}锛屼娇鐢ㄩ粯璁ら厤缃�");
+ }
+ return new StackerCraneCommandConfig();
}
public Task Execute(IJobExecutionContext context)
@@ -46,7 +69,7 @@
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " CommonStackerCraneJob Start");
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
- if (!flag || value is not CommonStackerCrane commonStackerCrane)
+ if (!flag || value is not IStackerCrane commonStackerCrane)
{
return Task.CompletedTask;
}
@@ -56,23 +79,17 @@
commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;
}
- if (commonStackerCrane.StackerCraneAutoStatusValue != StackerCraneAutoStatus.Automatic
- || commonStackerCrane.StackerCraneStatusValue != StackerCraneStatus.Normal)
+ if (commonStackerCrane.IsCanSendTask(commonStackerCrane.Communicator, commonStackerCrane.DeviceProDTOs, commonStackerCrane.DeviceProtocolDetailDTOs))
{
- return Task.CompletedTask;
- }
+ commonStackerCrane.CheckStackerCraneTaskCompleted();
- commonStackerCrane.CheckStackerCraneTaskCompleted();
-
- if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
- {
Dt_Task? task = GetTask(commonStackerCrane);
if (task != null)
{
- StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
+ object? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
if (stackerCraneTaskCommand != null)
{
- bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
+ bool sendFlag = SendStackerCraneCommand(commonStackerCrane, stackerCraneTaskCommand);
if (sendFlag)
{
commonStackerCrane.LastTaskType = task.TaskType;
@@ -99,12 +116,12 @@
CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
if (commonStackerCrane != null)
{
- if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
- {
+ //if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+ //{
Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
_taskService.StackCraneTaskCompleted(e.TaskNum);
commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
- }
+ //}
}
}
@@ -113,7 +130,7 @@
/// </summary>
/// <param name="commonStackerCrane">鍫嗗灈鏈哄璞�</param>
/// <returns></returns>
- private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
+ private Dt_Task? GetTask(IStackerCrane commonStackerCrane)
{
Dt_Task? task = null;
if (commonStackerCrane.LastTaskType == null)
@@ -135,10 +152,10 @@
if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
{
- if (IsOutTaskStationAvailable(task))
- {
+ //if (IsOutTaskStationAvailable(task))
+ //{
return task;
- }
+ //}
List<string> otherOutStationCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress, task.TaskType)
.Select(x => x.ChildPosi).ToList();
@@ -184,32 +201,95 @@
/// <summary>
/// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
/// </summary>
- /// <param name="task">浠诲姟瀹炰綋</param>
- /// <returns></returns>
- public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
+ public object? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
{
- StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand
- {
- Barcode = task.PalletCode,
- TaskNum = task.TaskNum,
- WorkType = 1,
- TrayType = 0
- };
+ // 鏍规嵁閰嶇疆鍒ゆ柇鍛戒护绫诲瀷
+ string commandType = GetCommandType(task.Roadway);
- TaskTypeGroup taskTypeGroup = task.TaskType.GetTaskTypeGroup();
- return taskTypeGroup switch
+ // 鍒涘缓骞舵瀯寤哄懡浠�
+ return commandType switch
{
- TaskTypeGroup.InboundGroup => BuildInboundCommand(task, stackerCraneTaskCommand),
- TaskTypeGroup.OutbondGroup => BuildOutboundCommand(task, stackerCraneTaskCommand),
- TaskTypeGroup.RelocationGroup => BuildRelocationCommand(task, stackerCraneTaskCommand),
- _ => stackerCraneTaskCommand
+ "Formation" => BuildCommand(task, CreateFormationCommand(task)),
+ _ => BuildCommand(task, CreateStandardCommand(task))
+ };
+ }
+
+ private static bool SendStackerCraneCommand(IStackerCrane commonStackerCrane, object command)
+ {
+ return command switch
+ {
+ FormationStackerCraneTaskCommand formationCommand => commonStackerCrane.SendCommand(formationCommand),
+ StackerCraneTaskCommand standardCommand => commonStackerCrane.SendCommand(standardCommand),
+ _ => false
};
}
/// <summary>
- /// 鏋勫缓鍏ュ簱鍛戒护
+ /// 鏍规嵁 Roadway 鑾峰彇鍛戒护绫诲瀷
/// </summary>
- private StackerCraneTaskCommand? BuildInboundCommand(Dt_Task task, StackerCraneTaskCommand command)
+ private string GetCommandType(string roadway)
+ {
+ foreach (var mapping in _config.RoadwayCommandMapping)
+ {
+ if (roadway.Contains(mapping.Key))
+ {
+ return mapping.Value;
+ }
+ }
+ return _config.DefaultCommandType;
+ }
+
+ /// <summary>
+ /// 鍒涘缓鏍囧噯鍫嗗灈鏈哄懡浠�
+ /// </summary>
+ private static StackerCraneTaskCommand CreateStandardCommand(Dt_Task task)
+ {
+ return new StackerCraneTaskCommand
+ {
+ //Barcode = task.PalletCode,
+ TaskNum = task.TaskNum,
+ WorkType = 1,
+ WorkAction = 1
+ };
+ }
+
+ /// <summary>
+ /// 鍒涘缓鍒嗗鍫嗗灈鏈哄懡浠�
+ /// </summary>
+ private static FormationStackerCraneTaskCommand CreateFormationCommand(Dt_Task task)
+ {
+ return new FormationStackerCraneTaskCommand
+ {
+ Barcode = task.PalletCode,
+ TaskNum = task.TaskNum,
+ WorkType = 1,
+ WorkAction = 1,
+ FireAlarm = 0,
+ HeartBeat = 0,
+ FieldName = string.Empty
+ };
+ }
+
+ /// <summary>
+ /// 閫氱敤鍛戒护鏋勫缓鏂规硶
+ /// </summary>
+ private T? BuildCommand<T>(Dt_Task task, T command) where T : class
+ {
+ TaskTypeGroup taskTypeGroup = task.TaskType.GetTaskTypeGroup();
+
+ return taskTypeGroup switch
+ {
+ TaskTypeGroup.InboundGroup => BuildInboundCommand(task, command),
+ TaskTypeGroup.OutbondGroup => BuildOutboundCommand(task, command),
+ TaskTypeGroup.RelocationGroup => BuildRelocationCommand(task, command),
+ _ => command
+ };
+ }
+
+ /// <summary>
+ /// 閫氱敤鍏ュ簱鍛戒护鏋勫缓
+ /// </summary>
+ private T? BuildInboundCommand<T>(Dt_Task task, T command) where T : class
{
Dt_Router? router = _routerService.QueryNextRoute(task.CurrentAddress, task.Roadway, task.TaskType);
if (router == null)
@@ -218,9 +298,9 @@
return null;
}
- command.StartRow = Convert.ToInt16(router.SrmRow);
- command.StartColumn = Convert.ToInt16(router.SrmColumn);
- command.StartLayer = Convert.ToInt16(router.SrmLayer);
+ SetCommandProperty(command, "StartRow", Convert.ToInt16(router.SrmRow));
+ SetCommandProperty(command, "StartColumn", Convert.ToInt16(router.SrmColumn));
+ SetCommandProperty(command, "StartLayer", Convert.ToInt16(router.SrmLayer));
if (!TryParseAddress(task.NextAddress, out short endRow, out short endColumn, out short endLayer))
{
@@ -228,17 +308,17 @@
return null;
}
- command.EndRow = endRow;
- command.EndColumn = endColumn;
- command.EndLayer = endLayer;
+ SetCommandProperty(command, "EndRow", endRow);
+ SetCommandProperty(command, "EndColumn", endColumn);
+ SetCommandProperty(command, "EndLayer", endLayer);
return command;
}
/// <summary>
- /// 鏋勫缓鍑哄簱鍛戒护
+ /// 閫氱敤鍑哄簱鍛戒护鏋勫缓
/// </summary>
- private StackerCraneTaskCommand? BuildOutboundCommand(Dt_Task task, StackerCraneTaskCommand command)
+ private T? BuildOutboundCommand<T>(Dt_Task task, T command) where T : class
{
Dt_Router? router = _routerService.QueryNextRoute(task.Roadway, task.TargetAddress, task.TaskType);
if (router == null)
@@ -247,9 +327,9 @@
return null;
}
- command.EndRow = Convert.ToInt16(router.SrmRow);
- command.EndColumn = Convert.ToInt16(router.SrmColumn);
- command.EndLayer = Convert.ToInt16(router.SrmLayer);
+ SetCommandProperty(command, "EndRow", Convert.ToInt16(router.SrmRow));
+ SetCommandProperty(command, "EndColumn", Convert.ToInt16(router.SrmColumn));
+ SetCommandProperty(command, "EndLayer", Convert.ToInt16(router.SrmLayer));
if (!TryParseAddress(task.CurrentAddress, out short startRow, out short startColumn, out short startLayer))
{
@@ -257,17 +337,17 @@
return null;
}
- command.StartRow = startRow;
- command.StartColumn = startColumn;
- command.StartLayer = startLayer;
+ SetCommandProperty(command, "StartRow", startRow);
+ SetCommandProperty(command, "StartColumn", startColumn);
+ SetCommandProperty(command, "StartLayer", startLayer);
return command;
}
/// <summary>
- /// 鏋勫缓绉诲簱鍛戒护
+ /// 閫氱敤绉诲簱鍛戒护鏋勫缓
/// </summary>
- private StackerCraneTaskCommand? BuildRelocationCommand(Dt_Task task, StackerCraneTaskCommand command)
+ private T? BuildRelocationCommand<T>(Dt_Task task, T command) where T : class
{
if (!TryParseAddress(task.NextAddress, out short endRow, out short endColumn, out short endLayer))
{
@@ -275,9 +355,9 @@
return null;
}
- command.EndRow = endRow;
- command.EndColumn = endColumn;
- command.EndLayer = endLayer;
+ SetCommandProperty(command, "EndRow", endRow);
+ SetCommandProperty(command, "EndColumn", endColumn);
+ SetCommandProperty(command, "EndLayer", endLayer);
if (!TryParseAddress(task.CurrentAddress, out short startRow, out short startColumn, out short startLayer))
{
@@ -285,11 +365,20 @@
return null;
}
- command.StartRow = startRow;
- command.StartColumn = startColumn;
- command.StartLayer = startLayer;
+ SetCommandProperty(command, "StartRow", startRow);
+ SetCommandProperty(command, "StartColumn", startColumn);
+ SetCommandProperty(command, "StartLayer", startLayer);
return command;
+ }
+
+ /// <summary>
+ /// 浣跨敤鍙嶅皠璁剧疆鍛戒护灞炴��
+ /// </summary>
+ private static void SetCommandProperty<T>(T command, string propertyName, object value) where T : class
+ {
+ var property = typeof(T).GetProperty(propertyName);
+ property?.SetValue(command, value);
}
/// <summary>
@@ -310,4 +399,4 @@
&& short.TryParse(parts[2], out layer);
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3