|
|
|
|
|
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 LineWcsrun;
|
|
|
|
|
|
private readonly BasePlcpoint LineSignal;
|
|
|
|
|
|
private readonly BasePlcpoint LineIsPallet;
|
|
|
|
|
|
private readonly BasePlcpoint LineSerialNO;
|
|
|
|
|
|
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("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 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();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now+":五楼CTU上件扫描监听启动");
|
|
|
|
|
|
LogManager.Info("五楼CTU上件扫描监听启动");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
var taskList = dbContext.WcsTask.Where(t => t.nextPointId == CTUID && (t.taskType == 7 || t.taskType == 8)).ToList();
|
|
|
|
|
|
if (taskList.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Info(FloorNo + "楼CTU无任务");
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var item in taskList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.taskStatus == 0)//下发任务
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 5 && t.equipType == 1);
|
|
|
|
|
|
WcsCmd wcsCmd = new WcsCmd()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = item.objid,
|
|
|
|
|
|
cmdStatus = 0,
|
|
|
|
|
|
taskId = item.orderId,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
cmdType = item.taskType,
|
|
|
|
|
|
containerNo = item.containerNo,
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
createBy = FloorNo + "楼AGV",
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.equipNo,
|
|
|
|
|
|
nextPointId = item.endPointId,
|
|
|
|
|
|
nextPointNo = item.endPointNo,
|
|
|
|
|
|
};
|
|
|
|
|
|
RequestAGVTaskDto agvTask = new RequestAGVTaskDto();
|
|
|
|
|
|
agvTask.reqCode = item.objid.ToString();
|
|
|
|
|
|
agvTask.positionCodePath = new List<Position>
|
|
|
|
|
|
{
|
|
|
|
|
|
new Position
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.currPointNo,
|
|
|
|
|
|
type="1"
|
|
|
|
|
|
},
|
|
|
|
|
|
new Position
|
|
|
|
|
|
{
|
|
|
|
|
|
positionCode=wcsCmd.nextPointNo,
|
|
|
|
|
|
type="2"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
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.Add(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsCmd? wcsCmd = dbContext.WcsCmd.FirstOrDefault(t => t.objid == item.objid);
|
|
|
|
|
|
if (wcsCmd != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wcsCmd.cmdStatus == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
RequestAGVTaskDto agvTask = new RequestAGVTaskDto();
|
|
|
|
|
|
agvTask.reqCode = item.objid.ToString();
|
|
|
|
|
|
agvTask.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 = 3;
|
|
|
|
|
|
dbContext.Update(wcsCmd);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (wcsCmd.cmdStatus == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
//任务完成
|
|
|
|
|
|
//如果是入库任务,更新库存信息,并删除任务
|
|
|
|
|
|
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);
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|