yangys
2024-03-27 44028c2d1a7f21da831cb07ecb1b4a7873d8627b
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
package com.qianwen.core.notify.notifier;
 
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.notify.NotifyType;
import com.qianwen.core.notify.Provider;
import com.qianwen.core.notify.event.NotifierEvent;
import com.qianwen.core.notify.template.Template;
import com.qianwen.core.tool.metadata.Values;
 
/* loaded from: blade-starter-notify-9.3.0.0-SNAPSHOT.jar:org/springblade/core/notify/notifier/NotifierProxy.class */
public abstract class NotifierProxy<T extends Template> implements Notifier<T> {
    private static final Logger log = LoggerFactory.getLogger(NotifierProxy.class);
    private Notifier<T> target;
 
    protected abstract void onEvent(NotifierEvent event);
 
    public NotifierProxy(final Notifier<T> target) {
        this.target = target;
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public NotifierProperties getNotifierProperties() {
        return this.target.getNotifierProperties();
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public String getNotifierId() {
        return this.target.getNotifierId();
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public NotifyType getType() {
        return this.target.getType();
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public Provider getProvider() {
        return this.target.getProvider();
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public void send(String templateId, String traceId, Values context, List<String> notifiedParty) {
        try {
            this.target.send(templateId, traceId, context, notifiedParty);
            log.info("发送[{}]通知[{}-{}]完成", new Object[]{this.target.getType().getName(), getNotifierId(), templateId});
            onSuccess(templateId, traceId, context);
        } catch (Exception exception) {
            log.error("发送[{}]通知[{}-{}]失败", new Object[]{this.target.getType().getName(), getNotifierId(), templateId, exception});
            onError(templateId, traceId, context, exception);
        }
    }
 
    
    @Override
    public void send(T template, String traceId, Values context, List<String> notifiedParty) {
        try {
          this.target.send(template, traceId, context, notifiedParty);
          onSuccess(template, traceId, context);
        } catch (Exception exception) {
          onError(template, traceId, context, exception);
        } 
      }
    
    protected void onError(T template, String traceId, Values ctx, Throwable error) {
        onEvent(NotifierEvent.builder().cause(error).context(ctx.getAllValues()).notifierId(getNotifierId()).notifyType(getType()).provider(getProvider()).template(template).traceId(traceId).build());
    }
 
    protected void onError(String templateId, String traceId, Values ctx, Throwable error) {
        onEvent(NotifierEvent.builder().cause(error).context(ctx.getAllValues()).notifierId(getNotifierId()).notifyType(getType()).provider(getProvider()).templateId(templateId).traceId(traceId).build());
    }
 
    protected void onSuccess(T template, String traceId, Values ctx) {
        onEvent(NotifierEvent.builder().success(true).context(ctx.getAllValues()).notifierId(getNotifierId()).notifyType(getType()).provider(getProvider()).template(template).traceId(traceId).build());
    }
 
    protected void onSuccess(String templateId, String traceId, Values ctx) {
        onEvent(NotifierEvent.builder().success(true).context(ctx.getAllValues()).notifierId(getNotifierId()).notifyType(getType()).provider(getProvider()).templateId(templateId).traceId(traceId).build());
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public void close() {
        this.target.close();
    }
 
    @Override // com.qianwen.core.notify.notifier.Notifier
    public <R extends Notifier<T>> R unwrap(Class<R> type) {
        return (R) this.target.unwrap(type);
    }
}