mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-22 03:28:04 +08:00
feat:update mail template & add ut (#63)
* feat:update mail template & add ut * fix: error workflow yml * feat: add core:check
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.databasir.core.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@EnableAsync
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
|
||||
@Bean
|
||||
public Executor mailThreadPoolTaskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
int availableProcessorCount = Runtime.getRuntime().availableProcessors();
|
||||
executor.setCorePoolSize(availableProcessorCount << 1);
|
||||
executor.setMaxPoolSize(32);
|
||||
executor.setAllowCoreThreadTimeOut(true);
|
||||
return executor;
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ import com.databasir.dao.tables.pojos.UserPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -24,6 +25,7 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Async("mailThreadPoolTaskExecutor")
|
||||
public class DocumentEventSubscriber {
|
||||
|
||||
private final ProjectDao projectDao;
|
||||
@@ -42,19 +44,20 @@ public class DocumentEventSubscriber {
|
||||
ProjectPojo project = projectDao.selectById(created.getProjectId());
|
||||
List<String> to = userDao.selectEnabledGroupMembers(project.getGroupId())
|
||||
.stream()
|
||||
.filter(UserPojo::getEnabled)
|
||||
.map(UserPojo::getEmail)
|
||||
.filter(userEmail -> userEmail.contains("@"))
|
||||
.collect(Collectors.toList());
|
||||
String subject = project.getName() + " 文档有新的内容变更";
|
||||
List<Map<String, String>> diffs = created.getDiff()
|
||||
.map(this::diffs)
|
||||
.orElseGet(Collections::emptyList);
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("diffs", diffs);
|
||||
context.put("projectName", project.getName());
|
||||
String message = mailTemplateProcessor.process("ftl/mail/DocumentUpdated.ftl", context);
|
||||
mailSender.batchSendHtml(mail, to, subject, message);
|
||||
if (!to.isEmpty()) {
|
||||
String subject = project.getName() + " 文档有新的内容变更";
|
||||
List<Map<String, String>> diffs = created.getDiff()
|
||||
.map(this::diffs)
|
||||
.orElseGet(Collections::emptyList);
|
||||
Map<String, Object> context = new HashMap<>();
|
||||
context.put("diffs", diffs);
|
||||
context.put("projectName", project.getName());
|
||||
String message = mailTemplateProcessor.process("ftl/mail/DocumentUpdated.ftl", context);
|
||||
mailSender.batchSendHtml(mail, to, subject, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -11,17 +11,16 @@ import com.databasir.dao.tables.pojos.UserPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO use html template instead of simple message
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Async("mailThreadPoolTaskExecutor")
|
||||
public class UserEventSubscriber {
|
||||
|
||||
private final MailSender mailSender;
|
||||
|
@@ -25,13 +25,15 @@
|
||||
尊敬的 ${nickname}:</p>
|
||||
<p style="color: rgb(32, 45, 64);font-size: 14px;font-family: PingFangSC-Regular;font-weight: normal;letter-spacing: 0px;margin: 0;margin-top: 20px;text-indent:2em;">
|
||||
您已成功注册 Databasir,用户名为 ${username}。
|
||||
</p>
|
||||
<p style="color: rgb(32, 45, 64);font-size: 14px;font-family: PingFangSC-Regular;font-weight: normal;letter-spacing: 0px;margin: 0;margin-top: 20px;text-indent:2em;">
|
||||
为了您的账号安全,请尽快通过以下密码登录系统并及时修改新密码
|
||||
</p>
|
||||
<div style="margin-left: 20px; margin-top: 10px;background-size: 3px;background-repeat: no-repeat;">
|
||||
<span style="padding:5px 8px 5px 8px; border:none ;background-color: #F56C6C;">
|
||||
<span target="_blank"
|
||||
style="text-decoration:none; font-family:'Oracle Sans', Arial, sans-serif; color:#FFF;">
|
||||
${newPassword}
|
||||
${password}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user