箱库存变更方法
This commit is contained in:
@@ -231,5 +231,100 @@ namespace WMS.Web.Domain.Services
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 入库回退上下架-箱库存的变更
|
||||
/// </summary>
|
||||
/// <param name="dtoDatas"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> GenerateBackBox(List<BoxInventoryBackGenerateDto> dtoDatas, bool isTransaction)
|
||||
{
|
||||
//1.判断来源数据是否存在
|
||||
if (dtoDatas != null || dtoDatas.Count == 0)
|
||||
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
|
||||
|
||||
var update_entitys = new List<BoxInventory>();
|
||||
var add_entitys = new List<BoxInventory>();
|
||||
|
||||
//2.获取“箱库存集合”
|
||||
var boxIds = dtoDatas.GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
var boxInventorys = await _boxInventoryRepositories.GetList(boxIds);
|
||||
var boxs = await _boxRepositories.GetEntityList(boxIds);
|
||||
var serialNumbers = await _serialNumbersRepositories.GetEntityListByBoxIds(boxIds);
|
||||
//3.遍历:dto
|
||||
foreach (var dto in dtoDatas)
|
||||
{
|
||||
//上架
|
||||
if (dto.BackRecordType == (int)BackRecordType.OutstockOn)
|
||||
{
|
||||
//3.1上架的时候:箱一定是不存在于箱库存当中的,有则返回提示“已有箱库存,不需要再扫上架”
|
||||
var ishave = boxInventorys.Where(x => x.BoxId == dto.BoxId).Any();
|
||||
if (ishave)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
|
||||
//3.1.1取箱信息
|
||||
var box = boxs.Where(x => x.Id == dto.BoxId).FirstOrDefault();
|
||||
if (box == null)
|
||||
return Result.ReFailure(ResultCodes.BoxNoData);
|
||||
//3.1.2去箱对应的序列号信息
|
||||
var box_serialNumbers = serialNumbers.Where(x => x.BoxId == dto.BoxId).Select(x => new { x.MaterialId, x.SerialNumber }).ToList();
|
||||
|
||||
//3.2组装要新增的箱库存信息:箱和明细和序列号
|
||||
var addEntity = _mapper.Map<BoxInventory>(dto);
|
||||
addEntity.Details = _mapper.Map<List<BoxInventoryDetails>>(box.Details);
|
||||
|
||||
add_entitys.Add(addEntity);
|
||||
|
||||
|
||||
}//下架
|
||||
else
|
||||
{
|
||||
//3.1下架的时候:箱一定是存在于箱库存当中的,没有则返回提示“箱不存在于库存,请扫其它箱”
|
||||
var boxInventory = boxInventorys.Where(x => x.BoxId == dto.BoxId).FirstOrDefault();
|
||||
if (boxInventory==null)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
//3.2创建更新对象
|
||||
var update_entity = new BoxInventory();
|
||||
update_entity.Details = new List<BoxInventoryDetails>();
|
||||
|
||||
//3.3遍历dto明细
|
||||
foreach (var dtoItem in dto.Details)
|
||||
{
|
||||
//找到原来的箱库存对应要改变的物料:这个一定是存在的,不存在就有问题
|
||||
var updateDetail = boxInventory.Details.Where(x => x.MaterialId == dtoItem.MaterialId).FirstOrDefault();
|
||||
if (updateDetail == null)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
//箱物料的库存数量不足;小于要拿出来的数量
|
||||
if (updateDetail.Qty < dtoItem.Qty)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoInventoryError);
|
||||
|
||||
var update_entity_det = new BoxInventoryDetails();
|
||||
update_entity_det.SerialNumbers = new List<string>();
|
||||
update_entity_det.Qty = updateDetail.Qty - dtoItem.Qty;
|
||||
|
||||
//先把现有的序列号复制过来
|
||||
update_entity_det.SerialNumbers = updateDetail.SerialNumbers;
|
||||
//再移除要改箱的序列号;最后就是原箱库存的新序列号
|
||||
update_entity_det.SerialNumbers.RemoveAll(x => dtoItem.SerialNumbers.Contains(x));
|
||||
|
||||
update_entity.Details.Add(update_entity_det);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isSuccess = true;
|
||||
//4.数据库更新操作:更新和添加
|
||||
if (add_entitys.Count != 0)
|
||||
{
|
||||
isSuccess = await _boxInventoryRepositories.AddRange(add_entitys, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user