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.
115 lines
4.2 KiB
115 lines
4.2 KiB
2 years ago
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel.DataAnnotations;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
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.Settings;
|
||
|
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}item-quality")]
|
||
|
|
||
|
public class ItemQualityAppService : SfsBaseDataAppServiceBase<ItemQuality, ItemQualityDTO, SfsBaseDataRequestInputBase, ItemQualityEditInput, ItemQualityImportInput>
|
||
|
, IItemQualityAppService
|
||
|
{
|
||
|
private readonly ISupplierAppService _supplierAppService;
|
||
|
|
||
|
private readonly IItemQualityManager _manager;
|
||
|
private readonly IItemBasicRepository _itemBasicRepository;
|
||
|
|
||
|
public ItemQualityAppService(
|
||
|
IItemQualityRepository repository
|
||
|
, IDistributedCache<ItemQualityDTO> cache
|
||
|
, ISupplierAppService supplierAppService
|
||
|
, IItemQualityManager manager
|
||
|
, IItemBasicRepository itemBasicRepository
|
||
|
) : base(repository, cache)
|
||
|
{
|
||
|
|
||
|
base.CreatePolicyName = ItemQualityPermissions.Create;
|
||
|
base.UpdatePolicyName = ItemQualityPermissions.Update;
|
||
|
base.DeletePolicyName = ItemQualityPermissions.Delete;
|
||
|
_supplierAppService = supplierAppService;
|
||
|
_manager = manager;
|
||
|
_itemBasicRepository = itemBasicRepository;
|
||
|
}
|
||
|
|
||
|
[HttpGet("get-by-itemcode")]
|
||
|
public virtual async Task<ItemQualityDTO> GetByItemCodeAsync(string itemCode, string supplierCode)
|
||
|
{
|
||
|
if (await SettingManager.IsTrueAsync(BasedataSettings.AQL.UseAbcClass).ConfigureAwait(false))
|
||
|
{
|
||
|
var item = await _itemBasicRepository.FindAsync(p => p.Code == itemCode).ConfigureAwait(false);
|
||
|
|
||
|
if (item.AbcClass == "A")
|
||
|
{
|
||
|
return BuildExamptItemQuality(itemCode, supplierCode);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var entity = (await _repository.FirstOrDefaultAsync(c => c.ItemCode == itemCode && c.SupplierCode == supplierCode).ConfigureAwait(false));
|
||
|
if (entity == null)
|
||
|
{
|
||
|
throw new UserFriendlyException($"供应商 {supplierCode} 的物料 {itemCode} 没有配置质量信息");
|
||
|
}
|
||
|
if (entity == null)
|
||
|
{
|
||
|
if (await SettingManager.IsTrueAsync(BasedataSettings.ItemQuality.NotFoundReturnExempt).ConfigureAwait(false))
|
||
|
{
|
||
|
return BuildExamptItemQuality(itemCode, supplierCode);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
var dto = ObjectMapper.Map<ItemQuality, ItemQualityDTO>(entity);
|
||
|
return dto;
|
||
|
}
|
||
|
|
||
|
throw new UserFriendlyException($"供应商 {supplierCode} 的物料 {itemCode} 没有配置质量信息");
|
||
|
|
||
|
}
|
||
|
|
||
|
private ItemQualityDTO BuildExamptItemQuality(string itemCode, string supplierCode)
|
||
|
{
|
||
|
var entity = new ItemQuality()
|
||
|
{
|
||
|
ItemCode = itemCode,
|
||
|
SupplierCode = supplierCode,
|
||
|
Status = EnumStatus.Open,
|
||
|
InspectType = EnumInspectType.Exempt,
|
||
|
};
|
||
|
var dto = ObjectMapper.Map<ItemQuality, ItemQualityDTO>(entity);
|
||
|
return dto;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据物品编号 查询 返回集合
|
||
|
/// </summary>
|
||
|
/// <param name="itemCode"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpGet("get-list-by-itemcode")]
|
||
|
public virtual async Task<List<ItemQualityDTO>> GetListByItemCode(string itemCode)
|
||
|
{
|
||
|
var entitys = await _repository.GetListAsync(c => c.ItemCode == itemCode).ConfigureAwait(false);
|
||
|
var dtos = ObjectMapper.Map<List<ItemQuality>, List<ItemQualityDTO>>(entitys);
|
||
|
return dtos;
|
||
|
}
|
||
|
|
||
|
protected override async Task ValidateImportModelAsync(ItemQualityImportInput importInput, List<ValidationResult> validationRresult)
|
||
|
{
|
||
|
await base.ValidateImportModelAsync(importInput, validationRresult).ConfigureAwait(false);
|
||
|
await base.CheckItemBasicItemCodeAsync(importInput.ItemCode, validationRresult).ConfigureAwait(false);
|
||
|
await base.CheckSupplierCodeAsync(importInput.SupplierCode, validationRresult).ConfigureAwait(false);
|
||
|
}
|
||
|
}
|