Browse Source

三方库库移功能优化

dev_DY_CC
周红军 1 year ago
parent
commit
d012d72d59
  1. 23
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Requests/ThirdLocationRequests/DTOs/ThirdLocationRequestDTO.cs
  2. 24
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Requests/ThirdLocationRequests/DTOs/ThirdLocationRequestDetailDTO.cs
  3. 24
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/ThirdLocationRequests/ThirdLocationRequestAppService.cs
  4. 8
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Requests/ThirdLocationRequests/ThirdLocationRequestDetail.cs
  5. 1
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Requests/ThirdLocationRequests/ThirdLocationRequestDbContextModelCreatingExtensions.cs
  6. 24
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Requests/ThirdLocationRequestAutoMapperProfile.cs
  7. 9
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Jobs/ThirdLocationJobEventHandler.cs
  8. 125
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ThirdLocationRequestEventHandler.cs
  9. 157
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ThirdLocationNoteEventHandler.cs

23
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Requests/ThirdLocationRequests/DTOs/ThirdLocationRequestDTO.cs

@ -5,9 +5,9 @@ namespace Win_in.Sfs.Wms.Store.Application.Contracts;
public class ThirdLocationRequestDTO : SfsStoreRequestDTOBase<ThirdLocationRequestDetailDTO>, IHasNumber public class ThirdLocationRequestDTO : SfsStoreRequestDTOBase<ThirdLocationRequestDetailDTO>, IHasNumber
{ {
/// <summary> /// <summary>
/// 叫料类型 /// 类型
/// </summary> /// </summary>
[Display(Name = "叫料类型")] [Display(Name = "类型")]
public string Type { get; set; } public string Type { get; set; }
/// <summary> /// <summary>
@ -22,24 +22,5 @@ public class ThirdLocationRequestDTO : SfsStoreRequestDTOBase<ThirdLocationReque
[Display(Name = "是否使用在途库")] [Display(Name = "是否使用在途库")]
public bool IsUseOnTheWayLocation { get; set; } public bool IsUseOnTheWayLocation { get; set; }
/// <summary>
/// 可用来源库位Json集合
/// </summary>
public string FromLocationCodeJsonList { get; set; }
/// <summary>
/// 叫料库位
/// </summary>
public string ToLocationCode { get; set; }
/// <summary>
/// 目标ERP储位
/// </summary>
[Display(Name = "目标ERP储位")]
public string ToLocationErpCode { get; set; }
/// <summary>
/// 来源库区
/// </summary>
public string FromLocationArea { get; set; }
} }

24
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Requests/ThirdLocationRequests/DTOs/ThirdLocationRequestDetailDTO.cs

