优化
This commit is contained in:
@@ -440,33 +440,31 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="dtoDatas"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> GenerateInStockBox(List<InStock> dtoDatas, bool isTransaction)
|
||||
public async Task<Result> GenerateInStockBox(InStock dtoData, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
if (dtoData == null)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//物料收发明细dtos
|
||||
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
|
||||
|
||||
#region 按箱
|
||||
//2.组装-按箱入库
|
||||
var dtoDatas_details_Method_box = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Box).SelectMany(x => x.Details).ToList();
|
||||
var generateDtoList_Metod_Box = dtoDatas_details_Method_box.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
|
||||
//2.组装-按箱和按产品入库
|
||||
var generateDtoList = dtoData.Details.GroupBy(x => new { x.BoxId })
|
||||
.Select(x => new BoxInventoryGenerateDto()
|
||||
{
|
||||
BoxId = x.Key.BoxId,
|
||||
OrgCode = x.Key.OrgCode,
|
||||
StockCode = x.Key.StockCode,
|
||||
SubStockId = x.Key.SubStockId,
|
||||
InventoryInOutMethod = (int)InventoryInOutMethod.Box,
|
||||
OrgCode = dtoData.OrgCode,
|
||||
StockCode = dtoData.StockCode,
|
||||
SubStockId = dtoData.SubStockId,
|
||||
InventoryInOutMethod = (int)dtoData.Method,
|
||||
InventoryInOutType = (int)InventoryInOutType.In
|
||||
}).ToList();
|
||||
|
||||
//2.1.遍历:组装明细
|
||||
generateDtoList_Metod_Box.ForEach(x =>
|
||||
generateDtoList.ForEach(x =>
|
||||
{
|
||||
foreach (var detItem in dtoDatas_details_Method_box)
|
||||
foreach (var detItem in dtoData.Details)
|
||||
{
|
||||
//2.1箱是当前的
|
||||
if (detItem.BoxId == x.BoxId)
|
||||
@@ -480,63 +478,21 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
}
|
||||
});
|
||||
#endregion
|
||||
|
||||
#region 按产品
|
||||
//3.组装-按产品入库
|
||||
var dtoDatas_details_Method_Product = dtoDatas.Where(x => x.Method == InventoryInOutMethod.Product).SelectMany(x => x.Details).ToList();
|
||||
var generateDtoList_Metod_Product = dtoDatas_details_Method_Product.GroupBy(x => new { x.BoxId, x.OrgCode, x.StockCode, x.SubStockId })
|
||||
.Select(x => new BoxInventoryGenerateDto()
|
||||
{
|
||||
BoxId = x.Key.BoxId,
|
||||
OrgCode = x.Key.OrgCode,
|
||||
StockCode = x.Key.StockCode,
|
||||
SubStockId = x.Key.SubStockId,
|
||||
InventoryInOutMethod = (int)InventoryInOutMethod.Product,
|
||||
InventoryInOutType = (int)InventoryInOutType.In
|
||||
}).ToList();
|
||||
|
||||
//3.1.遍历:组装明细
|
||||
generateDtoList_Metod_Product.ForEach(x =>
|
||||
{
|
||||
foreach (var detItem in dtoDatas_details_Method_Product)
|
||||
{
|
||||
//3.1箱是当前的
|
||||
if (detItem.BoxId == x.BoxId)
|
||||
{
|
||||
//3.2组装明细
|
||||
var det = new BoxInventoryGenerateDetailsDto();
|
||||
det.MaterialId = detItem.MaterialId;
|
||||
det.Qty = detItem.Qty;
|
||||
det.SerialNumbers = detItem.SerialNumbers;
|
||||
x.Details.Add(det);
|
||||
}
|
||||
}
|
||||
});
|
||||
#endregion
|
||||
|
||||
//整合一起
|
||||
var generateDtoList = new List<BoxInventoryGenerateDto>();
|
||||
generateDtoList.AddRange(generateDtoList_Metod_Box);
|
||||
generateDtoList.AddRange(generateDtoList_Metod_Product);
|
||||
//提交处理
|
||||
var result = await this.ExeInStockBox(generateDtoList, isTransaction);
|
||||
if (!result.IsSuccess)
|
||||
return result;
|
||||
|
||||
//5.组装物料收发明细dto
|
||||
foreach (var item in dtoDatas.SelectMany(x => x.Details).ToList())
|
||||
foreach (var item in dtoData.Details)
|
||||
{
|
||||
var entity = dtoDatas.Where(x => x.Id == item.Fid).FirstOrDefault();
|
||||
if (entity != null)
|
||||
{
|
||||
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
|
||||
item.BoxId, item.MaterialId,
|
||||
item.OrgCode, item.StockCode,
|
||||
item.SubStockId, InStockTypeConvert(entity.Type),
|
||||
item.SourceBillNo, item.Qty, InventoryInOutType.In);
|
||||
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
|
||||
}
|
||||
var inventoryInOutDet = _inventoryInOutDetailsService.GenerateDto(
|
||||
item.BoxId, item.MaterialId,
|
||||
dtoData.OrgCode, dtoData.StockCode,
|
||||
dtoData.SubStockId, InStockTypeConvert(dtoData.Type),
|
||||
item.SourceBillNo, item.Qty, InventoryInOutType.In);
|
||||
InventoryInOutDetailsGenerateDtoList.Add(inventoryInOutDet);
|
||||
|
||||
}
|
||||
//5.提交物料收发明细:新增
|
||||
if (InventoryInOutDetailsGenerateDtoList.Count != 0)
|
||||
@@ -565,16 +521,16 @@ namespace WMS.Web.Domain.Services
|
||||
var InventoryInOutDetailsGenerateDtoList = new List<InventoryInOutDetailsGenerateDto>();
|
||||
|
||||
//找出所有的箱库存
|
||||
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x=>x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxIds = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
|
||||
//判断箱库存是否存在
|
||||
foreach (var bid in boxIds)
|
||||
{
|
||||
var isHaveBoxInvetory= boxInventorys.Where(x => x.BoxId == bid).Any();
|
||||
var isHaveBoxInvetory = boxInventorys.Where(x => x.BoxId == bid).Any();
|
||||
if (!isHaveBoxInvetory)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//2.组装
|
||||
var generateDtoList = dtoData.Details.SelectMany(x => x.BoxsDetails).GroupBy(x => new { x.BoxId })
|
||||
@@ -590,7 +546,7 @@ namespace WMS.Web.Domain.Services
|
||||
{
|
||||
//从箱库存找到:组织、仓库、仓位、进行赋值;
|
||||
var current_box_invetory = boxInventorys.Where(t => t.BoxId == x.BoxId).FirstOrDefault();
|
||||
if (current_box_invetory != null && current_box_invetory.BoxId==x.BoxId)
|
||||
if (current_box_invetory != null && current_box_invetory.BoxId == x.BoxId)
|
||||
{
|
||||
x.OrgCode = current_box_invetory.OrgCode;
|
||||
x.StockCode = current_box_invetory.StockCode;
|
||||
@@ -1439,7 +1395,7 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="boxInventorys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas,List<BoxInventory> boxInventorys, bool isTransaction)
|
||||
private async Task<Result> ExeOutStockBox(List<BoxInventoryGenerateDto> dtoDatas, List<BoxInventory> boxInventorys, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
|
||||
Reference in New Issue
Block a user