#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_Common.TaskEnum; 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); } } catch (Exception ex) { //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); } return Task.CompletedTask; } /// /// 输送线请求入库 /// /// 输送线实例对象 public void RequestInbound(CommonConveyorLine conveyorLine) { try { List platformsList = _PlatformStationService.GetPlatformList(conveyorLine.DeviceCode); foreach (var plctationitem in platformsList) { ConveyorTaskCommand command = lineCommand(conveyorLine, plctationitem.Station_code); int kd = 1; if (command != null && kd!=1) { //是否需要写入反馈 DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == plctationitem.Station_code && x.DeviceProParamName == "HandShake" && x.DeviceProParamType == "DeviceCommand"); if (command.HandShake && command.Barcodest != "") { //调取申请 WebResponseContent content = _taskService.RequestWMSTask(int.Parse(command.Barcodest), int.Parse(plctationitem.Station_code)); if (content.Status) { conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)true); wcsWriteLog(plctationitem.Station_code, "成功", $"{command.Barcodest},反馈输送线读取到入库申请信号:true"); } } /* else { //conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (bool)false); //未读取到输送线申请 wcsWriteLog(plctationitem.Station_code, "错误", $"未读取到输送线入库申请或托盘条码为0,申请:{command.HandShake},托盘条码:{command.Barcodest}"); }*/ } } } catch (Exception ex) { wcsWriteLog("输送线请求错误", "错误", $"错误信息:{ex.Message}"); throw; } } /// /// 读取堆垛机出库站台信息,进行任务完成 /// /// 输送线实例对象 public void RequestInSCLine(CommonConveyorLine conveyorLine) { try { PlatformStation platformsList = _PlatformStationService.GetPlatInData(); ConveyorTaskCommand command = lineCommand(conveyorLine, platformsList.Station_code); DeviceProDTO? deviceProDTO6 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList.Station_code && x.DeviceProParamName == "StationNum" && x.DeviceProParamType == "DeviceCommand"); DeviceProDTO? deviceProDTO7 = conveyorLine.DeviceProDTOs.Find(x => x.DeviceChildCode == platformsList.Station_code && x.DeviceProParamName == "HandShake" && x.DeviceProParamType == "DeviceCommand"); if (command.HandShake && command.Barcodest != "") { //调取申请 Dt_Task task = _taskService.QueryConveyorLineTask(int.Parse(platformsList.Station_code), command.Barcodest); if (task != null) { conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (short)int.Parse(task.NextAddress)); _taskService.StackCraneTaskCompleted(task.TaskNum); conveyorLine.Communicator.Write(deviceProDTO7.DeviceProAddress, (bool)true); WriteLog.Write_Log("堆垛机放货站台", platformsList.Station_code + "站台", "成功", new { 信息 = $"写入条码:{command.Barcodest},去向:{task.NextAddress}" }); } /* else { WriteLog.Write_Log("堆垛机放货站台", platformsList.Station_code + "站台", "错误", new { 信息 = $"未找到条码:{command.Barcodest}的任务号" }); }*/ } /* else { //conveyorLine.Communicator.Write(deviceProDTO6.DeviceProAddress, (int)0); WriteLog.Write_Log("堆垛机放货站台", platformsList.Station_code + "站台", "错误", new { 信息 = $"未读取到检修出库放货站台申请或托盘条码,申请:{command.HandShake},托盘条码:{command.Barcodest},并清空写入条码" }); }*/ } catch (Exception ex) { wcsWriteLog("堆垛机站台进行任务完成", "错误", $"错误信息:{ex.Message}"); throw; } } /// /// 读取信息记录 /// /// /// /// public void wcsWriteLog(string SCLLinStack, string Logtype, string Magessadd) { WriteLog.Write_Log("堆垛机取货站台", SCLLinStack + "站台", Logtype, new { 信息 = Magessadd }); } public ConveyorTaskCommand lineCommand(CommonConveyorLine conveyorLine, string Station_code) { try { ConveyorTaskCommand conveyorLineCommand = new ConveyorTaskCommand(); 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(ConveyorTaskCommand).GetProperty(paramName); if (propertyInfo != null) { if (item.DeviceDataType == "bool") { 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; } catch (Exception ex) { wcsWriteLog("出库站台", "错误", $"错误信息:{ex.Message}"); throw; } } } }