@ -8,6 +8,30 @@ namespace Win_in.Sfs.Wms.Store.Application.Contracts;
public class ThirdLocationRequestDetailDTO : SfsStoreDetailWithQtyDTOBase public class ThirdLocationRequestDetailDTO : SfsStoreDetailWithQtyDTOBase
{ {
/// <summary>
/// 目标库位
/// </summary>
[Display(Name = "目标库位")]
public string ToLocationCode { get; set; }
/// <summary>
/// 目标ERP储位
/// </summary>
[Display(Name = "目标ERP储位")]
public string ToLocationErpCode { get; set; }
/// <summary>
/// 来源库位
/// </summary>
[Display(Name = "来源库位")]
public string FromLocationCode { get; set; }
/// <summary>
/// 来源库区
/// </summary>
[Display(Name = "来源库区")]
public string FromLocationArea { get; set; }
/// <summary> /// <summary>
/// 已发数量 /// 已发数量
/// </summary> /// </summary>

24
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/ThirdLocationRequests/ThirdLocationRequestAppService.cs

@ -20,6 +20,7 @@ using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Shared.Domain; using Win_in.Sfs.Shared.Domain;
using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Shared.Domain.Shared;
using Win_in.Sfs.Shared.Event; using Win_in.Sfs.Shared.Event;
using Win_in.Sfs.Wms.Inventory.Application.Contracts;
using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts;
using Win_in.Sfs.Wms.Store.Domain; using Win_in.Sfs.Wms.Store.Domain;
using Win_in.Sfs.Wms.Store.Domain.Shared; using Win_in.Sfs.Wms.Store.Domain.Shared;
@ -44,6 +45,8 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir
private readonly IProductionLineAppService _productionLineAppService; private readonly IProductionLineAppService _productionLineAppService;
private readonly IInjectionJobAppService _issueJobAppService; private readonly IInjectionJobAppService _issueJobAppService;
private readonly ITransactionTypeAppService _transactionTypeAppService; private readonly ITransactionTypeAppService _transactionTypeAppService;
private readonly IExpectOutAppService _expectOutAppService;
private readonly IBalanceAppService _balanceAppService;
public ThirdLocationRequestAppService( public ThirdLocationRequestAppService(
IThirdLocationRequestRepository repository, IThirdLocationRequestRepository repository,
@ -55,6 +58,8 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir
IItemBasicAppService itemBasicAppService, IItemBasicAppService itemBasicAppService,
IProductionLineAppService productionLineAppService, IProductionLineAppService productionLineAppService,
ITransactionTypeAppService transactionTypeAppService, ITransactionTypeAppService transactionTypeAppService,
IExpectOutAppService expectOutAppService,
IBalanceAppService balanceAppService,
IInjectionJobAppService issueJobAppService) IInjectionJobAppService issueJobAppService)
: base(repository, thirdLocationRequestManager) : base(repository, thirdLocationRequestManager)
{ {
@ -66,6 +71,8 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir
_productionLineAppService = productionLineAppService; _productionLineAppService = productionLineAppService;
_issueJobAppService = issueJobAppService; _issueJobAppService = issueJobAppService;
_transactionTypeAppService = transactionTypeAppService; _transactionTypeAppService = transactionTypeAppService;
_expectOutAppService= expectOutAppService;
_balanceAppService= balanceAppService;
} }
@ -97,6 +104,23 @@ public class ThirdLocationRequestAppService : SfsStoreRequestAppServiceBase<Thir
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detailInput.ItemCode).ConfigureAwait(false); var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detailInput.ItemCode).ConfigureAwait(false);
CheckItemBasic(itemBasicDto, detailInput.ItemCode); CheckItemBasic(itemBasicDto, detailInput.ItemCode);
var balanceNums= await _balanceAppService.GetListByLocationCodeAndItemCodeAsync(detailInput.ToLocationCode, detailInput.ItemCode).ConfigureAwait(false);
decimal balanceSum = 0;
foreach (var item in balanceNums)
{
balanceSum += item.Qty;
}
var expectOutNums= await _expectOutAppService.GetListByItemAsync(detailInput.ItemCode).ConfigureAwait(false);
decimal expectOutSum = 0;
foreach (var item in expectOutNums)
{
expectOutSum += item.Qty;
}
decimal realityBalance = balanceSum - expectOutSum;
if (detailInput.Qty> realityBalance)
{
throw new UserFriendlyException($"{detailInput.ItemCode} 物品的库存为 {realityBalance} ,库存不够");
}
detailInput.ProdLine = detailInput.ToLocationCode; detailInput.ProdLine = detailInput.ToLocationCode;
detailInput.ToLocationErpCode = toLocationDto.ErpLocationCode; detailInput.ToLocationErpCode = toLocationDto.ErpLocationCode;

8
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Domain/Requests/ThirdLocationRequests/ThirdLocationRequestDetail.cs

@ -47,10 +47,10 @@ public class ThirdLocationRequestDetail : SfsStoreDetailWithQtyEntityBase, IHasT
// /// <summary> /// <summary>
// /// 在途库库位 /// 在途库库位
// /// </summary> /// </summary>
// public string OnTheWayLocationCode { get; set; } public string OnTheWayLocationCode { get; set; }
/// <summary> /// <summary>
/// 生产线 /// 生产线

1
be/Modules/Store/src/Win_in.Sfs.Wms.Store.EntityFrameworkCore/Requests/ThirdLocationRequests/ThirdLocationRequestDbContextModelCreatingExtensions.cs

@ -48,6 +48,7 @@ public static class ThirdLocationRequestDbContextModelCreatingExtensions
b.Property(q => q.ToLocationGroup).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength); b.Property(q => q.ToLocationGroup).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength);
b.Property(q => q.FromLocationCode).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength); b.Property(q => q.FromLocationCode).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength);
b.Property(q => q.FromLocationArea).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength); b.Property(q => q.FromLocationArea).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength);
b.Property(q => q.OnTheWayLocationCode).IsRequired().HasMaxLength(SfsPropertyConst.CodeLength);
b.Property(q => q.ExpiredTime).IsRequired(); b.Property(q => q.ExpiredTime).IsRequired();
b.Property(q => q.ProdLine).HasMaxLength(SfsPropertyConst.CodeLength); b.Property(q => q.ProdLine).HasMaxLength(SfsPropertyConst.CodeLength);
b.Property(q => q.WorkStation).HasMaxLength(SfsPropertyConst.CodeLength); b.Property(q => q.WorkStation).HasMaxLength(SfsPropertyConst.CodeLength);

