|
|
@ -5,10 +5,13 @@ using System.Linq; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Office.CustomUI; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
@ -30,16 +33,20 @@ public class ProductReceiptRequestAppService : |
|
|
|
SfsStoreRequestInputBase, ProductReceiptRequestImportInput> |
|
|
|
{ |
|
|
|
private readonly IProductReceiptRequestManager _productReceiptRequestManager; |
|
|
|
|
|
|
|
private readonly IAreaAppService _areaApp; |
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
|
|
|
|
public ProductReceiptRequestAppService( |
|
|
|
IProductReceiptRequestRepository repository |
|
|
|
, IProductReceiptRequestManager productReceiptRequestManager |
|
|
|
, IAreaAppService areaApp |
|
|
|
) : base(repository, productReceiptRequestManager) |
|
|
|
, IAreaAppService areaApp, |
|
|
|
IItemBasicAppService itemBasicAppService, |
|
|
|
ILocationAppService locationAppService) : base(repository, productReceiptRequestManager) |
|
|
|
{ |
|
|
|
_areaApp = areaApp; |
|
|
|
_itemBasicAppService = itemBasicAppService; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_productReceiptRequestManager = productReceiptRequestManager; |
|
|
|
base.CreatePolicyName = ProductReceiptRequestPermissions.Create; |
|
|
|
base.UpdatePolicyName = ProductReceiptRequestPermissions.Update; |
|
|
@ -48,6 +55,61 @@ public class ProductReceiptRequestAppService : |
|
|
|
|
|
|
|
#region 东阳
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dictionary"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected override async Task<Dictionary<ProductReceiptRequest, EntityState>> ImportProcessingEntityAsync( |
|
|
|
Dictionary<ProductReceiptRequest, EntityState> dictionary) |
|
|
|
{ |
|
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
|
|
|
|
|
foreach (var productReceiptRequest in addList) |
|
|
|
{ |
|
|
|
productReceiptRequest.Worker = CurrentUser.GetUserName(); |
|
|
|
productReceiptRequest.CreatorId = CurrentUser.Id; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(productReceiptRequest).ConfigureAwait(false); |
|
|
|
foreach (var detail in productReceiptRequest.Details) |
|
|
|
{ |
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 赋值详情
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="detail"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetDetailPropertiesAsync(ProductReceiptRequestDetail detail) |
|
|
|
{ |
|
|
|
var itemBasic = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (itemBasic != null) |
|
|
|
{ |
|
|
|
detail.ItemName = itemBasic.Name; |
|
|
|
detail.ItemDesc1 = itemBasic.Desc1; |
|
|
|
detail.ItemDesc2 = itemBasic.Desc2; |
|
|
|
detail.StdPackQty = itemBasic.StdPackQty; |
|
|
|
detail.Uom = itemBasic.BasicUom; |
|
|
|
} |
|
|
|
|
|
|
|
var location = await _locationAppService.GetByCodeAsync(detail.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (location != null) |
|
|
|
{ |
|
|
|
detail.LocationErpCode = location.ErpLocationCode; |
|
|
|
detail.WarehouseCode = location.WarehouseCode; |
|
|
|
detail.LocationArea = location.AreaCode; |
|
|
|
detail.LocationGroup = location.LocationGroupCode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 设置事务类型
|
|
|
|
/// </summary>
|
|
|
@ -55,7 +117,7 @@ public class ProductReceiptRequestAppService : |
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetRequestAutoPropertiesAsync(ProductReceiptRequest entity) |
|
|
|
{ |
|
|
|
var enumTransSubType=EnumTransSubType.None; |
|
|
|
var enumTransSubType = EnumTransSubType.None; |
|
|
|
switch (entity.Type) |
|
|
|
{ |
|
|
|
case EnumProductReceiptType.ProductReceipt_Manual: |
|
|
@ -214,121 +276,97 @@ public class ProductReceiptRequestAppService : |
|
|
|
return transactionType; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task ImportDataAsync(List<ProductReceiptRequest> entites, |
|
|
|
List<ProductReceiptRequest> deleteEntities) |
|
|
|
{ |
|
|
|
await _productReceiptRequestManager.ImportDataAsync(entites, deleteEntities).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
protected override Func<ProductReceiptRequestImportInput, object> GetEntityExpression() |
|
|
|
{ |
|
|
|
return p => p.Type; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<(List<ProductReceiptRequest> entites, List<ProductReceiptRequest> deleteEntities)> |
|
|
|
BuildImportDataAsync(ImportResult<ProductReceiptRequestImportInput> importResult, |
|
|
|
EnumImportMethod importMethod = EnumImportMethod.Update, bool isAllowPartImport = false) |
|
|
|
{ |
|
|
|
if (importResult.Data.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
{ |
|
|
|
if (!isAllowPartImport) |
|
|
|
{ |
|
|
|
return (null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var entites = new List<ProductReceiptRequest>(); |
|
|
|
//protected virtual async Task ImportDataAsync(List<ProductReceiptRequest> entites,
|
|
|
|
// List<ProductReceiptRequest> deleteEntities)
|
|
|
|
//{
|
|
|
|
// await _productReceiptRequestManager.ImportDataAsync(entites, deleteEntities).ConfigureAwait(false);
|
|
|
|
//}
|
|
|
|
//protected virtual async Task<(List<ProductReceiptRequest> entites, List<ProductReceiptRequest> deleteEntities)>
|
|
|
|
// BuildImportDataAsync(ImportResult<ProductReceiptRequestImportInput> importResult,
|
|
|
|
// EnumImportMethod importMethod = EnumImportMethod.Update, bool isAllowPartImport = false)
|
|
|
|
//{
|
|
|
|
// if (importResult.Data.Any(t => t.ReportStatus == EnumImportReportStatus.Failed))
|
|
|
|
// {
|
|
|
|
// if (!isAllowPartImport)
|
|
|
|
// {
|
|
|
|
// return (null, null);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
var details = new List<ProductReceiptRequestDetail>(); |
|
|
|
// var entites = new List<ProductReceiptRequest>();
|
|
|
|
|
|
|
|
var deleteEntites = new List<ProductReceiptRequest>(); |
|
|
|
// var details = new List<ProductReceiptRequestDetail>();
|
|
|
|
|
|
|
|
var entityExpression = GetEntityExpression(); |
|
|
|
// var deleteEntites = new List<ProductReceiptRequest>();
|
|
|
|
|
|
|
|
var groupList = importResult.Data.ToList().GroupBy(entityExpression).Distinct().ToList(); |
|
|
|
// var entityExpression = GetEntityExpression();
|
|
|
|
|
|
|
|
foreach (var group in groupList) |
|
|
|
{ |
|
|
|
var input = group.FirstOrDefault(); |
|
|
|
// var groupList = importResult.Data.ToList().GroupBy(entityExpression).Distinct().ToList();
|
|
|
|
|
|
|
|
var inputDetails = group.ToList(); |
|
|
|
// foreach (var group in groupList)
|
|
|
|
// {
|
|
|
|
// var input = group.FirstOrDefault();
|
|
|
|
|
|
|
|
if (!inputDetails.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
{ |
|
|
|
var exist = await GetEntityAsync(input).ConfigureAwait(false); |
|
|
|
// var inputDetails = group.ToList();
|
|
|
|
|
|
|
|
var entity = ObjectMapper.Map<ProductReceiptRequestImportInput, ProductReceiptRequest>(input); |
|
|
|
// if (!inputDetails.Any(t => t.ReportStatus == EnumImportReportStatus.Failed))
|
|
|
|
// {
|
|
|
|
// var exist = await GetEntityAsync(input).ConfigureAwait(false);
|
|
|
|
|
|
|
|
await SetEntityPropertiesAsync(entity, input).ConfigureAwait(false); |
|
|
|
// var entity = ObjectMapper.Map<ProductReceiptRequestImportInput, ProductReceiptRequest>(input);
|
|
|
|
|
|
|
|
switch (importMethod) |
|
|
|
{ |
|
|
|
case EnumImportMethod.Update: |
|
|
|
entity.SetId(exist != null ? exist.Id : GuidGenerator.Create()); |
|
|
|
// await SetEntityPropertiesAsync(entity, input).ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
entity.SetId(exist.Id); |
|
|
|
} |
|
|
|
// switch (importMethod)
|
|
|
|
// {
|
|
|
|
// case EnumImportMethod.Update:
|
|
|
|
// entity.SetId(exist != null ? exist.Id : GuidGenerator.Create());
|
|
|
|
|
|
|
|
break; |
|
|
|
case EnumImportMethod.Replace: |
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
deleteEntites.Add(exist); |
|
|
|
} |
|
|
|
// if (exist != null)
|
|
|
|
// {
|
|
|
|
// entity.SetId(exist.Id);
|
|
|
|
// }
|
|
|
|
|
|
|
|
entity.SetId(GuidGenerator.Create()); |
|
|
|
break; |
|
|
|
} |
|
|
|
// break;
|
|
|
|
// case EnumImportMethod.Replace:
|
|
|
|
// if (exist != null)
|
|
|
|
// {
|
|
|
|
// deleteEntites.Add(exist);
|
|
|
|
// }
|
|
|
|
|
|
|
|
foreach (var inputDetail in inputDetails) |
|
|
|
{ |
|
|
|
var detail = |
|
|
|
ObjectMapper.Map<ProductReceiptRequestImportInput, ProductReceiptRequestDetail>(inputDetail); |
|
|
|
// entity.SetId(GuidGenerator.Create());
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
|
|
|
detail.SetIdAndNumber(GuidGenerator, entity.Id, entity.Number); |
|
|
|
// foreach (var inputDetail in inputDetails)
|
|
|
|
// {
|
|
|
|
// var detail =
|
|
|
|
// ObjectMapper.Map<ProductReceiptRequestImportInput, ProductReceiptRequestDetail>(inputDetail);
|
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail, input).ConfigureAwait(false); |
|
|
|
entity.AddDetail(detail); |
|
|
|
} |
|
|
|
// detail.SetIdAndNumber(GuidGenerator, entity.Id, entity.Number);
|
|
|
|
|
|
|
|
entites.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
// await SetDetailPropertiesAsync(detail, input).ConfigureAwait(false);
|
|
|
|
// entity.AddDetail(detail);
|
|
|
|
// }
|
|
|
|
|
|
|
|
return (entites, deleteEntites); |
|
|
|
} |
|
|
|
// entites.Add(entity);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
private async Task SetDetailPropertiesAsync(ProductReceiptRequestDetail detail, |
|
|
|
ProductReceiptRequestImportInput input) |
|
|
|
{ |
|
|
|
var itemBasic = await ItemBasicAclService.GetByCodeAsync(input.ItemCode).ConfigureAwait(false); |
|
|
|
// return (entites, deleteEntites);
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (itemBasic != null) |
|
|
|
{ |
|
|
|
detail.ItemName = itemBasic.Name; |
|
|
|
detail.ItemDesc1 = itemBasic.Desc1; |
|
|
|
detail.ItemDesc2 = itemBasic.Desc2; |
|
|
|
detail.Qty = input.Qty; |
|
|
|
detail.StdPackQty = itemBasic.StdPackQty; |
|
|
|
} |
|
|
|
|
|
|
|
var location = await LocationAclService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false); |
|
|
|
//private async Task SetEntityPropertiesAsync(ProductReceiptRequest entity, ProductReceiptRequestImportInput input)
|
|
|
|
//{
|
|
|
|
// entity.Worker = CurrentUser.GetUserName();
|
|
|
|
|
|
|
|
if (location != null) |
|
|
|
{ |
|
|
|
detail.LocationErpCode = location.ErpLocationCode; |
|
|
|
detail.WarehouseCode = location.WarehouseCode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetEntityPropertiesAsync(ProductReceiptRequest entity, ProductReceiptRequestImportInput input) |
|
|
|
{ |
|
|
|
entity.Worker = CurrentUser.GetUserName(); |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
// await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false);
|
|
|
|
//}
|
|
|
|
} |
|
|
|