using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.ConveyorLineEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_Tasks.ConveyorLineJob;
namespace WIDESEAWCS_Tasks
{
public partial class CommonConveyorLineJob
{
///
/// 输送线
///
///
///
public List ConveyorLineExtend(CommonConveyorLine conveyorLine)
{
List childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
List tasks = new List();
foreach (string childDeviceCode in childDeviceCodes)
{
try
{
ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer(childDeviceCode);
if (command != null)
{
if (childDeviceCode == "101" && command.Status == (ushort)ConveyorStatus.Wait)
{
ConveyorLineTaskCommandW taskCommand = new ConveyorLineTaskCommandW()
{
TaskNum = 131205,
NextAddress = 1004,
//PalletCode = "A0216",
WriterTrue=1
};
conveyorLine.SendCommand(taskCommand, childDeviceCode);
}
else if (childDeviceCode == "104" && command.Status == (ushort)ConveyorStatus.Stored)
{
}
else if (childDeviceCode == "108" && command.Status == (ushort)ConveyorStatus.Stored)
{
}
}
#region MyRegion
if (command != null && command.Status == (ushort)ConveyorStatus.Stored)//添加输送线状态ConveyorLineStatus enum
{
switch (childDeviceCode)
{
case "101":
{
RequestInbound(conveyorLine, command, childDeviceCode);
}
break;
case "104":
ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
break;
//case "105":
// RequestOutbound(conveyorLine, command, childDeviceCode);
// break;
case "108":
ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
break;
//default:
// RequestInNextAddress(conveyorLine, command, childDeviceCode);
// RequestOutNextAddress(conveyorLine, command, childDeviceCode);
// break;
}
}
#endregion
}
catch (Exception ex)
{
continue;
}
}
return tasks;
}
///
/// 输送线请求入库
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
//Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
Dt_Task task = _taskService.QueryConveyorLineTaskNum(conveyorLine.DeviceCode, childDeviceCode, command.TaskNum);
if (task != null)
{
if (command.Spec > 0)
{
DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.Spec.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommandR.Spec));
task.ExceptionMessage = deviceProtocolDetail?.ProtocolDetailDes;
_taskService.UpdateData(task);
return;
}
ConveyorLineDTO lineDTO = new ConveyorLineDTO()
{
TaskNum = task.TaskNum,
stationCode = childDeviceCode,
Barcode = command.Barcode,
Spec = command.Spec,
Weight = command.Weight,
};
var content = _taskService.RequestWMSTask(lineDTO);
if (content.Status)
{
task.CurrentAddress = childDeviceCode;
task.NextAddress = AppSettings.Configuration["OKAddress"];
task.ExceptionMessage = null;
ConveyorLineTaskCommandW taskCommand = _mapper.Map(task);
taskCommand.WriterTrue = 1;
if (conveyorLine.SendCommand(taskCommand, childDeviceCode))
_taskService.UpdateTaskStatusToNext(task);
}
else
{
//if (content.Code == 404)//修改终点地址
//{
task.CurrentAddress = childDeviceCode;
task.NextAddress = AppSettings.Configuration["NGAddress"];
task.ExceptionMessage = content.Message;
task.TaskState = (int)TaskInStatusEnum.InException;
ConveyorLineTaskCommandW taskCommand = _mapper.Map(task);
taskCommand.WriterTrue = 1;
if (conveyorLine.SendCommand(taskCommand, childDeviceCode)) _taskService.UpdateData(task);
//}
}
}
}
///
/// 输送线请求入库下一地址
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
if (task != null)
{
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
//if (newTask != null)
//{
// ConveyorLineTaskCommandW taskCommand = _mapper.Map(newTask);
// conveyorLine.SendCommand(taskCommand, childDeviceCode);
//}
}
}
///
/// 输送线入库完成
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
//Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.Barcode, childDeviceCode);
if (task != null) _taskService.UpdateTaskStatusToNext(task);
task = _taskService.QueryCompletedConveyorLineTask(command.TaskNum, childDeviceCode);
if (task != null && string.IsNullOrEmpty(task.TargetAddress))
{
_taskService.StackerCraneRequestInbound(task);
}
//if (task != null)
//{
// //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
// //向WMS更新任务状态,WMS返回入库任务终点
// WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
// //Console.Out.WriteLine(content.Serialize());
//}
}
///
/// 输送线请求出信息
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
if (task != null)
{
ConveyorLineTaskCommandW taskCommand = _mapper.Map(task);
conveyorLine.SendCommand(taskCommand, childDeviceCode);
_taskService.UpdateTaskStatusToNext(task);
}
}
///
/// 输送线请求出库下一地址
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
if (task != null)
{
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
//if (newTask != null)
//{
// ConveyorLineTaskCommandW taskCommand = _mapper.Map(newTask);
// conveyorLine.SendCommand(taskCommand, childDeviceCode);
//}
}
}
///
/// 输送线出库完成
///
/// 输送线实例对象
/// 读取的请求信息
/// 子设备编号
public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
{
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
if (task != null)
{
//conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
//Console.Out.WriteLine(content.Serialize());
}
}
}
}