master
2 years ago
parent 32ffabfb0a
commit edbf474e05

@ -177,13 +177,13 @@ namespace Khd.Core.Wcs.Wcs
try try
{ {
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
bool canCreate = dbContext.WcsTask.Where(t => t.nextPointId == 9).Any(); bool canCreate = dbContext.WcsTask.Where(t => t.nextPointId == 9).Where(t=>t.taskStatus<5).Any();
if (!canCreate) if (!canCreate)
{ {
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == 35); BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == 35);
if (baseEquip.emptyCount == (SystemData.maxTray / 2)) if (baseEquip.emptyCount == (SystemData.maxTray / 2))
{ {
var endEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.equipStatus == 1 && t.emptyCount == 5); var endEquip = dbContext.BaseEquip.FirstOrDefault(t => t.equipType == 15 && t.equipStatus == 1 && t.emptyCount == (SystemData.maxTray / 2));
if (endEquip != null) if (endEquip != null)
{ {
var wcsTask = new WcsTask() var wcsTask = new WcsTask()
@ -476,7 +476,8 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.saleOrderId == wmsRawOutstock.saleOrderId) .Where(t => t.saleOrderId == wmsRawOutstock.saleOrderId)
.Where(t => t.warehouseId == 311) .Where(t => t.warehouseId == 311)
.ToList(); .ToList();
var wmsBaseLocations = dbContext.WmsBaseLocation var AllWmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseId == 311).ToList();
var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") .Where(t => t.locationScrapType == "1")
@ -502,6 +503,7 @@ namespace Khd.Core.Wcs.Wcs
{ {
locRow = fistbill.a.locRow - 1; locRow = fistbill.a.locRow - 1;
} }
var lastbill = bill.Where(t => t.a.locRow == locRow) var lastbill = bill.Where(t => t.a.locRow == locRow)
.Where(t => t.a.locColumn == fistbill.a.locColumn) .Where(t => t.a.locColumn == fistbill.a.locColumn)
.Where(t => t.a.locDeep == 2) .Where(t => t.a.locDeep == 2)
@ -523,16 +525,31 @@ namespace Khd.Core.Wcs.Wcs
{ {
row = wmsBaseLocation.locRow - 1; row = wmsBaseLocation.locRow - 1;
} }
WmsBaseLocation? fromBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row) var lowLocationBill = bill.Where(t => t.a.locRow == locRow).Where(t => t.a.locColumn == wmsBaseLocation.locColumn).Where(t => t.a.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
wmsBaseLocation = lowLocationBill.a;
}
else
{
WmsBaseLocation? fromBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
.Where(t => t.locColumn == wmsBaseLocation.locColumn) .Where(t => t.locColumn == wmsBaseLocation.locColumn)
.Where(t => t.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault(); .Where(t => t.warehouseId == wmsBaseLocation.warehouseId).FirstOrDefault();
if (fromBaseLocation != null && !string.IsNullOrEmpty(fromBaseLocation.containerCode)) if (fromBaseLocation != null && !string.IsNullOrEmpty(fromBaseLocation.containerCode))
{ {
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == wmsBaseLocation.warehouseId) WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.locDeep == 1) .Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(); .Where(t=>t.locColumn>wmsBaseLocation.locColumn)
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == wmsBaseLocation.warehouseId) .OrderBy(t => t.locColumn)
.FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode))
.Where(t => t.locColumn < wmsBaseLocation.locColumn)
.OrderByDescending(t => t.locColumn)
.FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == wmsBaseLocation.warehouseId)
.Where(t => t.warehouseId != wmsBaseLocation.locationId) .Where(t => t.warehouseId != wmsBaseLocation.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode)) .Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault(); .FirstOrDefault();
@ -574,6 +591,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
if (wmsBaseLocation != null) if (wmsBaseLocation != null)
{ {
wmsRawStock = wmsRawStocks.Where(t => t.locationCode == wmsBaseLocation.locationCode).First(); wmsRawStock = wmsRawStocks.Where(t => t.locationCode == wmsBaseLocation.locationCode).First();
@ -736,6 +754,9 @@ namespace Khd.Core.Wcs.Wcs
try try
{ {
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
BaseEquip lineEquip = dbContext.BaseEquip.First(t => t.objid == 5);
if (lineEquip.equipStatus == 0)
{
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any(); bool task = dbContext.WcsTask.Where(t => t.nextPointId == 28 && t.taskStatus <= 5).Any();
if (!task) if (!task)
{ {
@ -758,10 +779,11 @@ namespace Khd.Core.Wcs.Wcs
var wmsproStocks = proStock var wmsproStocks = proStock
.Where(t => t.productId == item.productId && t.warehouseId == item.warehouseId) .Where(t => t.productId == item.productId && t.warehouseId == item.warehouseId)
.Where(t => t.totalAmount > t.frozenAmount)
.Select(t => t.locationCode) .Select(t => t.locationCode)
.ToList(); .ToList();
List<WmsBaseLocation> AllWmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseId == item.warehouseId).ToList();
var wmsBaseLocations = dbContext.WmsBaseLocation var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") .Where(t => t.locationScrapType == "1")
@ -785,57 +807,19 @@ namespace Khd.Core.Wcs.Wcs
from b in proStock from b in proStock
where a.locationCode == b.locationCode where a.locationCode == b.locationCode
select new { a, b }; select new { a, b };
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
{
bill = bill.OrderBy(t => t.a.locColumn).ToList();
}
else
{
bill = bill.OrderByDescending(t => t.a.locColumn).ToList();
}
//做数量限制
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28); BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28);
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 5);
foreach (var b in bill) foreach (var b in bill)
{ {
item.executeStatus = "1"; item.executeStatus = "1";
WmsBaseLocation location = b.a; WmsBaseLocation location = b.a;
WmsProductStock stock = b.b; WmsProductStock stock = b.b;
WcsTask wcsTask; WcsTask wcsTask;
int qty = 0;
if (stock.totalAmount - stock.frozenAmount <= needNumber)
{
item.outstockQty += stock.totalAmount - stock.frozenAmount;
qty = Convert.ToInt32(stock.totalAmount - stock.frozenAmount);
stock.updateDate = DateTime.Now; stock.updateDate = DateTime.Now;
}
else
{
item.outstockQty += needNumber;
qty = Convert.ToInt32(needNumber);
stock.updateDate = DateTime.Now;
}
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == stock.palletInfoCode); MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == stock.palletInfoCode);
if (mesBasePalletInfo != null) if (mesBasePalletInfo != null)
{ {
WmsProductOutstockDetail detail = new()
{
productId = item.productId,
productOutstockId = item.productOutstockId,
locationCode = location.locationCode,
executeStatus = "1",
beginTime = DateTime.Now,
warehouseId = item.warehouseId,
erpAmount = 0,
confirmAmount = 0,
outstockAmount = 1,
planAmount = 1,
productBatch = item.productBatch,
productOutstockDetailId = StaticData.SnowId.NextId(),
productBarcode = mesBasePalletInfo.materialBarcode
};
if (location.locDeep == 1) if (location.locDeep == 1)
{ {
int? row = 0; int? row = 0;
@ -847,15 +831,23 @@ namespace Khd.Core.Wcs.Wcs
{ {
row = location.locRow - 1; row = location.locRow - 1;
} }
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row) var lowLocationBill = bill.Where(t => t.a.locRow == row).Where(t => t.a.locColumn == location.locColumn).Where(t => t.a.warehouseId == location.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
location = lowLocationBill.a;
stock = lowLocationBill.b;
}
else
{
WmsBaseLocation? wmsBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
.Where(t => t.locColumn == location.locColumn) .Where(t => t.locColumn == location.locColumn)
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault(); .Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode)) if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
{ {
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.locDeep == 1) .Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(); .Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.warehouseId != location.locationId) .Where(t => t.warehouseId != location.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode)) .Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault(); .FirstOrDefault();
@ -879,7 +871,7 @@ namespace Khd.Core.Wcs.Wcs
endPointNo = toLocation.locationCode, endPointNo = toLocation.locationCode,
equipmentNo = agvEquip.equipNo, equipmentNo = agvEquip.equipNo,
useFlag = 1, useFlag = 1,
qty = qty qty = 1
}; };
toLocation.locationStatus = "4"; toLocation.locationStatus = "4";
toLocation.instockFlag = "1"; toLocation.instockFlag = "1";
@ -901,6 +893,24 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
WmsProductOutstockDetail detail = new()
{
productId = item.productId,
productOutstockId = item.productOutstockId,
locationCode = location.locationCode,
executeStatus = "1",
beginTime = DateTime.Now,
warehouseId = item.warehouseId,
erpAmount = 0,
confirmAmount = 0,
outstockAmount = 1,
planAmount = 1,
productBatch = item.productBatch,
productOutstockDetailId = StaticData.SnowId.NextId(),
productBarcode = mesBasePalletInfo.materialBarcode
};
wcsTask = new WcsTask() wcsTask = new WcsTask()
{ {
objid = StaticData.SnowId.NextId(), objid = StaticData.SnowId.NextId(),
@ -919,7 +929,7 @@ namespace Khd.Core.Wcs.Wcs
endPointNo = lineEquip.equipNo, endPointNo = lineEquip.equipNo,
equipmentNo = agvEquip.equipNo, equipmentNo = agvEquip.equipNo,
useFlag = 1, useFlag = 1,
qty = qty qty = 1
}; };
location.outstockFlag = "1"; location.outstockFlag = "1";
location.locationStatus = "6"; location.locationStatus = "6";
@ -943,6 +953,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.Message + ex.StackTrace); Console.WriteLine(ex.Message + ex.StackTrace);
@ -964,6 +975,9 @@ namespace Khd.Core.Wcs.Wcs
try try
{ {
dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload()); dbContext.ChangeTracker.Entries().ToList().ForEach(e => e.Reload());
BaseEquip lineEquip = dbContext.BaseEquip.First(t => t.objid == 2);
if (lineEquip.equipStatus == 0)
{
bool task = dbContext.WcsTask.Where(t => t.nextPointId == 8 && t.taskStatus <= 7).Any(); bool task = dbContext.WcsTask.Where(t => t.nextPointId == 8 && t.taskStatus <= 7).Any();
if (!task) if (!task)
{ {
@ -982,13 +996,12 @@ namespace Khd.Core.Wcs.Wcs
foreach (var item in proOutStock) foreach (var item in proOutStock)
{ {
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.floorNo == 2 && t.equipType == 1);
var wmsproStocks = proStock var wmsproStocks = proStock
.Where(t => t.productId == item.productId && t.saleOrderId == item.saleOrderId && t.warehouseId == item.warehouseId) .Where(t => t.productId == item.productId && t.saleOrderId == item.saleOrderId && t.warehouseId == item.warehouseId)
.Select(t => t.palletInfoCode) .Select(t => t.palletInfoCode)
.ToList(); .ToList();
List<WmsBaseLocation> AllWmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseId == item.warehouseId).ToList();
var wmsBaseLocations = dbContext.WmsBaseLocation var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") .Where(t => t.locationScrapType == "1")
@ -1012,14 +1025,15 @@ namespace Khd.Core.Wcs.Wcs
from b in proStock from b in proStock
where a.containerCode == b.palletInfoCode where a.containerCode == b.palletInfoCode
select new { a, b }; select new { a, b };
WmsBaseLocation? location = null;
WmsProductStock? stock = null;
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 8); BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 8);
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.objid == 1); BaseEquip endEquip = StaticData.BaseEquip.First(t => t.objid == 1);
foreach (var b in bill) foreach (var b in bill)
{ {
item.executeStatus = "1"; item.executeStatus = "1";
WmsBaseLocation location = b.a; location = b.a;
WmsProductStock stock = b.b; stock = b.b;
WcsTask wcsTask; WcsTask wcsTask;
int qty = 0; int qty = 0;
if (stock.totalAmount - stock.frozenAmount <= needNumber) if (stock.totalAmount - stock.frozenAmount <= needNumber)
@ -1064,12 +1078,20 @@ namespace Khd.Core.Wcs.Wcs
{ {
row = location.locRow - 1; row = location.locRow - 1;
} }
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row) var lowLocationBill = bill.Where(t => t.a.locRow == row).Where(t => t.a.locColumn == location.locColumn).Where(t => t.a.warehouseId == location.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
location = lowLocationBill.a;
stock = lowLocationBill.b;
}
else
{
WmsBaseLocation? wmsBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
.Where(t => t.locColumn == location.locColumn) .Where(t => t.locColumn == location.locColumn)
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault(); .Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode)) if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
{ {
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.locDeep == 1) .Where(t => t.locDeep == 1)
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
@ -1078,7 +1100,7 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.locationStatus == "1") .Where(t => t.locationStatus == "1")
.Where(t => t.outstockFlag == "0") .Where(t => t.outstockFlag == "0")
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(); .Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.warehouseId != location.locationId) .Where(t => t.warehouseId != location.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode)) .Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault(); .FirstOrDefault();
@ -1124,6 +1146,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
wcsTask = new WcsTask() wcsTask = new WcsTask()
{ {
objid = StaticData.SnowId.NextId(), objid = StaticData.SnowId.NextId(),
@ -1138,8 +1161,8 @@ namespace Khd.Core.Wcs.Wcs
currPointNo = location.locationCode, currPointNo = location.locationCode,
nextPointId = agvEquip.objid, nextPointId = agvEquip.objid,
nextPointNo = agvEquip.equipNo, nextPointNo = agvEquip.equipNo,
endPointId = lineEquip.objid, endPointId = endEquip.objid,
endPointNo = lineEquip.equipNo, endPointNo = endEquip.equipNo,
equipmentNo = agvEquip.equipNo, equipmentNo = agvEquip.equipNo,
useFlag = 1, useFlag = 1,
qty = qty qty = qty
@ -1169,6 +1192,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex.Message + ex.StackTrace); Console.WriteLine(ex.Message + ex.StackTrace);
@ -1396,8 +1420,8 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.materialId == order.MaterialId && t.warehouseId == 512) .Where(t => t.materialId == order.MaterialId && t.warehouseId == 512)
.Select(t => t.palletInfoCode) .Select(t => t.palletInfoCode)
.ToList(); .ToList();
var AllWmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseId == 512).ToList();
var wmsBaseLocations = dbContext.WmsBaseLocation var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") .Where(t => t.locationScrapType == "1")
@ -1699,7 +1723,8 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.totalAmount > t.frozenAmount) .Where(t => t.totalAmount > t.frozenAmount)
.Select(t => t.palletInfoCode) .Select(t => t.palletInfoCode)
.ToList(); .ToList();
var wmsBaseLocations = dbContext.WmsBaseLocation List<WmsBaseLocation> AllWmsBaseLocations = dbContext.WmsBaseLocation.Where(t => t.warehouseId == item.warehouseId).ToList();
var wmsBaseLocations = AllWmsBaseLocations
.Where(t => t.activeFlag == "1") .Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0") .Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") .Where(t => t.locationScrapType == "1")
@ -1723,15 +1748,7 @@ namespace Khd.Core.Wcs.Wcs
from b in rawStock from b in rawStock
where a.containerCode == b.palletInfoCode where a.containerCode == b.palletInfoCode
select new { a, b }; select new { a, b };
//如果第一列满足需求,则按第一列排序,否则按最后一列排序
if (bill.Where(t => t.a.locColumn == 1).Select(t => t.b.totalAmount - t.b.frozenAmount).Sum() > needNumber)
{
bill = bill.OrderBy(t => t.a.locColumn).Take(1).ToList();
}
else
{
bill = bill.OrderByDescending(t => t.a.locColumn).Take(1).ToList();
}
BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28); BaseEquip agvEquip = StaticData.BaseEquip.First(t => t.objid == 28);
BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.equipNo == item.endStationCode); BaseEquip lineEquip = StaticData.BaseEquip.First(t => t.equipNo == item.endStationCode);
@ -1768,15 +1785,23 @@ namespace Khd.Core.Wcs.Wcs
{ {
row = location.locRow - 1; row = location.locRow - 1;
} }
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row) var lowLocationBill = bill.Where(t => t.a.locRow == row).Where(t => t.a.locColumn == location.locColumn).Where(t => t.a.warehouseId == location.warehouseId).FirstOrDefault();
if (lowLocationBill != null)
{
location = lowLocationBill.a;
stock = lowLocationBill.b;
}
else
{
WmsBaseLocation? wmsBaseLocation = AllWmsBaseLocations.Where(t => t.locRow == row)
.Where(t => t.locColumn == location.locColumn) .Where(t => t.locColumn == location.locColumn)
.Where(t => t.warehouseId == location.warehouseId).FirstOrDefault(); .Where(t => t.warehouseId == location.warehouseId).FirstOrDefault();
if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode)) if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode))
{ {
WmsBaseLocation? toLocation = dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.locDeep == 1) .Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault(); .Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
toLocation ??= dbContext.WmsBaseLocation.Where(t => t.warehouseId == location.warehouseId) toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.warehouseId != location.locationId) .Where(t => t.warehouseId != location.locationId)
.Where(t => string.IsNullOrEmpty(t.containerCode)) .Where(t => string.IsNullOrEmpty(t.containerCode))
.FirstOrDefault(); .FirstOrDefault();
@ -1822,6 +1847,7 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
wcsTask = new WcsTask() wcsTask = new WcsTask()
{ {
objid = StaticData.SnowId.NextId(), objid = StaticData.SnowId.NextId(),

@ -109,10 +109,95 @@ namespace Khd.Core.Wcs.Wcs
//}; //};
//CallEmptyThread.Start(); //CallEmptyThread.Start();
Thread equipStatusThread = new Thread(EquipStatusLogic)
{
IsBackground = true
};
equipStatusThread.Start();
Console.WriteLine(DateTime.Now + ":一楼提升机线程启动成功"); Console.WriteLine(DateTime.Now + ":一楼提升机线程启动成功");
LogManager.Info("一楼提升机线程启动成功"); LogManager.Info("一楼提升机线程启动成功");
} }
private void EquipStatusLogic(object? obj)
{
using var scope = this._host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
while (true)
{
try
{
for (int i = 1; i <= 5; i++)
{
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == $"linesignal0{i}");
var lineSignal = StaticData.PlcDic[0].Read(basePlcpoint.plcpointAddress);
if (lineSignal != null)
{
if (Convert.ToInt32(lineSignal) == 1)
{
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == i);
if (baseEquip.equipStatus != 1)
{
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
else
{
bool hasTask = dbContext.WcsTask.Where(t => t.endPointId == i || t.currPointId == i).Any();
if (!hasTask)
{
baseEquip.equipStatus = 0;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
}
}
else
{
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == i);
bool hasTask = dbContext.WcsTask.Where(t => t.endPointId == i || t.currPointId == i).Any();
if (!hasTask)
{
baseEquip.equipStatus = 0;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
else
{
baseEquip.equipStatus = 1;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
}
}
}
}
catch (Exception ex)
{
if (ex is PlcException)
{
try
{
foreach (var item in StaticData.PlcDic)
{
if (item.Value.IP == ex.Message)
{
StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
StaticData.PlcDic[item.Key].Open();
}
}
}
catch
{
}
}
LogManager.Error(ex);
}
}
}
private void CallEmpty() private void CallEmpty()
{ {
using var scope = _host.Services.CreateScope(); using var scope = _host.Services.CreateScope();
@ -160,10 +245,28 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
catch (Exception ex)
{
if (ex is PlcException)
{
try
{
foreach (var item in StaticData.PlcDic)
{
if (item.Value.IP == ex.Message)
{
StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
StaticData.PlcDic[item.Key].Open();
}
}
}
catch catch
{ {
} }
}
LogManager.Error(ex);
}
Thread.Sleep(1000); Thread.Sleep(1000);
} }
} }
@ -296,17 +399,47 @@ namespace Khd.Core.Wcs.Wcs
else else
{ {
if (string.IsNullOrEmpty(task.containerNo)) if (string.IsNullOrEmpty(task.containerNo))
{
if (task.qty > 1)//多个托盘
{ {
if (task.useFlag == 1) if (task.useFlag == 1)
{ {
if (task.qty > 1)//多个托盘
{
if (task.endPointId != 1)
{
task.nextPointId = 6;
dbContext.SaveChanges();
} }
} }
else if (task.qty == 1) else if (task.qty == 1)
{ {
if (task.endPointId != 1)
{
task.nextPointId = 6;
task.containerNo = RFID001Value;
dbContext.SaveChanges();
}
}
}
}
else
{
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == RFID001Value);
if (mesBasePalletInfo != null)
{
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createBy = null;
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createTime = null;
mesBasePalletInfo.materialBarcode = null;
mesBasePalletInfo.materialCode = null;
mesBasePalletInfo.materialId = null;
mesBasePalletInfo.materialName = null;
mesBasePalletInfo.updateBy = "WCS";
mesBasePalletInfo.updateTime = DateTime.Now;
dbContext.Update(mesBasePalletInfo);
dbContext.Remove(task);
dbContext.WcsTaskLog.Where(t => t.objid == task.objid).Update(t => new WcsTaskLog { taskStatus = 6 });
dbContext.SaveChanges();
} }
} }
} }
@ -377,7 +510,7 @@ namespace Khd.Core.Wcs.Wcs
continue; continue;
} }
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo); BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress)) if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress) || (string.IsNullOrEmpty(wcsTask.containerNo) && wcsTask.qty > 1))
{ {
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo) if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)
{ {
@ -413,7 +546,7 @@ namespace Khd.Core.Wcs.Wcs
if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo) if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{ {
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo); BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress)) if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress) || (string.IsNullOrEmpty(wcsTask.containerNo)&&wcsTask.qty>1))
{ {
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层 if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层
{ {

@ -827,6 +827,20 @@ namespace Khd.Core.Wcs.Wcs
} }
else if (item.taskType == 42) else if (item.taskType == 42)
{ {
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == item.containerNo);
if (mesBasePalletInfo != null)
{
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createBy = null;
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createTime = null;
mesBasePalletInfo.materialBarcode = null;
mesBasePalletInfo.materialCode = null;
mesBasePalletInfo.materialId = null;
mesBasePalletInfo.materialName = null;
mesBasePalletInfo.updateBy = "WCS";
mesBasePalletInfo.updateTime=DateTime.Now;
dbContext.Update(mesBasePalletInfo);
BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35); BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35);
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.objid == 31); BaseEquip endEquip = dbContext.BaseEquip.First(t => t.objid == 31);
endEquip.emptyCount = 0; endEquip.emptyCount = 0;
@ -842,6 +856,7 @@ namespace Khd.Core.Wcs.Wcs
dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 });
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
}
else if (item.taskType == 43) else if (item.taskType == 43)
{ {
BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35); BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35);

