package com.qianwen.core.notify.provider.internal.message; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.notify.DefaultNotifyType; import com.qianwen.core.notify.NotifyType; import com.qianwen.core.notify.Provider; import com.qianwen.core.notify.notifier.AbstractNotifier; import com.qianwen.core.notify.notifier.NotifierProperties; import com.qianwen.core.notify.provider.internal.message.DefaultInternalMessageTemplate; import com.qianwen.core.notify.template.Template; import com.qianwen.core.notify.template.TemplateManager; import com.qianwen.core.tool.api.ResultCode; import com.qianwen.core.tool.metadata.Values; import com.qianwen.core.tool.utils.ExpressionUtils; import com.qianwen.core.tool.utils.Func; import com.qianwen.core.tool.utils.SpringUtil; import org.springframework.util.StringUtils; /* loaded from: blade-starter-notify-9.3.0.0-SNAPSHOT.jar:org/springblade/core/notify/provider/internal/message/DefaultInternalMessageNotifier.class */ public class DefaultInternalMessageNotifier extends AbstractNotifier { private static final Logger log = LoggerFactory.getLogger(DefaultInternalMessageNotifier.class); private NotifierProperties notifierProperties; private String notifierId; public void setNotifierProperties(final NotifierProperties notifierProperties) { this.notifierProperties = notifierProperties; } public DefaultInternalMessageNotifier(NotifierProperties properties, TemplateManager templateManager) { super(templateManager); this.notifierId = properties.getId(); this.notifierId = properties.getId(); this.notifierProperties = properties; } @Override // com.qianwen.core.notify.notifier.Notifier public String getNotifierId() { return this.notifierId; } @Override // com.qianwen.core.notify.notifier.Notifier public NotifyType getType() { return DefaultNotifyType.internalMessage; } @Override // com.qianwen.core.notify.notifier.Notifier public Provider getProvider() { return InternalMessageProvider.systemDefault; } @Override // com.qianwen.core.notify.notifier.Notifier public NotifierProperties getNotifierProperties() { return this.notifierProperties; } public void send(DefaultInternalMessageTemplate template, String traceId, Values context, List notifiedParty) { ParsedInternalMessageTemplate parsedEmailTemplate = convert(template, context.getAllValues()); doSend(parsedEmailTemplate, notifiedParty); } protected void doSend(ParsedInternalMessageTemplate template, List sendTo) { IInternalMessageServer server = (IInternalMessageServer) SpringUtil.getBean(IInternalMessageServer.class); if (Func.isNotEmpty(server)) { server.submitInternalMessage(template, sendTo); } else { new ServiceException("不存在站内信发送实现类"); } } protected ParsedInternalMessageTemplate convert(DefaultInternalMessageTemplate template, Map context) { String subject = template.getSubject(); String content = template.getContent(); if (StringUtils.isEmpty(subject) || StringUtils.isEmpty(content)) { throw new ServiceException(ResultCode.PARAM_MISS, new Throwable("模板内容错误,content 或者 subject 不能为空.")); } String sendContent = render(content, context); List tempAttachments = template.getAttachments(); Map attachments = new HashMap<>(); if (tempAttachments != null) { for (DefaultInternalMessageTemplate.Attachment tempAttachment : tempAttachments) { attachments.put(tempAttachment.getName(), render(tempAttachment.getLocation(), context)); } } return ParsedInternalMessageTemplate.builder().attachments(attachments).content(sendContent).subject(render(subject, context)).build(); } private String render(String str, Map context) { return ExpressionUtils.analytical(str, context, "spel"); } @Override // com.qianwen.core.notify.notifier.Notifier public void close() { } }