潘志宝
2024-11-14 afa8fc57084c423218c6816b710dfb2f0b87ea89
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.system.framework.sms.core.client.impl;
H 2
3 import com.iailab.module.system.framework.sms.core.client.SmsClient;
4 import com.iailab.module.system.framework.sms.core.property.SmsChannelProperties;
5 import lombok.extern.slf4j.Slf4j;
6
7 /**
8  * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码
9  *
10  * @author zzf
11  * @since 2021/2/1 9:28
12  */
13 @Slf4j
14 public abstract class AbstractSmsClient implements SmsClient {
15
16     /**
17      * 短信渠道配置
18      */
19     protected volatile SmsChannelProperties properties;
20
21     public AbstractSmsClient(SmsChannelProperties properties) {
22         this.properties = properties;
23     }
24
25     /**
26      * 初始化
27      */
28     public final void init() {
29         doInit();
30         log.debug("[init][配置({}) 初始化完成]", properties);
31     }
32
33     /**
34      * 自定义初始化
35      */
36     protected abstract void doInit();
37
38     public final void refresh(SmsChannelProperties properties) {
39         // 判断是否更新
40         if (properties.equals(this.properties)) {
41             return;
42         }
43         log.info("[refresh][配置({})发生变化,重新初始化]", properties);
44         this.properties = properties;
45         // 初始化
46         this.init();
47     }
48
49     @Override
50     public Long getId() {
51         return properties.getId();
52     }
53
54 }