From 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 09 七月 2025 22:55:27 +0800
Subject: [PATCH] 增加质检出入库逻辑
---
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs | 291 +++++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 216 insertions(+), 75 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index 5e14f93..1066bcb 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -1,151 +1,286 @@
锘縰sing Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
+using System.Net.Http.Json;
+using System.Net.NetworkInformation;
+using System.Reflection;
+using System.Reflection.Metadata;
+using System.Reflection.PortableExecutable;
using System.Text;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
-using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Common.StackerCraneEnum;
+using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_IShuttleCar;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_TaskInfoService;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_Tasks.ShuttleCarJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
- public class CommonStackerCraneJob : IJob
+ public partial class CommonStackerCraneJob : JobBase, IJob
{
private readonly ITaskService _taskService;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly ITaskRepository _taskRepository;
private readonly IRouterService _routerService;
+ private readonly IShuttleCarService _shuttleCarService;
+ private readonly ICacheService _cacheService;
- public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService)
+ public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IShuttleCarService shuttleCarService, ICacheService cacheService)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
_routerService = routerService;
+ _shuttleCarService = shuttleCarService;
+ _cacheService = cacheService;
}
public Task Execute(IJobExecutionContext context)
{
try
{
- CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
+ SpeStackerCrane commonStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
if (commonStackerCrane != null)
{
- if (!commonStackerCrane.IsEventSubscribed)
+ commonStackerCrane.Communicator.IsReadAfterWrite = false;
+ #region 鑾峰彇鍫嗗灈鏈轰俊鎭�
+ StackerCraneTaskCommandR common = ReadCustomer<StackerCraneTaskCommandR>(commonStackerCrane, commonStackerCrane.DeviceCode);
+ _cacheService.AddOrUpdate(commonStackerCrane.DeviceCode, common);
+ #endregion
+ #region 淇″彿浜や簰澶勭悊
+ //Heartbeat(commonStackerCrane);
+ ShuttleCarSignal(commonStackerCrane);
+ #endregion
+
+ #region 浠诲姟瀹屾垚
+ if (common.CompleteStatus == 2 || common.CompleteStatus == 3 || common.CompleteStatus == 4)
{
- commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
+ var remark = "姝e父瀹屾垚";
+ if (common.CompleteStatus == 2) remark = "鎵嬪姩瀹屾垚";
+ if (common.CompleteStatus == 4) remark = "閿欒瀹屾垚";
+ WriteDebug($"{commonStackerCrane.DeviceName}浠诲姟瀹屾垚", $"{remark},浠诲姟鍙枫�恵commonStackerCrane.CurrentTaskNum}銆�");
+ NormalCompleted(commonStackerCrane);
}
+ #endregion
- if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
+ #region 浠诲姟閫昏緫澶勭悊
+ if (common.Onlinestate == (short)Onlinestate.online)
{
- commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆�
-
- if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
+ #region 鏌ヨ浠诲姟,閫昏緫澶勭悊
+ if (common.RunStatus == (short)RunStatus.Standby)
{
- Dt_Task? task = GetTask(commonStackerCrane);
- if (task != null)
+ #region 绌挎杞︾Щ杞�/鍏呯數浠诲姟
+ var Task = _taskService.GetTaskState((int)CarChargingTaskEnum.CarCharging_Finish, (int)TaskOtherTypeEnum.RelocationCarCharging) ??
+ _taskService.GetTaskState((int)TaskCarStatusEnum.ShuttleCar_Finish, (int)TaskOtherTypeEnum.RelocationCar);
+ if (Task != null) SendTask(commonStackerCrane, Task);
+ #endregion
+ else
{
- StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
- if (stackerCraneTaskCommand != null)
- {
- bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
- if (sendFlag)
- {
- commonStackerCrane.LastTaskType = task.TaskType;
- _taskService.UpdateTaskStatusToNext(task.TaskNum);
- }
- }
+ Task = GetStackerCraneTask();
+ if (Task != null) SendTask(commonStackerCrane, Task);
}
}
+ #endregion
}
+ #endregion
}
}
catch (Exception ex)
{
- Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
+ //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
}
return Task.CompletedTask;
}
- /// <summary>
- /// 浠诲姟瀹屾垚浜嬩欢璁㈤槄鐨勬柟娉�
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
+ #region 浠诲姟涓嬪彂缁欏爢鍨涙満
+ private void SendTask(SpeStackerCrane commonStackerCrane, Dt_Task task)
{
- CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
- if (commonStackerCrane != null)
+
+ StackerCraneTaskCommandW? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
+ if (stackerCraneTaskCommand != null)
{
- if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+ bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
+ bool worktype = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, task.TaskType >= (int)TaskOtherTypeEnum.RelocationCar ? (short)WorkType.Car : (short)WorkType.Cargo);
+ if (sendFlag && worktype)
{
- Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
- _taskService.StackCraneTaskCompleted(e.TaskNum);
- commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+ if (commonStackerCrane.SetValue(StackerCraneDBName.CommandSend, sendFlag))
+ {
+ if (_taskService.TaskInboundTypes.Contains(task.TaskType) ||
+ _taskService.TaskOutboundTypes.Contains(task.TaskType))
+ commonStackerCrane.LastTaskType = task.TaskType;
+ _taskService.UpdateTaskStatusToNext(task.TaskNum);
+ }
}
}
}
+ #endregion
+ #region 浠诲姟瀹屾垚
+ /// <summary>
+ /// 浠诲姟瀹屾垚
+ /// </summary>
+ /// <param name="commonStackerCrane"></param>
+ public void NormalCompleted(SpeStackerCrane commonStackerCrane)
+ {
+ if (commonStackerCrane != null)
+ {
+ var content = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
+ commonStackerCrane.SetValue(StackerCraneDBName.ConfirmComplete, content.Status);
+ }
+ }
+ #endregion
+
+ private Dt_Task? GetStackerCraneTask()
+ {
+ Dt_Task? task = null;
+ task = _taskRepository.QueryFirst(x => _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && !string.IsNullOrEmpty(x.NextAddress), _taskService.TaskOrderBy);//鍏ュ簱浠诲姟
+ if (task != null) task = GetTaskOk(task);
+
+ if (task == null)
+ {
+ task = _taskRepository.QueryFirst(x => _taskService.TaskRelocationTypes.Contains(x.TaskType) &&
+ x.TaskState == (int)TaskRelocationStatusEnum.CarSource_Finish, _taskService.TaskOrderBy) ??//绉诲簱浠诲姟
+ _taskRepository.QueryFirst(x => _taskService.TaskOutboundTypes.Contains(x.TaskType) &&
+ x.TaskState == (int)TaskOutStatusEnum.Car_OutFinish, _taskService.TaskOrderBy);//鍑哄簱浠诲姟
+ if (task != null) task = GetTaskOk(task);
+ }
+ return task;
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇浠诲姟鏄惁婊¤冻鍫嗗灈鏈烘墽琛�
+ /// </summary>
+ /// <param name="task"></param>
+ /// <returns></returns>
+ public Dt_Task? GetTaskOk(Dt_Task? task)
+ {
+ #region 鍏ュ簱/绉诲簱浠诲姟
+ if (_taskService.TaskInboundTypes.Contains(task.TaskType) || _taskService.TaskRelocationTypes.Contains(task.TaskType))
+ {
+ var ShuttleCar = GetShuttleCarInfo(task.TargetAddress);//鍏ュ簱浠诲姟鍒ゆ柇缁堢偣鏄惁鏈夌┛姊溅
+ if (task.TargetIsPickPlace && ShuttleCar != null)//绉昏蛋
+ {
+ _taskService.AddRelocationCarTask(task.TargetAddress, "", ShuttleCar.ShuttleCarCode);
+ task = null;
+ }
+ else if (!task.TargetIsPickPlace && ShuttleCar == null)
+ {
+ _taskService.AddRelocationCarTask("", task.TargetAddress);
+ task = null;
+ }
+ else
+ {
+ if (ShuttleCar != null)
+ {
+ if (_taskRepository.QueryFirst(x => x.TaskType != task.TaskType && x.ShuttleCarCode == ShuttleCar.ShuttleCarCode) != null)
+ task = null;
+ else
+ {
+ task.ShuttleCarCode = ShuttleCar.ShuttleCarCode;
+ _taskService.UpdateData(task);
+ }
+ }
+ }
+ }
+ #endregion
+
+ #region 鍑哄簱浠诲姟
+ else
+ task = OutTaskStationIsOccupied(task);
+ #endregion
+
+ return task;
+ }
/// <summary>
/// 鑾峰彇浠诲姟
/// </summary>
/// <param name="commonStackerCrane">鍫嗗灈鏈哄璞�</param>
/// <returns></returns>
- private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
+ private Dt_Task? GetTask(SpeStackerCrane commonStackerCrane)
{
- Dt_Task task;
- if (commonStackerCrane.LastTaskType == null)
+ Dt_Task task = _taskService.QueryStackerCraneRelocationTask(commonStackerCrane.DeviceCode);//鑾峰彇绉诲簱浠诲姟
+ #region 瀛樺湪绉诲簱浠诲姟蹇呴』鍏堟墽琛岀Щ搴撲换鍔�
+ if (task != null)
{
- task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
+ return task;
+ //if (task.SourceIsPickPlace && task.ShuttleCarCode != null)
+ // return task;
+ //else return null;
}
+ #endregion
+
+ #region 鍑哄叆搴撲换鍔�
else
{
- if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+ //task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
+ //if (task != null) return task;
+ if (commonStackerCrane.LastTaskType == null)
{
- task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
- if (task == null)
- {
- task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
- }
+ task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
}
else
{
- task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
- }
- }
-
- if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
- {
- if (OutTaskStationIsOccupied(task) != null)
- {
- return task;
- }
- else
- {
- 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 (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
{
- if (OutTaskStationIsOccupied(task) != null)
+ task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ if (task == null)
{
- return task;
+ task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
}
}
- task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ else
+ {
+ task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode) /*?? _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode)*/;
+ if (task == null)
+ {
+ task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ }
+ }
}
- }
+ if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+ {
+ if (OutTaskStationIsOccupied(task) != null)
+ {
+ return task;
+ }
+ else
+ {
+ 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(item) != null)
+ {
+ return item;
+ }
+ }
+ task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
+ }
+ }
+ if (task != null && !string.IsNullOrEmpty(task.TargetAddress)) return task;//鍏ュ簱浠诲姟鍒ゆ柇鏄惁宸插垎閰嶈揣浣嶏紝WMS鍒ゆ柇璐т綅鐘舵�佹槸鍚﹀厑璁告斁璐�
+ }
+ #endregion
return task;
}
@@ -163,10 +298,15 @@
if (device != null)
{
CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
- if (conveyorLine.IsOccupied(router.ChildPosi))//鍑哄簱绔欏彴鏈鍗犵敤
+ ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer<ConveyorLineTaskCommandR>(router.ChildPosi);
+ if (command.Status == 4)
{
return task;
}
+ //if (conveyorLine.IsOccupied(router.ChildPosi))//鍑哄簱绔欏彴鏈鍗犵敤
+ //{
+ // return task;
+ //}
}
else
{
@@ -186,14 +326,11 @@
/// <param name="task">浠诲姟瀹炰綋</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
- public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
+ public StackerCraneTaskCommandW? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
{
- StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
+ StackerCraneTaskCommandW stackerCraneTaskCommand = new StackerCraneTaskCommandW();
- stackerCraneTaskCommand.Barcode = task.PalletCode;
stackerCraneTaskCommand.TaskNum = task.TaskNum;
- stackerCraneTaskCommand.WorkType = 1;
- stackerCraneTaskCommand.TrayType = 0;
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
{
List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway);
@@ -206,7 +343,8 @@
string[] targetCodes = task.NextAddress.Split("-");
if (targetCodes.Length == 3)
{
- stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
+ var EndRow = Convert.ToInt16(targetCodes[0]);
+ stackerCraneTaskCommand.EndRow = EndRow;// Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
}
@@ -235,7 +373,8 @@
string[] sourceCodes = task.CurrentAddress.Split("-");
if (sourceCodes.Length == 3)
{
- stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
+ var StartRow = Convert.ToInt16(sourceCodes[0]);
+ stackerCraneTaskCommand.StartRow = StartRow;// Convert.ToInt16(StartRow > 1 ? StartRow - 1 : StartRow);
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
}
@@ -252,12 +391,13 @@
return null;
}
}
- else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
+ else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup)
{
string[] targetCodes = task.NextAddress.Split("-");
if (targetCodes.Length == 3)
{
- stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
+ var EndRow = Convert.ToInt16(targetCodes[0]);
+ stackerCraneTaskCommand.EndRow = EndRow;// Convert.ToInt16(EndRow > 1 ? EndRow - 1 : EndRow);
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
}
@@ -270,7 +410,8 @@
string[] sourceCodes = task.CurrentAddress.Split("-");
if (sourceCodes.Length == 3)
{
- stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
+ var SourceRow = Convert.ToInt16(sourceCodes[0]);
+ stackerCraneTaskCommand.StartRow = SourceRow;// Convert.ToInt16(SourceRow > 1 ? SourceRow - 1 : SourceRow);
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
}
--
Gitblit v1.9.3