From 981a80940e47409300c09847684ca530f75b4a5f Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 10 一月 2025 23:56:33 +0800
Subject: [PATCH] 优化WCS辅料出库逻辑
---
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/干膜仓/StackerCraneJob_GM.cs | 136 +++++++++++++++++++++++++++++++++++----------
1 files changed, 105 insertions(+), 31 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/StackerCraneJob_GM.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/StackerCraneJob_GM.cs"
index ffa7452..cf2235c 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/StackerCraneJob_GM.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\345\271\262\350\206\234\344\273\223/StackerCraneJob_GM.cs"
@@ -1,4 +1,5 @@
锘縰sing Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
@@ -6,7 +7,9 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
@@ -20,32 +23,54 @@
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.HoisterJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
+using WIDESEAWCS_Core.Caches;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_QuartzJob.Repository;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
public class StackerCraneJob_GM : JobBase, IJob
{
+ private readonly ICacheService _cacheService;
private readonly ITaskService _taskService;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly ITaskRepository _taskRepository;
private readonly IRouterService _routerService;
private readonly IStationMangerRepository _stationMangerRepository;
+ private readonly IRouterRepository _routerRepository;
+ private List<Dt_ApiInfo> apiInfos;
- public StackerCraneJob_GM(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository)
+ public StackerCraneJob_GM(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
_routerService = routerService;
_stationMangerRepository = stationMangerRepository;
+ _cacheService = cacheService;
+ _routerRepository = routerRepository;
+
+ string? apiInfoStr = _cacheService.Get("apiInfos");
+ if (!string.IsNullOrEmpty(apiInfoStr))
+ {
+ List<Dt_ApiInfo>? infos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr);
+ if (infos == null || infos.Count == 0)
+ {
+ apiInfos = new List<Dt_ApiInfo>();
+ }
+ else
+ {
+ apiInfos = infos;
+ }
+ }
}
public Task Execute(IJobExecutionContext context)
{
- CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
try
{
+ CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
if (commonStackerCrane != null)
{
if (!commonStackerCrane.IsEventSubscribed)
@@ -65,12 +90,11 @@
if (sendFlag)
{
commonStackerCrane.LastTaskType = task.TaskType;
- int oldState = task.TaskState;
- task.TaskState = TaskStatusEnum.SC_Executing.ObjToInt();
- task.ExceptionMessage = "";
task.Dispatchertime = DateTime.Now;
- _taskRepository.UpdateData(task);
- _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskState}銆�");
+ task.ExceptionMessage = "";
+ _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing);
+
+ commonStackerCrane.Communicator.Write("DB105.54", (short)1);
}
}
}
@@ -79,7 +103,7 @@
}
catch (Exception ex)
{
- WriteError(commonStackerCrane.DeviceName, ex.Message, ex);
+ WriteError(nameof(CommonStackerCraneJob), ex.Message, ex);
}
return Task.CompletedTask;
}
@@ -92,30 +116,64 @@
private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
{
CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
+ if (commonStackerCrane != null)
+ {
+ if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+ {
+ StackerCraneTaskCompleted(e.TaskNum, commonStackerCrane.DeviceCode);
+ commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+ }
+ }
+ }
+
+ public WebResponseContent StackerCraneTaskCompleted(int taskNum, string deviceCode)
+ {
try
{
- if (commonStackerCrane != null)
+ Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
+ if (task != null)
{
- if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+ if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
{
- WriteInfo(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,{e.TaskNum}");
- Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
- if (task != null)
+ Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneStationCode == task.NextAddress);
+ if (stationManger == null)
{
- _taskService.TaskCompleted(e.TaskNum);
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"杈撻�佺嚎鍑哄簱绔欑偣鏈厤缃�,{task.NextAddress}");
+ _taskService.UpdateTaskExceptionMessage(taskNum, $"杈撻�佺嚎鍑哄簱绔欑偣鏈厤缃�,{task.NextAddress}");
+ return WebResponseContent.Instance.Error($"杈撻�佺嚎鍑哄簱绔欑偣鏈厤缃�,{task.NextAddress}");
}
- else
- {
- WriteInfo(commonStackerCrane.DeviceName, $"璇诲彇鍒颁换鍔″畬鎴愪俊鍙�,鏈壘鍒板搴旂殑浠诲姟淇℃伅,{e.TaskNum}");
- }
- commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+
+ int oldStatus = task.TaskState;
+ task.DeviceCode = stationManger.StationDeviceCode;
+ task.TaskState = TaskStatusEnum.Line_Execute.ObjToInt();
+ task.CurrentAddress = stationManger.StationCode;
+ _taskRepository.UpdateData(task);
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"绯荤粺鑷姩娴佺▼,锛屼换鍔$姸鎬佷粠銆恵oldStatus}銆戣浆鍒般�恵task.TaskState}銆�");
+ //todo 瀹屾垚
+ }
+ else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
+ {
+ _taskService.TaskCompleted(taskNum);
+ }
+ else
+ {
+ WriteInfo(deviceCode, $"鏈壘鍒拌浠诲姟绫诲瀷鍥炶皟WMS浠诲姟瀹屾垚鎺ュ彛,{task.TaskType}");
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"鏈壘鍒拌浠诲姟绫诲瀷鍥炶皟WMS浠诲姟瀹屾垚鎺ュ彛,{task.TaskType}");
+ _taskService.UpdateTaskExceptionMessage(taskNum, $"鏈壘鍒拌浠诲姟绫诲瀷鍥炶皟WMS浠诲姟瀹屾垚鎺ュ彛,{task.TaskType}");
}
}
+ else
+ {
+ WriteInfo(deviceCode, $"鏈壘鍒颁换鍔′俊鎭�,浠诲姟鍙�:{taskNum}");
+ return WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔′俊鎭�,浠诲姟鍙�:{taskNum}");
+ }
+
+ return WebResponseContent.Instance.OK();
}
catch (Exception ex)
{
- WriteError(commonStackerCrane?.DeviceCode ?? nameof(StackerCraneJob_YM), ex.Message, ex);
-
+ WriteError(deviceCode, $"浠诲姟瀹屾垚閿欒", ex);
+ return WebResponseContent.Instance.Error(ex.Message);
}
}
@@ -153,23 +211,37 @@
if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
{
- if (OutTaskStationIsOccupied(task) != null || true)
+ if (OutTaskStationIsOccupied(task) == null)
{
- return task;
- }
- else
- {
+ bool flag = false;
List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
foreach (var item in tasks)
{
if (OutTaskStationIsOccupied(task) != null)
{
- return task;
+ flag = true;
+ break;
}
}
- task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ if (!flag)
+ {
+ task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ }
}
+ }
+
+ if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+ {
+ string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.FeedBackWMSTaskCompleted.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"鏈壘鍒癢MS绉诲簱鍒ゆ柇鎺ュ彛");
+ WriteInfo(commonStackerCrane.DeviceCode, $"鏈壘鍒癢MS绉诲簱鍒ゆ柇鎺ュ彛");
+ _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒癢MS绉诲簱鍒ゆ柇鎺ュ彛");
+ return null;
+ }
+ HttpHelper.Post($"{url}?taskNum={task.TaskNum}&locationCode={task.NextAddress}", "");//todo 璋冪敤WMS浠诲姟瀹屾垚鏂规硶
}
return task;
@@ -182,14 +254,14 @@
/// <returns>濡傛灉鏈鍗犵敤锛岃繑鍥炰紶鍏ョ殑浠诲姟淇℃伅锛屽惁鍒欙紝杩斿洖null</returns>
private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task)
{
- Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.TargetAddress && x.StackerCraneCode == task.DeviceCode);
+ Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == task.DeviceCode);
if (stationManger != null)
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
if (device != null)
{
OtherDevice client = (OtherDevice)device;
- if (client.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode))//鍑哄簱绔欏彴鏈鍗犵敤
+ if (!client.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Goods, stationManger.StationCode))//鍑哄簱绔欏彴鏈鍗犵敤
{
task.NextAddress = stationManger.StackerCraneStationCode;
_taskRepository.UpdateData(task);
@@ -198,11 +270,13 @@
}
else
{
+ WriteInfo(task.DeviceCode, $"鏈壘鍒板嚭搴撶珯鍙般�恵stationManger.StationDeviceCode}銆戝搴旂殑閫氳瀵硅薄锛屾棤娉曞垽鏂嚭搴撶珯鍙版槸鍚﹁鍗犵敤");
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒板嚭搴撶珯鍙般�恵stationManger.StationDeviceCode}銆戝搴旂殑閫氳瀵硅薄锛屾棤娉曞垽鏂嚭搴撶珯鍙版槸鍚﹁鍗犵敤");
}
}
else
{
+ WriteInfo(task.DeviceCode, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鏍¢獙绔欏彴");
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鏍¢獙绔欏彴");
}
return null;
@@ -221,7 +295,7 @@
stackerCraneTaskCommand.Barcode = task.PalletCode;
stackerCraneTaskCommand.TaskNum = task.TaskNum;
stackerCraneTaskCommand.WorkType = 1;
- stackerCraneTaskCommand.TrayType = 1;
+ stackerCraneTaskCommand.TrayType = (Int16)task.PalletType;
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
{
string[] startCodes = task.CurrentAddress.Split("-");
--
Gitblit v1.9.3