24
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Requests/ThirdLocationRequestAutoMapperProfile.cs

@ -11,6 +11,30 @@ public partial class StoreEventAutoMapperProfile : Profile
{ {
private void ThirdLocationRequestAutoMapperProfile() private void ThirdLocationRequestAutoMapperProfile()
{ {
CreateMap<ThirdLocationRequestDetail, TransferLogEditInput>()
.Ignore(x => x.DocNumber)
.Ignore(x => x.JobNumber)
.Ignore(x => x.Worker)
.Ignore(x => x.TransType)
.Ignore(x => x.ExtraProperties)
.Ignore(x => x.TransSubType)
.Ignore(x => x.FromPackingCode)
.Ignore(x => x.ToPackingCode)
.Ignore(x => x.FromLot)
.Ignore(x => x.FromStatus)
.Ignore(x => x.FromWarehouseCode)
.Ignore(x => x.FromLocationGroup)
.Ignore(x => x.FromLocationErpCode)
.Ignore(x => x.FromContainerCode)
.Ignore(x => x.ToLot)
.Ignore(x => x.SupplierBatch)
.Ignore(x => x.ArriveDate)
.Ignore(x => x.ProduceDate)
.Ignore(x => x.ExpireDate)
.Ignore(x => x.ToStatus)
.Ignore(x => x.ToContainerCode)
;
CreateMap<ThirdLocationRequest, ThirdLocationJobEditInput>() CreateMap<ThirdLocationRequest, ThirdLocationJobEditInput>()
.ForMember(x => x.RequestNumber, y => y.MapFrom(d => d.Number)) .ForMember(x => x.RequestNumber, y => y.MapFrom(d => d.Number))
.ForMember(x => x.RequestType, y => y.MapFrom(d => d.Type)) .ForMember(x => x.RequestType, y => y.MapFrom(d => d.Type))

9
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Jobs/ThirdLocationJobEventHandler.cs

@ -37,6 +37,15 @@ public class ThirdLocationJobEventHandler :
public virtual async Task HandleEventAsync(SfsCompletedEntityEventData<ThirdLocationJob> eventData) public virtual async Task HandleEventAsync(SfsCompletedEntityEventData<ThirdLocationJob> eventData)
{ {
var entity = eventData.Entity; var entity = eventData.Entity;
entity.CompleteTime = Clock.Now;
entity.JobStatus = EnumJobStatus.Done;
foreach (var detail in eventData.Entity.Details)
{
detail.SetHandledFromRecommend();
}
var thirdLocationNote = await BuildThirdLocationNoteAsync(entity).ConfigureAwait(false); var thirdLocationNote = await BuildThirdLocationNoteAsync(entity).ConfigureAwait(false);
await _thirdLocationNoteAppService.CreateAsync(thirdLocationNote).ConfigureAwait(false); await _thirdLocationNoteAppService.CreateAsync(thirdLocationNote).ConfigureAwait(false);
} }

125
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/ThirdLocationRequestEventHandler.cs

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentValidation.Validators; using FluentValidation.Validators;
using IdentityServer4.Models;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.EventBus; using Volo.Abp.EventBus;
using Volo.Abp.SettingManagement; using Volo.Abp.SettingManagement;
@ -13,6 +15,7 @@ using Win_in.Sfs.Wms.Inventory.Application.Contracts;
using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts;
using Win_in.Sfs.Wms.Store.Domain; using Win_in.Sfs.Wms.Store.Domain;
using Win_in.Sfs.Wms.Store.Domain.Shared; using Win_in.Sfs.Wms.Store.Domain.Shared;
using Win_in.Sfs.Wms.Store.Event.Transactions;
namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest; namespace Win_in.Sfs.Wms.Store.Event.BusinessRequest;
@ -30,11 +33,16 @@ public class ThirdLocationRequestEventHandler
private readonly ILocationAppService _locationAppService; private readonly ILocationAppService _locationAppService;
private readonly IBalanceAppService _balanceAppService; private readonly IBalanceAppService _balanceAppService;
private const EnumTransType TransType = EnumTransType.TransferLib;
private readonly ITransferLogAppService _transferLogAppService;
public ThirdLocationRequestEventHandler( public ThirdLocationRequestEventHandler(
IThirdLocationJobAppService thirdLocationJobAppService IThirdLocationJobAppService thirdLocationJobAppService
, IProductionLineAppService productionLineAppService , IProductionLineAppService productionLineAppService
, IThirdLocationRequestManager thirdLocationRequestManager , IThirdLocationRequestManager thirdLocationRequestManager
, ILocationAppService locationAppService , ILocationAppService locationAppService
, ITransferLogAppService transferLogAppService
, IBalanceAppService balanceAppService) , IBalanceAppService balanceAppService)
{ {
_thirdLocationJobAppService = thirdLocationJobAppService; _thirdLocationJobAppService = thirdLocationJobAppService;
@ -42,6 +50,7 @@ public class ThirdLocationRequestEventHandler
_thirdLocationRequestManager = thirdLocationRequestManager; _thirdLocationRequestManager = thirdLocationRequestManager;
_locationAppService = locationAppService; _locationAppService = locationAppService;
_balanceAppService = balanceAppService; _balanceAppService = balanceAppService;
_transferLogAppService = transferLogAppService;
} }
/// <summary> /// <summary>
@ -88,8 +97,108 @@ public class ThirdLocationRequestEventHandler
{ {
await _thirdLocationJobAppService.CreateManyAsync(thirdLocationJobs).ConfigureAwait(false); await _thirdLocationJobAppService.CreateManyAsync(thirdLocationJobs).ConfigureAwait(false);
} }
//来源库位更新为在途库位
var transferLogs = new List<TransferLogEditInput>();
var route = entity.UseOnTheWayLocation
? EnumTransferRoute.SourceToOnTheWay
: EnumTransferRoute.SourceToDestination;
transferLogs.AddRange(await BuildTransferLogsAsync(entity, route).ConfigureAwait(false));
await _transferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false);
}
private async Task<List<TransferLogEditInput>> BuildTransferLogsAsync(ThirdLocationRequest thirdLocationRequest, EnumTransferRoute route)
{
var transferLogs = new List<TransferLogEditInput>();
foreach (var detail in thirdLocationRequest.Details.Where(detail => detail.Qty != 0))
{
var transferLog = ObjectMapper.Map<ThirdLocationRequestDetail, TransferLogEditInput>(detail);
LocationDTO fromLocationDTO = null;
LocationDTO toLocationDTO = null;
var transportLocation = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false);
if (transportLocation != null)
{
detail.OnTheWayLocationCode = transportLocation.Code;
}
else
{
throw new UserFriendlyException($"未获取到在途库代码");
} }
if (thirdLocationRequest.UseOnTheWayLocation)
{
var location = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
switch (route)
{
case EnumTransferRoute.SourceToOnTheWay:
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.FromLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
break;
case EnumTransferRoute.OnTheWayToDestination:
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false);
await RemovePackingCodeAndContainerCodeAndLotAsync(transferLog).ConfigureAwait(false);
break;
case EnumTransferRoute.SourceToDestination:
default:
throw new ArgumentOutOfRangeException(nameof(route), route, null);
}
}
else
{
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.FromLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false);
}
transferLog.FromLocationCode = fromLocationDTO.Code;
transferLog.FromLocationArea = fromLocationDTO.AreaCode;
transferLog.FromLocationErpCode = fromLocationDTO.ErpLocationCode;
transferLog.FromLocationGroup = fromLocationDTO.LocationGroupCode;
transferLog.FromWarehouseCode = fromLocationDTO.WarehouseCode;
transferLog.ToLocationCode = toLocationDTO.Code;
transferLog.ToLocationArea = toLocationDTO.AreaCode;
transferLog.ToLocationErpCode = toLocationDTO.ErpLocationCode;
transferLog.ToLocationGroup = toLocationDTO.LocationGroupCode;
transferLog.ToWarehouseCode = toLocationDTO.WarehouseCode;
transferLog.TransSubType = Enum.Parse<EnumTransSubType>(thirdLocationRequest.Type);
transferLog.TransType = TransType;
transferLog.DocNumber = thirdLocationRequest.Number;
transferLog.JobNumber = "";
transferLog.FromPackingCode = "";
transferLog.FromLot = "";
transferLog.ToPackingCode = "";
transferLog.ToLot = "";
transferLog.FromStatus = EnumInventoryStatus.OK;
transferLog.ToStatus = EnumInventoryStatus.OK;
transferLogs.Add(transferLog);
}
return transferLogs;
}
private async Task RemovePackingCodeAndContainerCodeAndLotAsync(TransferLogEditInput transferLogCreateInput)
{
transferLogCreateInput.ToPackingCode = "";
transferLogCreateInput.ToLot = "";
transferLogCreateInput.ToContainerCode = "";
transferLogCreateInput.FromPackingCode = "";
transferLogCreateInput.FromLot = "";
transferLogCreateInput.FromContainerCode = "";
}
/// <summary> /// <summary>
/// 驳回后 /// 驳回后
/// </summary> /// </summary>
@ -245,7 +354,7 @@ public class ThirdLocationRequestEventHandler
//ProductionLineDTO prodLine = await _productionLineAppService.GetByLocationGroupCodeAsync(toLocationGroupCode).ConfigureAwait(false); //ProductionLineDTO prodLine = await _productionLineAppService.GetByLocationGroupCodeAsync(toLocationGroupCode).ConfigureAwait(false);
var detail = ObjectMapper.Map<BalanceDTO, ThirdLocationJobDetailInput>(balance); var detail = ObjectMapper.Map<BalanceDTO, ThirdLocationJobDetailInput>(balance);
detail.FromLocationCode = thirdLocationRequestDetail.FromLocationCode;
detail.WorkStation = thirdLocationRequestDetail.WorkStation; detail.WorkStation = thirdLocationRequestDetail.WorkStation;
detail.ExpiredTime = thirdLocationRequestDetail.ExpiredTime; detail.ExpiredTime = thirdLocationRequestDetail.ExpiredTime;
detail.PositionCode = thirdLocationRequestDetail.PositionCode; detail.PositionCode = thirdLocationRequestDetail.PositionCode;
@ -271,7 +380,19 @@ public class ThirdLocationRequestEventHandler
detail.ToLocationErpCode = thirdLocationRequestDetail.ToLocationErpCode; detail.ToLocationErpCode = thirdLocationRequestDetail.ToLocationErpCode;
detail.ToLocationArea = thirdLocationRequestDetail.ToLocationArea; detail.ToLocationArea = thirdLocationRequestDetail.ToLocationArea;
detail.ToWarehouseCode = thirdLocationRequestDetail.ToWarehouseCode; detail.ToWarehouseCode = thirdLocationRequestDetail.ToWarehouseCode;
detail.FromLocationArea = thirdLocationRequestDetail.FromLocationArea;
var transportLocation = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false);
if (transportLocation != null)
{
detail.FromLocationCode = transportLocation.Code;
detail.FromLocationArea = transportLocation.AreaCode;
}
else
{
throw new UserFriendlyException($"未获取到在途库代码");
}
//detail.ProdLine = prodLine == null ? toLocationGroupCode : prodLine.Code; //detail.ProdLine = prodLine == null ? toLocationGroupCode : prodLine.Code;
detail.ProdLine = toLocationGroupCode; detail.ProdLine = toLocationGroupCode;

