即时库存-服务
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,10 @@ namespace WMS.Web.Domain.Mappers
|
||||
CreateMap<InventoryInOutDetailsGenerateDto, InventoryInOutDetails>()
|
||||
.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, "写入即时库存明细失败!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user