即时库存-服务
This commit is contained in:
@@ -2426,6 +2426,36 @@
|
||||
物料库存数量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto">
|
||||
<summary>
|
||||
即时库存明细:生成dto
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto.MaterialId">
|
||||
<summary>
|
||||
物料ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto.StockCode">
|
||||
<summary>
|
||||
仓库
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto.SubStockId">
|
||||
<summary>
|
||||
仓位ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto.Qty">
|
||||
<summary>
|
||||
数量:出入库
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto.InventoryInOutType">
|
||||
<summary>
|
||||
类型:1为入库,2为出库
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Core.Dto.Inventory.InventoryDetailsQueryRequest">
|
||||
<summary>
|
||||
即时库存明细-查询请求对象
|
||||
|
||||
@@ -2283,6 +2283,19 @@
|
||||
<param name="loginInfo"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.IService.IInventoryDetailsService">
|
||||
<summary>
|
||||
即时库存-服务接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.IService.IInventoryDetailsService.GenerateInventoryDetails(System.Collections.Generic.List{WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto},System.Boolean)">
|
||||
<summary>
|
||||
生成:即时库存明细
|
||||
</summary>
|
||||
<param name="dtos"></param>
|
||||
<param name="isTransaction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.IService.IInventoryInOutDetailsService">
|
||||
<summary>
|
||||
物料收发明细:服务接口
|
||||
@@ -3422,6 +3435,19 @@
|
||||
<param name="loginInfo"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Services.InventoryDetailsService">
|
||||
<summary>
|
||||
即时库存-服务
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Services.InventoryDetailsService.GenerateInventoryDetails(System.Collections.Generic.List{WMS.Web.Core.Dto.Inventory.InventoryDetailsGenerateDto},System.Boolean)">
|
||||
<summary>
|
||||
生成:即时库存明细
|
||||
</summary>
|
||||
<param name="dtos"></param>
|
||||
<param name="isTransaction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Services.InventoryInOutDetailsService">
|
||||
<summary>
|
||||
物料收发明细:服务
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WMS.Web.Core.Dto.Inventory
|
||||
{
|
||||
/// <summary>
|
||||
/// 即时库存明细:生成dto
|
||||
/// </summary>
|
||||
public class InventoryDetailsGenerateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料ID
|
||||
/// </summary>
|
||||
public int MaterialId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓库
|
||||
/// </summary>
|
||||
public string StockCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 仓位ID
|
||||
/// </summary>
|
||||
public int SubStockId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数量:出入库
|
||||
/// </summary>
|
||||
public decimal Qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类型:1为入库,2为出库
|
||||
/// </summary>
|
||||
public int InventoryInOutType { get; set; }
|
||||
}
|
||||
}
|
||||
23
src/WMS.Web.Domain/IService/IInventoryDetailsService.cs
Normal file
23
src/WMS.Web.Domain/IService/IInventoryDetailsService.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Inventory;
|
||||
using WMS.Web.Core.Internal.Results;
|
||||
|
||||
namespace WMS.Web.Domain.IService
|
||||
{
|
||||
/// <summary>
|
||||
/// 即时库存-服务接口
|
||||
/// </summary>
|
||||
public interface IInventoryDetailsService
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成:即时库存明细
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
Task<Result> GenerateInventoryDetails(List<InventoryDetailsGenerateDto> dtos, bool isTransaction);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,8 @@ namespace WMS.Web.Domain.Mappers
|
||||
.ForMember(x => x.OrderType, ops => ops.MapFrom(x => x.OrderType))
|
||||
.ForMember(x => x.Type, ops => ops.MapFrom(x => x.InventoryInOutType));
|
||||
|
||||
|
||||
//即时库存明细-映射
|
||||
CreateMap<InventoryDetailsGenerateDto, InventoryDetails>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
103
src/WMS.Web.Domain/Services/InventoryDetailsService.cs
Normal file
103
src/WMS.Web.Domain/Services/InventoryDetailsService.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
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 InventoryDetailsService: IInventoryDetailsService
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IBoxRepositories _boxRepositories;
|
||||
private readonly ISerialNumbersRepositories _serialNumbersRepositories;
|
||||
private readonly IInventoryDetailsRepositories _inventoryDetailsRepositories;
|
||||
public InventoryDetailsService(IMapper mapper, IBoxRepositories boxRepositories,
|
||||
ISerialNumbersRepositories serialNumbersRepositories,
|
||||
IInventoryDetailsRepositories inventoryDetailsRepositories)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_boxRepositories = boxRepositories;
|
||||
_inventoryDetailsRepositories = inventoryDetailsRepositories;
|
||||
_serialNumbersRepositories = serialNumbersRepositories;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成:即时库存明细
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Result> GenerateInventoryDetails(List<InventoryDetailsGenerateDto> dtos,bool isTransaction)
|
||||
{
|
||||
//找到物料对应的即时库存明细
|
||||
var materialIds = dtos.Select(x => x.MaterialId).ToList();
|
||||
var stockCodes = dtos.GroupBy(x => x.StockCode).Select(x => x.Key).ToList();
|
||||
var subStockIds = dtos.GroupBy(x => x.SubStockId).Select(x => x.Key).ToList();
|
||||
var inventoryDetails = await _inventoryDetailsRepositories.GetListBy(materialIds, stockCodes, subStockIds);
|
||||
|
||||
|
||||
var add_entitys = new List<InventoryDetails>();
|
||||
var update_entitys = new List<InventoryDetails>();
|
||||
|
||||
//2.遍历
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
//2.1当前的即时库存明细
|
||||
var currentDetail = inventoryDetails.Where(x => x.MaterialId == dto.MaterialId && x.StockCode == dto.StockCode && x.SubStockId == dto.SubStockId).FirstOrDefault();
|
||||
if (currentDetail == null)
|
||||
{
|
||||
//出库的时候,判断是否有库存,没有就返回错误
|
||||
if (dto.InventoryInOutType == (int)InventoryInOutType.Out)
|
||||
return Result.ReFailure(ResultCodes.InventoryDetailsNoInventoryError);
|
||||
|
||||
var entity = _mapper.Map<InventoryDetails>(dto);
|
||||
add_entitys.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = currentDetail;
|
||||
if (dto.InventoryInOutType == (int)InventoryInOutType.In)
|
||||
{
|
||||
//加库存
|
||||
entity.Qty = entity.Qty + dto.Qty;
|
||||
}
|
||||
else
|
||||
{
|
||||
//出库的时候,判断是否有库存,没有就返回错误
|
||||
if (entity.Qty<dto.Qty)
|
||||
return Result.ReFailure(ResultCodes.InventoryDetailsNoInventoryError);
|
||||
//减库存
|
||||
entity.Qty = entity.Qty - dto.Qty;
|
||||
}
|
||||
update_entitys.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//4.数据库更新操作:更新和删除和添加
|
||||
var isSuccess = true;
|
||||
if (add_entitys.Count != 0)
|
||||
{
|
||||
isSuccess = await _inventoryDetailsRepositories.AddRange(add_entitys, isTransaction);
|
||||
if (!isSuccess) return Result.ReFailure(ResultCodes.InventoryDetailsWriteError);
|
||||
}
|
||||
if (update_entitys.Count != 0)
|
||||
{
|
||||
isSuccess = await _inventoryDetailsRepositories.UpdateRange(update_entitys, isTransaction);
|
||||
if (!isSuccess) return Result.ReFailure(ResultCodes.InventoryDetailsWriteError);
|
||||
}
|
||||
return Result.ReSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,10 @@ namespace WMS.Web.Domain.Values
|
||||
public static ValueTuple<int, string> BoxInventoryNoDataError = (800011, "箱库存数据不存在,请稍候再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryMaterialNoDataError = (800041, "箱物料库存数据不存在,请稍候再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryNoInventoryError = (800012, "箱库存物料数量不足,请核对后再试!");
|
||||
public static ValueTuple<int, string> InventoryDetailsNoInventoryError = (800012, "物料库存数量不足,请核对后再试!");
|
||||
public static ValueTuple<int, string> BoxInventoryHaveInventoryError = (800013, "该箱库存已经存在,请核对后再试!");
|
||||
public static ValueTuple<int, string> InventoryInOutDetailsWriteError = (800014, "写入物料收发明细失败!");
|
||||
public static ValueTuple<int, string> InventoryDetailsWriteError = (800014, "写入即时库存明细失败!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -294,6 +294,7 @@ namespace WMS.Web.Repositories.DependencyInjection
|
||||
Services.AddTransient<ISerialNumberService, SerialNumberService>();
|
||||
Services.AddTransient<IBoxInventoryService, BoxInventoryService>();
|
||||
Services.AddTransient<IInventoryInOutDetailsService, InventoryInOutDetailsService>();
|
||||
Services.AddTransient<IInventoryDetailsService, InventoryDetailsService>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user