From 22df12f22167e7502ba268bfa60d7a505853e6b0 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 14 Jun 2023 10:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessFilter/ProjectExceptionFilter.cs | 3 +-- .../Helper/SendEmailHelper.cs | 5 +++-- .../Service/Management/UserService.cs | 20 ++++++++++++++++--- .../Context/IRaCISDBContext.cs | 12 ++++++++++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/IRaCIS.Core.Application/BusinessFilter/ProjectExceptionFilter.cs b/IRaCIS.Core.Application/BusinessFilter/ProjectExceptionFilter.cs index 7aef3c0d..e510e449 100644 --- a/IRaCIS.Core.Application/BusinessFilter/ProjectExceptionFilter.cs +++ b/IRaCIS.Core.Application/BusinessFilter/ProjectExceptionFilter.cs @@ -35,8 +35,7 @@ namespace IRaCIS.Core.Application.Filter } else { - context.Result = new JsonResult(ResponseOutput.NotOk(" 程序异常,请联系开发人员。 " + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/) - : (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException)); + context.Result = new JsonResult(ResponseOutput.NotOk("当前操作失败,请联系开发人员查看系统日志排查 ", ApiResponseCodeEnum.ProgramException)); } diff --git a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs index 45a129e7..5eb9e590 100644 --- a/IRaCIS.Core.Application/Helper/SendEmailHelper.cs +++ b/IRaCIS.Core.Application/Helper/SendEmailHelper.cs @@ -1,5 +1,6 @@ using DocumentFormat.OpenXml.Spreadsheet; using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infrastructure; using MailKit; using MailKit.Security; using MimeKit; @@ -42,7 +43,7 @@ public static class SendEmailHelper catch (Exception ex) { - throw new Exception("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员"); + throw new BusinessValidationFailedException("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员"); } @@ -62,7 +63,7 @@ public static class SendEmailHelper if (sMTPEmailConfig.ToMailAddressList.Count == 0) { - throw new ArgumentException("没有收件人"); + throw new BusinessValidationFailedException("没有收件人"); } else { diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index aa0dea79..5cecb507 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -8,6 +8,7 @@ using Panda.DynamicWebApi.Attributes; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Options; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; namespace IRaCIS.Application.Services { @@ -22,6 +23,8 @@ namespace IRaCIS.Application.Services private readonly IMemoryCache _cache; + private ILogger _logger; + private readonly IOptionsMonitor _verifyConfig; public UserService(IRepository userRepository, @@ -30,10 +33,12 @@ namespace IRaCIS.Application.Services IRepository doctorRepository, IMemoryCache cache, IRepository userTrialRepository, - IOptionsMonitor verifyConfig + IOptionsMonitor verifyConfig, + ILogger logger ) { + _logger=logger; _verifyConfig = verifyConfig; _cache = cache; _userRepository = userRepository; @@ -267,7 +272,7 @@ namespace IRaCIS.Application.Services } catch (Exception ex) { - throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败, 未能创建账户成功"); + throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败"); } @@ -506,8 +511,17 @@ namespace IRaCIS.Application.Services var success = await _userRepository.SaveChangesAsync(); + try + { + await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl); + + } + catch (Exception ex) + { + _logger.LogError(ex.Message); + throw new BusinessValidationFailedException("发送邮件失败, 未能创建账户成功"); + } - await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl); diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index bd4e98c5..cfb59af2 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -535,7 +535,17 @@ namespace IRaCIS.Core.Infra.EFCore throw new DBSaveFailedException("SQL 查询中存在语法错误。"); } - + catch (ReferenceConstraintException ex) + { + _logger.LogError(ex.Message); + throw new DBSaveFailedException("无法进行当前操作,当前数据不符合外键约束。"); + } + catch (DbUpdateConcurrencyException ex) + { + _logger.LogError(ex.Message); + + throw new DBSaveFailedException("SQL 事务失败,请检查环境。"); + } return result; }