From aaf84aae039bc87116e0067e594d2a631b0b4635 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 28 Jan 2023 20:08:03 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=9B2.=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=9C=A8=E5=A4=9A=E7=A7=9F=E6=88=B7=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/mail/MailSendServiceImpl.java | 14 ++++++-------- .../src/main/resources/application.yaml | 4 ++++ .../service/mail/MailSendServiceImplTest.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java index 57fbf5c29..40db4ee0f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImpl.java @@ -88,8 +88,8 @@ public class MailSendServiceImpl implements MailSendService { // 校验邮箱是否存在 mail = checkMail(mail); - // 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志 - List> newTemplateParams = buildTemplateParams(template, templateParams); + // 校验参数模版 + checkTemplateParams(template, templateParams); // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); @@ -152,21 +152,19 @@ public class MailSendServiceImpl implements MailSendService { } /** - * 将参数模板,处理成有序的 KeyValue 数组 + * 校验参数模板 * * @param template 邮箱模板 * @param templateParams 原始参数 - * @return 处理后的参数 */ @VisibleForTesting - public List> buildTemplateParams(MailTemplateDO template, Map templateParams) { - return template.getParams().stream().map(key -> { + public void checkTemplateParams(MailTemplateDO template, Map templateParams) { + template.getParams().forEach(key -> { Object value = templateParams.get(key); if (value == null) { throw exception(MAIL_SEND_TEMPLATE_PARAM_MISS, key); } - return new KeyValue<>(key, value); - }).collect(Collectors.toList()); + }); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml index b0b764492..647ab0c17 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml @@ -159,6 +159,10 @@ yudao: - system_sms_log - system_sensitive_word - system_oauth2_client + - system_mail_account + - system_mail_template + - system_mail_log + - system_notify_template sms-code: # 短信验证码相关的配置项 expire-times: 10m send-frequency: 1m diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImplTest.java index bd93cd00a..2d9dc2b65 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/mail/MailSendServiceImplTest.java @@ -153,7 +153,7 @@ class MailSendServiceImplTest extends BaseMockitoUnitTest { // mock 方法 // 调用,并断言异常 - assertServiceException(() -> mailSendService.buildTemplateParams(template, templateParams), + assertServiceException(() -> mailSendService.checkTemplateParams(template, templateParams), MAIL_SEND_TEMPLATE_PARAM_MISS, "code"); }