using HslCommunication;
|
using Mapster;
|
using Masuit.Tools;
|
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 CommonFrontOtherDevicesJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly IRouterService _routerService;
|
private readonly ICacheService _cacheService;
|
private readonly INoticeService _noticeService;
|
private readonly IDt_StationManagerRepository _stationManagerRepository;
|
private readonly IDt_StationManagerService _stationManagerService;
|
private readonly ITask_HtyRepository _task_htyRepository;
|
private readonly ISys_ConfigService _sys_ConfigService;
|
private static List<string>? userTokenIds;
|
private static List<int>? userIds;
|
|
public CommonFrontOtherDevicesJob(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
|
{
|
FrontOtherDevice frontOtherDevice = (FrontOtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
|
List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(frontOtherDevice.DeviceCode);
|
foreach (var item in stationManagers.Where(x=>x.stationType == 1))
|
{
|
//读取上料请求
|
var UpRequest = frontOtherDevice.GetValue<UpOtherDeviceDBName, short>(UpOtherDeviceDBName.UpRequest,item.stationChildCode);
|
if(UpRequest == 1)
|
{
|
await RequestUpMaterial(frontOtherDevice, item);
|
}
|
}
|
foreach (var item in stationManagers.Where(x => x.stationType == 2))
|
{
|
//读取下料请求
|
var DownRequest = frontOtherDevice.GetValue<DownOtherDeviceDBName, short>(DownOtherDeviceDBName.DownRequest, item.stationChildCode);
|
if (DownRequest == 1)
|
{
|
await RequestDownMaterialAsync(frontOtherDevice, item);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError("CommonOtherDevicesJob", "test", ex);
|
}
|
return;
|
}
|
|
/// <summary>
|
/// 请求上料
|
/// </summary>
|
/// <param name="frontOtherDevice"></param>
|
/// <param name="stationManager"></param>
|
/// <returns></returns>
|
public async Task RequestUpMaterial(FrontOtherDevice frontOtherDevice, Dt_StationManager stationManager)
|
{
|
WebResponseContent content = new WebResponseContent();
|
var wmsIpAddrss = _taskService.GetIpAddress(SysConfigKeyConst.RequestOutboundTask);
|
var result = await HttpHelper.PostAsync(wmsIpAddrss, JsonConvert.SerializeObject(new { Position = stationManager.stationChildCode }));
|
content = JsonConvert.DeserializeObject<WebResponseContent>(result);
|
if (!content.Status)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:{content.Message}");
|
return;
|
}
|
var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
|
if (task == null)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:返回数据解析失败");
|
return;
|
}
|
_taskService.ReceiveWMSTask(task);
|
}
|
|
/// <summary>
|
/// 请求下料
|
/// </summary>
|
/// <param name="frontOtherDevice"></param>
|
/// <param name="stationManager"></param>
|
public async Task RequestDownMaterialAsync(FrontOtherDevice frontOtherDevice, Dt_StationManager stationManager)
|
{
|
WebResponseContent content = new WebResponseContent();
|
if (stationManager.stationProcessCodeType == 1)
|
{
|
await RequestWMSInBoundTaskAsync(stationManager);
|
}
|
else
|
{
|
int sum = 0;
|
List<string> str = stationManager.stationNextProcessCode.IsNullOrEmpty() ? new List<string>() : stationManager.stationNextProcessCode.Split(',').ToList();
|
if (str.Count > 0)
|
{
|
foreach (var item in str)
|
{
|
var nextStation = _stationManagerRepository.QueryFirst(x => x.stationProcessCode == item);
|
var UpRequest = frontOtherDevice.GetValue<UpOtherDeviceDBName, short>(UpOtherDeviceDBName.UpRequest, nextStation.stationChildCode);
|
if (UpRequest == 1)
|
{
|
sum++;
|
var wmsIpAddrss = _taskService.GetIpAddress(SysConfigKeyConst.RequestInToOutTask);
|
var result = await HttpHelper.PostAsync(wmsIpAddrss, JsonConvert.SerializeObject(new { Position = stationManager.stationChildCode , TargetAddress = nextStation.stationChildCode }));
|
content = JsonConvert.DeserializeObject<WebResponseContent>(result);
|
if (!content.Status)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:{content.Message}");
|
return;
|
}
|
var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
|
if (task == null)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:返回数据解析失败");
|
return;
|
}
|
_taskService.ReceiveWMSTask(task);
|
return;
|
}
|
}
|
}
|
if (sum == 0)
|
{
|
//请求下料
|
await RequestWMSInBoundTaskAsync(stationManager);
|
}
|
}
|
}
|
|
public async Task RequestWMSInBoundTaskAsync(Dt_StationManager stationManager)
|
{
|
WebResponseContent content = new WebResponseContent();
|
var wmsIpAddrss = _taskService.GetIpAddress(SysConfigKeyConst.RequestInboundTask);
|
var result = await HttpHelper.PostAsync(wmsIpAddrss, JsonConvert.SerializeObject(new { Position = stationManager.stationChildCode }));
|
content = JsonConvert.DeserializeObject<WebResponseContent>(result);
|
if (!content.Status)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:{content.Message}");
|
return;
|
}
|
var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
|
if (task == null)
|
{
|
ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:返回数据解析失败");
|
return;
|
}
|
_taskService.ReceiveWMSTask(task);
|
return;
|
}
|
}
|
}
|