#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_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 : IJob { private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IMapper _mapper; public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; } public Task Execute(IJobExecutionContext context) { try { CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); if (conveyorLine != null) { List childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); List tasks = new List(); ConveyorLineTaskCommand command = new ConveyorLineTaskCommand(); command.Barcode=conveyorLine.Communicator.Read("DB801.10.0"); command.ISOutFinish = conveyorLine.Communicator.Read("DB801.0.0"); command.CL1001Free = conveyorLine.Communicator.Read("DB801.2.0"); command.CL1001Status = conveyorLine.Communicator.Read("DB801.4.0"); command.TaskNum = conveyorLine.Communicator.Read("DB801.6.0"); command.ISInFinish = conveyorLine.Communicator.Read("DB801.42.0"); command.CL1002Free = conveyorLine.Communicator.Read("DB801.44.0"); command.CL1002Status = conveyorLine.Communicator.Read("DB801.46.0"); command.Weight = conveyorLine.Communicator.Read("DB801.48.0"); command.CL1002Barcode = conveyorLine.Communicator.Read("DB801.52.0"); command.ISIn = conveyorLine.Communicator.Read("DB801.84.0"); if (command != null) { Dt_Task Intask = _taskService.QueryConveyorLineTask(command.CL1002Barcode); if (Intask != null) { //入库处理 //如果入库到位,则根据托盘码(条码)去获取WCS任务号 if (command.ISInFinish == 1) { _taskService.UpdateTaskStatus(Intask.TaskId, (int)TaskInStatusEnum.Line_InExecuting); _taskExecuteDetailService.AddTaskExecuteDetail(Intask.TaskId, $"输送线入库执行中"); //入库确认信号 conveyorLine.Communicator.Write("DB800.6.0", 1); _taskService.UpdateTaskStatus(Intask.TaskId, (int)TaskInStatusEnum.Line_InFinish); _taskExecuteDetailService.AddTaskExecuteDetail(Intask.TaskId, $"输送线入库完成"); } } Dt_Task Outtask = _taskService.QueryConveyorLineOutTask(command.Barcode); if (Outtask != null) { //出库处理 //如果出库到位,出库任务完成 if (command.ISOutFinish == 1) { _taskService.UpdateTaskStatus(Outtask.TaskId, (int)TaskOutStatusEnum.Line_OutExecuting); _taskExecuteDetailService.AddTaskExecuteDetail(Outtask.TaskId, $"输送线出库执行中"); _taskService.UpdateTaskStatus(Outtask.TaskId, (int)TaskOutStatusEnum.Line_OutFinish); _taskExecuteDetailService.AddTaskExecuteDetail(Outtask.TaskId, $"输送线出库完成"); //出库确认信号 conveyorLine.Communicator.Write("DB800.0.0", 1); _taskService.UpdateTaskStatus(Outtask.TaskId, (int)TaskOutStatusEnum.OutFinish); _taskExecuteDetailService.AddTaskExecuteDetail(Outtask.TaskId, $"出库任务完成"); } } } Task.WaitAll(tasks.ToArray()); } } catch (Exception ex) { Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); } finally { } return Task.CompletedTask; } /// /// 输送线请求入库 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 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(task); // taskCommand.InteractiveSignal = command.InteractiveSignal; conveyorLine.SendCommand(taskCommand, childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } /// /// 输送线请求入库下一地址 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 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(newTask); // //taskCommand.InteractiveSignal = command.InteractiveSignal; // conveyorLine.SendCommand(taskCommand, childDeviceCode); // } //} } /// /// 输送线入库完成 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 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()); //} } /// /// 输送线请求出信息 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode) { Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); if (task != null) { ConveyorLineTaskCommand taskCommand = _mapper.Map(task); //taskCommand.InteractiveSignal = command.InteractiveSignal; conveyorLine.SendCommand(taskCommand, childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } /// /// 输送线请求出库下一地址 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 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(newTask); // //taskCommand.InteractiveSignal = command.InteractiveSignal; // conveyorLine.SendCommand(taskCommand, childDeviceCode); // } //} } /// /// 输送线出库完成 /// /// 输送线实例对象 /// 读取的请求信息 /// 子设备编号 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()); // } } } }