|
|
|
|
|
using Khd.Core.Domain.Models;
|
|
|
|
|
|
using Khd.Core.EntityFramework;
|
|
|
|
|
|
using Khd.Core.Library.Mapper;
|
|
|
|
|
|
using Khd.Core.Wcs.Global;
|
|
|
|
|
|
using Masuit.Tools.Logging;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Z.EntityFramework.Plus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 二楼码垛输送线调度
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class SecondFloorPoint
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IHost _host;
|
|
|
|
|
|
private readonly Plc.S7.Plc _plc;
|
|
|
|
|
|
int FloorNo { get; set; }
|
|
|
|
|
|
public SecondFloorPoint(IHost host, Plc.S7.Plc plc, int floor)
|
|
|
|
|
|
{
|
|
|
|
|
|
this._host = host;
|
|
|
|
|
|
this._plc = plc;
|
|
|
|
|
|
FloorNo = floor;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动上件扫描监听
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
|
|
|
|
|
|
FlowPointThread.Start();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼码垛输送线调度启动成功");
|
|
|
|
|
|
LogManager.Info("二楼码垛输送线调度启动成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MonitorInLocatorPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
|
var rfidPoint = StaticData.BasePlcpointList.First(t => t.id == 52);
|
|
|
|
|
|
var agvGetPoint = StaticData.BasePlcpointList.First(t => t.id == 53);
|
|
|
|
|
|
var agvPutPoint = StaticData.BasePlcpointList.First(t => t.id == 54);
|
|
|
|
|
|
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 8);
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
|
var agvGetValue = this._plc.Read(agvGetPoint.plcpointAddress);
|
|
|
|
|
|
var agvPutValue = this._plc.Read(agvPutPoint.plcpointAddress);
|
|
|
|
|
|
var rfidValue = this._plc.ReadRFID(rfidPoint.plcpointAddress);
|
|
|
|
|
|
if (agvGetValue != null && agvPutValue != null && rfidValue != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Convert.ToInt32(agvPutValue) == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool canCreate = dbContext.WcsTask.Where(t => t.endPointId == 36 || t.nextPointId == 8).Any();
|
|
|
|
|
|
if (!canCreate)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip? baseEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 20 && t.emptyCount > 1 && t.equipStatus == 1);
|
|
|
|
|
|
BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 36);
|
|
|
|
|
|
if (baseEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
currPointId = baseEquip.objid,
|
|
|
|
|
|
currPointNo = baseEquip.equipNo,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
containerNo = null,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 2,
|
|
|
|
|
|
fromFloorNo = 2,
|
|
|
|
|
|
isEmpty = "1",
|
|
|
|
|
|
qty = baseEquip.emptyCount,
|
|
|
|
|
|
taskType = 57,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼码垛输送线生成请求空托盘任务成功:" + wcsTask.objid);
|
|
|
|
|
|
LogManager.Info("二楼码垛输送线生成请求空托盘任务成功:" + wcsTask.objid);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
baseEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.emptyCount > 1 && t.equipStatus == 1);
|
|
|
|
|
|
if (baseEquip != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip startEquip = dbContext.BaseEquip.First(t => t.objid == 40);
|
|
|
|
|
|
if (startEquip.emptyCount > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
WcsTaskManual wcsTaskManual = new WcsTaskManual()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
startPointId = startEquip.objid,
|
|
|
|
|
|
startPointNo = startEquip.equipNo,
|
|
|
|
|
|
endPointId = endEquip.objid,
|
|
|
|
|
|
endPointNo = endEquip.equipNo,
|
|
|
|
|
|
nextPointId = startEquip.objid,
|
|
|
|
|
|
nextPointNo = startEquip.equipNo,
|
|
|
|
|
|
currPointId = startEquip.objid,
|
|
|
|
|
|
currPointNo = startEquip.equipNo,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
containerNo = null,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 2,
|
|
|
|
|
|
fromFloorNo = 1,
|
|
|
|
|
|
isEmpty = "1",
|
|
|
|
|
|
qty = startEquip.emptyCount,
|
|
|
|
|
|
taskType = 53,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wcsTaskManual);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼码垛输送线生成一楼托盘库任务成功:" + wcsTaskManual.objid);
|
|
|
|
|
|
LogManager.Info("二楼码垛输送线生成一楼托盘库任务成功:" + wcsTaskManual.objid);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Convert.ToInt32(agvGetValue) == 1 && !string.IsNullOrEmpty(rfidValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == rfidValue);
|
|
|
|
|
|
if (mesBasePalletInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
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")
|
|
|
|
|
|
.Where(t => t.warehouseId == 231)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
var wmsProductStocks = dbContext.WmsProductStock
|
|
|
|
|
|
.Where(t => t.warehouseId == 231)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
WmsBaseLocation? wmsBaseLocation = null;
|
|
|
|
|
|
if (wmsBaseLocations.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<WmsBaseLocation> locDeepLocations = wmsBaseLocations.Where(t => t.locDeep == 1).ToList();
|
|
|
|
|
|
var bill = from a in wmsProductStocks
|
|
|
|
|
|
join b in locDeepLocations on a.locationCode equals b.locationCode
|
|
|
|
|
|
select new { a, b };
|
|
|
|
|
|
if (bill.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
int? row = 0;
|
|
|
|
|
|
foreach (var item in bill)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.b.locRow % 2 == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
row = item.b.locRow + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
row = item.b.locRow - 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
wmsBaseLocation = wmsBaseLocations
|
|
|
|
|
|
.Where(t => t.locDeep == 2)
|
|
|
|
|
|
.Where(t => t.locRow == row)
|
|
|
|
|
|
.Where(t => t.locColumn == item.b.locColumn)
|
|
|
|
|
|
.Where(t => t.containerCode == null || t.containerCode == "")
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations
|
|
|
|
|
|
.Where(t => t.containerCode == null || t.containerCode == "")
|
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => t.containerCode == null || t.containerCode == "").FirstOrDefault();
|
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
BaseEquip startEquip = StaticData.BaseEquip.First(t => t.objid == 37);
|
|
|
|
|
|
var wcsTask = new WcsTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
objid = StaticData.SnowId.NextId(),
|
|
|
|
|
|
currPointId = startEquip.objid,
|
|
|
|
|
|
currPointNo = startEquip.equipNo,
|
|
|
|
|
|
nextPointId = agvEquip.objid,
|
|
|
|
|
|
nextPointNo = agvEquip.equipNo,
|
|
|
|
|
|
endPointId = wmsBaseLocation.locationId,
|
|
|
|
|
|
endPointNo = wmsBaseLocation.locationCode,
|
|
|
|
|
|
taskStatus = 0,
|
|
|
|
|
|
useFlag = 1,
|
|
|
|
|
|
containerNo = rfidValue,
|
|
|
|
|
|
createBy = "WCS",
|
|
|
|
|
|
createTime = DateTime.Now,
|
|
|
|
|
|
floorNo = 2,
|
|
|
|
|
|
fromFloorNo = 2,
|
|
|
|
|
|
isEmpty = "0",
|
|
|
|
|
|
taskType = 49,
|
|
|
|
|
|
qty = 1,
|
|
|
|
|
|
};
|
|
|
|
|
|
dbContext.Add(wcsTask);
|
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(wcsTask);
|
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":二楼码垛输送线生成入库托盘任务成功:" + wcsTask.objid);
|
|
|
|
|
|
LogManager.Info("二楼码垛输送线生成入库托盘任务成功:" + wcsTask.objid);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogManager.Error(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|