|
|
@ -1,12 +1,17 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Vml.Office; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.ObjectMapping; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Basedata.Domain; |
|
|
@ -23,18 +28,27 @@ public class PositionCodeAppService |
|
|
|
, IPositionCodeAppService |
|
|
|
{ |
|
|
|
private readonly IPositionCodeManager _manager; |
|
|
|
|
|
|
|
private new readonly IPositionCodeRepository _repository; |
|
|
|
|
|
|
|
public PositionCodeAppService(IPositionCodeRepository repository, IDistributedCache<PositionCodeDTO> cache, IPositionCodeManager manager) : base(repository, cache) |
|
|
|
|
|
|
|
public PositionCodeAppService(IPositionCodeRepository repository, |
|
|
|
IDistributedCache<PositionCodeDTO> cache, IPositionCodeManager manager) : base(repository, cache) |
|
|
|
{ |
|
|
|
base.CreatePolicyName = CategoryPermissions.Create; |
|
|
|
base.UpdatePolicyName = CategoryPermissions.Update; |
|
|
|
base.DeletePolicyName = CategoryPermissions.Delete; |
|
|
|
_manager = manager; |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 新增实体
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
[HttpPost("")] |
|
|
|
[UnitOfWork] |
|
|
|
public override async Task<PositionCodeDTO> CreateAsync(PositionCodeEditInput input) |
|
|
@ -53,33 +67,82 @@ public class PositionCodeAppService |
|
|
|
|
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false); |
|
|
|
Check.NotNull(itemBasic, "物品代码", $"物品 {input.PartCode} 不存在"); |
|
|
|
//如果类型选择为原料,校验物料号类型必须为原料,器具、KItting 的不用加校验
|
|
|
|
if (input.Type == EnumRecommendType.W && itemBasic.Type != "10C02") |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{input.PartCode} 物料号类型必须为原料"); |
|
|
|
} |
|
|
|
input.PartName = itemBasic.Name; |
|
|
|
input.PartDesc = itemBasic.Desc1; |
|
|
|
input.BasicUom = itemBasic.BasicUom; |
|
|
|
input.StdPackQty = itemBasic.StdPackQty; |
|
|
|
|
|
|
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false); |
|
|
|
Check.NotNull(location, "库位代码", $"库位 {input.LocationCode} 不存在"); |
|
|
|
//如果类型选择为原料,库位的类型必须为原料库位
|
|
|
|
if (input.Type == EnumRecommendType.W && location.Type != EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{input.LocationCode} 库位的类型必须为原料库位"); |
|
|
|
} |
|
|
|
input.LocationName = location.Name; |
|
|
|
|
|
|
|
if(input.Code.Contains('W')) |
|
|
|
if(input.Type== EnumRecommendType.None) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"{input.Type} 位置码类型不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
return await base.CreateAsync(input).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 用来重写 更新实体
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id"></param>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
[HttpPut] |
|
|
|
[Route("{id}")] |
|
|
|
public override async Task<PositionCodeDTO> UpdateAsync(Guid id, PositionCodeEditInput input) |
|
|
|
{ |
|
|
|
var entity = await _repository.GetAsync(id).ConfigureAwait(false); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
input.Type = EnumRecommendType.W; |
|
|
|
throw new UserFriendlyException($"{id} 未找到位置码信息"); |
|
|
|
} |
|
|
|
else if (input.Code.Contains('Q')) |
|
|
|
var itemEntity = await _repository.FirstOrDefaultAsync(p => p.PartCode == input.PartCode && p.Code!=input.Code).ConfigureAwait(false); |
|
|
|
if (itemEntity != null) |
|
|
|
{ |
|
|
|
input.Type = EnumRecommendType.Q; |
|
|
|
throw new UserFriendlyException($"{input.PartCode} 物品已存在"); |
|
|
|
} |
|
|
|
else if(input.Code.Contains('K')) |
|
|
|
|
|
|
|
|
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false); |
|
|
|
Check.NotNull(itemBasic, "物品代码", $"物品 {input.PartCode} 不存在"); |
|
|
|
//如果类型选择为原料,校验物料号类型必须为原料,器具、KItting 的不用加校验
|
|
|
|
if (input.Type == EnumRecommendType.W && itemBasic.Type != "10C02") |
|
|
|
{ |
|
|
|
input.Type = EnumRecommendType.K; |
|
|
|
throw new UserFriendlyException($"{input.PartCode} 物料号类型必须为原料"); |
|
|
|
} |
|
|
|
else |
|
|
|
entity.PartName = itemBasic.Name; |
|
|
|
entity.PartDesc = itemBasic.Desc1; |
|
|
|
entity.BasicUom = itemBasic.BasicUom; |
|
|
|
entity.StdPackQty = itemBasic.StdPackQty; |
|
|
|
|
|
|
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false); |
|
|
|
Check.NotNull(location, "库位代码", $"库位 {input.LocationCode} 不存在"); |
|
|
|
//如果类型选择为原料,库位的类型必须为原料库位
|
|
|
|
if (input.Type == EnumRecommendType.W && location.Type!= EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
input.Type = EnumRecommendType.None; |
|
|
|
throw new UserFriendlyException($"{input.LocationCode} 库位的类型必须为原料库位"); |
|
|
|
} |
|
|
|
entity.LocationName = location.Name; |
|
|
|
|
|
|
|
await _repository.UpdateAsync(entity).ConfigureAwait(false); |
|
|
|
var dto = ObjectMapper.Map<PositionCode, PositionCodeDTO>(entity); |
|
|
|
|
|
|
|
return dto; |
|
|
|
|
|
|
|
return await base.CreateAsync(input).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -94,11 +157,48 @@ public class PositionCodeAppService |
|
|
|
|
|
|
|
foreach (var positionCode in addList) |
|
|
|
{ |
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(positionCode.PartCode).ConfigureAwait(false); |
|
|
|
positionCode.PartName = itemBasic.Name; |
|
|
|
positionCode.PartDesc = itemBasic.Desc1; |
|
|
|
positionCode.BasicUom = itemBasic.BasicUom; |
|
|
|
positionCode.StdPackQty = itemBasic.StdPackQty; |
|
|
|
positionCode.Code = positionCode.Type + positionCode.Code; |
|
|
|
positionCode.CreatorId= CurrentUser.Id; |
|
|
|
var location = await LocationAppService.GetByCodeAsync(positionCode.LocationCode).ConfigureAwait(false); |
|
|
|
positionCode.LocationName = location.Name; |
|
|
|
} |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task CheckPositionCodeInputAsync(PositionCodeImportInput input, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
var itemEntity = await _repository.FirstOrDefaultAsync(p => p.PartCode == input.PartCode && p.Code != input.Code).ConfigureAwait(false); |
|
|
|
if (itemEntity != null) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"物品代码{input.PartCode}已存在", new string[] { "物品代码" })); |
|
|
|
} |
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false); |
|
|
|
//如果类型选择为原料,校验物料号类型必须为原料,器具、KItting 的不用加校验
|
|
|
|
if (input.Type == EnumRecommendType.W && itemBasic.Type != "10C02") |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"物品代码{input.PartCode} 物料号类型必须为原料", new string[] { "物料号类型" })); |
|
|
|
} |
|
|
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false); |
|
|
|
//如果类型选择为原料,库位的类型必须为原料库位
|
|
|
|
if (input.Type==EnumRecommendType.W && location.Type != EnumLocationType.RAW) |
|
|
|
{ |
|
|
|
validationRresult.Add(new ValidationResult($"库位代码{input.LocationCode} 库位的类型必须为原料库位", new string[] { "库位类型" })); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override async Task ValidateImportModelAsync(PositionCodeImportInput importInput, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
await base.ValidateImportModelAsync(importInput, validationRresult).ConfigureAwait(false); |
|
|
|
await CheckPositionCodeInputAsync(importInput, validationRresult).ConfigureAwait(false); |
|
|
|
await base.CheckItemBasicItemCodeAsync(importInput.PartCode, validationRresult).ConfigureAwait(false); |
|
|
|
await base.CheckRawLocationAsync(importInput.LocationCode, validationRresult).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|