#region << 版 本 注 释 >>
/*----------------------------------------------------------------
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
* 创建者:胡童庆
* 创建时间:2024/8/2 16:13:36
* 版本:V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 修改时间:
* 版本:V1.0.1
* 修改说明:
*
*----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using AutoMapper;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
using static Microsoft.IO.RecyclableMemoryStreamManager;
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");
RequestInbound(conveyorLine); //检测入料口信息
RequestInNextAddress(conveyorLine);
}
catch (Exception ex)
{
//Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
}
finally
{
//Console.Out.WriteLine(DateTime.Now);
}
return Task.CompletedTask;
}
///
/// 输送线请求入库到哪个巷道
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void RequestInbound(CommonConveyorLine conveyorLine)
{
HandleEvent(conveyorLine, "PLC_WCS_B.03_EVENT", "PLC_WCS_B.03_PLC_LPN", "PLC_WCS_B.03_WCS_TO");
HandleEvent(conveyorLine, "PLC_WCS_C.02_EVENT", "PLC_WCS_C.02_PLC_LPN", "PLC_WCS_C.02_WCS_TO");
CheckForEmptyPallet(conveyorLine,"PLC_WCS_B.01_EVENT");
CheckForEmptyPallet(conveyorLine,"PLC_WCS_C.01_EVENT");
// 处理 B 站台事件
ProcessConveyorEvent(conveyorLine, "PLC_WCS_B.01_EVENT", "PLC_WCS_B.01_PLC_LPN", "B1", "R01-003-027-001-01");
// 处理 C 站台事件
ProcessConveyorEvent(conveyorLine, "PLC_WCS_C.03_EVENT", "PLC_WCS_C.03_PLC_LPN", "C7", "R01-003-041-001-01");
}
///
/// 判断出库站台是否需要空托
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine)
{
}
///
/// 用于入库判断巷道
///
///
///
///
///
private void HandleEvent(CommonConveyorLine conveyorLine,string eventTag, string barcodeTag, string writeTag)
{
int events = conveyorLine.Communicator.Read(eventTag); // 读取事件
if (events == 1)
{
string barcode = conveyorLine.Communicator.Read(barcodeTag); // 读取条码
if ((_taskService.ToPlatform(barcode)).Status)
{
// 写入去向1号堆垛机
bool result = conveyorLine.Communicator.Write(writeTag, 1);
if (result)
{
WriteLog.GetLog("PLC日志").Write("写入去向:1", "去向");
}
}
else
{
// 写入去向2号堆垛机
bool result = conveyorLine.Communicator.Write(writeTag, 2);
if (result)
{
WriteLog.GetLog("PLC日志").Write("写入去向:2", "去向");
}
}
}
}
//用于判断是否补空托
private void CheckForEmptyPallet(CommonConveyorLine conveyorLine,string eventTag)
{
int events = conveyorLine.Communicator.Read(eventTag); // 读取事件
if (events == 0)
{
WriteLog.GetLog("PLC日志").Write($"读取到出库口补空托信号:{events}", "需要空托");
// 生成堆垛机取空托任务
}
}
//用于判断入库站台
private void ProcessConveyorEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string stationId, string taskCode)
{
int eventStatus = conveyorLine.Communicator.Read(eventTag);
if (eventStatus == 1)
{
string barcode = conveyorLine.Communicator.Read(barcodeTag);
if (barcode != null)
{
// 拿取托盘条码申请入库信息
WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // 申请入库,生成堆垛机任务
if (content.Status)
{
WriteLog.GetLog("PLC入库站台日志").Write($"申请入库成功,站台编号为:{stationId}", "站台信息");
}
else
{
WriteLog.GetLog("PLC入库站台日志").Write($"申请入库失败,站台编号为:{stationId}", "站台信息");
}
}
else
{
WriteLog.GetLog("PLC入库站台日志").Write($"读取到输送线信息为空,站台编号为:{stationId}", "站台信息");
}
}
}
}
}