From 6a6da9e872e258eb173b609ae4bd95b285feb3c8 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Tue, 18 Jun 2024 11:13:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/OrderController.cs | 19 +++++++++++++++---- EntrustSettle.Model/Validator/AllValidator.cs | 19 ++++++------------- EntrustSettle.Services/HYDService.cs | 7 ++++--- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/EntrustSettle.Api/Controllers/OrderController.cs b/EntrustSettle.Api/Controllers/OrderController.cs index cdce274..11c21c4 100644 --- a/EntrustSettle.Api/Controllers/OrderController.cs +++ b/EntrustSettle.Api/Controllers/OrderController.cs @@ -153,8 +153,11 @@ namespace EntrustSettle.Api.Controllers //[UseTran] public async Task>> 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 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 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) { diff --git a/EntrustSettle.Model/Validator/AllValidator.cs b/EntrustSettle.Model/Validator/AllValidator.cs index a9d7afa..2b7bc7f 100644 --- a/EntrustSettle.Model/Validator/AllValidator.cs +++ b/EntrustSettle.Model/Validator/AllValidator.cs @@ -32,13 +32,6 @@ namespace EntrustSettle.Model.Validator //RuleFor(x => x.Remark).MaximumLength(2000).WithMessage("备注过长"); } } - public class FileTypeEnumValidator : AbstractValidator - { - public FileTypeEnumValidator() - { - RuleFor(x => x).IsInEnum(); - } - } public class ChangeStatusDtoValidator : AbstractValidator { 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("银行账户不能为空"); } } } \ No newline at end of file diff --git a/EntrustSettle.Services/HYDService.cs b/EntrustSettle.Services/HYDService.cs index 6ef9b9a..2ea1bfb 100644 --- a/EntrustSettle.Services/HYDService.cs +++ b/EntrustSettle.Services/HYDService.cs @@ -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); }