using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.ShuttleCarEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Core;
namespace WIDESEAWCS_Tasks
{
partial class CommonShuttleCarJob
{
///
/// 根据任务状态、类型获取任务
///
///
///
///
private Dt_Task GetTask(int TaskState, int TaskType)
{
return _taskService.GetTaskState(TaskState, TaskType);
}
///
/// 根据穿梭车编号获取穿梭车信息
///
///
///
public Dt_ShuttleCar QueryCode(string ShuttleCarCode)
{
return _shuttleCarService.QueryCode(ShuttleCarCode);
}
ShuttleCarTaskType GetCarTaskType(string remark) => remark switch
{
"Charging" => ShuttleCarTaskType.Charging,
"ExitCharge" => ShuttleCarTaskType.ExitCharge,
};
ShuttleCarTaskType GetCarTaskType(int TaskType, short Direction)
{
ShuttleCarTaskType taskType = new ShuttleCarTaskType();
switch (TaskType)
{
case (int)TaskInboundTypeEnum.Inbound:
taskType = ShuttleCarTaskType.In;
break;
case (int)TaskOutboundTypeEnum.Outbound:
taskType = ShuttleCarTaskType.Out;
break;
case (int)TaskOtherTypeEnum.RelocationCar:
taskType = Direction == 1 ? ShuttleCarTaskType.ZeroA : ShuttleCarTaskType.ZeroB;
break;
default:
break;
}
return taskType;
}
///
/// 获取任务状态
///
///
///
int GetTaskState(int TaskType)
{
int state = 0;
switch (TaskType)
{
case (int)TaskInboundTypeEnum.Inbound:
state = (int)TaskInStatusEnum.Car_InExecuting;
break;
case (int)TaskOutboundTypeEnum.Outbound:
state = (int)TaskOutStatusEnum.Car_OutExecuting;
break;
case (int)TaskOtherTypeEnum.RelocationCar:
state = (int)TaskCarStatusEnum.ShuttleCar_Executing;
break;
default:
break;
}
return state;
}
///
/// 读取穿梭车信息
///
///
///
///
///
///
public T ReadCustomer(ShuttleCar shuttleCar, string deviceChildCode) where T : IDataTransfer, new()
{
string deviceChildCode2 = deviceChildCode;
if (!shuttleCar.IsConnected)
{
throw new Exception("通讯连接错误,请检查网络");
}
DeviceProDTO? deviceProDTO = (from x in shuttleCar.DeviceProDTOs
where x.DeviceProParamType == "ReadDeviceCommand" && x.DeviceChildCode == deviceChildCode2
orderby x.DeviceProOffset
select x).FirstOrDefault();
if (deviceProDTO == null)
{
throw new Exception("未找到协议信息");
}
return shuttleCar.Communicator.ReadCustomer(deviceProDTO.DeviceProAddress);
}
}
}