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.
124 lines
4.4 KiB
124 lines
4.4 KiB
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.SettingManagement;
|
|
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}AQL")]
|
|
|
|
public class AQLAppService : SfsBaseDataAppServiceBase<AQL, AQLDTO, SfsBaseDataRequestInputBase, AQLEditInput, AQLImportInput>
|
|
, IAQLAppService
|
|
{
|
|
private readonly IAQLManager _manager;
|
|
private readonly IItemBasicRepository _itemBasicRepository;
|
|
private readonly ISupplierRepository _supplierRepository;
|
|
|
|
public AQLAppService(IAQLRepository repository
|
|
, IDistributedCache<AQLDTO> cache
|
|
, IAQLManager manager
|
|
, IItemBasicRepository itemBasicRepository
|
|
, ISupplierRepository supplierRepository
|
|
) : base(repository, cache)
|
|
{
|
|
base.CreatePolicyName = AQLPermissions.Create;
|
|
base.UpdatePolicyName = AQLPermissions.Update;
|
|
base.DeletePolicyName = AQLPermissions.Delete;
|
|
|
|
_manager = manager;
|
|
_itemBasicRepository = itemBasicRepository;
|
|
_supplierRepository = supplierRepository;
|
|
}
|
|
|
|
[HttpGet("get-aql")]
|
|
public virtual async Task<AQLDTO> GetAQLAsync(string itemCode, string supplierCode, decimal qty)
|
|
{
|
|
AQL entity = null;
|
|
if (await SettingManager.IsTrueAsync(BasedataSettings.AQL.UseAbcClass).ConfigureAwait(false))
|
|
{
|
|
var item = await _itemBasicRepository.FindAsync(p => p.Code == itemCode).ConfigureAwait(false);
|
|
if (item != null)
|
|
{
|
|
entity = await _repository.FindAsync(c =>
|
|
c.ItemCode == item.AbcClass
|
|
&& c.SupplierCode == item.AbcClass
|
|
&& c.FloorQty <= qty
|
|
&& c.CeilingQty >= qty).ConfigureAwait(false);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var list= await _repository.GetListAsync(c =>
|
|
c.ItemCode == itemCode
|
|
&& c.SupplierCode == supplierCode
|
|
&& c.FloorQty <= qty
|
|
&& c.CeilingQty >= qty).ConfigureAwait(false);
|
|
|
|
if (list.Count > 1)
|
|
{
|
|
throw new UserFriendlyException("物品质检标准信息配置的数量有重叠");
|
|
}
|
|
|
|
entity = list.First();
|
|
}
|
|
|
|
if (entity == null)
|
|
{
|
|
int.TryParse(await SettingManager.GetOrNullGlobalAsync(BasedataSettings.AQL.DefaultSampleQty).ConfigureAwait(false),
|
|
out var aqlDefaultSampleQty);
|
|
if (aqlDefaultSampleQty > 0)
|
|
{
|
|
entity = new AQL()
|
|
{
|
|
ItemCode = itemCode,
|
|
SupplierCode = supplierCode,
|
|
FloorQty = qty,
|
|
CeilingQty = qty,
|
|
SamplePercent = 0,
|
|
SampleQty = aqlDefaultSampleQty,
|
|
IsUsePercent = false
|
|
};
|
|
}
|
|
else
|
|
{
|
|
throw new UserFriendlyException($"没有找到供应商 {supplierCode} 物料 {itemCode},数量为 {qty} 的质检标准。");
|
|
}
|
|
}
|
|
|
|
var dto = ObjectMapper.Map<AQL, AQLDTO>(entity);
|
|
return dto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据物品编号 查询 返回集合
|
|
/// </summary>
|
|
/// <param name="itemCode"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("get-list-by-itemcode")]
|
|
public virtual async Task<List<AQLDTO>> GetListByItemCode(string itemCode)
|
|
{
|
|
var entitys = await _repository.GetListAsync(c => c.ItemCode == itemCode).ConfigureAwait(false);
|
|
var dtos = ObjectMapper.Map<List<AQL>, List<AQLDTO>>(entitys);
|
|
return dtos;
|
|
}
|
|
|
|
protected override async Task ValidateImportModelAsync(AQLImportInput 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);
|
|
}
|
|
|
|
}
|
|
|