#region MyRegion
|
#region << 版 本 注 释 >>
|
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using HslCommunication;
|
using Microsoft.AspNetCore.Server.HttpSys;
|
using Newtonsoft.Json;
|
using Quartz;
|
using SqlSugar;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Reflection;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_BasicInfoRepository;
|
using WIDESEAWCS_BasicInfoService;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DeviceBase;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class CommonConveyorLine_AfterJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IRouterService _routerService;
|
private readonly IMapper _mapper;
|
private readonly IDt_StationManagerService _stationManagerService;
|
|
public CommonConveyorLine_AfterJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository,IDt_StationManagerService stationManagerService)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_routerService = routerService;
|
_mapper = mapper;
|
_taskRepository = taskRepository;
|
_stationManagerService = stationManagerService;
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)context.JobDetail.JobDataMap.Get("JobParams");
|
if (conveyorLine != null)
|
{
|
List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
|
List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
|
//List<Task> tasks = new List<Task>();
|
foreach (string childDeviceCode in childDeviceCodes)
|
{
|
ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
|
|
if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = "";
|
|
DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
|
if (deviceProtocolDetails != null)
|
{
|
MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
|
if (method != null)
|
{
|
method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
|
}
|
}
|
}
|
//Task.WaitAll(tasks.ToArray());
|
}
|
}
|
catch (Exception ex)
|
{
|
Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
|
}
|
finally
|
{
|
//WriteDebug("CommonConveyorLineJob", "test");
|
//Console.Out.WriteLine(DateTime.Now);
|
}
|
return Task.CompletedTask;
|
}
|
|
/// <summary>
|
/// 输送线请求入库
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
|
{
|
|
var taskNew = _taskService.QueryCraneConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
|
if (taskNew == null)
|
{
|
string barcode = command.ConveyorLineBarcode.TrimEnd();
|
if (_taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode).Result.Status)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
|
//taskCommand.InteractiveSignal = command.InteractiveSignal;
|
taskCommand.ResponState = 1;
|
taskCommand.ConveyorLineTaskNum = task.TaskNum;
|
taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
//ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
}
|
|
var inTask = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
|
if (inTask != null)
|
{
|
ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(inTask);
|
//taskCommand.InteractiveSignal = command.InteractiveSignal;
|
taskCommand.ResponState = 1;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(inTask);
|
}
|
}
|
|
/// <summary>
|
/// 输送线入库完成
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
/// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
|
public void ConveyorLineInFinish(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode);
|
if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish)
|
{
|
//ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
|
|
//conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
|
WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
|
Console.Out.WriteLine(content.Serialize());
|
}
|
}
|
|
/// <summary>
|
/// 输送线请求出信息
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestOutbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
// ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
|
//taskCommand.InteractiveSignal = command.InteractiveSignal;
|
// conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
}
|
}
|
#endregion
|