From 5ef0425cc45797128279470ec0a38b81434a33f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=8D=A3=E5=9B=BD?= Date: Mon, 23 May 2022 11:47:18 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E7=BB=9F=E4=B8=80=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Asns/X12AsnAppService.cs | 116 ++++++++++++++---- 1 file changed, 89 insertions(+), 27 deletions(-) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs index 64e3bb2..c0fbd9b 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs @@ -28,6 +28,7 @@ using Volo.Abp.Domain.Entities; using System.Security.Cryptography; using IdentityModel; using Microsoft.Extensions.Options; +using Volo.Abp; namespace Win_in.Sfs.Scp.WebApi { @@ -47,7 +48,7 @@ namespace Win_in.Sfs.Scp.WebApi public X12AsnAppService( IX12AsnRepository repository , ITenantRepository tenantRepository - , IOptions options + , IOptions options ) : base(repository) { @@ -95,11 +96,21 @@ namespace Win_in.Sfs.Scp.WebApi [Route("unread-list")] public async Task> GetUnreadListAsync(string site, int count, bool autoUpdateStatus) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (count < 1 || count > _options.Value.MaxCount) + if (count < 1 || count > _options.Value.MaxCount) + { + throw new UserFriendlyException($"Count must between 1 and {_options.Value.MaxCount}"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"Count must bigger than 1 and smaller than {_options.Value.MaxCount}"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus); @@ -122,11 +133,21 @@ namespace Win_in.Sfs.Scp.WebApi [Route("between-uid")] public async Task> GetListAsync(string site, long beginUid, long endUid) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (endUid < beginUid) + if (endUid < beginUid) + { + throw new UserFriendlyException("beginUid can not bigger than endUid"); + } + } + catch (Exception ex) { - throw new AbpValidationException("beginUid can not bigger than endUid"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid); @@ -148,13 +169,22 @@ namespace Win_in.Sfs.Scp.WebApi [Route("between-date")] public async Task> GetListAsync(string site, DateTime beginDate, DateTime endDate) { - Validator.CheckSite(_tenantRepository, site); + try + { + Validator.CheckSite(_tenantRepository, site); - if (endDate < beginDate) + if (endDate < beginDate) + { + throw new UserFriendlyException("beginDate can not after endDate"); + } + } + catch (Exception ex) { - throw new AbpValidationException("beginDate can not after endDate"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate); var dtos = BuildDtos(entities); @@ -173,16 +203,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("by-uid")] public async Task> GetAsync(string site, long uid) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid); + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.UID == uid); - if (entity == null) - { + if (entity == null) + { - throw new AbpValidationException($"ASN of {uid} in {site} is not found"); + throw new UserFriendlyException($"ASN of {uid} in {site} is not found"); + } + } + catch (Exception ex) + { + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var dto = BuildDto(entity); return dto; @@ -199,15 +239,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("by-number")] public async Task> GetAsync(string site, string number) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); - if (entity == null) + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); + + if (entity == null) + { + throw new UserFriendlyException($"ASN of {number} in {site} is not found"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"ASN of {number} in {site} is not found"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var dto = BuildDto(entity); return dto; @@ -232,15 +283,26 @@ namespace Win_in.Sfs.Scp.WebApi [Route("update-status")] public async Task> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status) { - Validator.CheckSite(_tenantRepository, site); + X12Asn entity; + try + { + Validator.CheckSite(_tenantRepository, site); + - var entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); + entity = await _x12AsnRepository.FirstOrDefaultAsync(p => p.Site == site && p.BillNum == number); - if (entity == null) + if (entity == null) + { + throw new UserFriendlyException($"ASN of {number} in {site} is not found"); + } + } + catch (Exception ex) { - throw new AbpValidationException($"ASN of {number} in {site} is not found"); + throw new AbpValidationException(new List + { + new(ex.Message) + }); } - var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status); var dto = BuildDto(result);