验证逻辑完善

master
zhangxiaofeng 5 months ago
parent eafa1bb376
commit 6a6da9e872

@ -153,8 +153,11 @@ namespace EntrustSettle.Api.Controllers
//[UseTran]
public async Task<MessageModel<List<OrderSubmitResultDto>>> Submit(OrderSubmitDto inputDto)
{
var validator = new OrderSubmitDtoValidator();
validator.ValidateAndThrow(inputDto);
var validateResult = new OrderSubmitDtoValidator().Validate(inputDto);
if (!validateResult.IsValid)
{
throw new ArgumentException(validateResult.ToString("、"));
}
// 订单信息保存
inputDto.MblnoList = inputDto.MblnoList.Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToArray();
@ -342,7 +345,11 @@ namespace EntrustSettle.Api.Controllers
[HttpPost]
public async Task<MessageModel> ChangeStatus(ChangeStatusDto changeStatusDto)
{
new ChangeStatusDtoValidator().ValidateAndThrow(changeStatusDto);
var validateResult = new ChangeStatusDtoValidator().Validate(changeStatusDto);
if (!validateResult.IsValid)
{
throw new ArgumentException(validateResult.ToString("、"));
}
var order = await orderService.QueryById(changeStatusDto.Id);
if (order == null)
@ -877,7 +884,11 @@ namespace EntrustSettle.Api.Controllers
[HttpPost]
public async Task<MessageModel> ApplyInvoice(ApplyInvoiceDto input)
{
new ApplyInvoiceValidator().ValidateAndThrow(input);
var validateResult = new ApplyInvoiceValidator().Validate(input);
if (!validateResult.IsValid)
{
throw new ArgumentException(validateResult.ToString("、"));
}
if (input.OrderIdList?.Any() != true)
{

@ -32,13 +32,6 @@ namespace EntrustSettle.Model.Validator
//RuleFor(x => x.Remark).MaximumLength(2000).WithMessage("备注过长");
}
}
public class FileTypeEnumValidator : AbstractValidator<FileTypeEnum>
{
public FileTypeEnumValidator()
{
RuleFor(x => x).IsInEnum();
}
}
public class ChangeStatusDtoValidator : AbstractValidator<ChangeStatusDto>
{
public ChangeStatusDtoValidator()
@ -50,12 +43,12 @@ namespace EntrustSettle.Model.Validator
{
public ApplyInvoiceValidator()
{
RuleFor(x => x.CompanyName).NotNull().NotEmpty().WithMessage("公司全称不能为空");
RuleFor(x => x.Address).NotNull().NotEmpty().WithMessage("地址不能为空");
RuleFor(x => x.TaxCode).NotNull().NotEmpty().WithMessage("税号不能为空");
RuleFor(x => x.Tel).NotNull().NotEmpty().WithMessage("电话不能为空");
RuleFor(x => x.Bank).NotNull().NotEmpty().WithMessage("开户行不能为空");
RuleFor(x => x.BankAccount).NotNull().NotEmpty().WithMessage("银行账户不能为空");
RuleFor(x => x.CompanyName).NotEmpty().WithMessage("公司全称不能为空");
RuleFor(x => x.Address).NotEmpty().WithMessage("地址不能为空");
RuleFor(x => x.TaxCode).NotEmpty().WithMessage("税号不能为空");
RuleFor(x => x.Tel).NotEmpty().WithMessage("电话不能为空");
RuleFor(x => x.Bank).NotEmpty().WithMessage("开户行不能为空");
RuleFor(x => x.BankAccount).NotEmpty().WithMessage("银行账户不能为空");
}
}
}

@ -19,7 +19,8 @@ namespace EntrustSettle.Services
{
public class HYDService : IHYDService
{
private const string HYD_LOGIN_ERROR_MSG = "重新登录";
private const string HYD_LOGIN_ERROR_MSG1 = "重新登录";
private const string HYD_LOGIN_ERROR_MSG2 = "token";
private readonly ICaching caching;
private readonly ILogger logger;
private readonly IRestClient client;
@ -64,7 +65,7 @@ namespace EntrustSettle.Services
else
{
var msg = jobj.GetValue("msg").ToString();
if ((code > 400 && code < 500) || msg.Contains(HYD_LOGIN_ERROR_MSG))
if ((code > 400 && code < 500) || msg.Contains(HYD_LOGIN_ERROR_MSG1) || msg.Contains(HYD_LOGIN_ERROR_MSG2))
{
await caching.RemoveAsync(CacheConst.HydAccessToken);
}
@ -149,7 +150,7 @@ namespace EntrustSettle.Services
else
{
var msg = jobj.GetValue("msg").ToString();
if ((code > 400 && code < 500) || msg.Contains(HYD_LOGIN_ERROR_MSG))
if ((code > 400 && code < 500) || msg.Contains(HYD_LOGIN_ERROR_MSG1) || msg.Contains(HYD_LOGIN_ERROR_MSG2))
{
await caching.RemoveAsync(CacheConst.HydAccessToken);
}

Loading…
Cancel
Save