|
|
|
|
|
using Khd.Core.Domain.Dto.webapi;
|
|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 五楼CTU调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FiveFloorCTU
|
|
|
|
|
|
{
|
|
|
|
|
|
List<BasePlcpoint> ScanPoint { get; set; }//点位信息
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private readonly Plc.S7.Plc _plc;
|
|
|
|
|
|
private readonly BasePlcpoint LineRFID;
|
|
|
|
|
|
private readonly BasePlcpoint isarrive;
|
|
|
|
|
|
private readonly BasePlcpoint isput;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
int CTUID = 11;
|
|
|
|
|
|
public FiveFloorCTU(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("RFID5001"));
|
|
|
|
|
|
this.isarrive = this.ScanPoint.First(t => t.plcpointNo.Contains("isarrive"));
|
|
|
|
|
|
this.isput = this.ScanPoint.First(t => t.plcpointNo.Contains("isput"));
|
|
|
|
|
|
|
|
|
|
|
|
//var lineRFID = this._plc.Read(NodeSettingCarNo.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();
|
|
|
|
|
|
|
|
|
|
|
|
//Thread FlowCTUInWareThread = new Thread(MonitorInWare);
|
|
|
|
|
|
//FlowCTUInWareThread.Start();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":五楼CTU上件扫描监听启动");
|
|
|
|
|
|
LogManager.Info("五楼CTU上件扫描监听启动");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MonitorInWare(object? obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
var rfid = this._plc.Read(LineRFID.plcpointAddress);
|
|
|
|
|
|
var isArrive = this._plc.Read(isarrive.plcpointAddress);
|
|
|
|
|
|
if (rfid != null && isArrive != null && Convert.ToInt32(isArrive) == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
//根据rfid找到库位
|
|
|
|
|
|
//生成入库任务
|
|
|
|
|
|
var wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.containerCode == rfid.ToString());
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.equipNo == "FL051");
|
|
|
|
|
|
BaseEquip ctuEquip = StaticData.BaseEquip.First(t => t.objid == 11);
|
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
startPointId = baseEquip.objid,
|
|
|
|
|
|
startPointNo = baseEquip.agvPositionCode,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.agvPositionCode,
|
|
|
|
|
|
nextPointId = ctuEquip.objid,
|
|
|
|
|
|
nextPointNo = ctuEquip.equipNo,
|
|
|
|
|
|
endPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
endPointNo = wmsBaseLocation.agvPositionCode,
|
|
|
|
|
|
taskType = 1,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
floorNo = 5,
|
|
|
|
|
|
ud1 = "0",//是否是最后一个任务
|
|
|
|
|
|
containerNo = rfid.ToString(),
|
|
|
|
|
|
equipmentNo = baseEquip.equipNo,
|
|
|
|
|
|
createBy = FloorNo + "楼CTU",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<int?> taskType = new() { 1, 3, 5, 7 };
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID).ToList();
|
|
|
|
|
|
if (taskList.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info(FloorNo + "楼CTU无任务");
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskStatus == 0)//CTU会同时生成多个任务,生成就下发?
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskType == 30)//出库任务
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == item.endPointId);
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.startPointId);
|
|
|
|
|
|
var 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 + "楼CTU",
|
|
|
|
|
|
currPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
currPointNo = wmsBaseLocation.agvPositionCode,
|
|
|
|
|
|
nextPointId = baseEquip.objid,
|
|
|
|
|
|
nextPointNo = baseEquip.agvPositionCode,
|
|
|
|
|
|
taskCode = null
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.currPointNo,
|
|
|
|
|
|
type = "05"
|
|
|
|
|
|
},
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.nextPointNo,
|
|
|
|
|
|
type = "05"
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
ctnrTyp = "1",
|
|
|
|
|
|
taskTyp = "F504"
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.WcsCmd.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (item.taskType == 29)//入库任务
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.objid == item.startPointId);
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation.First(t => t.locationId == item.endPointId);
|
|
|
|
|
|
var 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 + "楼CTU",
|
|
|
|
|
|
nextPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
nextPointNo = wmsBaseLocation.agvPositionCode,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.agvPositionCode,
|
|
|
|
|
|
};
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.currPointNo,
|
|
|
|
|
|
type = "0"
|
|
|
|
|
|
},
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode = wcsCmd.nextPointNo,
|
|
|
|
|
|
type = "0"
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
ctnrTyp = "1",
|
|
|
|
|
|
taskTyp = "F503"
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask", message);
|
|
|
|
|
|
var reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsCmd.taskCode = reponseMessage.data;
|
|
|
|
|
|
wcsCmd.cmdStatus = 1;
|
|
|
|
|
|
item.taskStatus = 1;
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.taskId == item.objid);
|
|
|
|
|
|
if (wcsCmd != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wcsCmd.cmdStatus == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
var agvTask = new RequestAGVTaskDto
|
|
|
|
|
|
{
|
|
|
|
|
|
reqCode = StaticData.SnowId.NextId().ToString(),
|
|
|
|
|
|
taskCode = wcsCmd.taskCode
|
|
|
|
|
|
};
|
|
|
|
|
|
string message = JsonConvert.SerializeObject(agvTask);
|
|
|
|
|
|
string result = HttpHelper.HttpPost("http://172.16.12.24:8182/rcms/services/rest/hikRpcService/continueTask", message);
|
|
|
|
|
|
ReponseMessage? reponseMessage = JsonConvert.DeserializeObject<ReponseMessage>(result);
|
|
|
|
|
|
if (reponseMessage != null && reponseMessage.message == "成功")
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsCmd.cmdStatus = 4;
|
|
|
|
|
|
dbContext.Update(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (wcsCmd.cmdStatus == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
//任务完成
|
|
|
|
|
|
//如果是入库任务,更新库存信息,并删除任务
|
|
|
|
|
|
if (taskType.Contains(item.taskType))
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation
|
|
|
|
|
|
.First(t => t.locationId == item.startPointId && t.warehouseFloor == 5);
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "1";
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
|
|
|
|
|
|
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete();
|
|
|
|
|
|
dbContext.WcsTask.Where(t => t.objid == item.objid).Delete();
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else//如果是出库任务,更新库存信息,下一个任务为提升机
|
|
|
|
|
|
{
|
|
|
|
|
|
WmsBaseLocation wmsBaseLocation = dbContext.WmsBaseLocation
|
|
|
|
|
|
.First(t => t.locationId == item.startPointId && t.warehouseFloor == 5);
|
|
|
|
|
|
if (item.taskType == 29)
|
|
|
|
|
|
{
|
|
|
|
|
|
wmsBaseLocation.outstockFlag = "0";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "1";
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BaseEquip floorLineEquip = StaticData.BaseEquip.First(t => t.equipType == 1 && t.floorNo == 5);
|
|
|
|
|
|
BaseEquip eletorEquip = StaticData.BaseEquip.First(t => t.equipType == 2);
|
|
|
|
|
|
item.nextPointId = floorLineEquip.objid;
|
|
|
|
|
|
item.nextPointNo = floorLineEquip.equipNo;
|
|
|
|
|
|
item.fromFloorNo = 5;
|
|
|
|
|
|
item.floorNo = 1;
|
|
|
|
|
|
item.taskStatus = 6;
|
|
|
|
|
|
dbContext.Update(item);
|
|
|
|
|
|
dbContext.WcsCmd.Where(t => t.objid == wcsCmd.objid).Delete();
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 下发任务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="task"></param>
|
|
|
|
|
|
public void SendTask(long? orderId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.orderId == orderId).ToList();
|
|
|
|
|
|
//获取
|
|
|
|
|
|
if (taskList.Count == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
//首先判断是否已下发指令
|
|
|
|
|
|
var cmd = dbContext.WcsCmd.Where(t => taskList.Select(t => t.objid).ToList().Contains(t.taskId.GetValueOrDefault())).FirstOrDefault();
|
|
|
|
|
|
//指令表存在说明已下发
|
|
|
|
|
|
if (cmd != null) return;
|
|
|
|
|
|
//获取下发agv指令
|
|
|
|
|
|
string ip = ""; int port = 0; string url = "";
|
|
|
|
|
|
RequestAGVTaskDto agvtask = new RequestAGVTaskDto();
|
|
|
|
|
|
agvtask.reqCode = orderId.ToString();
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(agvtask);
|
|
|
|
|
|
HttpHelper.SendPostMessage(ip, port, url, json);
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
//未下发给agv下发指令
|
|
|
|
|
|
WcsCmd taskCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
taskId = item.objid,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
serialNo = item.serialNo,
|
|
|
|
|
|
equipmentNo = item.equipmentNo,
|
|
|
|
|
|
cmdStatus = 1,
|
|
|
|
|
|
createBy = FloorNo + "楼CTU",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(taskCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|