箱库存方法-优化1
This commit is contained in:
@@ -1830,6 +1830,46 @@
|
||||
保存入库单-请求对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.BoxInventoryChangeGenerateDto">
|
||||
<summary>
|
||||
改箱-使用
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryChangeGenerateDto.BoxId">
|
||||
<summary>
|
||||
原箱ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryChangeGenerateDto.TargetBoxId">
|
||||
<summary>
|
||||
目标箱ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryChangeGenerateDto.Details">
|
||||
<summary>
|
||||
明细
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.BoxInventoryDetailsChangeGenerateDto">
|
||||
<summary>
|
||||
箱库存明细
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryDetailsChangeGenerateDto.MaterialId">
|
||||
<summary>
|
||||
物料ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryDetailsChangeGenerateDto.Qty">
|
||||
<summary>
|
||||
数量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryDetailsChangeGenerateDto.SerialNumbers">
|
||||
<summary>
|
||||
序列号
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.BoxInventoryDto">
|
||||
<summary>
|
||||
箱库存
|
||||
@@ -1870,6 +1910,31 @@
|
||||
物料库存数量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto">
|
||||
<summary>
|
||||
移箱-上架和下架
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto.BoxId">
|
||||
<summary>
|
||||
箱ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto.StockCode">
|
||||
<summary>
|
||||
仓库code
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto.SubStockId">
|
||||
<summary>
|
||||
仓位
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.BoxInventoryMoveGenerateDto.IsOn">
|
||||
<summary>
|
||||
是否是上架:true是上架,false是下架
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.BoxInventoryQueryRequest">
|
||||
<summary>
|
||||
箱库存-查询请求对象
|
||||
|
||||
@@ -1424,6 +1424,20 @@
|
||||
<param name="boxBillNo"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IBoxInventoryRepositories.GetList(System.Collections.Generic.List{System.Int32})">
|
||||
<summary>
|
||||
列表-根据箱ids
|
||||
</summary>
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IBoxInventoryRepositories.Get(System.Int32)">
|
||||
<summary>
|
||||
实体
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IBoxInventoryRepositories.AddRange(System.Collections.Generic.List{WMS.Web.Domain.Entitys.BoxInventory},System.Boolean)">
|
||||
<summary>
|
||||
批量添加
|
||||
@@ -2369,6 +2383,11 @@
|
||||
入库相关-映射
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Mappers.InventoryMapper">
|
||||
<summary>
|
||||
即时库存映射对象
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Mappers.MapperList">
|
||||
<summary>
|
||||
集合映射
|
||||
@@ -2851,6 +2870,14 @@
|
||||
即时库存-服务
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.InventoryService.GenerateChangeBox(System.Collections.Generic.List{WMS.Web.Core.Dto.Inventory.BoxInventoryChangeGenerateDto},System.Boolean)">
|
||||
<summary>
|
||||
改箱-箱库存的变更
|
||||
</summary>
|
||||
<param name="dtoDatas"></param>
|
||||
<param name="isTransaction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Services.OutStockService">
|
||||
<summary>
|
||||
出库服务
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// 改箱-使用
|
||||
/// </summary>
|
||||
public class BoxInventoryChangeGenerateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 原箱ID
|
||||
/// </summary>
|
||||
public int BoxId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 目标箱ID
|
||||
/// </summary>
|
||||
public int TargetBoxId { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 仓库编码:目标仓库
|
||||
///// </summary>
|
||||
//public string StockCode { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 仓位:目标仓位
|
||||
///// </summary>
|
||||
//public int SubStockId { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 出入库类型:有个枚举的
|
||||
///// </summary>
|
||||
//public int InventoryInOutType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 明细
|
||||
/// </summary>
|
||||
public List<BoxInventoryDetailsChangeGenerateDto> Details { get; set; } = new List<BoxInventoryDetailsChangeGenerateDto>();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 箱库存明细
|
||||
/// </summary>
|
||||
public class BoxInventoryDetailsChangeGenerateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料ID
|
||||
/// </summary>
|
||||
public int MaterialId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量
|
||||
/// </summary>
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序列号
|
||||
/// </summary>
|
||||
public List<string> SerialNumbers { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// 移箱-上架和下架
|
||||
/// </summary>
|
||||
public class BoxInventoryMoveGenerateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 箱ID
|
||||
/// </summary>
|
||||
public int BoxId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库code
|
||||
/// </summary>
|
||||
public string StockCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓位
|
||||
/// </summary>
|
||||
public int SubStockId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否是上架:true是上架,false是下架
|
||||
/// </summary>
|
||||
public bool IsOn { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,20 @@ namespace WMS.Web.Domain.Infrastructure
|
||||
/// <param name="boxBillNo"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<BoxInventoryDetailsDto>> GetListDetailsBy(string boxBillNo);
|
||||
|
||||
/// <summary>
|
||||
/// 列表-根据箱ids
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<BoxInventory>> GetList(List<int> ids);
|
||||
|
||||
/// <summary>
|
||||
/// 实体
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<BoxInventory> Get(int id);
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
|
||||
25
src/WMS.Web.Domain/Mappers/InventoryMapper.cs
Normal file
25
src/WMS.Web.Domain/Mappers/InventoryMapper.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WMS.Web.Core.Dto.Inventory;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
|
||||
namespace WMS.Web.Domain.Mappers
|
||||
{
|
||||
/// <summary>
|
||||
/// 即时库存映射对象
|
||||
/// </summary>
|
||||
public class InventoryMapper:Profile
|
||||
{
|
||||
public InventoryMapper()
|
||||
{
|
||||
//改箱映射
|
||||
CreateMap<BoxInventoryDetailsChangeGenerateDto, BoxInventoryDetails>();
|
||||
|
||||
//移箱映射
|
||||
CreateMap<BoxInventoryMoveGenerateDto, BoxInventory>();
|
||||
CreateMap<BoxDetails, BoxInventoryDetails>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,191 @@
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Inventory;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.IService;
|
||||
using WMS.Web.Domain.Values;
|
||||
|
||||
namespace WMS.Web.Domain.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 即时库存-服务
|
||||
/// </summary>
|
||||
public class InventoryService: IInventoryService
|
||||
public class InventoryService : IInventoryService
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
public InventoryService(IMapper mapper)
|
||||
private readonly IBoxRepositories _boxRepositories;
|
||||
private readonly ISerialNumbersRepositories _serialNumbersRepositories;
|
||||
private readonly IBoxInventoryRepositories _boxInventoryRepositories;
|
||||
public InventoryService(IMapper mapper, IBoxRepositories boxRepositories,
|
||||
ISerialNumbersRepositories serialNumbersRepositories,
|
||||
IBoxInventoryRepositories boxInventoryRepositories)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_boxRepositories = boxRepositories;
|
||||
_serialNumbersRepositories = serialNumbersRepositories;
|
||||
_boxInventoryRepositories = boxInventoryRepositories;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 改箱-箱库存的变更
|
||||
/// </summary>
|
||||
/// <param name="dtoDatas"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> GenerateChangeBox(List<BoxInventoryChangeGenerateDto> 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>();
|
||||
|
||||
var boxIds = dtoDatas.GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
var targetBoxIds = dtoDatas.GroupBy(x => x.TargetBoxId).Select(x => x.Key).ToList();
|
||||
|
||||
//2.原来箱库存集合
|
||||
var sourceBoxInventorys = await _boxInventoryRepositories.GetList(boxIds);
|
||||
|
||||
//2.1目标箱库存集合
|
||||
var targetBoxInventorys = await _boxInventoryRepositories.GetList(targetBoxIds);
|
||||
|
||||
|
||||
foreach (var dto in dtoDatas)
|
||||
{
|
||||
#region 原箱库存-库存处理
|
||||
//2.1找到要改变的源箱数据:备注(原箱号库存一定是存在的)
|
||||
var sour = sourceBoxInventorys.Where(x => x.BoxId == dto.BoxId).FirstOrDefault();
|
||||
if (sour == null)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
|
||||
var sour_update_entity = new BoxInventory();
|
||||
sour_update_entity.Details = new List<BoxInventoryDetails>();
|
||||
foreach (var dtoItem in dto.Details)
|
||||
{
|
||||
//找到原来的箱库存对应要改变的物料:这个一定是存在的,不存在就有问题
|
||||
var sour_ChangeDetail = sour.Details.Where(x => x.MaterialId == dtoItem.MaterialId).FirstOrDefault();
|
||||
if(sour_ChangeDetail==null)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoDataError);
|
||||
//箱物料的库存数量不足;小于要拿出来的数量
|
||||
if(sour_ChangeDetail.Qty<dtoItem.Qty)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryNoInventoryError);
|
||||
|
||||
var s_update_entity_det = new BoxInventoryDetails();
|
||||
s_update_entity_det.SerialNumbers = new List<string>();
|
||||
s_update_entity_det.Qty = sour_ChangeDetail.Qty - dtoItem.Qty;
|
||||
|
||||
//先把现有的序列号复制过来
|
||||
s_update_entity_det.SerialNumbers = sour_ChangeDetail.SerialNumbers;
|
||||
//再移除要改箱的序列号;最后就是原箱库存的新序列号
|
||||
s_update_entity_det.SerialNumbers.RemoveAll(x => dtoItem.SerialNumbers.Contains(x));
|
||||
|
||||
sour_update_entity.Details.Add(s_update_entity_det);
|
||||
|
||||
}
|
||||
update_entitys.Add(sour_update_entity);
|
||||
#endregion
|
||||
|
||||
#region 目标箱库存-库存处理
|
||||
//2.2找到要改变的目标箱数据:备注(目标箱库存可能不存在库存,就要新增)
|
||||
var tagBox = targetBoxInventorys.Where(x => x.BoxId == dto.TargetBoxId).FirstOrDefault();
|
||||
if (tagBox == null)
|
||||
{
|
||||
var newTagBox = new BoxInventory();
|
||||
newTagBox.BoxId = dto.TargetBoxId;
|
||||
newTagBox.Details =_mapper.Map<List<BoxInventoryDetails>>(dto.Details);
|
||||
add_entitys.Add(newTagBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tag_update_entity = new BoxInventory();
|
||||
tag_update_entity.Details = new List<BoxInventoryDetails>();
|
||||
//2.2.1遍历改变的明细
|
||||
foreach (var item in dto.Details)
|
||||
{
|
||||
//2.2.2找到目标箱对应要改变的物料
|
||||
var tagChangeDetail = tagBox.Details.Where(x => x.MaterialId == item.MaterialId).FirstOrDefault();
|
||||
if (tagChangeDetail != null)
|
||||
{
|
||||
var update_entity_det = new BoxInventoryDetails();
|
||||
update_entity_det.SerialNumbers = new List<string>();
|
||||
update_entity_det.Qty = tagChangeDetail.Qty + item.Qty;
|
||||
update_entity_det.SerialNumbers.AddRange(tagChangeDetail.SerialNumbers);
|
||||
update_entity_det.SerialNumbers.AddRange(item.SerialNumbers);
|
||||
tag_update_entity.Details.Add(update_entity_det);
|
||||
}//2.3.没有对应的箱物料,就新增明细
|
||||
else
|
||||
{
|
||||
var newTagChangeDetail = new BoxInventoryDetails();
|
||||
newTagChangeDetail.MaterialId = item.MaterialId;
|
||||
newTagChangeDetail.Qty = item.Qty;
|
||||
newTagChangeDetail.SerialNumbers = item.SerialNumbers;
|
||||
tag_update_entity.Details.Add(newTagChangeDetail);
|
||||
}
|
||||
}
|
||||
update_entitys.Add(tag_update_entity);
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
//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);
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
|
||||
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 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);
|
||||
|
||||
//3.遍历:dto
|
||||
foreach (var dto in dtoDatas)
|
||||
{
|
||||
//上架
|
||||
if (dto.IsOn)
|
||||
{
|
||||
//3.1上架的时候:箱一定是不存在于箱库存当中的,
|
||||
var ishave = boxInventorys.Where(x => x.BoxId == dto.BoxId).Any();
|
||||
if (ishave)
|
||||
return Result.ReFailure(ResultCodes.BoxInventoryHaveInventoryError);
|
||||
var box = boxs.Where(x => x.Id == dto.BoxId).FirstOrDefault();
|
||||
//var serialNumbers= _serialNumbersRepositories.ge
|
||||
if (box==null)
|
||||
return Result.ReFailure(ResultCodes.BoxNoData);
|
||||
|
||||
var addEntity = _mapper.Map<BoxInventory>(dto);
|
||||
addEntity.Details = new List<BoxInventoryDetails>();
|
||||
|
||||
|
||||
}//下架
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ namespace WMS.Web.Domain.Values
|
||||
public static ValueTuple<int, string> ErpMaterialError = (80007, "获取Erp相关物料数据失败,请稍候再试!");
|
||||
public static ValueTuple<int, string> BoxHaveError = (80008, "该箱信息已被记录,请重新选择箱号!");
|
||||
public static ValueTuple<int, string> AdjustError = (80009, "与金蝶校准发生错误,请稍候再试!");
|
||||
public static ValueTuple<int, string> InventoryNoSourceError = (800010, "来源数据不存在,请稍候再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryNoDataError = (800011, "箱库存数据不存在,请稍候再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryNoInventoryError = (800012, "箱库存物料数量不足,请核对后再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryHaveInventoryError = (800013, "该箱库存已经存在,请核对后再试!");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,26 @@ namespace WMS.Web.Repositories
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表-根据箱ids
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<BoxInventory>> GetList(List<int> ids)
|
||||
{
|
||||
return await _context.BoxInventory.Include(x => x.Details).Where(x => ids.Contains(x.Id)).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体-根据箱id
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BoxInventory> Get(int id)
|
||||
{
|
||||
return await _context.BoxInventory.Include(x => x.Details).Where(x => x.Id==id).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user