Browse Source

[fix]统一返回信息

master
贾荣国 2 years ago
parent
commit
5ef0425cc4
  1. 88
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Asns/X12AsnAppService.cs

88
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 System.Security.Cryptography;
using IdentityModel; using IdentityModel;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
{ {
@ -94,12 +95,22 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet] [HttpGet]
[Route("unread-list")] [Route("unread-list")]
public async Task<ListResultDto<X12AsnDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus) public async Task<ListResultDto<X12AsnDTO>> GetUnreadListAsync(string site, int count, bool autoUpdateStatus)
{
try
{ {
Validator.CheckSite(_tenantRepository, site); Validator.CheckSite(_tenantRepository, site);
if (count < 1 || count > _options.Value.MaxCount) if (count < 1 || count > _options.Value.MaxCount)
{ {
throw new AbpValidationException($"Count must bigger than 1 and smaller than {_options.Value.MaxCount}"); throw new UserFriendlyException($"Count must between 1 and {_options.Value.MaxCount}");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
} }
var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus); var entities = await _x12AsnRepository.GetUnreadListAsync(site, count, autoUpdateStatus);
@ -121,12 +132,22 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet] [HttpGet]
[Route("between-uid")] [Route("between-uid")]
public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, long beginUid, long endUid) public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, long beginUid, long endUid)
{
try
{ {
Validator.CheckSite(_tenantRepository, site); Validator.CheckSite(_tenantRepository, site);
if (endUid < beginUid) if (endUid < beginUid)
{ {
throw new AbpValidationException("beginUid can not bigger than endUid"); throw new UserFriendlyException("beginUid can not bigger than endUid");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
} }
var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid); var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.UID >= beginUid && p.UID <= endUid);
@ -147,14 +168,23 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet] [HttpGet]
[Route("between-date")] [Route("between-date")]
public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate) public async Task<ListResultDto<X12AsnDTO>> GetListAsync(string site, DateTime beginDate, DateTime endDate)
{
try
{ {
Validator.CheckSite(_tenantRepository, site); Validator.CheckSite(_tenantRepository, site);
if (endDate < beginDate) if (endDate < beginDate)
{ {
throw new AbpValidationException("beginDate can not after endDate"); throw new UserFriendlyException("beginDate can not after endDate");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
} }
var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate); var entities = await _x12AsnRepository.GetListAsync(p => p.Site == site && p.EffectiveDate >= beginDate && p.EffectiveDate <= endDate);
var dtos = BuildDtos(entities); var dtos = BuildDtos(entities);
@ -172,17 +202,27 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet] [HttpGet]
[Route("by-uid")] [Route("by-uid")]
public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, long uid) public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, long uid)
{
X12Asn entity;
try
{ {
Validator.CheckSite(_tenantRepository, site); 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<ValidationResult>
{
new(ex.Message)
});
} }
var dto = BuildDto(entity); var dto = BuildDto(entity);
return dto; return dto;
@ -198,16 +238,27 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpGet] [HttpGet]
[Route("by-number")] [Route("by-number")]
public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, string number) public async Task<ActionResult<X12AsnDTO>> GetAsync(string site, string number)
{
X12Asn entity;
try
{ {
Validator.CheckSite(_tenantRepository, site); 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 AbpValidationException($"ASN of {number} in {site} is not found"); throw new UserFriendlyException($"ASN of {number} in {site} is not found");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
} }
var dto = BuildDto(entity); var dto = BuildDto(entity);
return dto; return dto;
@ -231,16 +282,27 @@ namespace Win_in.Sfs.Scp.WebApi
[HttpPost] [HttpPost]
[Route("update-status")] [Route("update-status")]
public async Task<ActionResult<X12AsnDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status) public async Task<ActionResult<X12AsnDTO>> UpdateStatusAsync(string site, string number, EnumExchangeDataStatus status)
{
X12Asn entity;
try
{ {
Validator.CheckSite(_tenantRepository, site); 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 AbpValidationException($"ASN of {number} in {site} is not found"); throw new UserFriendlyException($"ASN of {number} in {site} is not found");
}
}
catch (Exception ex)
{
throw new AbpValidationException(new List<ValidationResult>
{
new(ex.Message)
});
} }
var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status); var result = await _x12AsnRepository.UpdateStatusAsync(entity.Id, status);
var dto = BuildDto(result); var dto = BuildDto(result);

Loading…
Cancel
Save