using Autofac.Core;
using HslCommunication;
using HslCommunication.Core;
using HslCommunication.WebSocket;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualBasic.FileIO;
using Newtonsoft.Json;
using Quartz;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.OHT;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
public class ZXJJob : JobBase, IJob
{
private readonly ITaskService _taskService;
WebSocketServer _webSocketServer;
public ZXJJob(ITaskService taskService, WebSocketServer webSocketServer)
{
_taskService = taskService;//注入
_webSocketServer = webSocketServer;
}
public Task Execute(IJobExecutionContext context)
{
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
if (flag && value != null)
{
OtherDevice device = (OtherDevice)value;
try
{
//Example
//device.GetValue 读取
//device.SetValue 写入
//_taskService.Repository; //仓储层,进行数据库访问
OHTReadData oHTReadData = new OHTReadData();
//todo:读取设备数据,
//todo:设备状态数据发送给前端
//WriteInfo(device.DeviceName, "infoLog");
//WriteDebug(device.DeviceName, "debugLog");
}
catch (Exception ex)
{
WriteError(device.DeviceName, "错误", ex);
}
}
return Task.CompletedTask;
}
///
/// 任务实体转换成命令Model
///
/// 任务实体
///
///
public OHTTaskCommand? ConvertToOHTTaskCommand([NotNull] Dt_Task task)
{
OHTTaskCommand oHtTaskCommand = new OHTTaskCommand();
oHtTaskCommand.W_Task_Type = 1;
oHtTaskCommand.W_Load_Layer = 0;
oHtTaskCommand.W_Pick_Line = 1;
string[] SourceCodes = task.SourceAddress.Split("-");
if (SourceCodes.Length == 3)
{
oHtTaskCommand.W_Pick_Line = Convert.ToInt16(SourceCodes[1]);
oHtTaskCommand.W_Put_Column = Convert.ToInt16(SourceCodes[2]);
oHtTaskCommand.W_Put_Layer = Convert.ToInt16(SourceCodes[3]);
}
else
{
//数据配置错误
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务源地址配置错误!");
return null;
}
string[] targetCodes = task.TargetAddress.Split("-");
if (targetCodes.Length == 3)
{
oHtTaskCommand.W_Put_Line = Convert.ToInt16(targetCodes[1]);
oHtTaskCommand.W_Put_Column = Convert.ToInt16(targetCodes[2]);
oHtTaskCommand.W_Put_Layer = Convert.ToInt16(targetCodes[3]);
}
else
{
//数据配置错误
_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务目标地址配置错误");
return null;
}
return oHtTaskCommand;
}
///
/// 获取任务
///
///
private Dt_Task? GetTask()
{
Dt_Task task;
task = _taskService.QueryStackerCraneTask("R01");
return task;
}
}
}