|
|
@ -10,8 +10,10 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
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.Shared.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
@ -34,18 +36,122 @@ public class DeliverRequestAppService : |
|
|
|
private readonly IAreaAppService _areaApp; |
|
|
|
private readonly ICustomerAppService _customerApp; |
|
|
|
private readonly ICustomerAddressAppService _customerAddressApp; |
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
public DeliverRequestAppService( |
|
|
|
IDeliverRequestRepository repository |
|
|
|
, IDeliverRequestManager deliverRequestManager |
|
|
|
, IAreaAppService areaApp |
|
|
|
, ICustomerAppService customerApp |
|
|
|
, ICustomerAddressAppService customerAddressApp) |
|
|
|
, ICustomerAddressAppService customerAddressApp, |
|
|
|
IItemBasicAppService itemBasicAppService) |
|
|
|
: base(repository, deliverRequestManager) |
|
|
|
{ |
|
|
|
_deliverRequestManager = deliverRequestManager; |
|
|
|
_areaApp = areaApp; |
|
|
|
_customerApp = customerApp; |
|
|
|
_customerAddressApp = customerAddressApp; |
|
|
|
_itemBasicAppService = itemBasicAppService; |
|
|
|
} |
|
|
|
|
|
|
|
protected override async Task<Dictionary<DeliverRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<DeliverRequest, EntityState> dictionary) |
|
|
|
{ |
|
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
|
foreach (var request in addList) |
|
|
|
{ |
|
|
|
request.Worker = CurrentUser.GetUserName(); |
|
|
|
request.CreatorId = CurrentUser.Id; |
|
|
|
request.Remark = "成品发运手动导入"; |
|
|
|
request.ActiveDate = DateTime.Now; |
|
|
|
await SetRequestAutoPropertiesAsync(request).ConfigureAwait(false); |
|
|
|
var detailGroupCount= request.Details.GroupBy(r => new { r.AreaCode, r.MesDeliveryNo, r.MesDeliveryPlan }).Count(); |
|
|
|
if (detailGroupCount != 1) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"同一发货类型、发货时间、客户的发货区域、Mes发货单号、Mes发货计划号必须相同!"); |
|
|
|
} |
|
|
|
if (request.Details.Count != request.Details.Select(r => r.ItemCode).Distinct().Count()) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"同一发货类型、发货时间、客户的存在相同零件号!"); |
|
|
|
} |
|
|
|
foreach (var detail in request.Details) |
|
|
|
{ |
|
|
|
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
CheckItemBasic(itemBasicDto, detail.ItemCode); |
|
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
detail.ItemDesc2 = itemBasicDto.Desc2; |
|
|
|
detail.ItemName = itemBasicDto.Name; |
|
|
|
detail.Uom = itemBasicDto.BasicUom; |
|
|
|
detail.StdPackQty = itemBasicDto.StdPackQty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
protected override async Task SaveImportAsync(Dictionary<DeliverRequest, EntityState> dict) |
|
|
|
{ |
|
|
|
var addList = dict.Where(p => p.Value == EntityState.Added).Select(p => p.Key).ToList(); |
|
|
|
foreach (var item in addList) |
|
|
|
{ |
|
|
|
await SetRequestAutoPropertiesAsync(item).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
await _deliverRequestManager.CreateManyAsync(addList).ConfigureAwait(false); |
|
|
|
} |
|
|
|
private static void CheckItemBasic(ItemBasicDTO itemcBasicDto, string itemCode) |
|
|
|
{ |
|
|
|
if (itemcBasicDto == null) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"ERP料号为【{itemCode}】不存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 验证
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="model"></param>
|
|
|
|
/// <param name="validationRresult"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected override async Task ValidateImportModelAsync(DeliverRequestImportInput model, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
if (model.DeliverRequestType == EnumDeliverRequestType.FIS) |
|
|
|
{ |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.IdentityNo)) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{model.ItemCode}为FIS发货必须填写底盘号", new string[] { "底盘号" })); |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(model.MesDeliveryNo)) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{model.ItemCode}为FIS发货必须填写MES发货单号", new string[] { "MES发货单号" })); |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(model.MesDeliveryPlan)) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{model.ItemCode}为FIS发货MES发货计划单号应该为空", new string[] { "MES发货计划单号" })); |
|
|
|
} |
|
|
|
} |
|
|
|
if (model.DeliverRequestType == EnumDeliverRequestType.Normal ) |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(model.MesDeliveryPlan)) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{model.ItemCode}为看板发货必须填写MES发货计划单号", new string[] { "MES发货计划单号" })); |
|
|
|
} |
|
|
|
if(!string.IsNullOrEmpty(model.IdentityNo)|| !string.IsNullOrEmpty(model.MesDeliveryNo)) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"ERP料号{model.ItemCode}为看板发货底盘号和MES发货单号应该为空", new string[] { "底盘号" , "MES发货单号" })); |
|
|
|
} |
|
|
|
} |
|
|
|
var area = await _areaApp.GetByCodeAsync(model.AreaCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (area != null) |
|
|
|
{ |
|
|
|
if (!area.Name.Contains("成品"))//因为区域里没有类型,只能用名称判断
|
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"发货区域{model.AreaCode}不是成品储位", new string[] { "发货区域" })); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"发货区域{model.AreaCode}不存在", new string[] { "发货区域" })); |
|
|
|
} |
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 处理请求
|
|
|
|