using System.Collections.Generic; using System.ComponentModel.DataAnnotations; 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 , IAQLAppService { private readonly IAQLManager _manager; private readonly IItemBasicRepository _itemBasicRepository; private readonly ISupplierRepository _supplierRepository; public AQLAppService(IAQLRepository repository , IDistributedCache 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 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 { entity = await _repository.FindAsync(c => c.ItemCode == itemCode && c.SupplierCode == supplierCode && c.FloorQty <= qty && c.CeilingQty >= qty).ConfigureAwait(false); } 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(entity); return dto; } /// /// 根据物品编号 查询 返回集合 /// /// /// [HttpGet("get-list-by-itemcode")] public virtual async Task> GetListByItemCode(string itemCode) { var entitys = await _repository.GetListAsync(c => c.ItemCode == itemCode).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entitys); return dtos; } protected override async Task ValidateImportModelAsync(AQLImportInput importInput, List validationRresult) { await base.ValidateImportModelAsync(importInput, validationRresult).ConfigureAwait(false); await base.CheckItemBasicItemCodeAsync(importInput.ItemCode, validationRresult).ConfigureAwait(false); await base.CheckSupplierCodeAsync(importInput.SupplierCode, validationRresult).ConfigureAwait(false); } }