@ -11,7 +11,7 @@
WindowStyle="None" WindowStyle="None"
Loaded="Window_Loaded" Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Height="450" Width="800"> Height="600" Width="800">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -54,19 +54,37 @@
<Border BorderBrush="White" Grid.Column="1" BorderThickness="2" CornerRadius="5" Padding="10"> <Border BorderBrush="White" Grid.Column="1" BorderThickness="2" CornerRadius="5" Padding="10">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="6*" /> <RowDefinition Height="6*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="该物料新库存信息" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Text="该物料新库存信息" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1">
<TextBox x:Name="NewBarCode" Width="250" FontSize="20" hc:InfoElement.Placeholder="请扫描条码" Style="{StaticResource TextBoxExtend}" /> <TextBox x:Name="NewBarCode" LostFocus="NewBarCode_LostFocus" Width="250" FontSize="20" hc:InfoElement.Placeholder="请扫描条码" Style="{StaticResource TextBoxExtend}" />
<RepeatButton x:Name="ScanButton" Content="添加" Style="{StaticResource RepeatButtonPrimary}" Width="100" Margin="20,0,0,0" Click="ScanButton_Click" /> <RepeatButton x:Name="ScanButton" Content="添加" Style="{StaticResource RepeatButtonPrimary}" Width="100" Margin="20,0,0,0" Click="ScanButton_Click" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="2" Margin="0,20,0,0"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2">
<GroupBox Height="200" Header="条码" Padding="10"> <TextBlock Text="数量:" FontSize="16" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,0,0,0"/>
<TextBox x:Name="NewCount" Width="200" FontSize="20" hc:InfoElement.Placeholder="请输入数量" Style="{StaticResource TextBoxExtend}" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="3" Margin="0,10,0,0">
<GroupBox Height="250" Header="确认" Padding="10">
<Border Background="{DynamicResource RegionBrush}" CornerRadius="4"> <Border Background="{DynamicResource RegionBrush}" CornerRadius="4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="条码" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="数量" Grid.Column="1" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock x:Name="BarCodeList" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock x:Name="BarCodeList" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock x:Name="CountList" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Border> </Border>
</GroupBox> </GroupBox>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,20,0,0"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,20,0,0">

