箱库存-处理

This commit is contained in:
tongfei
2023-11-14 16:30:16 +08:00
parent 3f22b2b9a7
commit d3e7027adb
6 changed files with 115 additions and 14 deletions

View File

@@ -1511,6 +1511,14 @@
<param name="isTransaction"></param>
<returns></returns>
</member>
<member name="M:WMS.Web.Domain.Infrastructure.IBoxInventoryRepositories.DeleteRange(System.Collections.Generic.List{System.Int32},System.Boolean)">
<summary>
批量删除
</summary>
<param name="ids"></param>
<param name="isTransaction"></param>
<returns></returns>
</member>
<member name="T:WMS.Web.Domain.Infrastructure.IBoxRepositories">
<summary>
老ops箱信息
@@ -1789,6 +1797,9 @@
<member name="M:WMS.Web.Domain.Infrastructure.ISerialNumbersRepositories.GetEntityListByBoxId(System.Int32)">
根据箱Id查询集合
</member>
<member name="M:WMS.Web.Domain.Infrastructure.ISerialNumbersRepositories.GetEntityListByBoxIds(System.Collections.Generic.List{System.Int32})">
根据箱Ids查询集合
</member>
<member name="M:WMS.Web.Domain.Infrastructure.ISerialNumbersRepositories.EditEntityList(System.Collections.Generic.List{WMS.Web.Domain.Entitys.SerialNumbers},System.Boolean)">
修改实体集合
</member>
@@ -3060,6 +3071,14 @@
<param name="isTransaction"></param>
<returns></returns>
</member>
<member name="M:WMS.Web.Domain.Services.InventoryService.GenerateMoveBox(System.Collections.Generic.List{WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto},System.Boolean)">
<summary>
移箱-箱库存的变更
</summary>
<param name="dtoDatas"></param>
<param name="isTransaction"></param>
<returns></returns>
</member>
<member name="T:WMS.Web.Domain.Services.OutStockService">
<summary>
出库服务

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using WMS.Web.Core;
namespace WMS.Web.Domain.Entitys
{
@@ -10,12 +11,12 @@ namespace WMS.Web.Domain.Entitys
/// </summary>
[Serializable]
[Table("t_wms_box_inventory_details")]
public class BoxInventoryDetails
public class BoxInventoryDetails : EntityBase
{
/// <summary>
/// ID
/// </summary>
public int Id { get; set; }
public override int Id { get; set; }
/// <summary>
/// 上级ID

View File

@@ -55,5 +55,13 @@ namespace WMS.Web.Domain.Infrastructure
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<bool> UpdateRange(List<BoxInventory> entitys, bool isTransaction = true);
/// <summary>
/// 批量删除
/// </summary>
/// <param name="ids"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
Task<bool> DeleteRange(List<int> ids, bool isTransaction = false);
}
}

View File

@@ -19,7 +19,7 @@ namespace WMS.Web.Domain.Mappers
//移箱映射
CreateMap<BoxInventoryMoveGenerateDto, BoxInventory>();
CreateMap<BoxDetails, BoxInventoryDetails>();
CreateMap<BoxDetails, BoxInventoryDetails>() ;
}
}
}

View File

@@ -135,29 +135,42 @@ namespace WMS.Web.Domain.Services
#endregion
}
var isSuccess = true;
//4.数据库更新操作:更新和添加
var isSuccess= await _boxInventoryRepositories.AddRange(add_entitys, isTransaction);
if(!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
isSuccess = await _boxInventoryRepositories.UpdateRange(update_entitys, isTransaction);
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
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();
}
/// <summary>
/// 移箱-箱库存的变更
/// </summary>
/// <param name="dtoDatas"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<Result> GenerateMoveBox(List<BoxInventoryMoveGenerateDto> dtoDatas, bool isTransaction)
{
//1.判断来源数据是否存在
if (dtoDatas != null || dtoDatas.Count == 0)
return Result.ReFailure(ResultCodes.InventoryNoSourceError);
var update_entitys = new List<BoxInventory>();
var delete_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)
@@ -165,26 +178,57 @@ namespace WMS.Web.Domain.Services
//上架
if (dto.IsOn)
{
//3.1上架的时候:箱一定是不存在于箱库存当中的,
//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();
//var serialNumbers= _serialNumbersRepositories.ge
if (box==null)
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 = new List<BoxInventoryDetails>();
addEntity.Details = _mapper.Map<List<BoxInventoryDetails>>(box.Details);
//3.3组装要新增的箱库存:明细中的序列号
foreach (var item in addEntity.Details)
{
var box_serialNub = box_serialNumbers.Where(x => x.MaterialId == item.MaterialId).FirstOrDefault();
if (box_serialNub != null)
item.SerialNumbers.Add(box_serialNub.SerialNumber);
}
add_entitys.Add(addEntity);
}//下架
else
{
//3.1下架的时候:箱一定是存在于箱库存当中的,没有则返回提示“箱不存在于库存,请扫其它箱”
var ishave = boxInventorys.Where(x => x.BoxId == dto.BoxId).Any();
if (!ishave)
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
//3.2整箱移货下架-直接删除当前箱子所在的库存
var box_inventory= boxInventorys.Where(x => x.BoxId == dto.BoxId).FirstOrDefault();
delete_entitys.Add(box_inventory);
}
}
var isSuccess = true;
//4.数据库操作处理
if (add_entitys.Count != 0)
{
isSuccess = await _boxInventoryRepositories.AddRange(add_entitys, isTransaction);
if(!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
}
if (delete_entitys.Count != 0)
{
var delete_ids = add_entitys.Select(x => x.Id).ToList();
isSuccess = await _boxInventoryRepositories.DeleteRange(delete_ids,isTransaction);
if (!isSuccess) return Result.ReFailure(ResultCodes.DateWriteError);
}
return Result.ReSuccess();
}
}

View File

@@ -207,5 +207,34 @@ namespace WMS.Web.Repositories
return true;
}
}
/// <summary>
/// 批量删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> DeleteRange(List<int> ids, bool isTransaction = false)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
var list = await _context.BoxInventory.Include(x => x.Details)
.Where(f => ids.Contains(f.Id)).ToListAsync();
_context.BoxInventory.RemoveRange(list);
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
}
catch (Exception ex)
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
return true;
}
}
}