You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

237 lines
13 KiB
C#

1 year ago
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
1 year ago
using Khd.Core.Library.Mapper;
using Khd.Core.Wcs.Global;
using Masuit.Tools.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
2 years ago
using Z.EntityFramework.Plus;
namespace Khd.Core.Wcs.Wcs
{
/// <summary>
2 years ago
/// 二楼码垛输送线调度
/// </summary>
2 years ago
public class SecondFloorPoint
{
private readonly IHost _host;
private readonly Plc.S7.Plc _plc;
int FloorNo { get; set; }
1 year ago
public SecondFloorPoint(IHost host, Plc.S7.Plc plc, int floor)
{
this._host = host;
this._plc = plc;
FloorNo = floor;
}
/// <summary>
/// 启动上件扫描监听
/// </summary>
public void StartPoint()
{
2 years ago
Thread FlowPointThread = new Thread(MonitorInLocatorPoint);
FlowPointThread.Start();
2 years ago
Console.WriteLine(DateTime.Now + ":二楼码垛输送线调度启动成功");
LogManager.Info("二楼码垛输送线调度启动成功");
}
public void MonitorInLocatorPoint()
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
1 year ago
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);
1 year ago
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 8);
while (true)
{
try
{
2 years ago
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
1 year ago
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)
{
1 year ago
if (Convert.ToInt32(agvPutValue) == 0)
{
1 year ago
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)
{
1 year ago
1 year ago
}
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);
}
}
}
}
1 year ago
}
1 year ago
if (Convert.ToInt32(agvGetValue) == 1 && !string.IsNullOrEmpty(rfidValue))
1 year ago
{
1 year ago
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);
}
}
}
}
}