157
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/ThirdLocationNoteEventHandler.cs

@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.EventBus;
using Volo.Abp.Uow;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Shared.Domain.Shared;
using Win_in.Sfs.Shared.Event;
using Win_in.Sfs.Wms.Inventory.Application.Contracts;
using Win_in.Sfs.Wms.Store.Domain;
using Win_in.Sfs.Wms.Store.Event.Transaction;
namespace Win_in.Sfs.Wms.Store.Event.Transactions;
public class ThirdLocationNoteEventHandler
: StoreInventoryEventHandlerBase
, ILocalEventHandler<SfsCreatedEntityEventData<ThirdLocationNote>>
, ILocalEventHandler<SfsCreatedEntityEventData<List<ThirdLocationNote>>>
, ILocalEventHandler<SfsConfirmedEntityEventData<ThirdLocationNote>>
{
private const EnumTransType TransType = EnumTransType.TransferLib;
private readonly ILocationAppService _locationAppService;
public ThirdLocationNoteEventHandler(ILocationAppService locationAppService)
{
_locationAppService = locationAppService;
}
[UnitOfWork]
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<ThirdLocationNote> eventData)
{
var entity = eventData.Entity;
var transferLogs = new List<TransferLogEditInput>();
var route = EnumTransferRoute.OnTheWayToDestination;
transferLogs.AddRange(await BuildTransferLogsAsync(entity, route).ConfigureAwait(false));
await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false);
}
[UnitOfWork]
public virtual async Task HandleEventAsync(SfsCreatedEntityEventData<List<ThirdLocationNote>> eventData)
{
var entities = eventData.Entity;
var transferLogs = new List<TransferLogEditInput>();
//如果要做库存事务汇总,可以修改此处
foreach (var thirdLocationNote in entities)
{
var route = EnumTransferRoute.OnTheWayToDestination;
transferLogs.AddRange(await BuildTransferLogsAsync(thirdLocationNote, route).ConfigureAwait(false));
}
await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false);
}
[UnitOfWork]
public virtual async Task HandleEventAsync(SfsConfirmedEntityEventData<ThirdLocationNote> eventData)
{
var entity = eventData.Entity;
var inputList = await BuildTransferLogsAsync(entity, EnumTransferRoute.OnTheWayToDestination).ConfigureAwait(false);
await AddTransferLogsAsync(inputList).ConfigureAwait(false);
}
private async Task AddTransferLogsAsync(List<TransferLogEditInput> inputList)
{
var transferLogs = new List<TransferLogEditInput>();
transferLogs.AddRange(inputList);
await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false);
}
private async Task<List<TransferLogEditInput>> BuildTransferLogsAsync(ThirdLocationNote thirdLocationNote, EnumTransferRoute route)
{
var transferLogs = new List<TransferLogEditInput>();
foreach (var detail in thirdLocationNote.Details.Where(detail => detail.Qty != 0))
{
var transferLog = ObjectMapper.Map<ThirdLocationNoteDetail, TransferLogEditInput>(detail);
LocationDTO fromLocationDTO = null;
LocationDTO toLocationDTO = null;
if (thirdLocationNote.UseOnTheWayLocation)
{
var location = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
switch (route)
{
case EnumTransferRoute.SourceToOnTheWay:
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.FromLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
break;
case EnumTransferRoute.OnTheWayToDestination:
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.OnTheWayLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false);
await RemovePackingCodeAndContainerCodeAndLotAsync(transferLog).ConfigureAwait(false);
break;
case EnumTransferRoute.SourceToDestination:
default:
throw new ArgumentOutOfRangeException(nameof(route), route, null);
}
}
else
{
fromLocationDTO = await _locationAppService.GetByCodeAsync(detail.FromLocationCode).ConfigureAwait(false);
toLocationDTO = await _locationAppService.GetByCodeAsync(detail.ToLocationCode).ConfigureAwait(false);
}
transferLog.FromLocationCode = fromLocationDTO.Code;
transferLog.FromLocationArea = fromLocationDTO.AreaCode;
transferLog.FromLocationErpCode = fromLocationDTO.ErpLocationCode;
transferLog.FromLocationGroup = fromLocationDTO.LocationGroupCode;
transferLog.ToLocationCode = toLocationDTO.Code;
transferLog.ToLocationArea = toLocationDTO.AreaCode;
transferLog.ToLocationErpCode = toLocationDTO.ErpLocationCode;
transferLog.ToLocationGroup = toLocationDTO.LocationGroupCode;
transferLog.TransSubType = Enum.Parse<EnumTransSubType>(thirdLocationNote.RequestType);
transferLog.TransType = TransType;
transferLog.DocNumber = thirdLocationNote.Number;
transferLog.JobNumber = thirdLocationNote.JobNumber;
transferLog.FromPackingCode = "";
transferLog.FromLot = "";
transferLog.ToPackingCode = "";
transferLog.ToLot = "";
transferLog.FromStatus = EnumInventoryStatus.OK;
transferLog.ToStatus = EnumInventoryStatus.OK;
transferLogs.Add(transferLog);
}
return transferLogs;
}
private async Task RemovePackingCodeAndContainerCodeAndLotAsync(TransferLogEditInput transferLogCreateInput)
{
transferLogCreateInput.ToPackingCode = "";
transferLogCreateInput.ToLot = "";
transferLogCreateInput.ToContainerCode = "";
transferLogCreateInput.FromPackingCode = "";
transferLogCreateInput.FromLot = "";
transferLogCreateInput.FromContainerCode = "";
}
}
Loading…
Cancel
Save