From 516e36a4748cc5863bc1f0e00fef32062dcf7cde Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期四, 26 十二月 2024 21:56:24 +0800
Subject: [PATCH] 1
---
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/测试架仓/StackerCraneJob_CSJ.cs | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 107 insertions(+), 10 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\265\213\350\257\225\346\236\266\344\273\223/StackerCraneJob_CSJ.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\265\213\350\257\225\346\236\266\344\273\223/StackerCraneJob_CSJ.cs"
index b66585d..2911a93 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\265\213\350\257\225\346\236\266\344\273\223/StackerCraneJob_CSJ.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\265\213\350\257\225\346\236\266\344\273\223/StackerCraneJob_CSJ.cs"
@@ -1,4 +1,5 @@
锘縰sing Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
@@ -6,8 +7,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -19,26 +24,42 @@
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.HoisterJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
-using WIDESEAWCS_Tasks.闃荤剨浠�;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
public class StackerCraneJob_CSJ : 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 List<Dt_ApiInfo> apiInfos;
- public StackerCraneJob_CSJ(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository)
+ public StackerCraneJob_CSJ(ITaskService taskService, ICacheService cacheService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IStationMangerRepository stationMangerRepository)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
_routerService = routerService;
_stationMangerRepository = stationMangerRepository;
+ _cacheService = cacheService;
+
+ 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)
@@ -69,7 +90,10 @@
if (sendFlag)
{
commonStackerCrane.LastTaskType = task.TaskType;
- // _taskService.UpdateTaskStatusToNext(task.TaskNum);
+ int oldState = task.TaskState;
+ task.TaskState = TaskStatusEnum.SC_Executing.ObjToInt();
+ _taskRepository.UpdateData(task);
+ _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskState}銆�");
}
}
}
@@ -97,9 +121,62 @@
if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
{
Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
- // _taskService.StackCraneTaskCompleted(e.TaskNum);
+ StackerCraneTaskCompleted(e.TaskNum, commonStackerCrane.DeviceCode);
commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
}
+ }
+ }
+
+ public WebResponseContent StackerCraneTaskCompleted(int taskNum, string deviceCode)
+ {
+ try
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
+ if (task != null)
+ {
+ if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+ {
+ int oldStatus = task.TaskState;
+ task.DeviceCode = "AGV";
+ task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt();
+ task.CurrentAddress = task.NextAddress;
+ task.NextAddress = task.TargetAddress;
+ _taskRepository.UpdateData(task);
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"绯荤粺鑷姩娴佺▼,锛屼换鍔$姸鎬佷粠銆恵oldStatus}銆戣浆鍒般�恵task.TaskState}銆�");
+ }
+ else if (task.TaskType.GetTaskTypeGroup() != TaskTypeGroup.InboundGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
+ {
+ string? url = apiInfos.FirstOrDefault(x => x.ApiCode == APIEnum.FeedBackWMSTaskCompleted.ToString())?.ApiAddress;
+ if (string.IsNullOrEmpty(url))
+ {
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"鏈壘鍒板洖璋僕MS浠诲姟瀹屾垚鎺ュ彛");
+ WriteInfo(deviceCode, $"鏈壘鍒板洖璋僕MS浠诲姟瀹屾垚鎺ュ彛");
+ return WebResponseContent.Instance.Error();
+ }
+
+ HttpHelper.Post($"{url}?taskNum={taskNum}", "");//todo 璋冪敤WMS浠诲姟瀹屾垚鏂规硶
+ _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"绯荤粺鑷姩娴佺▼,浠诲姟瀹屾垚");
+ _taskRepository.DeleteAndMoveIntoHty(task, OperateTypeEnum.鑷姩瀹屾垚);
+ }
+ 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(deviceCode, $"浠诲姟瀹屾垚閿欒", ex);
+ return WebResponseContent.Instance.Error(ex.Message);
}
}
@@ -156,6 +233,19 @@
}
}
+ 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;
}
@@ -166,7 +256,7 @@
/// <returns>濡傛灉鏈鍗犵敤锛岃繑鍥炰紶鍏ョ殑浠诲姟淇℃伅锛屽惁鍒欙紝杩斿洖null</returns>
private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task)
{
- Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.TargetAddress && x.StackerCraneCode == task.Roadway);
+ 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);
@@ -175,18 +265,21 @@
OtherDevice client = (OtherDevice)device;
if (client.GetValue<GroundStationDBName, bool>(GroundStationDBName.R_IsCanPut, stationManger.StationCode))//鍑哄簱绔欏彴鏈鍗犵敤
{
- task.TargetAddress = stationManger.StackerCraneStationCode;
+ task.NextAddress = stationManger.StackerCraneStationCode;
_taskRepository.UpdateData(task);
+ client.SetValue(GroundStationDBName.R_IsCanPut, true, stationManger.StationCode);
return task;
}
}
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;
@@ -215,7 +308,7 @@
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(startCodes[2]);
string[] targetCodes = task.NextAddress.Split("-");
- if (targetCodes.Length == 3)
+ if (targetCodes.Length == 5)
{
stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
@@ -225,6 +318,7 @@
{
//鏁版嵁閰嶇疆閿欒
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
+ WriteInfo(task.DeviceCode, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
return null;
}
}
@@ -237,7 +331,7 @@
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
string[] sourceCodes = task.CurrentAddress.Split("-");
- if (sourceCodes.Length == 3)
+ if (sourceCodes.Length == 5)
{
stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
@@ -247,13 +341,14 @@
{
//鏁版嵁閰嶇疆閿欒
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
+ WriteInfo(task.DeviceCode, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
return null;
}
}
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
{
string[] targetCodes = task.NextAddress.Split("-");
- if (targetCodes.Length == 3)
+ if (targetCodes.Length == 5)
{
stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
@@ -263,10 +358,11 @@
{
//鏁版嵁閰嶇疆閿欒
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
+ WriteInfo(task.DeviceCode, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
return null;
}
string[] sourceCodes = task.CurrentAddress.Split("-");
- if (sourceCodes.Length == 3)
+ if (sourceCodes.Length == 5)
{
stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
@@ -276,6 +372,7 @@
{
//鏁版嵁閰嶇疆閿欒
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
+ WriteInfo(task.DeviceCode, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
return null;
}
}
--
Gitblit v1.9.3