@ -20,6 +20,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
private readonly string _materialName; private readonly string _materialName;
private readonly InventoryTaskForm _inventoryTaskForm; private readonly InventoryTaskForm _inventoryTaskForm;
private readonly string _locationCode; private readonly string _locationCode;
private Dictionary<string, string> _barCodeList;
public InventoryTaskEditForm(Microsoft.Extensions.Hosting.IHost _host, long materialId, string containerNo, string materialName, string locationCode, InventoryTaskForm inventoryTaskForm) public InventoryTaskEditForm(Microsoft.Extensions.Hosting.IHost _host, long materialId, string containerNo, string materialName, string locationCode, InventoryTaskForm inventoryTaskForm)
{ {
InitializeComponent(); InitializeComponent();
@ -29,6 +30,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
this._materialName = materialName; this._materialName = materialName;
this._inventoryTaskForm = inventoryTaskForm; this._inventoryTaskForm = inventoryTaskForm;
this._locationCode = locationCode; this._locationCode = locationCode;
_barCodeList = new Dictionary<string, string>();
} }
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
@ -77,7 +79,35 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text); var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text);
if (mesBaseBarcodeInfo != null) if (mesBaseBarcodeInfo != null)
{ {
try
{
_barCodeList.Add(mesBaseBarcodeInfo.barcodeInfo, this.NewCount.Text);
this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n"; this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n";
this.CountList.Text += this.NewCount.Text + "\n";
this.NewBarCode.Text = "";
}
catch
{
MessageBoxResult messageBoxResult = MessageBox.Show("该条码已经添加过,是否更新该条码?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.OK)
{
string[] barCodes = this.BarCodeList.Text.Split('\n');
string[] counts = this.CountList.Text.Split('\n');
for (int i = 0; i < barCodes.Length; i++)
{
if (this.BarCodeList.Text == barCodes[i])
{
counts[i] = this.NewCount.Text;
this.CountList.Text = string.Join("\n", counts);
this.BarCodeList.Text = string.Join("\n", barCodes);
this._barCodeList[mesBaseBarcodeInfo.barcodeInfo] = this.NewCount.Text;
break;
}
}
}
}
this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n";
this.CountList.Text += this.NewCount.Text + "\n";
this.NewBarCode.Text = ""; this.NewBarCode.Text = "";
} }
else else
@ -94,9 +124,9 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
private void SaveButton_Click(object sender, RoutedEventArgs e) private void SaveButton_Click(object sender, RoutedEventArgs e)
{ {
List<string> newList = this.BarCodeList.Text.Split('\n').Distinct().ToList(); List<string> newList = this.BarCodeList.Text.Split('\n').ToList();
List<string> list = this.BarCode.Text.Split('\n').ToList(); List<string> list = this.BarCode.Text.Split('\n').ToList();
StringBuilder addStr = new StringBuilder(); StringBuilder addStr = new();
List<string> addList = newList.Where(t => !list.Contains(t)).ToList(); List<string> addList = newList.Where(t => !list.Contains(t)).ToList();
if (addList.Count > 0) if (addList.Count > 0)
{ {
@ -209,5 +239,29 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
} }
this.Close(); this.Close();
} }
private void NewBarCode_LostFocus(object sender, RoutedEventArgs e)
{
try
{
using var scope = this._host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text);
if (mesBaseBarcodeInfo != null)
{
this.NewCount.Text = mesBaseBarcodeInfo.batchFlag == "1" ? mesBaseBarcodeInfo.amount.ToString() : "1";
}
else
{
MessageBox.Show("条码不存在,请重新扫码");
this.NewBarCode.Text = "";
}
}
catch
{
}
}
} }
} }

Loading…
Cancel
Save