#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using Quartz;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class CommonConveyorLineJob : JobBase, IJob, IDisposable
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly ITaskCZRepository _taskCZRepository;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IRouterService _routerService;
|
private readonly IMapper _mapper;
|
|
public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, ITaskCZRepository taskCZRepository)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_routerService = routerService;
|
_mapper = mapper;
|
_taskRepository = taskRepository;
|
_taskCZRepository = taskCZRepository;
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
// 从上下文中获取 JobParams 并转换为 CommonConveyorLine 类型
|
CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
|
if (conveyorLine == null)
|
{
|
throw new Exception("JobParams 不包含 CommonConveyorLine 类型参数");
|
}
|
|
// 定义线体实盘入库请求的地址和任务类型
|
var requests = new Dictionary<string, string>
|
{
|
{ "DB1002.293.0", "ZJXL-WLX002" },
|
{ "DB1002.1493.0", "FJXL-WLX002" }
|
};
|
|
foreach (var request in requests)
|
{
|
var isDownRequest = conveyorLine.Communicator.Read<bool>(request.Key);
|
if (!isDownRequest)
|
{
|
continue;
|
}
|
|
string fromAdd = request.Value;
|
string taskType = request.Value.Contains("ZJXL") ? "正极" : "负极";
|
|
// 查询是否存在已生成的新任务
|
var task = _taskRepository.QueryFirst(x => x.SourceAddress == fromAdd && x.TaskState == (int)TaskInStatusEnum.InNew);
|
if (task != null)
|
{
|
ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}下线请求入库,任务已生成存在,稍后重试......");
|
continue;
|
}
|
|
// 查询任务类型对应的czTask
|
DtCZTask czTask = _taskCZRepository.QueryFirst(x => x.TaskType == taskType);
|
if (czTask == null)
|
{
|
ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}下线请求入库,{taskType}任务不存在,稍后重试......");
|
continue;
|
}
|
|
// 创建新的任务并添加到任务仓库
|
task = new Dt_Task()
|
{
|
TaskNum = _taskService.GetTaskNum(),
|
CreateDate = DateTime.Now,
|
Creater = "system",
|
CurrentAddress = fromAdd,
|
SourceAddress = fromAdd,
|
TaskState = (int)TaskInStatusEnum.InNew,
|
TaskType = (int)TaskInboundTypeEnum.Inbound,
|
Grade = 1,
|
PalletCode = czTask.TaskProductCode,
|
TargetAddress = czTask.TaskEndAddress,
|
Roadway = $"{taskType}AGV",
|
WMSId = czTask.Id,
|
Remark = czTask.TaskOrderNo
|
};
|
_taskRepository.AddData(task);
|
ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}下线请求入库,任务已生成,等待执行......");
|
}
|
}
|
catch (Exception ex)
|
{
|
// 记录异常信息
|
// Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
|
ConsoleHelper.WriteErrorLine($"{nameof(CommonConveyorLineJob)}: 发生异常 - {ex.Message}");
|
}
|
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 conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
if (_taskService.RequestWMSTask(command.Barcode, childDeviceCode).Status)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
|
taskCommand.InteractiveSignal = command.InteractiveSignal;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 输送线请求入库下一地址
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
|
if (task != null)
|
{
|
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
|
if (newTask != null)
|
{
|
ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
|
taskCommand.InteractiveSignal = command.InteractiveSignal;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 输送线入库完成
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
|
if (task != null)
|
{
|
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 conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
|
taskCommand.InteractiveSignal = command.InteractiveSignal;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
|
/// <summary>
|
/// 输送线请求出库下一地址
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
|
if (task != null)
|
{
|
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
|
if (newTask != null)
|
{
|
ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
|
taskCommand.InteractiveSignal = command.InteractiveSignal;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 输送线出库完成
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
|
if (task != null)
|
{
|
conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
|
WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
|
Console.Out.WriteLine(content.Serialize());
|
}
|
}
|
|
public void Dispose()
|
{
|
GC.SuppressFinalize(this);
|
}
|
}
|
}
|