using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks
{
///
/// 龙门架
///
[DisallowConcurrentExecution]
public class GantryJob : JobBase, IJob
{
private readonly ITaskRepository _taskRepository;
private readonly ITaskService _taskService;
public GantryJob(ITaskRepository taskRepository, ITaskService taskService)
{
_taskRepository = taskRepository;
_taskService = taskService;
}
public Task Execute(IJobExecutionContext context)
{
try
{
bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
if (flag && value != null && value is OtherDevice)
{
OtherDevice otherDevice = (OtherDevice)value;
byte gantryStatus = otherDevice.GetValue(GantryDBName.GantryStatus);
byte gantryAutoStatus = otherDevice.GetValue(GantryDBName.GantryAutoStatus);
byte gantryWorkStatus = otherDevice.GetValue(GantryDBName.GantryWorkStatus);
if(gantryStatus == 1 && gantryAutoStatus == 3 && gantryWorkStatus == 0)
{
// 逻辑处理
// 1. 读取任务
// 2. 任务执行
// 3. 任务完成
Dt_Task? task = _taskService.QueryAGantryUnExecuteTask(otherDevice.DeviceCode);
if(task != null)
{
string[] takePositions = task.CurrentAddress.Split("-");
if(takePositions.Length != 4)
{
//WriteError
return Task.CompletedTask;
}
string[] putPositions = task.NextAddress.Split("-");
if (putPositions.Length != 4)
{
//WriteError
return Task.CompletedTask;
}
otherDevice.SetValue(GantryDBName.TwoHand, task.TaskNum);
otherDevice.SetValue(GantryDBName.TaskNum, task.TaskNum);
otherDevice.SetValue(GantryDBName.TakePosition, Convert.ToInt32(takePositions[0]));
otherDevice.SetValue(GantryDBName.TakePositionX, Convert.ToInt32(takePositions[1]));
otherDevice.SetValue(GantryDBName.TakePositionY, Convert.ToInt32(takePositions[2]));
otherDevice.SetValue(GantryDBName.TakePositionZ, Convert.ToInt32(takePositions[3]));
otherDevice.SetValue(GantryDBName.TakePositionR, 0);
otherDevice.SetValue(GantryDBName.PutPosition, Convert.ToInt32(putPositions[0]));
otherDevice.SetValue(GantryDBName.PutPositionX, Convert.ToInt32(putPositions[1]));
otherDevice.SetValue(GantryDBName.PutPositionY, Convert.ToInt32(putPositions[2]));
otherDevice.SetValue(GantryDBName.PutPositionZ, Convert.ToInt32(putPositions[3]));
otherDevice.SetValue(GantryDBName.PutPositionR, 0);
otherDevice.SetValue(GantryDBName.Length, task.TaskNum);
otherDevice.SetValue(GantryDBName.Width, task.TaskNum);
otherDevice.SetValue(GantryDBName.Height, task.TaskNum);
otherDevice.SetValue(GantryDBName.WorkType, task.TaskNum);
otherDevice.SetValue(GantryDBName.StartCommand, task.TaskNum);
}
}
else if(gantryWorkStatus == 5)
{
}
}
}
catch (Exception ex)
{
}
return Task.CompletedTask;
}
public Dt_Task GetTask()
{
return new Dt_Task();
}
}
}