沙钢智慧能源系统后端代码
houzhongjian
2024-10-09 97edd72e5e6dbb134cedae4b72c95be8c948c5ec
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
package com.iailab.module.shasteel.framework.sms.core.client.impl;
 
import com.iailab.module.shasteel.framework.sms.core.client.SmsClient;
import com.iailab.module.shasteel.framework.sms.core.property.SmsChannelProperties;
import lombok.extern.slf4j.Slf4j;
 
/**
 * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码
 *
 * @author zzf
 * @since 2021/2/1 9:28
 */
@Slf4j
public abstract class AbstractSmsClient implements SmsClient {
 
    /**
     * 短信渠道配置
     */
    protected volatile SmsChannelProperties properties;
 
    public AbstractSmsClient(SmsChannelProperties properties) {
        this.properties = properties;
    }
 
    /**
     * 初始化
     */
    public final void init() {
        doInit();
        log.debug("[init][配置({}) 初始化完成]", properties);
    }
 
    /**
     * 自定义初始化
     */
    protected abstract void doInit();
 
    public final void refresh(SmsChannelProperties properties) {
        // 判断是否更新
        if (properties.equals(this.properties)) {
            return;
        }
        log.info("[refresh][配置({})发生变化,重新初始化]", properties);
        this.properties = properties;
        // 初始化
        this.init();
    }
 
    @Override
    public Long getId() {
        return properties.getId();
    }
 
}