using HslCommunication;
|
using Mapster;
|
using Microsoft.AspNetCore.Components.Routing;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
using Quartz;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Text;
|
using WIDESEAWCS_BasicInfoRepository;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Caches;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_Core.HttpContextUser;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_DTO.WMS;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_ISystemServices;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DeviceBase;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
|
using WIDESEAWCS_SignalR;
|
using WIDESEAWCS_Tasks.StackerCraneJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
[DisallowConcurrentExecution]
|
public class CommonStackerCraneJob : JobBase, IJob
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly ITaskRepository _taskRepository;
|
private readonly IRouterService _routerService;
|
private readonly ICacheService _cacheService;
|
private readonly INoticeService _noticeService;
|
private readonly IDt_StationManagerRepository _stationManagerRepository;
|
private readonly ITask_HtyRepository _task_htyRepository;
|
private readonly ISys_ConfigService _sys_ConfigService;
|
private static List<string>? userTokenIds;
|
private static List<int>? userIds;
|
|
public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_taskRepository = taskRepository;
|
_routerService = routerService;
|
_cacheService = cacheService;
|
_noticeService = noticeService;
|
_stationManagerRepository = stationManagerRepository;
|
_task_htyRepository = task_htyRepository;
|
_sys_ConfigService = sys_ConfigService;
|
}
|
|
public Task Execute(IJobExecutionContext context)
|
{
|
try
|
{
|
CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
|
if (commonStackerCrane != null)
|
{
|
if (!commonStackerCrane.IsEventSubscribed)
|
{
|
commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
|
}
|
|
if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.ComputerMode)
|
{
|
commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
|
|
if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
|
{
|
Dt_Task? task = GetTask(commonStackerCrane);
|
if (task != null)
|
{
|
StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
|
if (stackerCraneTaskCommand != null)
|
{
|
bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
|
if (sendFlag)
|
{
|
Thread.Sleep(1000);
|
commonStackerCrane.Communicator.Write("DB100.18.0", Convert.ToInt16(1));
|
commonStackerCrane.LastTaskType = task.TaskType;
|
_taskService.UpdateTaskStatusToNext(task.TaskNum);
|
Thread.Sleep(2000);
|
}
|
}
|
}
|
}
|
}
|
|
#region 调用事件总线通知前端
|
|
var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
|
if (tokenInfos != null && tokenInfos.Any())
|
{
|
var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList();
|
var userIds = tokenInfos?.Select(x => x.UserId).ToList();
|
|
object obj = new
|
{
|
commonStackerCrane.StackerCraneAutoStatusDes,
|
commonStackerCrane.StackerCraneWorkStatusDes,
|
commonStackerCrane.DeviceCode,
|
commonStackerCrane.DeviceName,
|
StackerAlarm = StackerCraneAlarm(commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Alarm)),
|
commonStackerCrane.CurrentTaskNum,
|
commonStackerCrane.LastTaskNum,
|
};
|
_noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj });
|
}
|
|
#endregion 调用事件总线通知前端
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteError("CommonStackerCraneJob", "test", ex);
|
ConsoleHelper.WriteErrorLine($"{ex.Message}");
|
}
|
return Task.CompletedTask;
|
}
|
|
#region 报警代码转换成文字说明
|
public string StackerCraneAlarm(short alarm) => alarm switch
|
{
|
1 => "左超限",
|
2 => "右超限",
|
3 => "前超限",
|
4 => "后超限",
|
5 => "高超限",
|
6 => "取货载货台有货",
|
7 => "放货载货台无货",
|
8 => "取货左货格无货",
|
9 => "取货右货格无货",
|
10 => "放货左一有货",
|
11 => "放货右一有货",
|
12 => "取左二货格无货",
|
13 => "取右二货格无货",
|
14 => "放货左二货格有货",
|
15 => "放货右二货格有货",
|
16 => "左二取货左一有货",
|
17 => "右二取货右一有货",
|
18 => "左取货失败",
|
19 => "右取货失败",
|
20 => "左放货失败",
|
21 => "右放货失败",
|
22 => "货叉运行超时",
|
23 => "货叉断路器跳闸",
|
24 => "货叉变频器报警",
|
25 => "货叉编码器故障",
|
26 => "货叉伸叉故障",
|
27 => "层运行货叉不在中位",
|
28 => "列运行货叉不在中位",
|
29 => "货叉中位开关故障",
|
30 => "货叉变频器通讯故障",
|
31 => "货叉编码器通讯故障",
|
32 => "伸叉超出左极限",
|
33 => "伸又超出右极限",
|
34 => "入左二货格货时左一货格有货",
|
35 => "入右二货格货时右一货格有货",
|
36 => "货叉右侧回中停止位置错误",
|
37 => "货叉左侧回中停止位置错误",
|
38 => "货叉左侧极限停止位置错误",
|
39 => "货叉右侧极限停止位置错误",
|
40 => "面板急停",
|
41 => "远程急停",
|
42 => "主接触器控制回路故障",
|
43 => "超重保护",
|
44 => "松绳保护",
|
45 => "限速保护",
|
46 => "层停止位置错误",
|
47 => "列停止位置错误",
|
48 => "接收任务错误",
|
49 => "接收列超限",
|
50 => "接收层超限",
|
51 => "行走前进极限",
|
52 => "行走后退极限",
|
53 => "提升上极限",
|
54 => "提升下极限",
|
55 => "行走运行超时",
|
56 => "提升运行超时",
|
57 => "行走断路器跳闸",
|
58 => "提升断路器跳闸",
|
59 => "行走变频器故障",
|
60 => "提升变频器故障",
|
61 => "行走测距/条码故障",
|
62 => "提升测距/条码故障",
|
63 => "行走测距/条码被挡",
|
64 => "提升测距/条码被挡",
|
65 => "上升减速光电故障",
|
66 => "下降减速光电故障",
|
67 => "提升原点光电故障",
|
68 => "行走前减速光电故障",
|
69 => "行走后减速光电故障",
|
70 => "行走原点光电故障",
|
71 => "与输送机通讯故障",
|
72 => "升降超出最小层",
|
73 => "升降超出最大层",
|
74 => "行走超出最小列",
|
75 => "行走超出最大列",
|
76 => "接收排错误",
|
77 => "起始站货格被禁用",
|
78 => "目的站货格被禁用",
|
79 => "行走抱闸故障",
|
80 => "提升抱闸故障",
|
81 => "安全门打开故障",
|
_ => $"未知报警({alarm})"
|
};
|
#endregion
|
|
|
/// <summary>
|
/// 任务完成事件订阅的方法
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
|
{
|
CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
|
if (commonStackerCrane != null)
|
{
|
if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.FinishConfirm) != 1)
|
{
|
Thread.Sleep(1000);
|
ConsoleHelper.WriteColorLine($"【{commonStackerCrane.DeviceName}】堆垛机作业状态:【{(int)commonStackerCrane.StackerCraneWorkStatusValue}】时间【{DateTime.Now}】", ConsoleColor.Magenta);
|
|
string str = $"【{commonStackerCrane.DeviceName}】任务完成,任务号:【{e.TaskNum}】时间【{DateTime.Now}】";
|
WriteInfo(commonStackerCrane.DeviceName, str);
|
ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
|
var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum);
|
|
if (task == null)
|
{
|
commonStackerCrane.SetValue(StackerCraneDBName.FinishConfirm, 1);
|
return;
|
}
|
|
var isWorkType = commonStackerCrane.Communicator.WriteNoRead("DB100.0", Convert.ToInt16(1));
|
|
ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取任务
|
/// </summary>
|
/// <param name="commonStackerCrane">堆垛机对象</param>
|
/// <returns></returns>
|
private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
|
{
|
return new Dt_Task();
|
}
|
|
/// <summary>
|
/// 任务实体转换成命令Model
|
/// </summary>
|
/// <param name="task">任务实体</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
|
{
|
StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
|
|
stackerCraneTaskCommand.TaskNum = Convert.ToInt16(task.TaskNum);
|
stackerCraneTaskCommand.WorkType = Convert.ToInt16(1);
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
|
{
|
var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.CurrentAddress);
|
string[] sourceCodes = station.stationLocation.Split("-");
|
if (sourceCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
|
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
|
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
string[] targetCodes = task.NextAddress.Split("-");
|
if (targetCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
|
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
|
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务终点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
string[] sourceCodes = task.CurrentAddress.Split("-");
|
if (sourceCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
|
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
|
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
var station = _stationManagerRepository.QueryFirst(x => x.stationType == 1 && x.stationChildCode == task.NextAddress);
|
string[] targetCodes = station.stationLocation.Split("-");
|
if (targetCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
|
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
|
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务终点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
|
{
|
string[] sourceCodes = task.CurrentAddress.Split("-");
|
if (sourceCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
|
stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
|
stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
|
string[] targetCodes = task.NextAddress.Split("-");
|
if (targetCodes.Length == 3)
|
{
|
stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
|
stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
|
stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
|
}
|
else
|
{
|
//数据配置错误
|
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务终点错误,起点:【{task.CurrentAddress}】");
|
return null;
|
}
|
}
|
return stackerCraneTaskCommand;
|
}
|
}
|
}
|