|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Org.BouncyCastle.Asn1.Ocsp; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
@ -15,6 +16,7 @@ using Volo.Abp.Domain.Entities.Events.Distributed; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Win_in.Sfs.Basedata.Application; |
|
|
|
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.Domain; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
|
@ -37,20 +39,35 @@ public class DeliverRequestAppService : |
|
|
|
private readonly ICustomerAppService _customerApp; |
|
|
|
private readonly ICustomerAddressAppService _customerAddressApp; |
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
private readonly ICustomerItemAppService _customerItemAppService; |
|
|
|
private readonly ISalePriceSheetRepository _salePriceSheetRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DeliverRequestAppService( |
|
|
|
IDeliverRequestRepository repository |
|
|
|
, IDeliverRequestManager deliverRequestManager |
|
|
|
, IAreaAppService areaApp |
|
|
|
, ICustomerAppService customerApp |
|
|
|
, ICustomerAddressAppService customerAddressApp, |
|
|
|
IItemBasicAppService itemBasicAppService) |
|
|
|
, ICustomerAddressAppService customerAddressApp |
|
|
|
, IItemBasicAppService itemBasicAppService, |
|
|
|
ICustomerItemAppService customerItemAppService, |
|
|
|
|
|
|
|
ISalePriceSheetRepository salePriceSheetRepository |
|
|
|
|
|
|
|
) |
|
|
|
: base(repository, deliverRequestManager) |
|
|
|
{ |
|
|
|
_customerItemAppService = customerItemAppService; |
|
|
|
|
|
|
|
_deliverRequestManager = deliverRequestManager; |
|
|
|
_areaApp = areaApp; |
|
|
|
_customerApp = customerApp; |
|
|
|
_customerAddressApp = customerAddressApp; |
|
|
|
_itemBasicAppService = itemBasicAppService; |
|
|
|
_customerItemAppService = customerItemAppService; |
|
|
|
_salePriceSheetRepository = salePriceSheetRepository; |
|
|
|
} |
|
|
|
|
|
|
|
protected override async Task<Dictionary<DeliverRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<DeliverRequest, EntityState> dictionary) |
|
|
@ -76,8 +93,12 @@ IItemBasicAppService itemBasicAppService) |
|
|
|
{ |
|
|
|
request.DeliverPlanNumber = request.Details.First().MesDeliveryPlan; |
|
|
|
} |
|
|
|
|
|
|
|
await CheckCustomerItem(request).ConfigureAwait(false); |
|
|
|
|
|
|
|
foreach (var detail in request.Details) |
|
|
|
{ |
|
|
|
|
|
|
|
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
CheckItemBasic(itemBasicDto, detail.ItemCode); |
|
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
@ -90,6 +111,68 @@ IItemBasicAppService itemBasicAppService) |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 成品发运价格校验
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
/// <param name="truckNumber"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
[HttpPost("check-sale-price")] |
|
|
|
public async Task<List<string>> CheckSalePriceAsync(List<Guid> ids, string truckNumber) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(truckNumber)) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"车牌号不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
var entitys = await _repository.GetListAsync(r => ids.Contains(r.Id), true).ConfigureAwait(false); |
|
|
|
if (entitys.Select(r => r.CustomerCode).Distinct().Count() > 1) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"所选申请涉及多个客户不能创建为一个发货单,请重新选择!"); |
|
|
|
} |
|
|
|
//一车发运车牌号相同
|
|
|
|
entitys.ForEach(r => { r.MesTruckNumber = truckNumber; }); |
|
|
|
Check.NotNull(entitys, typeof(DeliverRequest).Name); |
|
|
|
List<string> errors=new List<string>(); |
|
|
|
foreach (var request in entitys) |
|
|
|
{ |
|
|
|
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}"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return errors; |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
{ |
|
|
|
var addList = dict.Where(p => p.Value == EntityState.Added).Select(p => p.Key).ToList(); |
|
|
@ -182,6 +265,10 @@ IItemBasicAppService itemBasicAppService) |
|
|
|
entitys.ForEach(r => { r.MesTruckNumber = truckNumber; }); |
|
|
|
|
|
|
|
Check.NotNull(entitys, typeof(DeliverRequest).Name); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _deliverRequestManager.HandleListAsync(entitys).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<DeliverRequest>, List<DeliverRequestDTO>>(entitys); |
|
|
|
return dtos; |
|
|
@ -209,6 +296,10 @@ IItemBasicAppService itemBasicAppService) |
|
|
|
{ |
|
|
|
var entity = ObjectMapper.Map<DeliverRequestEditInput, DeliverRequest>(input); |
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
await CheckCustomerItem(entity).ConfigureAwait(false); |
|
|
|
|
|
|
|
await _deliverRequestManager.CreateAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<DeliverRequest, DeliverRequestDTO>(entity); |
|
|
|