using Microsoft.AspNetCore.Components.Routing;
|
using Newtonsoft.Json;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection.Metadata;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_Core;
|
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;
|
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class ConveyorLineJob_YLOld : 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_YLOld(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;
|
//获取所有协议的输送线站台
|
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(WR_CLineYLDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
if (deviceProRead != null)
|
{
|
R_ConveyorLineYLInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineYLInfo>(deviceProRead.DeviceProAddress);
|
if (conveyorLineInfoRead != null && item.StationType == StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && conveyorLineInfoRead.WR_ToHode <= 0 && conveyorLineInfoRead.WR_Request == 86 && !string.IsNullOrEmpty(conveyorLineInfoRead.WR_TMID)) //老厂申请入库
|
{
|
WebResponseContent content = _taskService.YLPurchaseBoxing(conveyorLineInfoRead.WR_TMID);
|
if (content.Status)
|
{
|
device.SetValue(WR_CLineYLDB.WR_Reresult, 86, item.StationCode);
|
WriteInfo(item.StationCode, $"请求退料条码:{conveyorLineInfoRead.WR_TMID}");
|
}
|
else
|
{
|
WriteError(item.StationCode, $"请求退料失败:{content.Message}");
|
}
|
}
|
}
|
else
|
{
|
WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息");
|
}
|
}
|
}
|
return Task.CompletedTask;
|
}
|
}
|
}
|