using Microsoft.AspNetCore.Components.Routing;
|
using Newtonsoft.Json;
|
using Quartz;
|
using SqlSugar.Extensions;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Common.TaskEnum;
|
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;
|
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class ConveyorLineJob_FL : 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 ConveyorLineJob_FL(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)
|
{
|
try
|
{
|
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
|
if (flag && value != null)
|
{
|
OtherDevice device = (OtherDevice)value;
|
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)))
|
{
|
DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineFLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null)
|
{
|
R_ConveyorLineFLInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineFLInfo>(deviceProRead.DeviceProAddress);
|
bool conveyArrivaled = device.GetValue<R_ConveyorLineFLDB, bool>(R_ConveyorLineFLDB.ConveyArrivaled, item.StationCode);
|
if (conveyArrivaled)
|
{
|
Dt_Task newTask = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum.ObjToInt() && x.PalletCode == conveyorLineInfoRead.Barcode && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.DeviceCode == item.StackerCraneCode && !string.IsNullOrEmpty(x.DeviceCode));
|
if (newTask != null)
|
{
|
_taskService.UpdateTask(newTask, TaskStatusEnum.AGV_Execute);
|
}
|
WriteError(item.StationName, $"入库到位信号,托盘号{conveyorLineInfoRead.Barcode},任务号:{conveyorLineInfoRead.TaskNum}");
|
}
|
}
|
}
|
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError(nameof(ConveyorLineJob_FL), ex.Message, ex);
|
}
|
return Task.CompletedTask;
|
}
|
}
|
}
|