You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
9.0 KiB
205 lines
9.0 KiB
1 year ago
|
using System;
|
||
1 year ago
|
using System.Collections.Generic;
|
||
1 year ago
|
using System.ComponentModel.DataAnnotations;
|
||
1 year ago
|
using System.Linq;
|
||
1 year ago
|
using System.Threading.Tasks;
|
||
1 year ago
|
using DocumentFormat.OpenXml.Vml.Office;
|
||
1 year ago
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
1 year ago
|
using Microsoft.EntityFrameworkCore;
|
||
1 year ago
|
using Volo.Abp;
|
||
|
using Volo.Abp.Caching;
|
||
1 year ago
|
using Volo.Abp.Domain.Entities;
|
||
1 year ago
|
using Volo.Abp.Domain.Repositories;
|
||
1 year ago
|
using Volo.Abp.ObjectMapping;
|
||
1 year ago
|
using Volo.Abp.Uow;
|
||
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
||
|
using Win_in.Sfs.Basedata.Domain;
|
||
|
using Win_in.Sfs.Basedata.Domain.Shared;
|
||
1 year ago
|
using Win_in.Sfs.Shared.Domain.Shared;
|
||
1 year ago
|
|
||
|
namespace Win_in.Sfs.Basedata.Application;
|
||
|
|
||
|
[Authorize]
|
||
|
[Route($"{BasedataConsts.RootPath}position-code")]
|
||
|
|
||
|
public class PositionCodeAppService
|
||
|
: SfsBaseDataWithCodeAppServiceBase<PositionCode, PositionCodeDTO, SfsBaseDataRequestInputBase, PositionCodeEditInput, PositionCodeImportInput>
|
||
1 year ago
|
, IPositionCodeAppService
|
||
1 year ago
|
{
|
||
|
private readonly IPositionCodeManager _manager;
|
||
1 year ago
|
|
||
|
private new readonly IPositionCodeRepository _repository;
|
||
|
|
||
1 year ago
|
|
||
1 year ago
|
public PositionCodeAppService(IPositionCodeRepository repository,
|
||
|
IDistributedCache<PositionCodeDTO> cache, IPositionCodeManager manager) : base(repository, cache)
|
||
1 year ago
|
{
|
||
|
base.CreatePolicyName = CategoryPermissions.Create;
|
||
|
base.UpdatePolicyName = CategoryPermissions.Update;
|
||
|
base.DeletePolicyName = CategoryPermissions.Delete;
|
||
|
_manager = manager;
|
||
1 year ago
|
_repository = repository;
|
||
1 year ago
|
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
/// <summary>
|
||
|
/// 用来重写 新增实体
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
/// <exception cref="UserFriendlyException"></exception>
|
||
1 year ago
|
[HttpPost("")]
|
||
|
[UnitOfWork]
|
||
|
public override async Task<PositionCodeDTO> CreateAsync(PositionCodeEditInput input)
|
||
|
{
|
||
1 year ago
|
var existEntity = await GetByCodeAsync(input.Code).ConfigureAwait(false);
|
||
1 year ago
|
if (existEntity != null)
|
||
|
{
|
||
|
throw new UserFriendlyException($"{input.Code} 已存在");
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
var itemEntity = await _repository.FirstOrDefaultAsync(p => p.PartCode == input.PartCode).ConfigureAwait(false);
|
||
|
if(itemEntity != null)
|
||
|
{
|
||
|
throw new UserFriendlyException($"{input.PartCode} 物品已存在");
|
||
|
}
|
||
|
|
||
1 year ago
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false);
|
||
|
Check.NotNull(itemBasic, "物品代码", $"物品 {input.PartCode} 不存在");
|
||
1 year ago
|
//如果类型选择为原料,校验物料号类型必须为原料,器具、KItting 的不用加校验
|
||
|
if (input.Type == EnumRecommendType.W && itemBasic.Type != "10C02")
|
||
|
{
|
||
|
throw new UserFriendlyException($"{input.PartCode} 物料号类型必须为原料");
|
||
|
}
|
||
1 year ago
|
input.PartName = itemBasic.Name;
|
||
|
input.PartDesc = itemBasic.Desc1;
|
||
1 year ago
|
input.BasicUom = itemBasic.BasicUom;
|
||
1 year ago
|
input.StdPackQty = itemBasic.StdPackQty;
|
||
1 year ago
|
|
||
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false);
|
||
|
Check.NotNull(location, "库位代码", $"库位 {input.LocationCode} 不存在");
|
||
1 year ago
|
//如果类型选择为原料,库位的类型必须为原料库位
|
||
|
if (input.Type == EnumRecommendType.W && location.Type != EnumLocationType.RAW)
|
||
|
{
|
||
|
throw new UserFriendlyException($"{input.LocationCode} 库位的类型必须为原料库位");
|
||
|
}
|
||
1 year ago
|
input.LocationName = location.Name;
|
||
1 year ago
|
|
||
1 year ago
|
if(input.Type== EnumRecommendType.None)
|
||
1 year ago
|
{
|
||
1 year ago
|
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)
|
||
|
{
|
||
|
throw new UserFriendlyException($"{id} 未找到位置码信息");
|
||
1 year ago
|
}
|
||
1 year ago
|
var itemEntity = await _repository.FirstOrDefaultAsync(p => p.PartCode == input.PartCode && p.Code!=input.Code).ConfigureAwait(false);
|
||
|
if (itemEntity != null)
|
||
1 year ago
|
{
|
||
1 year ago
|
throw new UserFriendlyException($"{input.PartCode} 物品已存在");
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
|
|
||
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false);
|
||
|
Check.NotNull(itemBasic, "物品代码", $"物品 {input.PartCode} 不存在");
|
||
|
//如果类型选择为原料,校验物料号类型必须为原料,器具、KItting 的不用加校验
|
||
|
if (input.Type == EnumRecommendType.W && itemBasic.Type != "10C02")
|
||
1 year ago
|
{
|
||
1 year ago
|
throw new UserFriendlyException($"{input.PartCode} 物料号类型必须为原料");
|
||
1 year ago
|
}
|
||
1 year ago
|
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)
|
||
1 year ago
|
{
|
||
1 year ago
|
throw new UserFriendlyException($"{input.LocationCode} 库位的类型必须为原料库位");
|
||
1 year ago
|
}
|
||
1 year ago
|
entity.LocationName = location.Name;
|
||
1 year ago
|
|
||
1 year ago
|
await _repository.UpdateAsync(entity).ConfigureAwait(false);
|
||
|
var dto = ObjectMapper.Map<PositionCode, PositionCodeDTO>(entity);
|
||
|
|
||
|
return dto;
|
||
|
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
|
/// <summary>
|
||
|
/// 用来重写 导入数据时可以加工数据
|
||
|
/// </summary>
|
||
|
/// <param name="dictionary"></param>
|
||
|
/// <returns></returns>
|
||
|
protected override async Task<Dictionary<PositionCode, EntityState>> ImportProcessingEntityAsync(
|
||
|
Dictionary<PositionCode, EntityState> dictionary)
|
||
|
{
|
||
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key);
|
||
|
|
||
|
foreach (var positionCode in addList)
|
||
|
{
|
||
1 year ago
|
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;
|
||
1 year ago
|
positionCode.Code = positionCode.Type + positionCode.Code;
|
||
|
positionCode.CreatorId= CurrentUser.Id;
|
||
1 year ago
|
var location = await LocationAppService.GetByCodeAsync(positionCode.LocationCode).ConfigureAwait(false);
|
||
|
positionCode.LocationName = location.Name;
|
||
1 year ago
|
}
|
||
|
|
||
|
return dictionary;
|
||
|
}
|
||
|
|
||
1 year ago
|
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);
|
||
|
|
||
|
}
|
||
|
|
||
1 year ago
|
}
|