|
|
|
|
|
using Khd.Core.Domain.Dto.webapi;
|
|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Library.Mapper;
|
|
|
|
|
|
using Khd.Core.Plc;
|
|
|
|
|
|
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>
|
|
|
|
|
|
/// 三楼接驳位调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ThirdFloorPoint
|
|
|
|
|
|
{
|
|
|
|
|
|
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; }
|
|
|
|
|
|
int EquipID = 3;
|
|
|
|
|
|
string EquipNo = "";
|
|
|
|
|
|
public ThirdFloorPoint(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 + ":三楼接驳位调度启动成功");
|
|
|
|
|
|
LogManager.Info("三楼接驳位调度启动成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<int> ITypes = new List<int> { 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 rfid = this._plc.ReadRFID(LineRFID.plcpointAddress);
|
|
|
|
|
|
var isSignal = this._plc.Read(LineSignal.plcpointAddress);
|
|
|
|
|
|
if (rfid != null && isSignal != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (Convert.ToInt32(isSignal) == 1)//托盘到位
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip baseEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 1);
|
|
|
|
|
|
var wcsTask = dbContext.WcsTask.FirstOrDefault(t => t.containerNo == rfid && t.nextPointId == baseEquip.objid);
|
|
|
|
|
|
var AgvEquip = StaticData.BaseEquip.First(t => t.floorNo == 3 && t.equipType == 4);//背负Agv
|
|
|
|
|
|
if (wcsTask != null)//如果不是null
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wcsTask.taskStatus == 5)//提升机任务是完成状态
|
|
|
|
|
|
{
|
|
|
|
|
|
if (wcsTask.isEmpty == "1")
|
|
|
|
|
|
{
|
|
|
|
|
|
var emptyEquip = StaticData.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.emptyCount == 0);
|
|
|
|
|
|
if(emptyEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsTask.taskStatus = 0;//创建状态
|
|
|
|
|
|
wcsTask.updateTime = DateTime.Now;
|
|
|
|
|
|
wcsTask.currPointId = baseEquip.objid;
|
|
|
|
|
|
wcsTask.currPointNo = baseEquip.equipNo;
|
|
|
|
|
|
wcsTask.nextPointId = AgvEquip.objid;
|
|
|
|
|
|
wcsTask.nextPointNo = AgvEquip.equipNo;
|
|
|
|
|
|
wcsTask.endPointId = emptyEquip.objid;
|
|
|
|
|
|
wcsTask.endPointNo = emptyEquip.equipNo;
|
|
|
|
|
|
wcsTask.useFlag = 1;
|
|
|
|
|
|
dbContext.Update(wcsTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseFloor == FloorNo)
|
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
|
.Where(t => t.instockFlag == "0")
|
|
|
|
|
|
.Where(t => t.outstockFlag == "0")
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
List<string> containerCodes = wmsBaseLocations.Where(t => t.locDeep == 1).Select(t => t.containerCode).ToList();//深库位的托盘
|
|
|
|
|
|
List<MesBasePalletInfo> mesBasePalletInfos = dbContext.MesBasePalletInfo
|
|
|
|
|
|
.Where(t => t.materialId == wcsTask.materialId)
|
|
|
|
|
|
.Where(t => containerCodes.Contains(t.palletInfoCode)).ToList();//深库位的托盘的物料等于当前任务的物料
|
|
|
|
|
|
|
|
|
|
|
|
var bill = from a in mesBasePalletInfos
|
|
|
|
|
|
join b in wmsBaseLocations.Where(t => t.locDeep == 1) on a.palletInfoCode equals b.containerCode
|
|
|
|
|
|
select new { b };//等于当前任务的物料的托盘的库位信息
|
|
|
|
|
|
|
|
|
|
|
|
var outBill = from a in bill
|
|
|
|
|
|
from b in wmsBaseLocations
|
|
|
|
|
|
where a.b.layerNum == b.layerNum
|
|
|
|
|
|
&& b.locDeep == 2
|
|
|
|
|
|
&& a.b.locRow == b.locRow
|
|
|
|
|
|
&& a.b.locColumn == b.locColumn
|
|
|
|
|
|
&& b.locationStatus == "1"
|
|
|
|
|
|
&& b.outstockFlag == "0"
|
|
|
|
|
|
&& b.instockFlag == "0"
|
|
|
|
|
|
&& string.IsNullOrEmpty(b.containerCode)
|
|
|
|
|
|
select new { a.b };//在上面的基础上获取对应托盘的外侧库位的空库位信息
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = null;
|
|
|
|
|
|
wmsBaseLocation ??= outBill.FirstOrDefault()?.b;//先找相同物料的外侧库位
|
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(t => t.locDeep == 2);//找不到再找深库位
|
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位
|
|
|
|
|
|
|
|
|
|
|
|
if (wmsBaseLocations.Count > 0 && wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsTask.taskStatus = 0;//创建状态
|
|
|
|
|
|
wcsTask.updateTime = DateTime.Now;
|
|
|
|
|
|
wcsTask.currPointId = baseEquip.objid;
|
|
|
|
|
|
wcsTask.currPointNo = baseEquip.equipNo;
|
|
|
|
|
|
wcsTask.nextPointId = AgvEquip.objid;
|
|
|
|
|
|
wcsTask.nextPointNo = AgvEquip.equipNo;
|
|
|
|
|
|
wcsTask.endPointId = wmsBaseLocation.locationId;
|
|
|
|
|
|
wcsTask.endPointNo = wmsBaseLocation.locationCode;
|
|
|
|
|
|
if (wmsBaseLocation.warehouseId == 311)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcsTask.taskType = 39;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("查找入库库位失败");
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
wcsTask.useFlag = 1;
|
|
|
|
|
|
wmsBaseLocation.instockFlag = "1";
|
|
|
|
|
|
wmsBaseLocation.locationStatus = "2";
|
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
|
dbContext.Update(wcsTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":三楼楼接驳位调度入库任务,未找到库位");
|
|
|
|
|
|
LogManager.Info("三楼接驳位调度入库任务,未找到库位");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (wcsTask.taskStatus == 6)//小车任务是完成状态,说明是出库
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip nextEquip = StaticData.BaseEquip.First(t => t.equipType == 2);//提升机
|
|
|
|
|
|
wcsTask.nextPointId = nextEquip.objid;
|
|
|
|
|
|
wcsTask.nextPointNo = nextEquip.equipNo;
|
|
|
|
|
|
wcsTask.currPointId = baseEquip.objid;
|
|
|
|
|
|
wcsTask.currPointNo = baseEquip.equipNo;
|
|
|
|
|
|
wcsTask.fromFloorNo = FloorNo;
|
|
|
|
|
|
wcsTask.taskStatus = 0;
|
|
|
|
|
|
wcsTask.updateTime = DateTime.Now;
|
|
|
|
|
|
dbContext.Update(wcsTask);
|
|
|
|
|
|
dbContext.WcsTaskLog.Where(t => t.objid == wcsTask.objid)
|
|
|
|
|
|
.Update(t => new WcsTaskLog
|
|
|
|
|
|
{
|
|
|
|
|
|
nextPointId = nextEquip.objid,
|
|
|
|
|
|
nextPointNo = nextEquip.equipNo,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.equipNo,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
updateTime = DateTime.Now,
|
|
|
|
|
|
});
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|