|
|
|
@ -19,22 +19,34 @@ using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.Business.@base
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 航班任务业务类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BaseTaskInfoBusiness
|
|
|
|
|
{
|
|
|
|
|
public const int AMRStackNumber = 10;
|
|
|
|
|
public const int DeliverStackNumber = 15;
|
|
|
|
|
private TcpServer _tcpServer = null;
|
|
|
|
|
public Action<AirportTask> _Taskaction;
|
|
|
|
|
public Action<string> _RefreshLogMessageAction;
|
|
|
|
|
private static BaseTaskInfoBusiness instance;
|
|
|
|
|
private ILogger<BaseTaskInfoBusiness> _logger;
|
|
|
|
|
private IAirportTaskService _Taskservice;
|
|
|
|
|
private IAGVMapPointService _AGVMapPointService;
|
|
|
|
|
private IAGVStateService _AGVStateService;
|
|
|
|
|
private IAGVJobService _AGVJobService;
|
|
|
|
|
private AirPorthttpClient _airpttpClient;
|
|
|
|
|
private BaseAGVBusiness _baseAGVBusiness;
|
|
|
|
|
System.Timers.Timer RefreshTimer;
|
|
|
|
|
public BaseTaskInfoBusiness(
|
|
|
|
|
ILogger<BaseTaskInfoBusiness> logger,
|
|
|
|
|
IAirportTaskService Taskservice,
|
|
|
|
|
IAGVStateService agvService,
|
|
|
|
|
IAGVMapPointService aGVMapPointService,
|
|
|
|
|
IAGVJobService agvJobService,
|
|
|
|
|
TcpServer tcpServer,
|
|
|
|
|
AirPorthttpClient airPorthttpClient)
|
|
|
|
|
AirPorthttpClient airPorthttpClient,
|
|
|
|
|
BaseAGVBusiness baseAGVBusiness)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_tcpServer = tcpServer;
|
|
|
|
@ -43,18 +55,26 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
_airpttpClient = airPorthttpClient;
|
|
|
|
|
InitClearTimer();
|
|
|
|
|
//doWhileGetAGVTaskInfo();
|
|
|
|
|
RefreshTimer = new System.Timers.Timer(1000);
|
|
|
|
|
RefreshTimer.Elapsed += (sender, e) => RefreshTaskState();
|
|
|
|
|
_baseAGVBusiness = baseAGVBusiness;
|
|
|
|
|
_AGVMapPointService = aGVMapPointService;
|
|
|
|
|
_AGVJobService = agvJobService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BaseTaskInfoBusiness GetInstance(
|
|
|
|
|
ILogger<BaseTaskInfoBusiness> logger,
|
|
|
|
|
IAirportTaskService Taskservice,
|
|
|
|
|
IAGVStateService agvService,
|
|
|
|
|
IAGVMapPointService aGVMapPointService,
|
|
|
|
|
IAGVJobService aAGVJobService,
|
|
|
|
|
TcpServer tcpServer,
|
|
|
|
|
AirPorthttpClient airPorthttpClient)
|
|
|
|
|
AirPorthttpClient airPorthttpClient,
|
|
|
|
|
BaseAGVBusiness baseAGVBusiness)
|
|
|
|
|
{
|
|
|
|
|
if (instance == null)
|
|
|
|
|
{
|
|
|
|
|
instance = new BaseTaskInfoBusiness(logger, Taskservice, agvService, tcpServer, airPorthttpClient);
|
|
|
|
|
instance = new BaseTaskInfoBusiness(logger, Taskservice, agvService, aGVMapPointService, aAGVJobService, tcpServer, airPorthttpClient, baseAGVBusiness);
|
|
|
|
|
}
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
@ -76,8 +96,8 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
deliveragvisarrive = string.Empty, //需要判断,更新 Deliver是否到达
|
|
|
|
|
totalcount = totalCount, //判断条件 总数量是多少
|
|
|
|
|
loadcount = 0, //需要判断,更新 现抓取数量
|
|
|
|
|
taskstate = "新任务待分配", //需要判断,更新 任务状态
|
|
|
|
|
starttime = DateTime.Now,
|
|
|
|
|
taskstate = "等待", //需要判断,更新 任务状态
|
|
|
|
|
starttime = DateTime.Now,
|
|
|
|
|
finishtime = null,
|
|
|
|
|
deliveragvTaskNo = string.Empty, //需要判断,更新
|
|
|
|
|
amragvTaskNo = string.Empty, //需要判断,更新
|
|
|
|
@ -94,7 +114,87 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AGV状态查询控制
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state"></param>
|
|
|
|
|
public void AGVStateUpdateTimerOperation(TimerControl state)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case TimerControl.Start:
|
|
|
|
|
RefreshTimer.Start();
|
|
|
|
|
break;
|
|
|
|
|
case TimerControl.Stop:
|
|
|
|
|
RefreshTimer.Stop();
|
|
|
|
|
break;
|
|
|
|
|
case TimerControl.Dispose:
|
|
|
|
|
RefreshTimer.Dispose();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
_logger.LogError("未知状态");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("AGV状态操作失败!" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Timer刷新任务状态, 有新任务初次下发AGV
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RefreshTaskState()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//获取任务列表
|
|
|
|
|
List<AirportTask> Task = _Taskservice.GetAGVTaskInfos();
|
|
|
|
|
if (Task != null && Task.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//更新前端
|
|
|
|
|
_RefreshLogMessageAction?.Invoke("任务数量:" + Task.Count);
|
|
|
|
|
foreach(AirportTask taskItem in Task)
|
|
|
|
|
{
|
|
|
|
|
//查询待执行任务
|
|
|
|
|
if (taskItem.taskstate == "等待" || string.IsNullOrEmpty(taskItem.amragvno))
|
|
|
|
|
{
|
|
|
|
|
//首先调一辆最优AMR
|
|
|
|
|
AGVState firstAMR = _baseAGVBusiness.GetBestAGV(AgvType.AMR);
|
|
|
|
|
string amrTaskId = _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(
|
|
|
|
|
firstAMR.agvno,
|
|
|
|
|
_AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入位", taskItem.conveyorno).JobName);
|
|
|
|
|
taskItem.amragvTaskNo = amrTaskId;
|
|
|
|
|
taskItem.amragvno = firstAMR.agvno;
|
|
|
|
|
taskItem.amragvisarrive = "未到达";
|
|
|
|
|
taskItem.taskstate = "执行中";
|
|
|
|
|
//需要AGV和AMR才能装下
|
|
|
|
|
if (taskItem.totalcount > (AMRStackNumber - firstAMR.stackcount))
|
|
|
|
|
{
|
|
|
|
|
//调一辆最优Deliver
|
|
|
|
|
AGVState firstDeliver = _baseAGVBusiness.GetBestAGV(AgvType.Deliver);
|
|
|
|
|
string deliverTaskID = _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(
|
|
|
|
|
firstDeliver.agvno,
|
|
|
|
|
_AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入位", taskItem.conveyorno).JobName);
|
|
|
|
|
taskItem.deliveragvTaskNo = amrTaskId;
|
|
|
|
|
taskItem.deliveragvno = firstDeliver.agvno;
|
|
|
|
|
taskItem.deliveragvisarrive = "未到达";
|
|
|
|
|
}
|
|
|
|
|
_Taskservice.UpdateTaskAsync(taskItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"查询任务列表初次下发任务发生错误Message:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取任务列表,向待执行任务派发AGV (定期执行)
|
|
|
|
@ -128,6 +228,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
_logger.LogInformation($"正在为AGV,AMR分配任务");
|
|
|
|
|
|
|
|
|
|
//查询AGV设备状态及AMR设备状态
|
|
|
|
|
|
|
|
|
|
//这里要看AGV是否会立刻更新状态
|
|
|
|
|
CreateAGVTask(taskItem);
|
|
|
|
|
//查询机械臂状态
|
|
|
|
@ -147,7 +248,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
_logger.LogInformation($"正在为AGV分配任务");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_Taskaction?.Invoke(taskItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -196,7 +297,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Task.Run((() =>
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
@ -204,7 +305,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
Task.Delay(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -228,7 +329,7 @@ namespace SlnMesnac.Business.@base
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 向AMR派发任务
|
|
|
|
|