增加构建通知
This commit is contained in:
parent
8b6b4652ce
commit
5205c6aaa1
@ -26,8 +26,6 @@ import java.util.Properties;
|
|||||||
@Component
|
@Component
|
||||||
public class EmailChannelAdapter implements INotificationChannelAdapter<EmailNotificationConfig, EmailSendNotificationRequest> {
|
public class EmailChannelAdapter implements INotificationChannelAdapter<EmailNotificationConfig, EmailSendNotificationRequest> {
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(EmailNotificationConfig emailConfig, EmailSendNotificationRequest request) throws Exception {
|
public void send(EmailNotificationConfig emailConfig, EmailSendNotificationRequest request) throws Exception {
|
||||||
// 1. 校验配置
|
// 1. 校验配置
|
||||||
|
|||||||
@ -31,6 +31,11 @@ public interface INotificationTemplateRepository extends IBaseRepository<Notific
|
|||||||
*/
|
*/
|
||||||
Optional<NotificationTemplate> findByCodeAndEnabled(String code, Boolean enabled);
|
Optional<NotificationTemplate> findByCodeAndEnabled(String code, Boolean enabled);
|
||||||
|
|
||||||
|
|
||||||
|
@Query("SELECT t FROM NotificationTemplate t WHERE t.id = :id AND t.enabled = :enabled AND t.deleted = false")
|
||||||
|
Optional<NotificationTemplate> findByIdAndEnabled(@Param("id") Long id, @Param("enabled") Boolean enabled);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据渠道类型查找模板
|
* 根据渠道类型查找模板
|
||||||
*/
|
*/
|
||||||
@ -46,10 +51,10 @@ public interface INotificationTemplateRepository extends IBaseRepository<Notific
|
|||||||
* 分页查询模板
|
* 分页查询模板
|
||||||
*/
|
*/
|
||||||
@Query("SELECT t FROM NotificationTemplate t WHERE " +
|
@Query("SELECT t FROM NotificationTemplate t WHERE " +
|
||||||
"(:name IS NULL OR t.name LIKE %:name%) AND " +
|
"(:name IS NULL OR t.name LIKE %:name%) AND " +
|
||||||
"(:code IS NULL OR t.code LIKE %:code%) AND " +
|
"(:code IS NULL OR t.code LIKE %:code%) AND " +
|
||||||
"(:channelType IS NULL OR t.channelType = :channelType) AND " +
|
"(:channelType IS NULL OR t.channelType = :channelType) AND " +
|
||||||
"(:enabled IS NULL OR t.enabled = :enabled)")
|
"(:enabled IS NULL OR t.enabled = :enabled)")
|
||||||
Page<NotificationTemplate> findByConditions(
|
Page<NotificationTemplate> findByConditions(
|
||||||
@Param("name") String name,
|
@Param("name") String name,
|
||||||
@Param("code") String code,
|
@Param("code") String code,
|
||||||
|
|||||||
@ -26,6 +26,8 @@ public interface INotificationTemplateService extends IBaseService<NotificationT
|
|||||||
|
|
||||||
String renderByCode(String templateCode, Map<String, Object> params);
|
String renderByCode(String templateCode, Map<String, Object> params);
|
||||||
|
|
||||||
|
String renderById(Long id, Map<String, Object> params);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据编码获取模板
|
* 根据编码获取模板
|
||||||
|
|||||||
@ -143,8 +143,7 @@ public class NotificationChannelServiceImpl extends BaseServiceImpl<Notification
|
|||||||
|
|
||||||
// 6. 发送通知
|
// 6. 发送通知
|
||||||
try {
|
try {
|
||||||
log.info("发送通知 - 渠道ID: {}, 渠道类型: {}, 内容: {}",
|
log.info("发送通知 - 渠道ID: {}, 渠道类型: {}, 内容: {}", channel.getId(), channel.getChannelType(), request.getContent());
|
||||||
channel.getId(), channel.getChannelType(), request.getContent());
|
|
||||||
|
|
||||||
adapter.send(config, request);
|
adapter.send(config, request);
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ public class NotificationServiceImpl implements INotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 5. 渲染模板内容
|
// 5. 渲染模板内容
|
||||||
String content = notificationTemplateService.renderByCode(template.getCode(), request.getParams());
|
String content = notificationTemplateService.renderTemplate(template.getContentTemplate(), request.getParams());
|
||||||
|
|
||||||
// 6. 根据渠道类型发送通知
|
// 6. 根据渠道类型发送通知
|
||||||
switch (template.getChannelType()) {
|
switch (template.getChannelType()) {
|
||||||
|
|||||||
@ -69,6 +69,12 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
|
|||||||
return processTemplate(template.getContentTemplate(), params);
|
return processTemplate(template.getContentTemplate(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String renderById(Long id, Map<String, Object> params) {
|
||||||
|
NotificationTemplate template = getTemplateById(id);
|
||||||
|
return processTemplate(template.getContentTemplate(), params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NotificationTemplateDTO getByCode(String code) {
|
public NotificationTemplateDTO getByCode(String code) {
|
||||||
@ -92,6 +98,11 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
|
|||||||
.orElseThrow(() -> new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_NOT_FOUND));
|
.orElseThrow(() -> new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_NOT_FOUND));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NotificationTemplate getTemplateById(Long id) {
|
||||||
|
return notificationTemplateRepository.findByIdAndEnabled(id, true)
|
||||||
|
.orElseThrow(() -> new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_NOT_FOUND));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FreeMarker模板处理
|
* FreeMarker模板处理
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user