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.
203 lines
8.7 KiB
203 lines
8.7 KiB
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;
|
|
using Win_in.Sfs.Basedata.Domain.Shared;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
|
|
namespace Win_in.Sfs.Basedata.Application;
|
|
|
|
[Authorize]
|
|
[Route($"{BasedataConsts.RootPath}position-code")]
|
|
|
|
public class PositionCodeAppService
|
|
: SfsBaseDataWithCodeAppServiceBase<PositionCode, PositionCodeDTO, SfsBaseDataRequestInputBase, PositionCodeEditInput, PositionCodeImportInput>
|
|
, IPositionCodeAppService
|
|
{
|
|
private readonly IPositionCodeManager _manager;
|
|
|
|
private new readonly IPositionCodeRepository _repository;
|
|
|
|
|
|
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)
|
|
{
|
|
var existEntity = await GetByCodeAsync(input.Code).ConfigureAwait(false);
|
|
if (existEntity != null)
|
|
{
|
|
throw new UserFriendlyException($"位置码{input.Code} 已存在!");
|
|
}
|
|
|
|
//var itemEntity = await _repository.FirstOrDefaultAsync(p => p.LocationCode == input.LocationCode && p.PartCode == input.PartCode && p.Type == input.Type).ConfigureAwait(false);
|
|
//if (itemEntity != null)
|
|
//{
|
|
// throw new UserFriendlyException($"类型{input.Type.ToString()}物品{input.PartCode}目标库位{input.LocationCode}已存在!");
|
|
//}
|
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false);
|
|
Check.NotNull(itemBasic, "ERP料号", $"物品 {input.PartCode} 不存在");
|
|
input.PartName = itemBasic.Name;
|
|
input.PartDesc = itemBasic.Desc1;
|
|
input.BasicUom = itemBasic.BasicUom;
|
|
|
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false);
|
|
Check.NotNull(location, "库位代码", $"库位 {input.LocationCode} 不存在");
|
|
|
|
input.LocationName = location.Name;
|
|
|
|
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} 未找到位置码信息");
|
|
}
|
|
var itemEntity = await _repository.FirstOrDefaultAsync(p => p.PartCode == input.PartCode && p.Code==input.Code).ConfigureAwait(false);
|
|
if (itemEntity != null)
|
|
{
|
|
throw new UserFriendlyException($"位置码{input.Code}已存在物品{input.PartCode}的信息 ");
|
|
}
|
|
|
|
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false);
|
|
Check.NotNull(itemBasic, "ERP料号", $"物品 {input.PartCode} 不存在");
|
|
|
|
entity.PartCode = input.PartCode;
|
|
entity.PartName = itemBasic.Name;
|
|
entity.PartDesc = itemBasic.Desc1;
|
|
|
|
|
|
var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false);
|
|
Check.NotNull(location, "库位代码", $"库位 {input.LocationCode} 不存在");
|
|
|
|
entity.LocationCode = input.LocationCode;
|
|
entity.LocationName = location.Name;
|
|
|
|
entity.StdPackQty = input.StdPackQty;
|
|
entity.BasicUom = input.BasicUom;
|
|
entity.Type = input.Type;
|
|
|
|
await _repository.UpdateAsync(entity).ConfigureAwait(false);
|
|
var dto = ObjectMapper.Map<PositionCode, PositionCodeDTO>(entity);
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
/// <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)
|
|
{
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(positionCode.PartCode).ConfigureAwait(false);
|
|
positionCode.PartName = itemBasic.Name;
|
|
positionCode.PartDesc = itemBasic.Desc1;
|
|
if (string.IsNullOrEmpty(positionCode.BasicUom)) positionCode.BasicUom = itemBasic.BasicUom;
|
|
switch (positionCode.Type)
|
|
{
|
|
case EnumPositionCodeType.InjectionIssue:
|
|
positionCode.Code = "S"+ positionCode.Code;
|
|
break;
|
|
case EnumPositionCodeType.CoatingIssue:
|
|
positionCode.Code = "P" + positionCode.Code;
|
|
break;
|
|
case EnumPositionCodeType.AssembleIssue:
|
|
positionCode.Code = "Z" + positionCode.Code;
|
|
break;
|
|
case EnumPositionCodeType.KITTING:
|
|
positionCode.Code = "K" + positionCode.Code;
|
|
break;
|
|
default:
|
|
positionCode.Code = positionCode.Type + positionCode.Code;
|
|
break;
|
|
}
|
|
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($"ERP料号{input.PartCode}已存在", new string[] { "ERP料号" }));
|
|
//}
|
|
//var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.PartCode).ConfigureAwait(false);
|
|
////如果类型选择为原料,校验ERP料号类型必须为原料,器具、KItting 的不用加校验
|
|
//if (input.Type == EnumRecommendType.RAW && itemBasic.Type != "10C02")
|
|
//{
|
|
// validationRresult.Add(new ValidationResult($"ERP料号{input.PartCode} ERP料号类型必须为原料", new string[] { "ERP料号类型" }));
|
|
//}
|
|
//var location = await LocationAppService.GetByCodeAsync(input.LocationCode).ConfigureAwait(false);
|
|
////如果类型选择为原料,库位的类型必须为原料库位
|
|
//if (input.Type==EnumRecommendType.RAW && 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.CheckLocationAsync(importInput.PartCode, importInput.LocationCode, validationRresult).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|