增加构建通知
This commit is contained in:
parent
8b6b4652ce
commit
5205c6aaa1
@ -26,8 +26,6 @@ import java.util.Properties;
|
||||
@Component
|
||||
public class EmailChannelAdapter implements INotificationChannelAdapter<EmailNotificationConfig, EmailSendNotificationRequest> {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void send(EmailNotificationConfig emailConfig, EmailSendNotificationRequest request) throws Exception {
|
||||
// 1. 校验配置
|
||||
|
||||
@ -31,6 +31,11 @@ public interface INotificationTemplateRepository extends IBaseRepository<Notific
|
||||
*/
|
||||
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 " +
|
||||
"(:name IS NULL OR t.name LIKE %:name%) AND " +
|
||||
"(:code IS NULL OR t.code LIKE %:code%) AND " +
|
||||
"(:channelType IS NULL OR t.channelType = :channelType) AND " +
|
||||
"(:enabled IS NULL OR t.enabled = :enabled)")
|
||||
"(:name IS NULL OR t.name LIKE %:name%) AND " +
|
||||
"(:code IS NULL OR t.code LIKE %:code%) AND " +
|
||||
"(:channelType IS NULL OR t.channelType = :channelType) AND " +
|
||||
"(:enabled IS NULL OR t.enabled = :enabled)")
|
||||
Page<NotificationTemplate> findByConditions(
|
||||
@Param("name") String name,
|
||||
@Param("code") String code,
|
||||
|
||||
@ -26,6 +26,8 @@ public interface INotificationTemplateService extends IBaseService<NotificationT
|
||||
|
||||
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. 发送通知
|
||||
try {
|
||||
log.info("发送通知 - 渠道ID: {}, 渠道类型: {}, 内容: {}",
|
||||
channel.getId(), channel.getChannelType(), request.getContent());
|
||||
log.info("发送通知 - 渠道ID: {}, 渠道类型: {}, 内容: {}", channel.getId(), channel.getChannelType(), request.getContent());
|
||||
|
||||
adapter.send(config, request);
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ public class NotificationServiceImpl implements INotificationService {
|
||||
}
|
||||
|
||||
// 5. 渲染模板内容
|
||||
String content = notificationTemplateService.renderByCode(template.getCode(), request.getParams());
|
||||
String content = notificationTemplateService.renderTemplate(template.getContentTemplate(), request.getParams());
|
||||
|
||||
// 6. 根据渠道类型发送通知
|
||||
switch (template.getChannelType()) {
|
||||
|
||||
@ -69,6 +69,12 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
|
||||
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
|
||||
public NotificationTemplateDTO getByCode(String code) {
|
||||
@ -92,6 +98,11 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
|
||||
.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模板处理
|
||||
|
||||
Loading…
Reference in New Issue
Block a user