using HslCommunication;
|
using Mapster;
|
using Microsoft.AspNetCore.Components.Routing;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
using Quartz;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core.Caches;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_SignalR;
|
using WIDESEAWCS_Tasks.OtherDeviceJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class CommonOtherDevicesJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly IRouterService _routerService;
|
private readonly ICacheService _cacheService;
|
private readonly INoticeService _noticeService;
|
private readonly IDt_StationManagerRepository _stationManagerRepository;
|
private readonly ITask_HtyRepository _task_htyRepository;
|
private readonly ISys_ConfigService _sys_ConfigService;
|
private static List<string>? userTokenIds;
|
private static List<int>? userIds;
|
|
public CommonOtherDevicesJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_taskRepository = taskRepository;
|
_routerService = routerService;
|
_cacheService = cacheService;
|
_noticeService = noticeService;
|
_stationManagerRepository = stationManagerRepository;
|
_task_htyRepository = task_htyRepository;
|
_sys_ConfigService = sys_ConfigService;
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
OtherDevice otherDevice = (OtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
|
if (otherDevice != null)
|
{
|
#region 上料
|
|
var UpRequest = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.UpRequest);
|
ConsoleHelper.WriteInfoLine($"接收上料请求信号:【{UpRequest}】");
|
|
if (UpRequest == 1)
|
{
|
var UpPosition = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.UpPosition);
|
ConsoleHelper.WriteInfoLine($"上料位置信息:【{UpPosition}】");
|
var task = _taskRepository.QueryFirst(x => x.SourceAddress == UpPosition.ToString());
|
if (task == null)
|
{
|
Dt_Task taskNew = new Dt_Task()
|
{
|
TaskNum = _taskRepository.GetTaskNo().Result,
|
PalletCode = Random.Shared.Next(1, 100).ToString(),
|
Roadway = "R001",
|
TaskType = (int)TaskInboundTypeEnum.Inbound,
|
TaskState = (int)TaskInStatusEnum.AGV_InExecuting,
|
SourceAddress = UpPosition.ToString(),
|
TargetAddress = "TargetAddress",
|
CurrentAddress = UpPosition.ToString(),
|
NextAddress = "TargetAddress",
|
Grade = 1,
|
AGVSign = 1.ToString()
|
};
|
_taskRepository.AddData(taskNew);
|
Thread.Sleep(2000);
|
//回复收到信号
|
otherDevice.SetValue(OtherDeviceDBName.UpReplyRequest, 1);
|
Thread.Sleep(2000);
|
//请求放料
|
otherDevice.SetValue(OtherDeviceDBName.RequestPut, 1);
|
}
|
else
|
{
|
ConsoleHelper.WriteInfoLine($"已有任务不允许重复生成【{task.Serialize()}】");
|
}
|
}
|
|
var AllowPut = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.AllowPut);
|
ConsoleHelper.WriteInfoLine($"读取允许放料信号:【{AllowPut}】");
|
|
if (AllowPut == 1)
|
{
|
var task = _taskRepository.QueryFirst(x => x.AGVSign != null && x.TaskType == (int)TaskInboundTypeEnum.Inbound);
|
|
otherDevice.SetValue(OtherDeviceDBName.PutFinish, 1);
|
otherDevice.SetValue(OtherDeviceDBName.UpBarcode, task != null ? task.PalletCode : "1111");
|
_taskRepository.DeleteData(task);
|
}
|
|
#endregion
|
|
#region 下料
|
|
var DownRequest = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.DownRequest);
|
ConsoleHelper.WriteInfoLine($"接收下料请求信号:【{UpRequest}】");
|
|
if (DownRequest == 1)
|
{
|
var DownPosition = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.DownPosition);
|
ConsoleHelper.WriteInfoLine($"下料位置信息:【{DownPosition}】");
|
|
var task = _taskRepository.QueryFirst(x => x.TargetAddress == DownPosition.ToString());
|
if (task == null)
|
{
|
Dt_Task taskNew = new Dt_Task()
|
{
|
TaskNum = _taskRepository.GetTaskNo().Result,
|
PalletCode = Random.Shared.Next(1, 100).ToString(),
|
Roadway = "R001",
|
TaskType = (int)TaskOutboundTypeEnum.Outbound,
|
TaskState = (int)TaskOutStatusEnum.AGV_OutExecuting,
|
SourceAddress = "SourceAddress",
|
TargetAddress = DownPosition.ToString(),
|
CurrentAddress = "SourceAddress",
|
NextAddress = DownPosition.ToString(),
|
Grade = 1,
|
AGVSign = 1.ToString()
|
};
|
_taskRepository.AddData(taskNew);
|
Thread.Sleep(2000);
|
//回复收到信号
|
otherDevice.SetValue(OtherDeviceDBName.DownReplyRequest, 1);
|
Thread.Sleep(2000);
|
//请求取料
|
otherDevice.SetValue(OtherDeviceDBName.RequestPickUp, 1);
|
}
|
else
|
{
|
ConsoleHelper.WriteInfoLine($"已有任务不允许重复生成【{task.Serialize()}】");
|
}
|
}
|
|
var AllowPickUp = otherDevice.GetValue<OtherDeviceDBName, short>(OtherDeviceDBName.AllowPickUp);
|
ConsoleHelper.WriteInfoLine($"读取允许取料信号:【{AllowPickUp}】");
|
|
if (AllowPickUp == 1)
|
{
|
var task = _taskRepository.QueryFirst(x => x.AGVSign != null && x.TaskType == (int)TaskOutboundTypeEnum.Outbound);
|
otherDevice.SetValue(OtherDeviceDBName.PickUpFinish, 1);
|
otherDevice.SetValue(OtherDeviceDBName.DownBarcode, task != null ? task.PalletCode : "1111");
|
|
_taskRepository.DeleteData(task);
|
}
|
|
#endregion
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError("CommonOtherDevicesJob", "test", ex);
|
//ConsoleHelper.WriteErrorLine($"{ex.Message}");
|
}
|
return Task.CompletedTask;
|
}
|
}
|
}
|