1. 优化邮件的代码;2. 修复邮件在多租户下的报错

pull/25/head
YunaiV 2023-01-28 20:08:03 +08:00
parent c44ecf08ff
commit aaf84aae03
3 changed files with 11 additions and 9 deletions

View File

@ -88,8 +88,8 @@ public class MailSendServiceImpl implements MailSendService {
// 校验邮箱是否存在
mail = checkMail(mail);
// 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志
List<KeyValue<String, Object>> 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<KeyValue<String, Object>> buildTemplateParams(MailTemplateDO template, Map<String, Object> templateParams) {
return template.getParams().stream().map(key -> {
public void checkTemplateParams(MailTemplateDO template, Map<String, Object> 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());
});
}
}

View File

@ -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

View File

@ -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");
}