优化该箱
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Inventory;
|
||||
using WMS.Web.Core.Help;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
@@ -28,14 +29,16 @@ namespace WMS.Web.Domain.Services
|
||||
private readonly ISerialNumbersRepositories _serialNumbersRepositories;
|
||||
private readonly IBoxInventoryRepositories _boxInventoryRepositories;
|
||||
private readonly ILogger<BoxInventoryService> _logger;
|
||||
private readonly IBoxService _boxService;
|
||||
public BoxInventoryService(IMapper mapper, IBoxRepositories boxRepositories, ILogger<BoxInventoryService> logger,
|
||||
IInventoryDetailsService inventoryDetailsService,
|
||||
IInventoryDetailsService inventoryDetailsService, IBoxService boxService,
|
||||
IInventoryInOutDetailsService inventoryInOutDetailsService,
|
||||
ISerialNumbersRepositories serialNumbersRepositories,
|
||||
IBoxInventoryRepositories boxInventoryRepositories)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_logger = logger;
|
||||
_boxService = boxService;
|
||||
_boxRepositories = boxRepositories;
|
||||
_inventoryDetailsService = inventoryDetailsService;
|
||||
_serialNumbersRepositories = serialNumbersRepositories;
|
||||
@@ -587,6 +590,9 @@ namespace WMS.Web.Domain.Services
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var delete_ids = new List<int>();
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var add_entitys = new List<BoxInventory>();
|
||||
@@ -633,10 +639,19 @@ namespace WMS.Web.Domain.Services
|
||||
//4.1判断要修改的箱库存对象:是否所有的物料库存的数量都为0,“是”则删除该箱库存,"否"则修改;
|
||||
var isAllNoInventory = sour_update_entity.Details.All(x => x.Qty == 0);
|
||||
if (isAllNoInventory)
|
||||
{
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(sour_update_entity.Clone()));
|
||||
delete_ids.Add(sour_update_entity.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//4.2添加要更新的箱库存实体
|
||||
update_entitys.Add(sour_update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(sour_update_entity.Clone());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -657,7 +672,7 @@ namespace WMS.Web.Domain.Services
|
||||
//2.2.3.在变更目标箱的-仓库-仓位-组织
|
||||
tag_update_entity.StockCode = dto.StockCode;
|
||||
tag_update_entity.SubStockId = dto.SubStockId.Value;
|
||||
tag_update_entity.OrgCode = dto.TargetBoxOrgCode;
|
||||
tag_update_entity.OrgCode = dto.TargetBoxOrgCode;
|
||||
}
|
||||
tag_update_entity.Details = tagBox.Details;
|
||||
|
||||
@@ -725,10 +740,18 @@ namespace WMS.Web.Domain.Services
|
||||
//2.4箱库存:要修改的集合
|
||||
update_entitys.Add(tag_update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(tag_update_entity.Clone());
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (add_entitys.Count != 0)
|
||||
@@ -788,12 +811,15 @@ namespace WMS.Web.Domain.Services
|
||||
/// <param name="boxs"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Result> ExeMoveBox(List<BoxInventoryMoveGenerateDto> dtoDatas, List<BoxInventory> boxInventorys,bool isTransaction)
|
||||
private async Task<Result> ExeMoveBox(List<BoxInventoryMoveGenerateDto> dtoDatas, List<BoxInventory> boxInventorys, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var delete_entitys = new List<BoxInventory>();
|
||||
var add_entitys = new List<BoxInventory>();
|
||||
var InventoryDetailsGenerateDto = new List<InventoryDetailsGenerateDto>();
|
||||
@@ -807,15 +833,18 @@ namespace WMS.Web.Domain.Services
|
||||
//3.1上架的时候:箱一定是不存在于箱库存当中的,有则返回提示“已有箱库存,不需要再扫上架”
|
||||
var ishave = boxInventorys.Where(x => x.BoxId == dto.BoxId).Any();
|
||||
if (ishave)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
|
||||
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
|
||||
|
||||
//3.2组装要新增的箱库存信息:箱和明细
|
||||
var addEntity = _mapper.Map<BoxInventory>(dto);
|
||||
addEntity.Details = _mapper.Map<List<BoxInventoryDetails>>(dto.Details);
|
||||
|
||||
|
||||
//3.4箱库存:要新增的集合
|
||||
add_entitys.Add(addEntity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(addEntity.Clone());
|
||||
|
||||
//4.1即时库存:组装入库
|
||||
foreach (var item in dto.Details)
|
||||
{
|
||||
@@ -845,6 +874,9 @@ namespace WMS.Web.Domain.Services
|
||||
var box_inventory = boxInventorys.Where(x => x.BoxId == dto.BoxId).FirstOrDefault();
|
||||
delete_entitys.Add(box_inventory);
|
||||
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(box_inventory.Clone()));
|
||||
|
||||
//4.1即时库存:组装出库
|
||||
foreach (var item in box_inventory.Details)
|
||||
{
|
||||
@@ -861,6 +893,12 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库操作处理
|
||||
if (add_entitys.Count != 0)
|
||||
@@ -920,6 +958,9 @@ namespace WMS.Web.Domain.Services
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var delete_ids = new List<int>();
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var add_entitys = new List<BoxInventory>();
|
||||
@@ -971,6 +1012,9 @@ namespace WMS.Web.Domain.Services
|
||||
|
||||
#endregion
|
||||
add_entitys.Add(addEntity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(addEntity.Clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1014,22 +1058,25 @@ namespace WMS.Web.Domain.Services
|
||||
update_entity.Details.ForEach(x =>
|
||||
{
|
||||
var current_box_mat_serNums = dto.Details.Where(m => m.MaterialId == x.MaterialId).FirstOrDefault();
|
||||
if (current_box_mat_serNums != null && current_box_mat_serNums.MaterialId == x.MaterialId)
|
||||
if (current_box_mat_serNums != null && current_box_mat_serNums.MaterialId == x.MaterialId)
|
||||
{
|
||||
foreach (var serialitem in current_box_mat_serNums.SerialNumbers)
|
||||
{
|
||||
var isHaveSerial= x.SerialNumbers.Where(sn => sn == serialitem).Any();
|
||||
var isHaveSerial = x.SerialNumbers.Where(sn => sn == serialitem).Any();
|
||||
if (!isHaveSerial)
|
||||
x.SerialNumbers.Add(serialitem);
|
||||
}
|
||||
// x.SerialNumbers.AddRange(current_box_mat_serNums.SerialNumbers);
|
||||
// x.SerialNumbers.AddRange(current_box_mat_serNums.SerialNumbers);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
update_entitys.Add(update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(update_entity.Clone());
|
||||
}
|
||||
|
||||
//4.1即时库存:组装入库
|
||||
@@ -1092,13 +1139,28 @@ namespace WMS.Web.Domain.Services
|
||||
//4.1判断要修改的箱库存对象:是否所有的物料库存的数量都为0,“是”则删除该箱库存,"否"则修改;
|
||||
var isAllNoInventory = update_entity.Details.All(x => x.Qty == 0);
|
||||
if (isAllNoInventory)
|
||||
{
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(update_entity.Clone()));
|
||||
|
||||
delete_ids.Add(update_entity.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//4.2添加要更新的箱库存实体
|
||||
update_entitys.Add(update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(update_entity.Clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (add_entitys.Count != 0)
|
||||
@@ -1161,6 +1223,9 @@ namespace WMS.Web.Domain.Services
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var delete_ids = new List<int>();
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var InventoryDetailsGenerateDto = new List<InventoryDetailsGenerateDto>();
|
||||
@@ -1219,6 +1284,9 @@ namespace WMS.Web.Domain.Services
|
||||
//3.5要处理的修改集合
|
||||
update_entitys.Add(updateEntity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(updateEntity.Clone());
|
||||
|
||||
}
|
||||
//出库
|
||||
else
|
||||
@@ -1262,13 +1330,27 @@ namespace WMS.Web.Domain.Services
|
||||
//4.1判断要修改的箱库存对象:是否所有的物料库存的数量都为0,“是”则删除该箱库存,"否"则修改;
|
||||
var isAllNoInventory = update_entity.Details.All(x => x.Qty == 0);
|
||||
if (isAllNoInventory)
|
||||
{
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(update_entity.Clone()));
|
||||
delete_ids.Add(update_entity.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//4.2添加要更新的箱库存实体
|
||||
update_entitys.Add(update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(update_entity.Clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (update_entitys.Count != 0)
|
||||
@@ -1331,18 +1413,21 @@ namespace WMS.Web.Domain.Services
|
||||
var boxIds = out_SerialNumbers.GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var delete_ids1 = new List<int>();
|
||||
var update_entitys1 = new List<BoxInventory>();
|
||||
var InventoryDetailsGenerateDto1 = new List<InventoryDetailsGenerateDto>();
|
||||
foreach (var item in boxInventorys)
|
||||
{
|
||||
|
||||
item.Details.ForEach(x =>
|
||||
item.Details.ForEach(x =>
|
||||
{
|
||||
var current_sers_info = out_SerialNumbers.Where(o => o.BoxId == item.BoxId && o.MaterialId == x.MaterialId).ToList();
|
||||
if (current_sers_info != null && current_sers_info.Count != 0)
|
||||
if (current_sers_info != null && current_sers_info.Count != 0)
|
||||
{
|
||||
x.Qty=x.Qty- current_sers_info.Count;
|
||||
x.Qty = x.Qty - current_sers_info.Count;
|
||||
var crrent_sers = current_sers_info.Select(t => t.SerialNumber).ToList();
|
||||
x.SerialNumbers.RemoveAll(r => crrent_sers.Contains(r));
|
||||
|
||||
@@ -1362,12 +1447,26 @@ namespace WMS.Web.Domain.Services
|
||||
//4.1判断要修改的箱库存对象:是否所有的物料库存的数量都为0,“是”则删除该箱库存,"否"则修改;
|
||||
var isAllNoInventory = item.Details.All(x => x.Qty == 0);
|
||||
if (isAllNoInventory)
|
||||
{
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(item.Clone()));
|
||||
delete_ids1.Add(item.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//4.2添加要更新的箱库存实体
|
||||
update_entitys1.Add(item);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(item.Clone());
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (update_entitys1.Count != 0)
|
||||
@@ -1401,6 +1500,9 @@ namespace WMS.Web.Domain.Services
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var add_entitys = new List<BoxInventory>();
|
||||
var InventoryDetailsGenerateDto = new List<InventoryDetailsGenerateDto>();
|
||||
@@ -1434,6 +1536,9 @@ namespace WMS.Web.Domain.Services
|
||||
addEntity.Details = _mapper.Map<List<BoxInventoryDetails>>(dtoDets_merge);
|
||||
add_entitys.Add(addEntity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(addEntity.Clone());
|
||||
|
||||
//4.组装即时库存
|
||||
foreach (var detItem in dto.Details)
|
||||
{
|
||||
@@ -1470,6 +1575,9 @@ namespace WMS.Web.Domain.Services
|
||||
addEntity.Details = _mapper.Map<List<BoxInventoryDetails>>(dtoDets_merge);
|
||||
add_entitys.Add(addEntity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(addEntity.Clone());
|
||||
|
||||
//3.3.遍历:dto明细;组装即时库存数据
|
||||
foreach (var dtoItem in dto.Details)
|
||||
{
|
||||
@@ -1520,10 +1628,17 @@ namespace WMS.Web.Domain.Services
|
||||
InventoryDetailsGenerateDto.Add(inventoryDet);
|
||||
}
|
||||
update_entitys.Add(update_entity);
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(update_entity.Clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result = await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if (!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (add_entitys.Count != 0)
|
||||
@@ -1583,6 +1698,10 @@ namespace WMS.Web.Domain.Services
|
||||
if (dtoDatas == null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
//这个实体给改箱的服务进行处理
|
||||
var changeBox_inventoryList = new List<BoxInventory>();
|
||||
|
||||
|
||||
var delete_ids = new List<int>();
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var InventoryDetailsGenerateDto = new List<InventoryDetailsGenerateDto>();
|
||||
@@ -1601,6 +1720,9 @@ namespace WMS.Web.Domain.Services
|
||||
//直接添加要删除的箱
|
||||
delete_ids.Add(boxInventory.Id);
|
||||
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(boxInventory.Clone()));
|
||||
|
||||
//4.组装即时库存
|
||||
foreach (var detItem in dto.Details)
|
||||
{
|
||||
@@ -1654,13 +1776,26 @@ namespace WMS.Web.Domain.Services
|
||||
//4.1判断要修改的箱库存对象:是否所有的物料库存的数量都为0,“是”则删除该箱库存,"否"则修改;
|
||||
var isAllNoInventory = update_entity.Details.All(x => x.Qty == 0);
|
||||
if (isAllNoInventory)
|
||||
{
|
||||
//给改箱服务用:按箱的话,就要把明细里的数量修改为0
|
||||
changeBox_inventoryList.Add(GenerateBoxInventory(update_entity.Clone()));
|
||||
delete_ids.Add(update_entity.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
//4.2添加要更新的箱库存实体
|
||||
update_entitys.Add(update_entity);
|
||||
|
||||
//给改箱服务用
|
||||
changeBox_inventoryList.Add(update_entity.Clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//改箱
|
||||
var changeBox_result= await _boxService.BoxInventorySync(changeBox_inventoryList, isTransaction);
|
||||
if(!changeBox_result.IsSuccess)
|
||||
return changeBox_result;
|
||||
|
||||
//4.数据库更新操作:更新和删除
|
||||
var isSuccess = true;
|
||||
@@ -1742,7 +1877,16 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BoxInventory GenerateBoxInventory(BoxInventory boxInventory)
|
||||
{
|
||||
// 使用 LINQ 将box里的明细全部设置为0
|
||||
boxInventory.Details.Select(detail =>
|
||||
{
|
||||
detail.Qty = 0;
|
||||
return detail;
|
||||
}).ToList();
|
||||
return boxInventory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理箱库存变更:出入库
|
||||
|
||||
Reference in New Issue
Block a user