From 0c824220cc22b8d1bc51ff68f6e8ba3a748beefb Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期五, 24 十月 2025 15:25:30 +0800
Subject: [PATCH] 1
---
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs | 273 ++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 221 insertions(+), 52 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs"
index 076126c..7cc2d82 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RGVJob/CommonRGVJob.cs"
@@ -19,12 +19,17 @@
using HslCommunication;
using Newtonsoft.Json;
using Quartz;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
+using System.Threading.Tasks;
+using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
+using WIDESEAWCS_DTO.Enum;
+using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -33,9 +38,11 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
-using WIDESEAWCS_QuartzJob.RGV;
+using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
+using WIDESEAWCS_TaskInfoRepository;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.RGVJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
@@ -43,20 +50,22 @@
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
- public class CommonRGVJob :JobBase, IJob
+ public class CommonRGVJob : JobBase, IJob
{
private readonly ITaskService _taskService;
private readonly ITaskRepository _taskRepository;
+ private readonly ITask_HtyRepository _task_HtyRepository;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly IRouterService _routerService;
private readonly IDt_StationManagerService _stationManagerService;
+ private readonly IDt_StationManagerRepository _stationManagerRepository;
private readonly IMapper _mapper;
private readonly ICacheService _cacheService;
private readonly INoticeService _noticeService;
private static List<string>? userTokenIds;
private static List<int>? userIds;
- public CommonRGVJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository)
+ public CommonRGVJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository,IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_HtyRepository)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
@@ -66,6 +75,8 @@
_cacheService = cacheService;
_noticeService = noticeService;
_taskRepository = taskRepository;
+ _stationManagerRepository = stationManagerRepository;
+ _task_HtyRepository = task_HtyRepository;
}
public Task Execute(IJobExecutionContext context)
@@ -75,25 +86,22 @@
CommonRGV commonRGV = (CommonRGV)context.JobDetail.JobDataMap.Get("JobParams");
if (commonRGV != null)
{
- if (!commonRGV.IsEventSubscribed)
+ if (commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.WorkCompleted))
{
- commonRGV.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
+ RGVTaskFinish(commonRGV, commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
}
- commonRGV.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆�
-
-
- if (commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic) && !commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault) && !commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running))
+ if (commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Fault) && !commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Running))
{
- Dt_Task? task = GetTask(commonRGV);
+ Dt_Task? task = GetTask(commonRGV, commonRGV.GetValue<RGVDBName, bool>(RGVDBName.InStock));
if (task != null)
{
- var taskCommand = _mapper.Map<RGVTaskCommandWrite>(task);
- if (taskCommand != null)
+ RGVTaskCommand? rgvTaskCommand = ConvertToRGVTaskCommand(task);
+ if (rgvTaskCommand != null)
{
Thread.Sleep(1000);
- bool sendFlag = commonRGV.SendCommand(taskCommand);
+ bool sendFlag = SendCommand(commonRGV,rgvTaskCommand);
if (sendFlag)
{
_taskService.UpdateTaskStatusToNext(task.TaskNum);
@@ -111,20 +119,33 @@
}
var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
var userIds = tokenInfos?.Select(x => x.UserId).ToList();
-
+ string RGVAutoStatus(bool AutoStatus) => AutoStatus switch
+ {
+ true => "鑱旀満妯″紡",
+ false => "鍗曟満妯″紡",
+ };
+ string RGVWorkStatus(bool WorkStatus) => WorkStatus switch
+ {
+ true => "杩愯涓�",
+ false => "寰呮満",
+ };
+ string RGVStatus(bool Status) => Status switch
+ {
+ true => "鏁呴殰",
+ false => "姝e父",
+ };
object obj = new
{
- Automatic = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic),
- Fault = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault),
- Running = commonRGV.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running),
- commonRGV.StackerCraneAutoStatusDes,
- commonRGV.StackerCraneWorkStatusDes,
+ Automatic = RGVAutoStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Automatic)),
+ Fault = RGVStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Fault)),
+ Running = RGVWorkStatus(commonRGV.GetValue<RGVDBName, bool>(RGVDBName.Running)),
+ LevelPoint = commonRGV.GetValue<RGVDBName, int>(RGVDBName.LevelPoint),
+ CurrentTaskNum = commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum),
+ InStock = commonRGV.GetValue<RGVDBName, bool>(RGVDBName.InStock),
commonRGV.DeviceCode,
commonRGV.DeviceName,
- commonRGV.CurrentTaskNum,
- commonRGV.LastTaskNum,
};
- _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonRGV.DeviceName, data = obj });
+ _noticeService.RGVData(userIds?.FirstOrDefault(), userTokenIds, new { commonRGV.DeviceName, data = obj });
#endregion 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
}
@@ -135,31 +156,84 @@
}
return Task.CompletedTask;
}
- /// <summary>
- /// 浠诲姟瀹屾垚浜嬩欢璁㈤槄鐨勬柟娉�
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
+
+
+ public void RGVTaskFinish(CommonRGV commonRGV, int TaskNum)
{
- CommonRGV? commonRGV = sender as CommonRGV;
if (commonRGV != null)
{
- if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+ WriteInfo("RGV浠诲姟瀹屾垚", $"{commonRGV.DeviceName}瀹屾垚浠诲姟鍙穥TaskNum}");
+ var task = _taskRepository.QueryFirst(x => x.TaskNum == TaskNum);
+ if (task != null)
{
- ConsoleHelper.WriteColorLine($"銆恵commonRGV.DeviceName}銆戝爢鍨涙満浣滀笟鐘舵�侊細銆恵(int)commonRGV.StackerCraneWorkStatusValue}銆戞椂闂淬�恵DateTime.Now}銆�", ConsoleColor.Magenta);
+ if (task.TaskState == (int)TaskInStatusEnum.RGV_Indispatch)
+ {
+ if (task.SourceAddress == "3002")
+ {
+ task.TaskState = (int)TaskInStatusEnum.RGV_IndispatchFinish;
+ _taskRepository.UpdateData(task);
+ return;
+ }
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
+ if (stationManager != null)
+ {
+ IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
+ if (device != null)
+ {
+ CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+ Thread.Sleep(100);
- string str = $"銆恵commonRGV.DeviceName}銆戜换鍔″畬鎴�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
- WriteInfo(commonRGV.DeviceName, str);
- ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
+ DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
+ var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 5);
+ string Barcode = Encoding.UTF8.GetString(x);
- var content = _taskService.StackCraneTaskCompleted(e.TaskNum);
- commonRGV.SetValue(StackerCraneDBName.WorkType, 5);
+ short y = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode);
+ var structs = BitConverter.GetBytes(y).ToArray().ToBoolArray();
- var isWorkType = commonRGV.SetValue(StackerCraneDBName.WorkType, 5);
- str = $"{commonRGV.DeviceName}銆慦MS|WCS浠诲姟瀹屾垚锛氥�恵content.Status}銆�,鍫嗗灈鏈哄畬鎴愪俊鍙峰啓鍏ワ細銆恵isWorkType}銆�,浠诲姟鍙凤細銆恵e.TaskNum}銆戞椂闂淬�恵DateTime.Now}銆�";
- WriteInfo(commonRGV.DeviceName, str);
- ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
+ if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0") || structs[5])
+ {
+ WriteInfo("鍏ュ簱寮傚父淇℃伅", $"鎵樼洏鍙枫�恵Barcode}銆戞灏恒�恵structs[5]}銆戜换鍔″彿銆恵TaskNum}銆�");
+ commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, Convert.ToSByte(stationManager.stationRemark));
+ commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(task.TaskNum));
+ commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(4));
+
+ task.ModifyDate = DateTime.Now;
+ task.Modifier = "System";
+
+ Dt_Task_Hty task_Hty = _mapper.Map<Dt_Task_Hty>(task);
+ task_Hty.TaskId = 0;
+ task_Hty.OperateType = (int)OperateTypeEnum.寮傚父閫�鍥�;
+
+ _taskRepository.DeleteData(task);
+ _task_HtyRepository.AddData(task_Hty);
+ return;
+ }
+ var content = _taskService.RGVTaskCompleted(TaskNum, Barcode);
+ }
+ }
+ }
+ else
+ {
+ if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutExecuting)
+ {
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress && x.stationType == 7);
+ if (stationManager != null)
+ {
+ IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC);
+ if (device != null)
+ {
+ CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
+ Thread.Sleep(100);
+ conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, Convert.ToInt16(stationManager.stationNextChildCode), stationManager.stationChildCode);
+ Thread.Sleep(100);
+ conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTaskNum, Convert.ToInt16(1), stationManager.stationChildCode);
+ Thread.Sleep(100);
+ conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(2), stationManager.stationChildCode);
+ }
+ }
+ }
+ var content = _taskService.RGVTaskCompleted(TaskNum);
+ }
}
}
}
@@ -169,33 +243,34 @@
/// </summary>
/// <param name="commonRGV">鍫嗗灈鏈哄璞�</param>
/// <returns></returns>
- private Dt_Task? GetTask(CommonRGV commonRGV)
+ private Dt_Task? GetTask(CommonRGV commonRGV, bool InStock)
{
Dt_Task task;
-
- task = _taskService.QueryRelocationTask(commonRGV.DeviceCode);
- if (task != null)
+ if (InStock)
{
- return task;
+ task = _taskService.QueryRGVExecutingTask(commonRGV.DeviceCode, commonRGV.GetValue<RGVDBName, short>(RGVDBName.RGVTaskNum));
+ if (task != null)
+ {
+ return task;
+ }
}
-
if (commonRGV.LastTaskType == null)
{
- task = _taskService.QueryStackerCraneTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVTask(commonRGV.DeviceCode);
}
else
{
if (commonRGV.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
{
- task = _taskService.QueryStackerCraneInTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVInTask(commonRGV.DeviceCode);
if (task == null)
{
- task = _taskService.QueryStackerCraneOutTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVOutTask(commonRGV.DeviceCode);
}
}
else
{
- task = _taskService.QueryStackerCraneOutTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVOutTask(commonRGV.DeviceCode);
}
}
@@ -203,7 +278,7 @@
{
if (task == null)
{
- task = _taskService.QueryStackerCraneInTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVInTask(commonRGV.DeviceCode);
}
else
{
@@ -212,12 +287,106 @@
}
else if (task == null)
{
- task = _taskService.QueryStackerCraneInTask(commonRGV.DeviceCode);
+ task = _taskService.QueryRGVInTask(commonRGV.DeviceCode);
}
return task;
}
+ /// <summary>
+ /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
+ /// </summary>
+ /// <param name="task">浠诲姟瀹炰綋</param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public RGVTaskCommand? ConvertToRGVTaskCommand([NotNull] Dt_Task task)
+ {
+ RGVTaskCommand rgvTaskCommand = new RGVTaskCommand();
+
+ rgvTaskCommand.TaskNum = Convert.ToInt16(task.TaskNum);
+ if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
+ {
+ if (task.TaskState == (int)TaskInStatusEnum.InNew)
+ {
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
+ rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
+ rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
+ }
+ else if (task.TaskState == (int)TaskInStatusEnum.RGV_IndispatchFinish)
+ {
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
+ rgvTaskCommand.TaskType = (byte)Convert.ToSByte(4);
+ rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
+ }
+ else
+ {
+ _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅");
+ return null;
+ }
+ }
+ else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+ {
+ if (task.TaskState == (int)TaskOutStatusEnum.Line_OutFinish)
+ {
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.CurrentAddress);
+ rgvTaskCommand.TaskType = (byte)Convert.ToSByte(3);
+ rgvTaskCommand.PickupLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
+ }
+ else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutdispatchFinish)
+ {
+ Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.NextAddress);
+ rgvTaskCommand.TaskType = (byte)Convert.ToSByte(4);
+ rgvTaskCommand.PutcargoLocation = (byte)Convert.ToSByte(stationManager.stationRemark);
+ }
+ else
+ {
+ _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅");
+ return null;
+ }
+ }
+
+ return rgvTaskCommand;
+ }
+
+ public bool SendCommand(CommonRGV commonRGV, RGVTaskCommand? rgvTaskCommand)
+ {
+ commonRGV.SetValue(StackerCraneDBName.TaskNum, rgvTaskCommand.TaskNum);
+ Thread.Sleep(100);
+ commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, rgvTaskCommand.PutcargoLocation);
+ Thread.Sleep(100);
+ commonRGV.SetValue(StackerCraneDBName.PickupLocation, rgvTaskCommand.PickupLocation);
+ Thread.Sleep(100);
+ commonRGV.SetValue(StackerCraneDBName.TaskType,Convert.ToSByte(rgvTaskCommand.TaskType));
+ for (int i = 0; i < 6; i++)
+ {
+
+ if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.TaskNum) == rgvTaskCommand.TaskNum && commonRGV.GetValue<StackerCraneDBName, byte>(StackerCraneDBName.TaskType) == rgvTaskCommand.TaskType && commonRGV.GetValue<StackerCraneDBName, byte>(StackerCraneDBName.PutcargoLocation) == rgvTaskCommand.PutcargoLocation && commonRGV.GetValue<StackerCraneDBName, byte>(StackerCraneDBName.PickupLocation) == rgvTaskCommand.PickupLocation)
+ {
+ WriteInfo(commonRGV.DeviceName, $"鍐欏叆浠诲姟鎴愬姛鍐欏叆娆℃暟{i}鍐欏叆浠诲姟銆恵JsonConvert.SerializeObject(rgvTaskCommand)}銆�");
+ return true;
+ }
+ if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.TaskNum) == rgvTaskCommand.TaskNum)
+ {
+ commonRGV.SetValue(StackerCraneDBName.TaskNum, rgvTaskCommand.TaskNum);
+ Thread.Sleep(100);
+ }
+ if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.PutcargoLocation) == rgvTaskCommand.PutcargoLocation)
+ {
+ commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, rgvTaskCommand.PutcargoLocation);
+ }
+ if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.PickupLocation) == rgvTaskCommand.PickupLocation)
+ {
+ commonRGV.SetValue(StackerCraneDBName.PickupLocation, rgvTaskCommand.PickupLocation);
+ }
+ if (commonRGV.GetValue<StackerCraneDBName, short>(StackerCraneDBName.TaskType) == rgvTaskCommand.TaskType)
+ {
+ commonRGV.SetValue(StackerCraneDBName.TaskType, rgvTaskCommand.TaskType);
+ }
+ }
+ WriteInfo(commonRGV.DeviceName, $"RGV浠诲姟鍐欏叆澶辫触銆恵JsonConvert.SerializeObject(rgvTaskCommand)}銆�");
+ return false;
+ }
+
public async Task LogAndWarn(string deviceName, string log, string color = "red")
{
ConsoleHelper.WriteWarningLine(log);
--
Gitblit v1.9.3