|
|
|
|
|
using Khd.Core.Domain.Dto.webapi;
|
|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Library.Mapper;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Masuit.Tools;
|
|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 二楼AGV调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class SecondFloorAGV
|
|
|
|
|
|
{
|
|
|
|
|
|
List<BasePlcpoint> ScanPoint { get; set; }//点位信息
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private readonly Plc.S7.Plc _plc;
|
|
|
|
|
|
private readonly BasePlcpoint LineRFID;
|
|
|
|
|
|
private readonly BasePlcpoint LineWcsrun;
|
|
|
|
|
|
private readonly BasePlcpoint LineSignal;
|
|
|
|
|
|
private readonly BasePlcpoint LineIsPallet;
|
|
|
|
|
|
private readonly BasePlcpoint LineSerialNO;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
int EquipID = 8; //2楼AGV
|
|
|
|
|
|
List<int> taskInType = new List<int> { 1, 3, 5, 7 };
|
|
|
|
|
|
List<int> taskOutType = new List<int> { 2, 4, 6, 8 };
|
|
|
|
|
|
public SecondFloorAGV(IHost host, Plc.S7.Plc plc, int floor, string equipNo)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
this._plc = plc;
|
|
|
|
|
|
FloorNo = floor;
|
|
|
|
|
|
EquipNo = equipNo;
|
|
|
|
|
|
this.ScanPoint = StaticData.BasePlcpointList.Where(t => t.floorNo == floor).ToList();//加载当前站点所对应的点位
|
|
|
|
|
|
this.LineRFID = this.ScanPoint.First(t => t.plcpointNo.Contains("RFID"));
|
|
|
|
|
|
this.LineWcsrun = this.ScanPoint.First(t => t.plcpointNo.Contains("wcsrun"));
|
|
|
|
|
|
this.LineSignal = this.ScanPoint.First(t => t.plcpointNo.Contains("linesignal"));
|
|
|
|
|
|
this.LineIsPallet = this.ScanPoint.First(t => t.plcpointNo.Contains("ispallet"));
|
|
|
|
|
|
this.LineSerialNO = this.ScanPoint.First(t => t.plcpointNo.Contains("serialno"));
|
|
|
|
|
|
|
|
|
|
|
|
//var IsPallet = this._plc.Read(LineIsPallet.plcpointAddress);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//默认启动,清理plc的上位机写入点位值
|
|
|
|
|
|
//this._plc.Write(LineRFID.plcpointAddress, MainCentralControl.QingKongDianWei);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("楼层" + floor + " 初始化数据异常" + ex.Message);
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动上件扫描监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
|
|
|
|
|
|
FlowPointThread.Start();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼AGV上件扫描监听启动成功");
|
|
|
|
|
|
LogManager.Info("二楼AGV上件扫描监听启动成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
BaseEquip inEquip = StaticData.BaseEquip.First(t => t.objid == 36);
|
|
|
|
|
|
BaseEquip outEquip = StaticData.BaseEquip.First(t => t.objid == 37);
|
|
|
|
|
|
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 2);
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == EquipID);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
//获取条码号,如果该条码任务存在就继续任务,如果条码不存在,创建入库任务并调度agv
|
|
|
|
|
|
var taskList = dbContext.WcsTask
|
|
|
|
|
|
.Where(t => t.useFlag == 1)
|
|
|
|
|
|
.Where(t => t.nextPointId == EquipID).OrderBy(t => t.createTime).ToList();
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (taskList.Where(t => t.taskStatus > 0).Where(t => t.objid != item.objid).Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info($"2楼AGV线程:有其他任务正在执行,跳过当前任务{item.objid}");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (item.taskStatus == 0)//下发任务
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseDictionary baseDictionary = StaticData.BaseDictionary.First(t => t.objid == item.taskType);
|
|
|
|
|
|
if (item.taskType == 50)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd wcsCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
cmdStatus = 0,
|
|
|
|
|
|
taskId = item.objid,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
containerNo = item.containerNo,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = FloorNo + "楼AGV",
|
|
|
|
|
|
currPointId = item.currPointId,
|
|
|
|
|
|
currPointNo = lineEquip.agvPositionCode,
|
|
|
|
|
|
nextPointId = item.endPointId,
|
|
|
|
|
|
nextPointNo = inEquip.agvPositionCode,
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = wcsCmd.objid.ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.currPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
},
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.nextPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
taskTyp = baseDictionary.dicValue,
|
|
|
|
|
|
ctnrTyp = "2",
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼AGV线程下发任务" + agvTask.ToJsonString() + "\n" + message);
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼AGV线程下发任务" + item.startPointNo + "," + item.endPointNo);
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 });
|
|
|
|
|
|
WcsCmdLog wcsCmdLog = CoreMapper.Map<WcsCmdLog>(wcsCmd);
|
|
|
|
|
|
dbContext.Add(wcsCmdLog);
|
|
|
|
|
|
dbContext.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("五楼Agv下发任务失败" + item.taskType + message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 51)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd wcsCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
cmdStatus = 0,
|
|
|
|
|
|
taskId = item.objid,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
containerNo = item.containerNo,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = FloorNo + "楼AGV",
|
|
|
|
|
|
currPointId = item.currPointId,
|
|
|
|
|
|
currPointNo = lineEquip.agvPositionCode,
|
|
|
|
|
|
nextPointId = item.endPointId,
|
|
|
|
|
|
nextPointNo = outEquip.agvPositionCode,
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = wcsCmd.objid.ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.currPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
},
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.nextPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
taskTyp = baseDictionary.dicValue,
|
|
|
|
|
|
ctnrTyp = "2",
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼AGV线程下发任务" + agvTask.ToJsonString() + "\n" + message);
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼AGV线程下发任务" + item.startPointNo + "," + item.endPointNo);
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 });
|
|
|
|
|
|
WcsCmdLog wcsCmdLog = CoreMapper.Map<WcsCmdLog>(wcsCmd);
|
|
|
|
|
|
dbContext.Add(wcsCmdLog);
|
|
|
|
|
|
dbContext.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼Agv下发任务失败" + item.taskType + message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 52)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd wcsCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
cmdStatus = 0,
|
|
|
|
|
|
taskId = item.objid,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
containerNo = item.containerNo,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = FloorNo + "楼AGV",
|
|
|
|
|
|
currPointId = item.currPointId,
|
|
|
|
|
|
currPointNo = lineEquip.agvPositionCode,
|
|
|
|
|
|
nextPointId = item.endPointId,
|
|
|
|
|
|
nextPointNo = lineEquip.agvPositionCode,
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = wcsCmd.objid.ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.currPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
},
|
|
|
|
|
|
new ()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.nextPointNo,
|
|
|
|
|
|
type="00"
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
taskTyp = baseDictionary.dicValue,
|
|
|
|
|
|
ctnrTyp = "2",
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼AGV线程继续任务" + item.objid + "," + item.startPointNo + "," + item.endPointNo);
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼AGV线程继续任务" + item.startPointNo + "," + item.endPointNo);
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 1 });
|
|
|
|
|
|
WcsCmdLog wcsCmdLog = CoreMapper.Map<WcsCmdLog>(wcsCmd);
|
|
|
|
|
|
dbContext.Add(wcsCmdLog);
|
|
|
|
|
|
dbContext.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼Agv下发任务失败" + item.taskType + message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid);
|
|
|
|
|
|
if (wcsCmd != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info("二楼AGV线程完成任务" + item.objid);
|
|
|
|
|
|
if (wcsCmd.cmdStatus == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
taskCode = wcsCmd.taskCode
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.SendPostMessage(baseEquip.serverIp, baseEquip.serverPort.Value, "rcms/services/rest/hikRpcService/continueTask", message);
|
|
|
|
|
|
ReponseMessage? reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsCmd.cmdStatus = 4;
|
|
|
|
|
|
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmd() { cmdStatus = 4 });
|
|
|
|
|
|
dbContext.Update(wcsCmd);
|
|
|
|
|
|
dbContext.WcsTask.Where(t => t.objid == item.objid).Update(t => new WcsTask() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 4 });
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (wcsCmd.cmdStatus == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskType == 50)
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.Remove(item);
|
|
|
|
|
|
dbContext.Remove(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
|
|
|
|
|
|
dbContext.WcsCmdLog.Where(t => t.taskId == item.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 });
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 51)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "1";
|
|
|
|
|
|
wmsBaseLocation.instockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.containerCode = item.containerNo;
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Remove(item);
|
|
|
|
|
|
dbContext.Remove(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
|
|
|
|
|
|
dbContext.WcsCmdLog.Where(t => t.taskId == item.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 });
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 52)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId);
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "1";
|
|
|
|
|
|
wmsBaseLocation.instockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.containerCode = null;
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
item.taskStatus = 6;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.Remove(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog() { taskStatus = 6 });
|
|
|
|
|
|
dbContext.WcsCmdLog.Where(t => t.taskId == item.objid).Update(t => new WcsCmdLog() { cmdStatus = 6 });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|