Browse Source

修改 生产线导入报错

dev_DY_CC
郑勃旭 4 months ago
parent
commit
52b8627525
  1. 6
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/ProductLineItems/Inputs/ProductionLineItemImportInput.cs
  2. 103
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/ProductionLineItems/ProductionLineItemAppService.cs

6
be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application.Contracts/ProductLineItems/Inputs/ProductionLineItemImportInput.cs

@ -49,19 +49,19 @@ public class ProductionLineItemImportInput : SfsBaseDataImportInputBase
/// <summary>
/// 原料库位
/// </summary>
[Display(Name = "原料库位Json集合")]
[Display(Name = "[来源]/")]
public string RawLocationCodeListJson { get; set; }
/// <summary>
/// 成品库位
/// </summary>
[Display(Name = "完工库位Json集合")]
[Display(Name = "[来源]")]
public string ProductLocationCodeListJson { get; set; }
/// <summary>
/// 线边库位
/// </summary>
[Display(Name = "线边库位Json集合")]
[Display(Name = "[完工]线")]
public string WipLocationCodeListJson { get; set; }
/// <summary>

103
be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/ProductionLineItems/ProductionLineItemAppService.cs

@ -3,22 +3,16 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.ExcelAc;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Caching;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Basedata.Domain;
using Win_in.Sfs.Basedata.Domain.Shared;
using Win_in.Sfs.Shared.Domain;
using Win_in.Sfs.Shared.Domain.Shared;
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store;
using static Win_in.Sfs.Basedata.Domain.BasedataSettings;
namespace Win_in.Sfs.Basedata.Application;
@ -28,11 +22,14 @@ public class ProductionLineItemAppService :
SfsBaseDataAppServiceBase<ProductionLineItem, ProductionLineItemDTO, SfsBaseDataRequestInputBase,
ProductionLineItemEditInput, ProductionLineItemImportInput>, IProductionLineItemAppService
{
private readonly IProductionLineAppService _productionLineAppService ;
private readonly ILocationAppService _locationAppService ;
private readonly IProductionLineAppService _productionLineAppService;
private readonly ILocationAppService _locationAppService;
private readonly IItemBasicAppService _itemBasicAppService;
public ProductionLineItemAppService(
IProductionLineItemRepository repository, IDistributedCache<ProductionLineItemDTO> cache, IProductionLineAppService productionLineAppService, ILocationAppService locationAppService, IItemBasicAppService itemBasicAppService
IProductionLineItemRepository repository, IDistributedCache<ProductionLineItemDTO> cache,
IProductionLineAppService productionLineAppService, ILocationAppService locationAppService,
IItemBasicAppService itemBasicAppService
) : base(repository, cache)
{
base.CreatePolicyName = ProductionLineItemPermissions.Create;
@ -40,7 +37,7 @@ public class ProductionLineItemAppService :
base.DeletePolicyName = ProductionLineItemPermissions.Delete;
_productionLineAppService = productionLineAppService;
_locationAppService = locationAppService;
_itemBasicAppService= itemBasicAppService;
_itemBasicAppService = itemBasicAppService;
}
[HttpPost("upsert")]
@ -49,22 +46,25 @@ public class ProductionLineItemAppService :
var entity = ObjectMapper.Map<ProductionLineItemEditInput, ProductionLineItem>(input);
await _repository.UpdateAsync(entity).ConfigureAwait(false);
}
/// <summary>
/// 用来重写 导入数据时可以加工数据
/// 用来重写 导入数据时可以加工数据
/// </summary>
/// <param name="dictionary"></param>
/// <returns></returns>
protected override async Task<Dictionary<ProductionLineItem, EntityState>> ImportProcessingEntityAsync(Dictionary<ProductionLineItem, EntityState> dictionary)
protected override async Task<Dictionary<ProductionLineItem, EntityState>> ImportProcessingEntityAsync(
Dictionary<ProductionLineItem, EntityState> dictionary)
{
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key);
foreach (var list in addList)
{
if (!string.IsNullOrEmpty(list.RawLocationCodeListJson))
{
var rawlocationcodelist = list.RawLocationCodeListJson.Split(",");
list.RawLocationCodeListJson = JsonSerializer.Serialize(rawlocationcodelist);
{
var rawlocationcodelist = list.RawLocationCodeListJson.Split(",");
list.RawLocationCodeListJson = JsonSerializer.Serialize(rawlocationcodelist);
}
if (!string.IsNullOrEmpty(list.ProductLocationCodeListJson))
{
var productlocationcodelist = list.ProductLocationCodeListJson.Split(",");
@ -76,42 +76,49 @@ public class ProductionLineItemAppService :
var wiplocationcodelist = list.WipLocationCodeListJson.Split(",");
list.WipLocationCodeListJson = JsonSerializer.Serialize(wiplocationcodelist);
}
var baseItem= await _itemBasicAppService.GetByCodeAsync(list.ItemCode).ConfigureAwait(false);
var baseItem = await _itemBasicAppService.GetByCodeAsync(list.ItemCode).ConfigureAwait(false);
list.ItemName = baseItem?.Name;
list.ItemDesc1 = baseItem?.Desc1;
list.ItemDesc2 = baseItem?.Desc2;
}
return dictionary;
}
protected override async Task ValidateImportModelAsync(ProductionLineItemImportInput importInput,
List<ValidationResult> validationRresult)
{
await base.ValidateImportModelAsync(importInput, validationRresult).ConfigureAwait(false);
await CheckItemBasicItemCodeAsync(importInput.ItemCode, validationRresult).ConfigureAwait(false);
await CheckProductionLineProdLineCodeAsync(importInput.ProdLineCode, validationRresult).ConfigureAwait(false);
await CheckSameItem(importInput.ProdLineCode, importInput.ItemCode, validationRresult).ConfigureAwait(false);
CheckProductionLineProdLineCodeJsonAsync(importInput.RawLocationCodeListJson, validationRresult);
CheckProductionLineProdLineCodeJsonAsync(importInput.ProductLocationCodeListJson, validationRresult);
CheckProductionLineProdLineCodeJsonAsync(importInput.WipLocationCodeListJson, validationRresult);
await CheckSameItemAsync(importInput.ProdLineCode, importInput.ItemCode, validationRresult)
.ConfigureAwait(false);
CheckProductionLineProdLineCodeJsonAsync(importInput,validationRresult);
}
private async Task CheckSameItem(string ProdLineCode,string ItemCode, List<ValidationResult> validationRresult)
private async Task CheckSameItemAsync(string prodLineCode, string ItemCode,
List<ValidationResult> validationRresult)
{
var item =await _repository.FirstOrDefaultAsync(r=>r.ProdLineCode== ProdLineCode&&r.ItemCode==ItemCode).ConfigureAwait(false);
if (item!=null)
{
validationRresult.Add(new ValidationResult($"生产线{ProdLineCode}物料号{ItemCode}已存在", new string[] { "生产线", "物料号" }));
var item = await _repository.FirstOrDefaultAsync(r => r.ProdLineCode == prodLineCode && r.ItemCode == ItemCode)
.ConfigureAwait(false);
if (item != null)
{
validationRresult.Add(new ValidationResult($"生产线{prodLineCode}物料号{ItemCode}已存在", new[] { "生产线", "物料号" }));
}
}
private void CheckProductionLineProdLineCodeJsonAsync(string locationCodeList, List<ValidationResult> validationRresult)
private void CheckProductionLineProdLineCodeJsonAsync(ProductionLineItemImportInput input ,
List<ValidationResult> validationRresult)
{
if (string.IsNullOrEmpty(locationCodeList))
if (string.IsNullOrEmpty(input.ProductLocationCodeListJson)&&
string.IsNullOrEmpty(input.RawLocationCodeListJson)&&
string.IsNullOrEmpty(input.WipLocationCodeListJson))
{
validationRresult.Add(new ValidationResult($"请维护生产线和库位关系"));
validationRresult.Add(new ValidationResult("[来源]成品/半成品库位 或 [来源]原材料库位 或 [完工]线边库位 不能都为空"));
}
}
[HttpPost("get-by-product")]
public virtual async Task<List<ProductionLineItemDTO>> GetByProductLineCodeAsync(string productLineCode)
{
@ -124,30 +131,34 @@ public class ProductionLineItemAppService :
string itemCode)
{
var entity = await _repository
.FirstOrDefaultAsync(p => p.ProdLineCode == productLineCode && p.ItemCode == itemCode).ConfigureAwait(false);
.FirstOrDefaultAsync(p => p.ProdLineCode == productLineCode && p.ItemCode == itemCode)
.ConfigureAwait(false);
return ObjectMapper.Map<ProductionLineItem, ProductionLineItemDTO>(entity);
}
[HttpPost("get-by-productlinecode-and-itemcode-and-erplocationcode-async")]
public virtual async Task<List<string>> GetByProductLineCodeAndItemCodeAndErpLocationCodeAsync(List<EnumLocationType> locationType, string erpLocationCodes,string itemCode)
public virtual async Task<List<string>> GetByProductLineCodeAndItemCodeAndErpLocationCodeAsync(
List<EnumLocationType> locationType, string erpLocationCodes, string itemCode)
{
List<string> list = new List<string>();
var locations= await _locationAppService.GetListByTypesAndErpCodeAsync(locationType, erpLocationCodes).ConfigureAwait(false);
var list = new List<string>();
var locations = await _locationAppService.GetListByTypesAndErpCodeAsync(locationType, erpLocationCodes)
.ConfigureAwait(false);
if (locations.Count <= 0)
{
throw new UserFriendlyException($"未维护储位基础信息!");
throw new UserFriendlyException("未维护储位基础信息!");
}
else
var pls = await _productionLineAppService.GetByLocationCodesAsync(locations.Select(r => r.Code).ToList())
.ConfigureAwait(false);
var plscode = pls.Select(r => r.Code).ToList();
var entitys = await _repository.GetListAsync(r => r.ItemCode == itemCode && plscode.Contains(r.ProdLineCode))
.ConfigureAwait(false);
foreach (var entity in entitys)
{
var pls= await _productionLineAppService.GetByLocationCodesAsync(locations.Select(r=>r.Code).ToList()).ConfigureAwait(false);
var plscode = pls.Select(r => r.Code).ToList();
var entitys= await _repository.GetListAsync(r => r.ItemCode == itemCode && plscode.Contains(r.ProdLineCode)).ConfigureAwait(false);
foreach (var entity in entitys)
{
var locationcodes= JsonSerializer.Deserialize<List<string>>(entity.ProductLocationCodeListJson);
list.AddRange(locationcodes);
}
var locationcodes = JsonSerializer.Deserialize<List<string>>(entity.ProductLocationCodeListJson);
list.AddRange(locationcodes);
}
return list;
}
}

Loading…
Cancel
Save