|
|
|
|
@ -32,10 +32,10 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void StartPoint()
|
|
|
|
|
{
|
|
|
|
|
var createRemoveThread = new Thread(CreateRemoveLogic);
|
|
|
|
|
createRemoveThread.IsBackground = true;
|
|
|
|
|
createRemoveThread.Name = "CreateRemoveLogic";
|
|
|
|
|
createRemoveThread.Start();
|
|
|
|
|
//var createRemoveThread = new Thread(CreateRemoveLogic);
|
|
|
|
|
//createRemoveThread.IsBackground = true;
|
|
|
|
|
//createRemoveThread.Name = "CreateRemoveLogic";
|
|
|
|
|
//createRemoveThread.Start();
|
|
|
|
|
|
|
|
|
|
//背负式Agv返库任务
|
|
|
|
|
var createBearAgvReturnThread = new Thread(CreateBearAgvReturnLogic);
|
|
|
|
|
@ -99,7 +99,7 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
{
|
|
|
|
|
using var scope = _host.Services.CreateScope();
|
|
|
|
|
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
|
|
|
|
|
List<string> cannotIn=new List<string>();
|
|
|
|
|
List<string> cannotIn = new List<string>();
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
@ -155,14 +155,13 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
|
|
|
|
var outBill = from a in bill//深库位托盘和当前任务绑定物料一致的托盘库位
|
|
|
|
|
from b in wmsBaseLocations//所有库位
|
|
|
|
|
where a.b.layerNum == b.layerNum//层数相同
|
|
|
|
|
&& b.locDeep == 2//浅库位
|
|
|
|
|
where b.locDeep == 2//浅库位
|
|
|
|
|
&& b.locRow == (a.b.locRow % 2 == 0 ? a.b.locRow - 1 : a.b.locRow + 1)
|
|
|
|
|
//如果是4则找3,如果是1则找2
|
|
|
|
|
&& a.b.locColumn == b.locColumn//列数相同
|
|
|
|
|
&& string.IsNullOrEmpty(b.containerCode)
|
|
|
|
|
select new { a,b };//在上面的基础上获取对应托盘的外侧库位的空库位信息
|
|
|
|
|
wmsBaseLocation ??= outBill.Where(t=> !cannotIn.Contains(t.b.locationCode)).FirstOrDefault()?.b;//先找相同物料的外侧库位
|
|
|
|
|
select new { a, b };//在上面的基础上获取对应托盘的外侧库位的空库位信息
|
|
|
|
|
wmsBaseLocation ??= outBill.Where(t => !cannotIn.Contains(t.b.locationCode)).FirstOrDefault()?.b;//先找相同物料的外侧库位
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => !cannotIn.Contains(t.locationCode)).Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(t => t.locDeep == 1);//找不到再找深库位
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => !cannotIn.Contains(t.locationCode)).Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位
|
|
|
|
|
if (wmsBaseLocation != null)//如果找到库位,生成入库任务
|
|
|
|
|
@ -270,8 +269,7 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
|
|
|
|
|
var outBill = from a in bill//深库位托盘和当前任务绑定物料一致的托盘库位
|
|
|
|
|
from b in wmsBaseLocations//所有库位
|
|
|
|
|
where a.b.layerNum == b.layerNum//层数相同
|
|
|
|
|
&& b.locDeep == 2//浅库位
|
|
|
|
|
where b.locDeep == 2//浅库位
|
|
|
|
|
&& b.locRow == (a.b.locRow % 2 == 0 ? a.b.locRow - 1 : a.b.locRow + 1)
|
|
|
|
|
//如果是4则找3,如果是1则找2
|
|
|
|
|
&& a.b.locColumn == b.locColumn//列数相同
|
|
|
|
|
@ -354,18 +352,89 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
|
|
|
|
|
WcsTask? wcsTask = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.useFlag == 0 && t.currPointId == 29).FirstOrDefault();
|
|
|
|
|
if (wcsTask != null)
|
|
|
|
|
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == 29);
|
|
|
|
|
if (baseEquip.emptyCount == 1)
|
|
|
|
|
{
|
|
|
|
|
WcsTask? wcsTask = dbContext.WcsTask.Where(t => t.nextPointId == 28).FirstOrDefault();
|
|
|
|
|
if (wcsTask == null)
|
|
|
|
|
{
|
|
|
|
|
WmsRawInstock? wmsRawInstock = dbContext.WmsRawInstock.Where(t => t.warehouseId == 511 && t.instockType == "2" && t.executeStatus == "0").FirstOrDefault();
|
|
|
|
|
if (wmsRawInstock != null)
|
|
|
|
|
{
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == wcsTask.containerNo);
|
|
|
|
|
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == wmsRawInstock.palletInfoCode);
|
|
|
|
|
if (mesBasePalletInfo != null)
|
|
|
|
|
{
|
|
|
|
|
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == mesBasePalletInfo.materialBarcode);
|
|
|
|
|
if (mesBaseBarcodeInfo != null)
|
|
|
|
|
{
|
|
|
|
|
var wmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseFloor == 5)
|
|
|
|
|
.Where(t => t.activeFlag == "1")
|
|
|
|
|
.Where(t => t.delFlag == "0")
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
.Where(t => t.warehouseId == 511)
|
|
|
|
|
.Where(t => t.locationStatus == "1")
|
|
|
|
|
.OrderByDescending(t => t.locColumn)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
List<string> containerCodes = wmsBaseLocations
|
|
|
|
|
.Where(t => t.locDeep == 1)
|
|
|
|
|
.Select(t => t.containerCode).ToList();//深库位的托盘
|
|
|
|
|
containerCodes.RemoveAll(t => string.IsNullOrEmpty(t));
|
|
|
|
|
List<MesBaseBarcodeInfo> mesBasePalletInfos = dbContext.MesBaseBarcodeInfo
|
|
|
|
|
.Where(t => t.materialId == mesBasePalletInfo.materialId)
|
|
|
|
|
.Where(t => t.saleOrderId == mesBaseBarcodeInfo.saleOrderId)
|
|
|
|
|
.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 b.locDeep == 2
|
|
|
|
|
&& b.locRow == (a.b.locRow % 2 == 0 ? a.b.locRow - 1 : a.b.locRow + 1)
|
|
|
|
|
&& a.b.locColumn == b.locColumn
|
|
|
|
|
&& b.locationStatus == "1"
|
|
|
|
|
&& 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 == 1);//找不到再找深库位
|
|
|
|
|
wmsBaseLocation ??= wmsBaseLocations.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();//找不到再找任意库位
|
|
|
|
|
//深浅库位问题?库位入库优先级等
|
|
|
|
|
|
|
|
|
|
var AgvEquip = StaticData.BaseEquip.First(t => t.objid == 28);//5楼叉车
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
{
|
|
|
|
|
if (wmsBaseLocation.locDeep == 1)
|
|
|
|
|
{
|
|
|
|
|
bool hasLocation = wmsBaseLocations
|
|
|
|
|
.Where(t => t.locRow == (wmsBaseLocation.locRow % 2 == 1 ? (wmsBaseLocation.locRow + 1) : (wmsBaseLocation.locRow - 1)))
|
|
|
|
|
.Where(t => t.locColumn == wmsBaseLocation.locColumn).Any();
|
|
|
|
|
if (!hasLocation)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(DateTime.Now + $":目标库位{wmsBaseLocation.locationCode}的浅库位库位状态异常,无法入库");
|
|
|
|
|
_logger.Info($"目标库位{wmsBaseLocation.locationCode}的浅库位库位状态异常,无法入库");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
WcsTask newTask = new WcsTask();
|
|
|
|
|
newTask.taskStatus = 0;//创建状态
|
|
|
|
|
newTask.updateTime = DateTime.Now;
|
|
|
|
|
newTask.currPointId = baseEquip.objid;
|
|
|
|
|
newTask.currPointNo = baseEquip.equipNo;
|
|
|
|
|
newTask.nextPointId = AgvEquip.objid;
|
|
|
|
|
newTask.nextPointNo = AgvEquip.equipNo;
|
|
|
|
|
newTask.endPointId = wmsBaseLocation.locationId;
|
|
|
|
|
newTask.endPointNo = wmsBaseLocation.locationCode;
|
|
|
|
|
newTask.containerNo = mesBasePalletInfo.palletInfoCode;
|
|
|
|
|
newTask.materialId = mesBasePalletInfo.materialId;
|
|
|
|
|
newTask.objid = StaticData.SnowId.NextId();
|
|
|
|
|
newTask.createTime = DateTime.Now;
|
|
|
|
|
newTask.taskType = 28;
|
|
|
|
|
newTask.useFlag = 1;
|
|
|
|
|
wmsBaseLocation.locationStatus = "2";
|
|
|
|
|
WmsRawInstockDetail wmsRawInstockDetail = new WmsRawInstockDetail
|
|
|
|
|
{
|
|
|
|
|
rawInstockDetailId = StaticData.SnowId.NextId(),
|
|
|
|
|
@ -381,7 +450,7 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
instockBatch = mesBasePalletInfo.materialBarcode,
|
|
|
|
|
instockTime = DateTime.Now,
|
|
|
|
|
instockWay = "2",
|
|
|
|
|
locationCode = wcsTask.endPointNo,
|
|
|
|
|
locationCode = newTask.endPointNo,
|
|
|
|
|
machineName = mesBaseBarcodeInfo.machineName,
|
|
|
|
|
materialBarcode = mesBasePalletInfo.materialBarcode,
|
|
|
|
|
materialId = mesBaseBarcodeInfo.materialId,
|
|
|
|
|
@ -392,16 +461,18 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
taskCode = wmsRawInstock.taskCode,
|
|
|
|
|
};
|
|
|
|
|
dbContext.Add(wmsRawInstockDetail);
|
|
|
|
|
wmsRawInstock.executeStatus = "1";
|
|
|
|
|
wcsTask.useFlag = 1;
|
|
|
|
|
dbContext.Update(wmsRawInstock);
|
|
|
|
|
dbContext.Update(wcsTask);
|
|
|
|
|
dbContext.Update(wmsBaseLocation);
|
|
|
|
|
dbContext.Add(newTask);
|
|
|
|
|
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(newTask);
|
|
|
|
|
dbContext.Add(wcsTaskLog);
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
|
|
|
|
@ -661,6 +732,7 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
.Where(t => t.locationScrapType == "1")
|
|
|
|
|
.Where(t => t.locationStatus == "1")
|
|
|
|
|
.Where(t => t.containerCode == null)
|
|
|
|
|
.Where(t=>t.warehouseId==521)
|
|
|
|
|
.OrderByDescending(t => t.locColumn)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
if (wmsBaseLocation != null)
|
|
|
|
|
@ -2025,7 +2097,7 @@ namespace Khd.Core.Wcs.Wcs
|
|
|
|
|
.Where(t => t.locRow == row)
|
|
|
|
|
.Where(t => t.locColumn == location.locColumn)
|
|
|
|
|
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
|
|
|
|
|
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode)&&wmsBaseLocation.locationStatus=="1")
|
|
|
|
|
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
|
|
|
|
|
{
|
|
|
|
|
WmsRawStock? wmsRawStock = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode);
|
|
|
|
|
if (wmsRawStock != null)
|
|
|
|
|
|