change-修改五楼成品出库移库

master
liuwf 1 year ago
parent 9bbc05a1ff
commit 714966307b

@ -10,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using System.Data; using System.Data;
using System.Drawing.Text;
using Z.EntityFramework.Plus; using Z.EntityFramework.Plus;
namespace Khd.Core.Wcs.Wcs namespace Khd.Core.Wcs.Wcs
@ -1584,38 +1585,39 @@ namespace Khd.Core.Wcs.Wcs
} }
var lowLocationBill = bill.Where(t => t.a.locRow == row).Where(t => t.a.locColumn == location.locColumn).Where(t => t.a.warehouseId == location.warehouseId).FirstOrDefault(); 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) if (lowLocationBill != null)
{ { //对应的浅库位满足条件,直接出浅库位
location = lowLocationBill.a; location = lowLocationBill.a;
stock = lowLocationBill.b; stock = lowLocationBill.b;
} }
else else
{ {
// 目标出库库位对应的浅库位
WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.Where(t => t.locRow == row) WmsBaseLocation? wmsBaseLocation = dbContext.WmsBaseLocation.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) && wmsBaseLocation.locationStatus == "1") if (wmsBaseLocation != null && !string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
{ {//浅库位有库存
WmsProductStock? wmsProductStock = dbContext.WmsProductStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode); WmsProductStock? wmsProductStock = dbContext.WmsProductStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode);
if (wmsProductStock != null)
{ #region 找寻移库目标库位
WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId) // 寻找移库目的库位
.Where(t => t.locDeep == 1) WmsBaseLocation? toLocation = null;
.Where(t => t.activeFlag == "1")
.Where(t => t.delFlag == "0")
.Where(t => t.locationScrapType == "1") var moveLocationList = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId)
.Where(t => t.locationStatus == "1")
.Where(t => string.IsNullOrEmpty(t.containerCode)).FirstOrDefault();
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) && t.locationStatus == "1").OrderBy(t => t.locDeep).ToList();
.FirstOrDefault();
if (toLocation != null) foreach (WmsBaseLocation itemLocation in moveLocationList)
{ {
if (toLocation.locDeep == 1)
if (itemLocation.locDeep == 1)
{ {
bool hasLocation = AllWmsBaseLocations bool hasLocation = AllWmsBaseLocations
.Where(t => t.locRow == (toLocation.locRow % 2 == 1 ? (toLocation.locRow + 1) : (toLocation.locRow - 1))) .Where(t => t.locRow == (itemLocation.locRow % 2 == 1 ? (itemLocation.locRow + 1) : (itemLocation.locRow - 1)))
.Where(t => t.locColumn == toLocation.locColumn) .Where(t => t.locColumn == itemLocation.locColumn)
.Where(t => t.locationStatus == "1" && string.IsNullOrEmpty(t.containerCode))
.Any(); .Any();
if (!hasLocation) if (!hasLocation)
{ {
@ -1623,6 +1625,26 @@ namespace Khd.Core.Wcs.Wcs
_logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库"); _logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
continue; continue;
} }
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
if (toLocation == null)
{
// 找寻下一个可出库库存
continue;
} }
var RemoveTask = new WcsTask() var RemoveTask = new WcsTask()
{ {
@ -1657,25 +1679,17 @@ namespace Khd.Core.Wcs.Wcs
dbContext.Add(RemoveTask); dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask); WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog); dbContext.Add(wcsTaskLog);
#endregion
} }
else else if (wmsBaseLocation.locationStatus != "1")
{ {
// 浅库位状态异常,找寻下一个可出库库存
continue; continue;
} }
}
else
{
continue;
}
}
else if (wmsBaseLocation != null && wmsBaseLocation.locationStatus != "1")
{
Console.WriteLine(DateTime.Now + $":{wmsBaseLocation.locationCode}库位状态异常,无法移库");
_logger.Info($"{wmsBaseLocation.locationCode}库位状态异常,无法移库");
continue;
}
} }
} }
wcsTask = new WcsTask() wcsTask = new WcsTask()
{ {
objid = StaticData.SnowId.NextId(), objid = StaticData.SnowId.NextId(),
@ -2423,6 +2437,12 @@ namespace Khd.Core.Wcs.Wcs
MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == stock.instockBatch).FirstOrDefault(); MesBaseBarcodeInfo? mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == stock.instockBatch).FirstOrDefault();
if (mesBaseBarcodeInfo != null) if (mesBaseBarcodeInfo != null)
{ {
if (location.locationStatus != "1")
{
Console.WriteLine(DateTime.Now + $":{location.locationCode}库位状态异常,无法出库");
_logger.Info($"{location.locationCode}库位状态异常,无法出库");
return;
}
if (location.locDeep == 1) if (location.locDeep == 1)
{ {
int? row = 0; int? row = 0;
@ -2439,27 +2459,30 @@ namespace Khd.Core.Wcs.Wcs
.Where(t => t.locRow == row) .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) && wmsBaseLocation.locationStatus == "1")
if (!string.IsNullOrEmpty(wmsBaseLocation.containerCode) && wmsBaseLocation.locationStatus == "1")
{ {
// 浅库位有托盘 // 浅库位有库存
WmsRawStock? wmsRawStock = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode); WmsRawStock? wmsRawStock = dbContext.WmsRawStock.FirstOrDefault(t => t.locationCode == wmsBaseLocation.locationCode);
if (wmsRawStock != null)
{
// 寻找目的库位 // 寻找移库目的库位
WmsBaseLocation? toLocation = AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId) WmsBaseLocation? toLocation = null;
.Where(t => t.locDeep == 1)
.Where(t => string.IsNullOrEmpty(t.containerCode) && t.locationStatus == "1").FirstOrDefault();
toLocation ??= AllWmsBaseLocations.Where(t => t.warehouseId == location.warehouseId) var moveLocationList = 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) && t.locationStatus == "1").OrderBy(t => t.locDeep).ToList();
.FirstOrDefault();
if (toLocation != null) foreach (WmsBaseLocation itemLocation in moveLocationList)
{ {
if (toLocation.locDeep == 1)
if (itemLocation.locDeep == 1)
{ {
bool hasLocation = AllWmsBaseLocations bool hasLocation = AllWmsBaseLocations
.Where(t => t.locRow == (toLocation.locRow % 2 == 1 ? (toLocation.locRow + 1) : (toLocation.locRow - 1))) .Where(t => t.locRow == (itemLocation.locRow % 2 == 1 ? (itemLocation.locRow + 1) : (itemLocation.locRow - 1)))
.Where(t => t.locColumn == toLocation.locColumn) .Where(t => t.locColumn == itemLocation.locColumn)
.Where(t => t.locationStatus == "1" && string.IsNullOrEmpty(t.containerCode))
.Any(); .Any();
if (!hasLocation) if (!hasLocation)
{ {
@ -2467,6 +2490,27 @@ namespace Khd.Core.Wcs.Wcs
_logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库"); _logger.Info($"目标库位{toLocation.locationCode}的浅库位库位状态异常,无法移库");
continue; continue;
} }
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
else
{
// 找到可以移库的目标库位
toLocation = itemLocation;
break;
}
}
if (toLocation == null)
{
// TODO : 没有找到可以移库的目标库位,添加报警
Console.WriteLine("5F原材料前往背板安装需要先移库没有找到可以移库的目标库位添加报警");
return;
} }
var RemoveTask = new WcsTask() var RemoveTask = new WcsTask()
{ {
@ -2499,23 +2543,15 @@ namespace Khd.Core.Wcs.Wcs
dbContext.Add(RemoveTask); dbContext.Add(RemoveTask);
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask); WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(RemoveTask);
dbContext.Add(wcsTaskLog); dbContext.Add(wcsTaskLog);
} }
else else if (wmsBaseLocation.locationStatus != "1")
{ {
continue; Console.WriteLine("浅库位状态异常,禁止出库,请检查浅库位状态");
return;
} }
} }
else
{
continue;
}
}
else if (wmsBaseLocation != null && wmsBaseLocation.locationStatus != "1")
{
Console.WriteLine(DateTime.Now + $":{wmsBaseLocation.locationCode}库位状态异常,无法移库");
_logger.Info($"{wmsBaseLocation.locationCode}库位状态异常,无法移库");
continue;
}
//else //else
//{ //{
// Console.WriteLine(DateTime.Now + $":{location.locationCode}浅库位状态异常,无法移库"); // Console.WriteLine(DateTime.Now + $":{location.locationCode}浅库位状态异常,无法移库");
@ -2544,33 +2580,33 @@ namespace Khd.Core.Wcs.Wcs
qty = qty qty = qty
}; };
//location是出库的库位mesBaseBarcodeInfo是条码信息表数据item是出库申请单 //location是出库的库位mesBaseBarcodeInfo是条码信息表数据item是出库申请单
WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail() //WmsRawOutstockDetail wmsProductOutstockDetail = new WmsRawOutstockDetail()
{ //{
rawOutstockDetailId = StaticData.SnowId.NextId(), // rawOutstockDetailId = StaticData.SnowId.NextId(),
rawOutstockId = item.rawOutstockId, // rawOutstockId = item.rawOutstockId,
materialId = item.materialId, // materialId = item.materialId,
createDate = DateTime.Now, // createDate = DateTime.Now,
createBy = "WCS", // createBy = "WCS",
taskCode = wcsTask.objid.ToString(), // taskCode = wcsTask.objid.ToString(),
executeStatus = "1", // executeStatus = "1",
locationCode = location.locationCode, // locationCode = location.locationCode,
outstockAmount = qty, // outstockAmount = qty,
planAmount = item.outstockAmount, // planAmount = item.outstockAmount,
warehouseId = item.warehouseId, // warehouseId = item.warehouseId,
materialBarcode = mesBaseBarcodeInfo.barcodeInfo, // materialBarcode = mesBaseBarcodeInfo.barcodeInfo,
instockBatch = mesBaseBarcodeInfo.batchCode, // instockBatch = mesBaseBarcodeInfo.batchCode,
stackAmount = qty, // stackAmount = qty,
outstockPerson = "WCS", // outstockPerson = "WCS",
outstockTime = DateTime.Now, // outstockTime = DateTime.Now,
outstockWay = "2", // outstockWay = "2",
materialProductionDate = mesBaseBarcodeInfo.productionDate // materialProductionDate = mesBaseBarcodeInfo.productionDate
}; //};
if (item.beginTime == null) if (item.beginTime == null)
{ {
item.beginTime = DateTime.Now; item.beginTime = DateTime.Now;
} }
SystemData.LockOutLocation(location, dbContext); SystemData.LockOutLocation(location, dbContext);
dbContext.Add(wmsProductOutstockDetail); //dbContext.Add(wmsProductOutstockDetail);
location.locationStatus = "6"; location.locationStatus = "6";
location.updateBy = "WCS"; location.updateBy = "WCS";
location.updateTime = DateTime.Now; location.updateTime = DateTime.Now;
@ -2591,7 +2627,6 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error(ex.Message + "\n" + ex.StackTrace); _logger.Error(ex.Message + "\n" + ex.StackTrace);
@ -2599,7 +2634,8 @@ namespace Khd.Core.Wcs.Wcs
Thread.Sleep(3000); Thread.Sleep(3000);
} }
}
}
} }
} }

Loading…
Cancel
Save