|
|
@ -3,7 +3,7 @@ using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Win_in.Sfs.Auth.Application.Contracts; |
|
|
@ -29,75 +29,160 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
_departmentApp = departmentApp; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<(List<UnplannedReceiptRequest> entites, List<UnplannedReceiptRequest> deleteEntities)> BuildImportDataAsync(ImportResult<UnplannedReceiptRequestImportInput> importResult, EnumImportMethod importMethod = EnumImportMethod.Update, bool isAllowPartImport = false) |
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dictionary"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected override async Task<Dictionary<UnplannedReceiptRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<UnplannedReceiptRequest, EntityState> dictionary) |
|
|
|
{ |
|
|
|
if (importResult.Data.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
|
|
|
|
|
foreach (var unplannedIssueRequest in addList) |
|
|
|
{ |
|
|
|
if (!isAllowPartImport) |
|
|
|
unplannedIssueRequest.Worker = CurrentUser.GetUserName(); |
|
|
|
unplannedIssueRequest.CreatorId = CurrentUser.Id; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(unplannedIssueRequest).ConfigureAwait(false); |
|
|
|
await SetEntityPropertiesAsync(unplannedIssueRequest).ConfigureAwait(false); |
|
|
|
|
|
|
|
foreach (var detail in unplannedIssueRequest.Details) |
|
|
|
{ |
|
|
|
return (null, null); |
|
|
|
await SetDetailPropertiesAsync(detail).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var entites = new List<UnplannedReceiptRequest>(); |
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
|
|
|
|
var details = new List<UnplannedReceiptRequestDetail>(); |
|
|
|
#region 赋值
|
|
|
|
|
|
|
|
var deleteEntites = new List<UnplannedReceiptRequest>(); |
|
|
|
/// <summary>
|
|
|
|
/// 赋值详情
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="detail"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetDetailPropertiesAsync(UnplannedReceiptRequestDetail detail) |
|
|
|
{ |
|
|
|
var itemBasic = await ItemBasicAclService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
var entityExpression = GetEntityExpression(); |
|
|
|
if (itemBasic != null) |
|
|
|
{ |
|
|
|
detail.ItemName = itemBasic.Name; |
|
|
|
detail.ItemDesc1 = itemBasic.Desc1; |
|
|
|
detail.ItemDesc2 = itemBasic.Desc2; |
|
|
|
detail.StdPackQty = itemBasic.StdPackQty; |
|
|
|
detail.Uom = itemBasic.BasicUom; |
|
|
|
} |
|
|
|
|
|
|
|
var groupList = importResult.Data.ToList().GroupBy(entityExpression).Distinct().ToList(); |
|
|
|
var location = await LocationAclService.GetByCodeAsync(detail.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
foreach (var group in groupList) |
|
|
|
if (location != null) |
|
|
|
{ |
|
|
|
var input = group.FirstOrDefault(); |
|
|
|
detail.LocationErpCode = location.ErpLocationCode; |
|
|
|
detail.WarehouseCode = location.WarehouseCode; |
|
|
|
detail.LocationArea = location.AreaCode; |
|
|
|
detail.LocationGroup = location.LocationGroupCode; |
|
|
|
} |
|
|
|
|
|
|
|
var inputDetails = group.ToList(); |
|
|
|
detail.Lot = string.Empty; |
|
|
|
detail.ContainerCode = string.Empty; |
|
|
|
detail.PackingCode = string.Empty; |
|
|
|
detail.Status = EnumInventoryStatus.OK; |
|
|
|
|
|
|
|
if (!inputDetails.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
{ |
|
|
|
var exist = await GetEntityAsync(input).ConfigureAwait(false); |
|
|
|
//if (!string.IsNullOrEmpty(detail.OnceBusiCode))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAclService.GetByCodeAsync(nameof(input.OnceBusiCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
var entity = ObjectMapper.Map<UnplannedReceiptRequestImportInput, UnplannedReceiptRequest>(input); |
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.OnceBusiCode);
|
|
|
|
|
|
|
|
await SetEntityPropertiesAsync(entity, input).ConfigureAwait(false); |
|
|
|
// Check.NotNull(item, "次交易码", "次交易码不存在");
|
|
|
|
|
|
|
|
switch (importMethod) |
|
|
|
{ |
|
|
|
case EnumImportMethod.Update: |
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
entity.SetId(exist.Id); |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case EnumImportMethod.Replace: |
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
deleteEntites.Add(exist); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
// detail.SetProperty("OnceBusiCode", item.Code);
|
|
|
|
// detail.SetProperty("OnceBusiName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
foreach (var inputDetail in inputDetails) |
|
|
|
{ |
|
|
|
var detail = ObjectMapper.Map<UnplannedReceiptRequestImportInput, UnplannedReceiptRequestDetail>(inputDetail); |
|
|
|
//if (!string.IsNullOrEmpty(input.CaseCode))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAclService.GetByCodeAsync(nameof(input.CaseCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
detail.SetIdAndNumber(GuidGenerator, entity.Id, entity.Number); |
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.CaseCode);
|
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail, inputDetail).ConfigureAwait(false); |
|
|
|
entity.AddDetail(detail); |
|
|
|
} |
|
|
|
// Check.NotNull(item, "专案代码", "专案代码不存在");
|
|
|
|
|
|
|
|
entites.Add(entity); |
|
|
|
} |
|
|
|
// detail.SetProperty("CaseCode", item.Code);
|
|
|
|
// detail.SetProperty("CaseName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (!string.IsNullOrEmpty(input.ProjCapacityCode))
|
|
|
|
//{
|
|
|
|
// var dict = await DictAclService.GetByCodeAsync(nameof(input.ProjCapacityCode)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// if (dict.Items != null && dict.Items.Count > 0)
|
|
|
|
// {
|
|
|
|
// var item = dict.Items.FirstOrDefault(t => t.Code == input.ProjCapacityCode);
|
|
|
|
|
|
|
|
// Check.NotNull(item, "项目分类代码", "项目分类代码不存在");
|
|
|
|
|
|
|
|
// detail.SetProperty("ProjCapacityCode", item.Code);
|
|
|
|
// detail.SetProperty("ProjCapacityName", item.Name);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 赋值主记录
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetEntityPropertiesAsync(UnplannedReceiptRequest entity) |
|
|
|
{ |
|
|
|
var userName = CurrentUser.GetUserName(); |
|
|
|
|
|
|
|
var department = await _departmentApp.GetByUsernameAsync(userName).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (department != null) |
|
|
|
{ |
|
|
|
entity.DeptCode = department.Code; |
|
|
|
entity.DeptName = department.Name; |
|
|
|
} |
|
|
|
|
|
|
|
return (entites, deleteEntites); |
|
|
|
entity.Worker = userName; |
|
|
|
|
|
|
|
entity.BuildDate = DateTime.Now; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
protected async Task<BalanceDTO> CheckBalanceAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
/// <summary>
|
|
|
|
/// 赋值业务事务
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetRequestAutoPropertiesAsync(UnplannedReceiptRequest entity) |
|
|
|
{ |
|
|
|
var tranType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.UnplannedReceipt, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
|
|
|
|
|
entity.AutoCompleteJob = tranType.AutoCompleteJob; |
|
|
|
entity.AutoSubmit = tranType.AutoSubmitRequest; |
|
|
|
entity.AutoAgree = tranType.AutoAgreeRequest; |
|
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
|
|
|
protected virtual async Task<BalanceDTO> CheckBalanceAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var balance = await BalanceAclService.GetByItemLocationAndPackingAsync( |
|
|
|
string.Empty, |
|
|
@ -118,7 +203,7 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
return balance; |
|
|
|
} |
|
|
|
|
|
|
|
protected async Task CheckCaseCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
protected virtual async Task CheckCaseCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(importInput.CaseCode)) |
|
|
|
{ |
|
|
@ -161,7 +246,7 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
protected async Task<ItemBasicDTO> CheckItemBasicAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
protected virtual async Task<ItemBasicDTO> CheckItemBasicAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var item = await ItemBasicAclService.GetByCodeAsync(importInput.ItemCode).ConfigureAwait(false); |
|
|
|
if (item == null) |
|
|
@ -176,7 +261,7 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
return item; |
|
|
|
} |
|
|
|
|
|
|
|
protected async Task<LocationDTO> CheckLocationAsync(string locationCode, List<ValidationResult> validationRresult) |
|
|
|
protected virtual async Task<LocationDTO> CheckLocationAsync(string locationCode, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var location = await LocationAclService.GetByCodeAsync(locationCode).ConfigureAwait(false); |
|
|
|
if (location == null) |
|
|
@ -186,7 +271,7 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
return location; |
|
|
|
} |
|
|
|
|
|
|
|
protected async Task CheckOnceBusiCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
protected virtual async Task CheckOnceBusiCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(importInput.OnceBusiCode)) |
|
|
|
{ |
|
|
@ -208,7 +293,8 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
protected async Task CheckProjCapacityCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
|
|
|
|
protected virtual async Task CheckProjCapacityCodeAsync(UnplannedReceiptRequestImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var dict = await DictAclService.GetByCodeAsync(nameof(importInput.ProjCapacityCode)).ConfigureAwait(false); |
|
|
|
if (dict == null) |
|
|
@ -227,7 +313,8 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
protected async Task<TransactionTypeDTO> CheckTransactionTypeAsync(EnumTransType enumTransType, List<ValidationResult> validationRresult) |
|
|
|
|
|
|
|
protected virtual async Task<TransactionTypeDTO> CheckTransactionTypeAsync(EnumTransType enumTransType, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(enumTransType, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
if (transactionType == null) |
|
|
@ -237,116 +324,5 @@ public class UnplannedReceiptRequestForDongyangAppService : UnplannedReceiptRequ |
|
|
|
return transactionType; |
|
|
|
} |
|
|
|
|
|
|
|
protected override Func<UnplannedReceiptRequestImportInput, object> GetEntityExpression() |
|
|
|
{ |
|
|
|
return p => (1); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task ImportDataAsync(List<UnplannedReceiptRequest> entites, List<UnplannedReceiptRequest> deleteEntities) |
|
|
|
{ |
|
|
|
await _unplannedReceiptRequestManager.ImportDataAsync(entites, deleteEntities).ConfigureAwait(false); |
|
|
|
} |
|
|
|
private async Task SetDetailPropertiesAsync(UnplannedReceiptRequestDetail detail, UnplannedReceiptRequestImportInput input) |
|
|
|
{ |
|
|
|
var itemBasic = await ItemBasicAclService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (itemBasic != null) |
|
|
|
{ |
|
|
|
detail.ItemName = itemBasic.Name; |
|
|
|
detail.ItemDesc1 = itemBasic.Desc1; |
|
|
|
detail.ItemDesc2 = itemBasic.Desc2; |
|
|
|
detail.StdPackQty = itemBasic.StdPackQty; |
|
|
|
} |
|
|
|
|
|
|
|
var location = await LocationAclService.GetByCodeAsync(detail.LocationCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (location != null) |
|
|
|
{ |
|
|
|
detail.LocationErpCode = location.ErpLocationCode; |
|
|
|
detail.WarehouseCode = location.WarehouseCode; |
|
|
|
detail.Lot = string.Empty; |
|
|
|
detail.ContainerCode = string.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
detail.PackingCode = string.Empty; |
|
|
|
|
|
|
|
detail.Status = EnumInventoryStatus.OK; |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(input.OnceBusiCode)) |
|
|
|
{ |
|
|
|
var dict = await DictAclService.GetByCodeAsync(nameof(input.OnceBusiCode)).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (dict.Items != null && dict.Items.Count > 0) |
|
|
|
{ |
|
|
|
var item = dict.Items.FirstOrDefault(t => t.Code == input.OnceBusiCode); |
|
|
|
|
|
|
|
Check.NotNull(item, "次交易码", "次交易码不存在"); |
|
|
|
|
|
|
|
detail.SetProperty("OnceBusiCode", item.Code); |
|
|
|
detail.SetProperty("OnceBusiName", item.Name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(input.CaseCode)) |
|
|
|
{ |
|
|
|
var dict = await DictAclService.GetByCodeAsync(nameof(input.CaseCode)).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (dict.Items != null && dict.Items.Count > 0) |
|
|
|
{ |
|
|
|
var item = dict.Items.FirstOrDefault(t => t.Code == input.CaseCode); |
|
|
|
|
|
|
|
Check.NotNull(item, "专案代码", "专案代码不存在"); |
|
|
|
|
|
|
|
detail.SetProperty("CaseCode", item.Code); |
|
|
|
detail.SetProperty("CaseName", item.Name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(input.ProjCapacityCode)) |
|
|
|
{ |
|
|
|
var dict = await DictAclService.GetByCodeAsync(nameof(input.ProjCapacityCode)).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (dict.Items != null && dict.Items.Count > 0) |
|
|
|
{ |
|
|
|
var item = dict.Items.FirstOrDefault(t => t.Code == input.ProjCapacityCode); |
|
|
|
|
|
|
|
Check.NotNull(item, "项目分类代码", "项目分类代码不存在"); |
|
|
|
|
|
|
|
detail.SetProperty("ProjCapacityCode", item.Code); |
|
|
|
detail.SetProperty("ProjCapacityName", item.Name); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetEntityPropertiesAsync(UnplannedReceiptRequest entity, UnplannedReceiptRequestImportInput input) |
|
|
|
{ |
|
|
|
var userName = CurrentUser.GetUserName(); |
|
|
|
|
|
|
|
var department = await _departmentApp.GetByUsernameAsync(userName).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (department != null) |
|
|
|
{ |
|
|
|
entity.DeptCode = department.Code; |
|
|
|
entity.DeptName = department.Name; |
|
|
|
} |
|
|
|
|
|
|
|
entity.Worker = userName; |
|
|
|
|
|
|
|
entity.BuildDate = DateTime.Now; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetRequestAutoPropertiesAsync(UnplannedReceiptRequest entity) |
|
|
|
{ |
|
|
|
var tranType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.UnplannedReceipt, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
|
|
|
|
|
entity.AutoCompleteJob = tranType.AutoCompleteJob; |
|
|
|
entity.AutoSubmit = tranType.AutoSubmitRequest; |
|
|
|
entity.AutoAgree = tranType.AutoAgreeRequest; |
|
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|