出库-箱库存变更

This commit is contained in:
tongfei
2023-11-16 14:35:41 +08:00
parent a98ecfff21
commit dc3d984bd5
6 changed files with 221 additions and 3 deletions

View File

@@ -370,7 +370,7 @@ namespace WMS.Web.Domain.Services
foreach (var dto in dtoDatas)
{
//3.1上架的时候:箱一定是不存在于箱库存当中的,有则返回提示“已有箱库存,不需要再扫上架”
var ishave = boxInventorys.Where(x =>dto.BoxIds.Contains(x.BoxId)).Any();
var ishave = dto.BoxIds.All(x => boxInventorys.Any(t => t.BoxId == x));////代码意义当前dto中的BoxIds是否全部等于箱库存中的boxId;dto中有一个boxID不等于箱库存中的就失败
if (ishave)
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
@@ -416,8 +416,8 @@ namespace WMS.Web.Domain.Services
if (dto.ShelfMethod == (int)ShelfMethod.Box)
{
//3.1上架的时候:箱一定是不存在于箱库存当中的,有则返回提示“已有箱库存,不需要再扫上架”
var ishave = boxInventorys.Where(x => dto.BoxIds.Contains(x.BoxId)).Any();
if (ishave)
var isAllTrueHave = dto.BoxIds.All(x => boxInventorys.Any(t => t.BoxId == x));//代码意义当前dto中的BoxIds是否全部等于箱库存中的boxId;dto中有一个boxID不等于箱库存中的就失败
if (isAllTrueHave)
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
//3.2组装要新增的箱库存信息:箱和明细和序列号
@@ -486,5 +486,89 @@ namespace WMS.Web.Domain.Services
}
return Result.ReSuccess();
}
/// <summary>
/// 出库下架-箱库存变更
/// </summary>
/// <param name="dtoDatas"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<Result> GenerateOutStockBox(List<BoxInventoryOutStockGenerateDto> dtoDatas, bool isTransaction)
{
//1.判断来源数据是否存在
if (dtoDatas != null || dtoDatas.Count == 0)
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
var delete_entitys_ids = new List<int>();
var update_entitys = new List<BoxInventory>();
//1.1通过箱IDS获取箱库存
var boxIds = dtoDatas.Select(x => x.BoxId).ToList();
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
//2.遍历dto
foreach (var dto in dtoDatas)
{
//3.1出库的时候:箱一定是存在于箱库存当中的,没有则返回提示“箱库存数据不存在,请稍候再试!”
// 获取箱库存
var boxInventory = boxInventorys.Where(x => x.BoxId == dto.BoxId).FirstOrDefault();
if (boxInventory==null)
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
//按箱:出库
if (dto.InOutInventoryMethod == (int)InOutInventoryMethod.Box)
{
//直接添加要删除的箱
delete_entitys_ids.Add(boxInventory.Id);
}
//按产品:出库
else
{
//3.3创建更新对象
var update_entity = boxInventory;
update_entity.Details = boxInventory.Details;
//3.2.遍历dto明细
foreach (var dtoItem in dto.Details)
{
//3.3.找到当前明细物料:没有则返回失败;提示:“该箱物料库存不存在”
var update_entityDetail = update_entity.Details.Where(x => x.MaterialId == dtoItem.MaterialId).FirstOrDefault();
if (update_entityDetail == null)
return Result.ReFailure(ResultCodes.BoxInventoryMaterialNoDataError);
//3.4判断库存数量是否不足
if (update_entityDetail.Qty < dtoItem.Qty)
return Result.ReFailure(ResultCodes.BoxInventoryNoInventoryError);
//3.5物料库存数量变更:减库存
update_entityDetail.Qty = update_entityDetail.Qty - dtoItem.Qty;
//3.6移除要出库的序列号
update_entityDetail.SerialNumbers.RemoveAll(x => dtoItem.SerialNumbers.Contains(x));
}
//4.1判断要修改的箱库存对象是否所有的物料库存的数量都为0“是”则删除该箱库存,"否"则修改;
var isAllNoInventory = update_entity.Details.All(x => x.Qty == 0);
if (isAllNoInventory)
delete_entitys_ids.Add(update_entity.Id);
else
//4.2添加要更新的箱库存实体
update_entitys.Add(update_entity);
}
}
//4.数据库更新操作:更新和删除
var isSuccess = true;
if (delete_entitys_ids.Count != 0)
{
isSuccess = await _boxInventoryRepositories.DeleteRange(delete_entitys_ids, isTransaction);
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
}
if (update_entitys.Count != 0)
{
isSuccess = await _boxInventoryRepositories.UpdateRange(update_entitys, isTransaction);
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
}
return Result.ReSuccess();
}
}
}