using HslCommunication; using Mapster; using Microsoft.AspNetCore.Components.Routing; using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using Quartz; using WIDESEAWCS_BasicInfoService; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Caches; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_IBasicInfoRepository; using WIDESEAWCS_IBasicInfoService; 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 CommonMiddleOtherDevicesJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly ITaskRepository _taskRepository; private readonly IRouterService _routerService; private readonly IDt_StationManagerService _stationManagerService; 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? userTokenIds; private static List? userIds; public CommonMiddleOtherDevicesJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, IDt_StationManagerService stationManagerService, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _taskRepository = taskRepository; _routerService = routerService; _cacheService = cacheService; _noticeService = noticeService; _stationManagerService = stationManagerService; _stationManagerRepository = stationManagerRepository; _task_htyRepository = task_htyRepository; _sys_ConfigService = sys_ConfigService; } public async Task Execute(IJobExecutionContext context) { try { MiddleOtherDevice middleOtherDevice = (MiddleOtherDevice)context.JobDetail.JobDataMap.Get("JobParams"); List stationManagers = _stationManagerService.GetAllStationByDeviceCode(middleOtherDevice.DeviceCode); foreach (var item in stationManagers.Where(x => x.stationType == 2)) { //读取下料请求 var DownRequest = middleOtherDevice.GetValue(DownOtherDeviceDBName.DownRequest, item.stationChildCode); if (DownRequest == 1) { await RequestDownMaterialAsync(middleOtherDevice, item); } } } catch (Exception ex) { WriteError("CommonOtherDevicesJob", "test", ex); } return; } /// /// 请求下料 /// /// /// public async Task RequestDownMaterialAsync(MiddleOtherDevice middleOtherDevice, Dt_StationManager stationManager) { WebResponseContent content = new WebResponseContent(); if (stationManager.stationProcessCodeType == 2) { List str = stationManager.stationNextProcessCode.IsNullOrEmpty() ? new List() : stationManager.stationNextProcessCode.Split(',').ToList(); if (str.Count > 0) { foreach (var item in str) { var nextStation = _stationManagerRepository.QueryFirst(x => x.stationProcessCode == item); var UpRequest = middleOtherDevice.GetValue(UpOtherDeviceDBName.UpRequest, nextStation.stationChildCode); if (UpRequest == 1) { var UpPosition = middleOtherDevice.GetValue(UpOtherDeviceDBName.UpPosition, nextStation.stationChildCode); var wmsIpAddrss = _taskService.GetIpAddress(SysConfigKeyConst.RequsetInToGWOrCW); var result = await HttpHelper.PostAsync(wmsIpAddrss, JsonConvert.SerializeObject(new { Position = stationManager.stationChildCode , TargetAddress = UpPosition , TargetStationManager = item})); content = JsonConvert.DeserializeObject(result); if (!content.Status) { ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:{content.Message}"); return; } var task = JsonConvert.DeserializeObject(content.Data.ToString()); if (task == null) { ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:返回数据解析失败"); return; } _taskService.ReceiveWMSTask(task); return; } } } } } } }