using Microsoft.AspNetCore.Components.Routing;
|
using Microsoft.IdentityModel.Tokens;
|
using Newtonsoft.Json;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Common.Helper;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Caches;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Repository;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class RGVJob_BC : JobBase, IJob
|
{
|
private readonly ICacheService _cacheService;
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly IStationMangerRepository _stationMangerRepository;
|
private readonly IRouterRepository _routerRepository;
|
private readonly IRouterService _routerService;
|
private readonly IRouterExtension _routerExtension;
|
private readonly List<Dt_WarehouseDevice> warehouseDevices;
|
|
public RGVJob_BC(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
|
{
|
_cacheService = cacheService;
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_taskRepository = taskRepository;
|
_stationMangerRepository = stationMangerRepository;
|
_routerRepository = routerRepository;
|
_routerService = routerService;
|
_routerExtension = routerExtension;
|
|
string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
|
if (!string.IsNullOrEmpty(warehouseDevicesStr))
|
{
|
warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>();
|
}
|
else
|
{
|
warehouseDevices = new List<Dt_WarehouseDevice>();
|
}
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
|
if (flag && value != null)
|
{
|
OtherDevice device = (OtherDevice)value;
|
|
//Dt_WarehouseDevice? warehouseDevice = warehouseDevices.FirstOrDefault(x => x.DeviceCode == device.DeviceCode);
|
//if (warehouseDevice == null)
|
//{
|
// WriteError(device.DeviceName, $"请配置仓库设备信息");
|
// return Task.CompletedTask;
|
//}
|
|
List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
|
List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
|
|
foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
|
{
|
try
|
{
|
if (device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.STB)/*&& conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm*/ && !device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.ACK) && device.GetValue<R_ConveyorLineDB, int>(R_ConveyorLineDB.TaskNum) != 0 && device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.TaskFinish))//RGV入库任务完成
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == device.GetValue<R_ConveyorLineDB, int>(R_ConveyorLineDB.TaskNum) && x.TaskState == TaskStatusEnum.RGV_Executing.ObjToInt());
|
if (task != null)
|
{
|
if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt())//RGV入库任务完成
|
{
|
List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.Roadway, task.TaskType);
|
Dt_Router? router = routers.FirstOrDefault();
|
_taskService.UpdateTask(task, TaskStatusEnum.RGV_Finish, sourceAddress: router.NextPosi);
|
}
|
else
|
{
|
//出库任务是否需要跟出库口输送线对接完成任务
|
WriteDebug(device.DeviceName, $"任务完成,任务号:{task.TaskNum}");
|
_taskService.TaskCompleted(task.TaskNum);
|
|
}
|
device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
|
}
|
|
}
|
if (device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Online) && device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Free) && !device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Goods) && device.GetValue<R_ConveyorLineDB, int>(R_ConveyorLineDB.TaskNum) == 0 && !device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Alarm))
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.TaskType >= TaskTypeEnum.Inbound.ObjToInt() && x.TaskState == TaskStatusEnum.RGV_NEW.ObjToInt());
|
if (task != null)
|
{
|
//写入RGV任务
|
device.SetValue(W_ConveyorLineDB.TaskNo, task.TaskNum, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.StartPos, task.SourceAddress, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.TaskType, 2, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
|
_taskService.UpdateTask(task, TaskStatusEnum.RGV_Executing);
|
}
|
Dt_Task task1 = _taskRepository.QueryFirst(x => x.TaskType >= TaskTypeEnum.Outbound.ObjToInt() && x.TaskState == TaskStatusEnum.RGV_Execute.ObjToInt());
|
if (task1 != null)
|
{
|
//写入RGV任务
|
device.SetValue(W_ConveyorLineDB.TaskNo, task1.TaskNum, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.StartPos, task1.SourceAddress, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.TaskType, 2, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.EndPos, task1.NextAddress, item.StationCode);
|
device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode);
|
|
_taskService.UpdateTask(task1, TaskStatusEnum.RGV_Executing);
|
}
|
}
|
|
if (device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.ACK))
|
{
|
device.SetValue(W_ConveyorLineDB.STB, false, item.StationCode);
|
}
|
if (device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Pcikfinish) && device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.STB))
|
{
|
device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
|
}
|
if (!device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.Pcikfinish) && !device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.STB))
|
{
|
device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
|
}
|
if (device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.TaskFinish) && !device.GetValue<R_ConveyorLineDB, bool>(R_ConveyorLineDB.STB))
|
{
|
device.SetValue(W_ConveyorLineDB.ACK, false, item.StationCode);
|
}
|
}
|
catch (Exception ex)
|
{
|
}
|
|
//DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
|
//DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
|
//if (deviceProRead != null && deviceProWrite != null)
|
//{
|
// R_ConveyorLineInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
|
// R_ConveyorLineInfo conveyorLineInfoReadRGV = device.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
|
// W_ConveyorLineInfo conveyorLineInfoWrite = device.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
|
// if (conveyorLineInfoRead == null || conveyorLineInfoWrite == null)
|
// {
|
// continue;
|
// }
|
|
// R_ConveyorLineStatus conveyorLineStatus = conveyorLineInfoRead.Status.ByteToBoolObject<R_ConveyorLineStatus>();
|
|
// ConveyorLineSignal conveyorLineSignalRead = conveyorLineInfoRead.Signal.ByteToBoolObject<ConveyorLineSignal>();
|
|
// ConveyorLineSignal conveyorLineSignalWrite = conveyorLineInfoWrite.Signal.ByteToBoolObject<ConveyorLineSignal>();
|
// if (conveyorLineSignalRead.STB && !conveyorLineSignalWrite.ACK && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode) && conveyorLineInfoRead.TaskNo == 0)//入库
|
// {
|
// Dt_Task task = _taskRepository.QueryFirst(x => x.TaskType >= TaskTypeEnum.Inbound.ObjToInt() && x.TaskState == TaskStatusEnum.RGV_Execute.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId);
|
// if (task != null)
|
// {
|
// //写入RGV任务
|
// device.SetValue(W_ConveyorLineDB.TaskNo, task.TaskNum, item.StationCode);
|
// device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode);
|
// device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Inbound.ObjToInt(), item.StationCode);
|
// device.SetValue(W_ConveyorLineDB.EndPos, task.TargetAddress, item.StationCode);
|
// device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
|
// _taskService.UpdateTask(task, TaskStatusEnum.RGV_Executing);
|
// }
|
// }
|
// else if (conveyorLineSignalRead.STB /*&& conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm*/ && !conveyorLineSignalWrite.ACK && conveyorLineInfoRead.TaskNo > 0)//出库
|
// {
|
// WriteDebug(device.DeviceName, $"任务完成,任务号:{conveyorLineInfoRead.TaskNo}");
|
// _taskService.TaskCompleted(conveyorLineInfoRead.TaskNo);
|
// device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode);
|
// }
|
//}
|
//else
|
//{
|
// WriteError(device.DeviceName, $"未找到设备子编号{item.StationCode}的协议信息");
|
//}
|
}
|
}
|
|
return Task.CompletedTask;
|
}
|
}
|
}
|