Browse Source

添加创建发运校验

Agv分支2024-11-19
赵新宇 6 months ago
parent
commit
6707a8f073
  1. 80
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs

80
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Requests/DeliverRequests/DeliverRequestAppService.cs

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Org.BouncyCastle.Asn1.Ocsp;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@ -15,6 +16,7 @@ using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Win_in.Sfs.Basedata.Application; using Win_in.Sfs.Basedata.Application;
using Win_in.Sfs.Basedata.Application.Contracts; using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Basedata.Domain;
using Win_in.Sfs.Shared.Application.Contracts; using Win_in.Sfs.Shared.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;
@ -37,20 +39,35 @@ public class DeliverRequestAppService :
private readonly ICustomerAppService _customerApp; private readonly ICustomerAppService _customerApp;
private readonly ICustomerAddressAppService _customerAddressApp; private readonly ICustomerAddressAppService _customerAddressApp;
private readonly IItemBasicAppService _itemBasicAppService; private readonly IItemBasicAppService _itemBasicAppService;
private readonly ICustomerItemAppService _customerItemAppService;
private readonly ISalePriceSheetRepository _salePriceSheetRepository;
public DeliverRequestAppService( public DeliverRequestAppService(
IDeliverRequestRepository repository IDeliverRequestRepository repository
, IDeliverRequestManager deliverRequestManager , IDeliverRequestManager deliverRequestManager
, IAreaAppService areaApp , IAreaAppService areaApp
, ICustomerAppService customerApp , ICustomerAppService customerApp
, ICustomerAddressAppService customerAddressApp, , ICustomerAddressAppService customerAddressApp
IItemBasicAppService itemBasicAppService) , IItemBasicAppService itemBasicAppService,
ICustomerItemAppService customerItemAppService,
ISalePriceSheetRepository salePriceSheetRepository
)
: base(repository, deliverRequestManager) : base(repository, deliverRequestManager)
{ {
_customerItemAppService = customerItemAppService;
_deliverRequestManager = deliverRequestManager; _deliverRequestManager = deliverRequestManager;
_areaApp = areaApp; _areaApp = areaApp;
_customerApp = customerApp; _customerApp = customerApp;
_customerAddressApp = customerAddressApp; _customerAddressApp = customerAddressApp;
_itemBasicAppService = itemBasicAppService; _itemBasicAppService = itemBasicAppService;
_customerItemAppService = customerItemAppService;
_salePriceSheetRepository = salePriceSheetRepository;
} }
protected override async Task<Dictionary<DeliverRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<DeliverRequest, EntityState> dictionary) protected override async Task<Dictionary<DeliverRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<DeliverRequest, EntityState> dictionary)
@ -76,8 +93,12 @@ IItemBasicAppService itemBasicAppService)
{ {
request.DeliverPlanNumber = request.Details.First().MesDeliveryPlan; request.DeliverPlanNumber = request.Details.First().MesDeliveryPlan;
} }
await CheckCustomerItem(request).ConfigureAwait(false);
foreach (var detail in request.Details) foreach (var detail in request.Details)
{ {
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false);
CheckItemBasic(itemBasicDto, detail.ItemCode); CheckItemBasic(itemBasicDto, detail.ItemCode);
detail.ItemDesc1 = itemBasicDto.Desc1; detail.ItemDesc1 = itemBasicDto.Desc1;
@ -90,6 +111,52 @@ IItemBasicAppService itemBasicAppService)
return dictionary; return dictionary;
} }
private async Task CheckSalePrice(List<DeliverRequest> requests)
{
List<string> errors=new List<string>();
foreach (var request in requests)
{
foreach (var itm in request.Details)
{
var price = await _salePriceSheetRepository.FindAsync(p => p.ItemCode == itm.ItemCode && p.CustomerCode == request.CustomerCode).ConfigureAwait(false);
if (price == null)
{
errors.Add($"请求单号:{request.Number}零件编号:{itm.ItemCode}客户编号:{request.CustomerCode}");
}
}
}
if (errors.Count > 0)
{
throw new UserFriendlyException($"{string.Format(",",errors.ToArray())+""}");
}
}
private async Task CheckCustomerItem(DeliverRequest request)
{
List<string> errors= new List<string>();
foreach (var detail in request.Details)
{
var entity = await _customerItemAppService.GetByCustomerAndItemAsync(detail.ItemCode, request.CustomerCode).ConfigureAwait(false);
if (entity == null)
{
errors.Add($"零件编号:{detail.ItemCode}客户编号:{request.CustomerCode}|");
}
}
if (errors.Count > 0)
{
throw new UserFriendlyException(string.Format(",",errors.ToArray())+ "在客户零件关系表里不存在!");
}
}
protected override async Task SaveImportAsync(Dictionary<DeliverRequest, EntityState> dict) protected override async Task SaveImportAsync(Dictionary<DeliverRequest, EntityState> dict)
{ {
var addList = dict.Where(p => p.Value == EntityState.Added).Select(p => p.Key).ToList(); var addList = dict.Where(p => p.Value == EntityState.Added).Select(p => p.Key).ToList();
@ -182,6 +249,11 @@ IItemBasicAppService itemBasicAppService)
entitys.ForEach(r => { r.MesTruckNumber = truckNumber; }); entitys.ForEach(r => { r.MesTruckNumber = truckNumber; });
Check.NotNull(entitys, typeof(DeliverRequest).Name); Check.NotNull(entitys, typeof(DeliverRequest).Name);
await CheckSalePrice(entitys).ConfigureAwait(false);
var result = await _deliverRequestManager.HandleListAsync(entitys).ConfigureAwait(false); var result = await _deliverRequestManager.HandleListAsync(entitys).ConfigureAwait(false);
var dtos = ObjectMapper.Map<List<DeliverRequest>, List<DeliverRequestDTO>>(entitys); var dtos = ObjectMapper.Map<List<DeliverRequest>, List<DeliverRequestDTO>>(entitys);
return dtos; return dtos;
@ -209,6 +281,10 @@ IItemBasicAppService itemBasicAppService)
{ {
var entity = ObjectMapper.Map<DeliverRequestEditInput, DeliverRequest>(input); var entity = ObjectMapper.Map<DeliverRequestEditInput, DeliverRequest>(input);
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false);
await CheckCustomerItem(entity).ConfigureAwait(false);
await _deliverRequestManager.CreateAsync(entity).ConfigureAwait(false); await _deliverRequestManager.CreateAsync(entity).ConfigureAwait(false);
var dto = ObjectMapper.Map<DeliverRequest, DeliverRequestDTO>(entity); var dto = ObjectMapper.Map<DeliverRequest, DeliverRequestDTO>(entity);

Loading…
Cancel
Save