#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using Autofac.Core;
|
using AutoMapper;
|
using Microsoft.AspNetCore.Routing;
|
using Newtonsoft.Json;
|
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;
|
using WIDESEAWCS_Common.Helper;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Caches;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Repository;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class CommonConveyorLineJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IRouterService _routerService;
|
private readonly IRouterRepository _routerRepository;
|
private readonly ITaskRepository _taskRepository;
|
private readonly IMapper _mapper;
|
private readonly IStationMangerRepository _stationMangerRepository;
|
private readonly ICacheService _cacheService;
|
private readonly List<Dt_WarehouseDevice> warehouseDevices;
|
|
public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, ITaskRepository taskRepository, ICacheService cacheService, IMapper mapper)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_routerService = routerService;
|
_stationMangerRepository = stationMangerRepository;
|
_taskRepository = taskRepository;
|
_routerRepository = routerRepository;
|
_cacheService = cacheService;
|
_mapper = mapper;
|
|
string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
|
if (!string.IsNullOrEmpty(warehouseDevicesStr))
|
{
|
warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>();
|
}
|
else
|
{
|
warehouseDevices = new List<Dt_WarehouseDevice>();
|
}
|
|
}
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
|
if (conveyorLine != null)
|
{
|
List<string> deviceStations = conveyorLine.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
|
List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == conveyorLine.DeviceCode);
|
foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
|
{
|
try
|
{
|
DeviceProDTO? deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
|
DeviceProDTO? deviceProWrite = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineDBName)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
|
if (deviceProRead != null && deviceProWrite != null)
|
{
|
R_ConveyorLineInfo conveyorLineInfoRead = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
|
W_ConveyorLineInfo conveyorLineInfoWrite = conveyorLine.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
|
if (conveyorLineInfoRead == null || conveyorLineInfoWrite == null)
|
{
|
continue;
|
}
|
|
R_ConveyorLineStatus conveyorLineStatus = conveyorLineInfoRead.Status.ByteToBoolObject<R_ConveyorLineStatus>();
|
|
ConveyorLineSignal conveyorLineSignalRead = conveyorLineInfoRead.Signal.ByteToBoolObject<ConveyorLineSignal>();
|
|
|
bool ACK = conveyorLine.GetValue<W_ConveyorLineDBName, bool>(W_ConveyorLineDBName.W_ConveyorLine_ACK, item.StationCode);
|
|
bool STB = conveyorLine.GetValue<W_ConveyorLineDBName, bool>(W_ConveyorLineDBName.W_ConveyorLine_STB, item.StationCode);
|
|
//bool Return = conveyorLine.GetValue<W_ConveyorLineDB, bool>(W_ConveyorLineDB.Return, item.StationCode);
|
if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
|
{
|
|
if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
|
{
|
if (conveyorLineInfoRead.TaskNo == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//采购入库
|
{
|
WebResponseContent webResponse = _taskService.ApplyLocation(conveyorLineInfoRead.Barcode);
|
if (webResponse.Status)
|
{
|
List<Dt_WarehouseDevice> warehouseDevicesList = warehouseDevices.Where(x => x.WarehouseId == webResponse.Data.ObjToInt()).ToList();
|
|
foreach (var list in warehouseDevicesList)
|
{
|
Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == item.StationCode && x.ChildPosiDeviceCode == list.DeviceCode);
|
#region 先找允许入库的输送线入口
|
deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == routers.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.NextAddress == routers.NextPosi);
|
if (dt_Task != null) { continue; }
|
if (deviceProRead != null)
|
{
|
R_ConveyorLineInfo conveyorLineInfoRead1 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
R_ConveyorLineStatus conveyorLineStatus1 = conveyorLineInfoRead1.Status.ByteToBoolObject<R_ConveyorLineStatus>();
|
if (conveyorLineInfoRead1.Status == 6 && conveyorLineStatus1.Free && conveyorLineStatus1.Online && !conveyorLineStatus1.Goods)
|
{
|
|
#region 请求WMS生成任务后给输送线启动信号
|
WebResponseContent content = _taskService.CPRequestWMSTaskSimple(conveyorLineInfoRead.Barcode, routers.NextPosi, conveyorLineInfoRead.Spare2, item.StationCode);
|
if (content.Status)
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.Barcode && x.CurrentAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.New.ObjToInt());
|
if (task != null)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
|
_taskService.UpdateTask(task, TaskStatusEnum.RGV_NEW, sourceAddress: item.StationCode, RGVCode: item.AGVStationCode);
|
WebResponseContent responseContent = _taskService.LedShowTask(item.StationCode, task.PalletCode, task.TaskType);
|
}
|
|
}
|
#endregion
|
}
|
}
|
#endregion
|
}
|
}
|
}
|
}
|
}
|
if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt())
|
{
|
if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
|
{
|
if (conveyorLineInfoRead.TaskNo == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//采购入库
|
{
|
WebResponseContent webResponse = _taskService.ApplyLocation(conveyorLineInfoRead.Barcode);
|
if (webResponse.Status)
|
{
|
List<Dt_WarehouseDevice> warehouseDevicesList = warehouseDevices.Where(x => x.WarehouseId == webResponse.Data.ObjToInt()).ToList();
|
|
foreach (var list in warehouseDevicesList)
|
{
|
Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == item.StationCode && x.ChildPosiDeviceCode == list.DeviceCode);
|
#region 先找允许入库的输送线入口
|
deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == routers.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.NextAddress == routers.NextPosi);
|
if (dt_Task != null) { continue; }
|
if (deviceProRead != null)
|
{
|
R_ConveyorLineInfo conveyorLineInfoRead1 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
R_ConveyorLineStatus conveyorLineStatus1 = conveyorLineInfoRead1.Status.ByteToBoolObject<R_ConveyorLineStatus>();
|
if (conveyorLineInfoRead1.Status == 6 && conveyorLineStatus1.Free && conveyorLineStatus1.Online && !conveyorLineStatus1.Goods)
|
{
|
|
#region 请求WMS生成任务后给输送线启动信号
|
WebResponseContent content = _taskService.CPRequestWMSTaskSimple(conveyorLineInfoRead.Barcode, routers.NextPosi, conveyorLineInfoRead.Spare2, item.StationCode);
|
if (content.Status)
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.Barcode && x.CurrentAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.New.ObjToInt());
|
if (task != null)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
|
_taskService.UpdateTask(task, TaskStatusEnum.RGV_NEW, sourceAddress: item.StationCode, RGVCode: item.AGVStationCode);
|
|
}
|
|
}
|
#endregion
|
}
|
}
|
}
|
}
|
#endregion
|
}
|
}
|
}
|
//出库站台
|
if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
|
{
|
|
}
|
if (item.StationType == StationTypeEnum.SC_In.ObjToInt())
|
{
|
if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StationCode && x.DeviceCode == item.StationDeviceCode && x.TaskState == TaskStatusEnum.RGV_Finish.ObjToInt());
|
if (task != null)
|
{
|
_taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: task.Roadway, currentAddress: task.NextAddress);
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
|
}
|
}
|
}
|
if (item.StationType == StationTypeEnum.SC_Out.ObjToInt())
|
{
|
if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && !ACK)
|
{
|
Dt_Task _Task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt());
|
if (_Task != null)
|
{
|
Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == _Task.CurrentAddress);
|
if (routers != null)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_TaskNo, _Task.TaskNum, item.StationCode);
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_EndPos, routers.NextPosi, item.StationCode);
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_STB, true, item.StationCode);
|
_taskService.UpdateTask(_Task, TaskStatusEnum.Line_Executing, nextAddress: routers.NextPosi);
|
WriteDebug($"堆垛机出库口{item.StationCode}", $"堆垛机出库口任务更新,任务号{_Task.TaskId},目标出口位置{_Task.TargetAddress},托盘号:{_Task.PalletCode}");
|
}
|
}
|
|
}
|
//堆垛机出库口外面一段出库站台
|
if (conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && !ACK)
|
{
|
Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
|
if (task != null)
|
{
|
List<Dt_Router> routers = _routerRepository.QueryData(x => x.StartPosi == item.StationCode).ToList();
|
foreach (var items in routers)
|
{
|
deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == items.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
|
if (deviceProRead != null)
|
{
|
R_ConveyorLineInfo conveyorLineInfoRead3 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
|
|
R_ConveyorLineStatus conveyorLineStatus3 = conveyorLineInfoRead3.Status.ByteToBoolObject<R_ConveyorLineStatus>();
|
|
ConveyorLineSignal conveyorLineSignalRead3 = conveyorLineInfoRead3.Signal.ByteToBoolObject<ConveyorLineSignal>();
|
|
if (!conveyorLineSignalRead3.STB && !conveyorLineSignalRead3.ACK && conveyorLineStatus3.Online && conveyorLineStatus3.Free && !conveyorLineStatus3.Goods && !conveyorLineStatus3.Alarm && !STB && !ACK)//判断出库口是否空闲
|
{
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TargetAddress == items.NextPosi);
|
if (dt_Task == null)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
|
_taskService.UpdateTask(task, TaskStatusEnum.RGV_Execute, currentAddress: item.StationCode, targetAddress: items.NextPosi, nextAddress: items.NextPosi, RGVCode: item.AGVStationCode);
|
Thread.Sleep(500);
|
}
|
}
|
}
|
}
|
|
}
|
|
}
|
}
|
if (!conveyorLineSignalRead.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && STB && !ACK)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_STB, false, item.StationCode);
|
}
|
if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && ACK)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
|
}
|
if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && !conveyorLineStatus.Alarm && !STB && ACK)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
|
}
|
//if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && !conveyorLineStatus.Alarm && !STB && !ACK && Return)
|
//{
|
// conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_Return, false, item.StationCode);
|
//}
|
if (conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && ACK)
|
{
|
conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
|
}
|
|
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError(nameof(CommonConveyorLine), ex.Message, ex);
|
}
|
|
}
|
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError(nameof(CommonConveyorLine), ex.Message, ex);
|
}
|
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)
|
{
|
|
}
|
|
/// <summary>
|
/// 输送线请求入库下一地址
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
|
}
|
|
/// <summary>
|
/// 输送线入库完成
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
|
}
|
|
/// <summary>
|
/// 输送线请求出信息
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
|
}
|
|
/// <summary>
|
/// 输送线请求出库下一地址
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
|
}
|
|
/// <summary>
|
/// 输送线出库完成
|
/// </summary>
|
/// <param name="conveyorLine">输送线实例对象</param>
|
/// <param name="command">读取的请求信息</param>
|
/// <param name="childDeviceCode">子设备编号</param>
|
public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
|
{
|
|
}
|
}
|
}
|