1. 优化邮件的代码;2. 修复邮件在多租户下的报错
parent
c44ecf08ff
commit
aaf84aae03
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue