yangys
2024-04-23 cacfe3693e552724a07ff65ee620cee91787da76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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<DefaultInternalMessageTemplate> {
    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<String> notifiedParty) {
        ParsedInternalMessageTemplate parsedEmailTemplate = convert(template, context.getAllValues());
        doSend(parsedEmailTemplate, notifiedParty);
    }
 
    protected void doSend(ParsedInternalMessageTemplate template, List<String> 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<String, Object> 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<DefaultInternalMessageTemplate.Attachment> tempAttachments = template.getAttachments();
        Map<String, String> 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<String, Object> context) {
        return ExpressionUtils.analytical(str, context, "spel");
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public void close() {
    }
}