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_Communicator; using WIDESEAWCS_Core; using WIDESEAWCS_DTO.TaskInfo; 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_CPH : 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 warehouseDevices; public ConveyorLineJob_CPH(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(nameof(Dt_WarehouseDevice)); if (!string.IsNullOrEmpty(warehouseDevicesStr)) { warehouseDevices = JsonConvert.DeserializeObject>(warehouseDevicesStr) ?? new List(); } else { warehouseDevices = new List(); } } public Task Execute(IJobExecutionContext context) { bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); if (flag && value != null) { //获取当前设备 OtherDevice device = (OtherDevice)value; List deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList(); List 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_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null) { R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer(deviceProRead.DeviceProAddress); //码垛环线请求任务 if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request==1) { WebResponseContent content = _taskService.RequestWMSTaskSimple(conveyorLineInfoRead.R_BoxCode, item.StationCode); //向WMS请求任务 if (true) { } } } else if(item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null) { R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer(deviceProRead.DeviceProAddress); //获取码垛口任务更新任务状态 if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0) { } } else if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && deviceProRead != null) { R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer(deviceProRead.DeviceProAddress); //码垛环线排出口请求取消任务 if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0 && conveyorLineInfoRead.R_Request == 2) { } } else { WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息"); } } } return Task.CompletedTask; } } }