#region << 版 本 注 释 >>
/*----------------------------------------------------------------
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
* 创建者:胡童庆
* 创建时间:2024/8/2 16:13:36
* 版本:V1.0.0
* 描述:
*
* ----------------------------------------------------------------
* 修改人:
* 修改时间:
* 版本:V1.0.1
* 修改说明:
*
*----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using AutoMapper;
using Quartz;
using SqlSugar;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Core;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
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 IPlatformStationService _PlatformStationService;
private readonly IMapper _mapper;
public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, IPlatformStationService platformStation)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_routerService = routerService;
_mapper = mapper;
_PlatformStationService = platformStation;
}
public Task Execute(IJobExecutionContext context)
{
try
{
CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
if (conveyorLine != null)
{
//读取输送线入库申请
RequestInbound(conveyorLine);
//读取堆垛机入库站台信号
RequestInSCLine(conveyorLine);
//堆垛机站台进行下发输送线任务
RequestOutSCLine(conveyorLine);
//读取Rgv出库口任务
RequestOutbound(conveyorLine);
//读取出库站台,获取出库口更新出库任务
RequestOutAdd(conveyorLine);
}
}
catch (Exception ex)
{
//Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
}
return Task.CompletedTask;
}
///
/// 输送线请求入库
///
/// 输送线实例对象
public void RequestInbound(CommonConveyorLine conveyorLine)
{
List platformsList = _PlatformStationService.GetPlatformList(conveyorLine.DeviceCode);
foreach (var RGVStationitem in platformsList)
{
ConveyorLineCommand command = lineCommand(conveyorLine,RGVStationitem.Station_code);
if (command != null)
{
if (command.Online)
{
if (command.STB)
{
WebResponseContent content = _taskService.RequestWMSTask(command.BarCode, RGVStationitem.Station_code.ToString(), command.GoodsType);
if (content.Status)
{
DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem.Station_code.ToString() && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
if (deviceProDTO6 != null)
{
conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true);
wcsWriteLog(RGVStationitem.Station_code.ToString(), "正常日志", $"{RGVStationitem.Station_code}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:true");
}
else
{
wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"未找到对于的读取模块{RGVStationitem.Station_code}");
}
}
else
{
wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"入库站台:{RGVStationitem.Station_code},错误信息:{content.Message}");
}
}
else
{
DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem.Station_code.ToString() && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
if (deviceProDTO6 != null)
{
conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
wcsWriteLog(RGVStationitem.Station_code.ToString(), "正常日志", $"{RGVStationitem.Station_code}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:false");
}
else
{
wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"未找到对于的读取模块{RGVStationitem.Station_code}");
}
}
}
else
{
wcsWriteLog(RGVStationitem.Station_code.ToString(), "错误日志", $"该站台{RGVStationitem.Station_code}不处于联机状态");
}
}
}
}
///
/// 读取堆垛机入库站台信息,进行任务完成
///
/// 输送线实例对象
public void RequestInSCLine(CommonConveyorLine conveyorLine)
{
List platformsList = _PlatformStationService.GetPlatIn(conveyorLine.DeviceCode); //读取站台信息
foreach (var RGVStationitem in platformsList)
{
ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem);
if (command != null)
{
if (command.Online && command.STB && command.TaskNo != 0)
{
//写入反馈
DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
if (conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)true))
{
DeviceProDTO? deviceProDTO2 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "STB" && x.DeviceProParamType == "ReadDeviceCommand");
if (conveyorLine.Communicator.Read(deviceProDTO2.DeviceProAddress))
{
conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)false);
_taskService.UpdateTaskStatusToNext2(command.TaskNo);
wcsWriteLog5(RGVStationitem, "正常信息", $"清除站台:{RGVStationitem}的交互信号写入:false,地址:{deviceProDTO.DeviceProAddress}");
}
else
{
wcsWriteLog5(RGVStationitem, "错误信息", $"未读取到站台:{RGVStationitem}的交互信号:true,地址:{deviceProDTO.DeviceProAddress}");
}
}
else
{
conveyorLine.Communicator.Write(deviceProDTO.DeviceProAddress, (bool)false);
wcsWriteLog5(RGVStationitem, "错误信息", $"{RGVStationitem}的交互信号写入:true ==》 false,地址:{deviceProDTO.DeviceProAddress}");
}
}
else
{
wcsWriteLog5(RGVStationitem, "错误信息", $"未读取到站台:{RGVStationitem}的申请信号,目前信号状态为。Online:{command.Online},STB:{command.STB},TaskNo:{command.TaskNo},");
}
}
}
}
///
/// RGV输送线请求出站
///
/// 输送线实例对象
public void RequestOutbound(CommonConveyorLine conveyorLine)
{
List platformsList = _PlatformStationService.GetPlatform2(conveyorLine.DeviceCode);
foreach (var RGVStationitem in platformsList)
{
ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem);
if (command != null)
{
if(command.Online)
{
if (command.STB)
{
if (_taskService.UpdateTaskStatusToNext(command.TaskNo).Status)
{
DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
if (deviceProDTO6 != null)
{
conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true);
wcsWriteLog2(RGVStationitem, "正常日志", $"{RGVStationitem}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:true");
}
else
{
wcsWriteLog2(RGVStationitem, "错误日志", $"未找到对于的读取模块{RGVStationitem}");
}
}
else
{
wcsWriteLog2(RGVStationitem, "错误日志", $"任务信息更改失败");
}
}
else
{
DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == RGVStationitem && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "DeviceCommand");
if (deviceProDTO6 != null)
{
conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
wcsWriteLog2(RGVStationitem, "正常日志", $"{RGVStationitem}写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:false");
}
else
{
wcsWriteLog2(RGVStationitem, "错误日志", $"未找到对于的读取模块{RGVStationitem}");
}
}
}
else
{
wcsWriteLog2(RGVStationitem, "错误日志", $"该站台{RGVStationitem}不处于联机状态");
}
}
}
}
///
/// 获取出库站台,更新出库任务
///
/// 输送线实例对象
public void RequestOutAdd(CommonConveyorLine conveyorLine)
{
List platformsList = _PlatformStationService.GetPlatformOutList(conveyorLine.DeviceCode);
foreach (var RGVStationitem in platformsList)
{
ConveyorLineCommand command = lineCommand(conveyorLine, RGVStationitem.Station_code);
if (command != null)
{
if(command.Online)
{
if (command.Free)
{
if (_taskService.OutConveyorLineTask(RGVStationitem)) //查找是否被占用
{
wcsWriteLog3(RGVStationitem.Station_code.ToString(), "更新成功", $"任务信息更新成功");
}
else
{
wcsWriteLog3(RGVStationitem.Station_code.ToString(), "错误信息", $"已有该站台的出库任务或任务更新失败");
}
}
else
{
wcsWriteLog3(RGVStationitem.Station_code.ToString(), "错误信息", $"该出库站台不可放货");
}
}
else
{
wcsWriteLog3(RGVStationitem.Station_code.ToString(), "是否联机", $"该站台{RGVStationitem.Station_code}不处于联机状态");
}
}
}
}
///
/// 堆垛机出库站台,根据任务进行下发至输送线
///
/// 输送线实例对象
public void RequestOutSCLine(CommonConveyorLine conveyorLine)
{
List StationData = _taskService.StackerCraneOutTask();
foreach (var LinSCStationitem in StationData)
{
string platformsList = _PlatformStationService.GetOutSCName(LinSCStationitem.Roadway, LinSCStationitem.Station_storey);
DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "STB" && x.DeviceProParamType == "DeviceCommand");
DeviceProDTO? deviceProDTO7 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "TaskNo" && x.DeviceProParamType == "DeviceCommand");
if (deviceProDTO6 != null && deviceProDTO7 != null)
{
conveyorLine.Communicator.Write(deviceProDTO7.DeviceProAddress, (int)LinSCStationitem.TaskNum);
if (conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true))
{
DeviceProDTO? deviceProDTO8 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList && x.DeviceProParamName == "ACK" && x.DeviceProParamType == "ReadDeviceCommand");
if (deviceProDTO8 != null)
{
if (conveyorLine.Communicator.Read(deviceProDTO8.DeviceProAddress))
{
_taskService.UpdateTaskStatusToNext(LinSCStationitem.TaskNum);
conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false);
conveyorLine.Communicator.Write(deviceProDTO8.DeviceProAddress, (int)0);
//写入输送线回应信号与
}
else
{
wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未读取到输送线回应信号:ACK,{LinSCStationitem}");
}
}
else
{
wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未找到对于的读取模块{LinSCStationitem}");
}
}
else
{
wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台失败", $"写入输送线信号,模块{deviceProDTO6.DeviceProAddress}:失败");
}
}
else
{
wcsWriteLog4(LinSCStationitem.TargetAddress, "申请出库堆垛机站台错误信息", $"未找到对于的写入模块{LinSCStationitem}");
}
}
}
///
/// 读取信息记录
///
///
///
///
public void wcsWriteLog(string SCLLinStack, string Logtype, string Magessadd)
{
WriteLog.Write_Log("入库口", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
}
public void wcsWriteLog2(string SCLLinStack, string Logtype, string Magessadd)
{
WriteLog.Write_Log("RGV站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
}
public void wcsWriteLog3(string SCLLinStack, string Logtype, string Magessadd)
{
WriteLog.Write_Log("出库口", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
}
public void wcsWriteLog4(string SCLLinStack, string Logtype, string Magessadd)
{
WriteLog.Write_Log("堆垛机站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
}
public void wcsWriteLog5(string SCLLinStack, string Logtype, string Magessadd)
{
WriteLog.Write_Log("堆垛机入库站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd });
}
public ConveyorLineCommand lineCommand(CommonConveyorLine conveyorLine,string Station_code)
{
ConveyorLineCommand conveyorLineCommand = new ConveyorLineCommand();
List deviceProDTO6 = conveyorLine.DeviceProDTOs
.Where(x => x.DeviceChildCode == Station_code
&& DBLine.ListDBdata.Contains(x.DeviceProParamName)
&& x.DeviceProParamType == "ReadDeviceCommand")
.ToList();
foreach (var item in deviceProDTO6)
{
var paramName = item.DeviceProParamName;
var propertyInfo = typeof(ConveyorLineCommand).GetProperty(paramName);
if (propertyInfo != null)
{
if (item.DeviceDataType == "bool")
{
var value = conveyorLine.Communicator.Read(item.DeviceProAddress);
propertyInfo.SetValue(conveyorLineCommand, value);
}else if(item.DeviceDataType == "int")
{
var value = conveyorLine.Communicator.Read(item.DeviceProAddress);
propertyInfo.SetValue(conveyorLineCommand, value);
}else if(item.DeviceDataType == "string")
{
var value = conveyorLine.Communicator.Read(item.DeviceProAddress);
propertyInfo.SetValue(conveyorLineCommand, value);
}
}
}
return conveyorLineCommand;
}
}
}