yangys
2024-03-30 4684d271ea0107097209f7de0951bf451e48df21
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.qianwen.smartman.modules.resource.builder.sms;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.sms.SmsTemplate;
import com.qianwen.core.sms.enums.SmsEnum;
import com.qianwen.core.sms.enums.SmsStatusEnum;
import com.qianwen.core.sms.props.SmsProperties;
import com.qianwen.core.tool.constant.BladeConstant;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.StringUtil;
import com.qianwen.core.tool.utils.WebUtil;
import com.qianwen.smartman.modules.resource.entity.Sms;
import com.qianwen.smartman.modules.resource.service.ISmsService;
 
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/resource/builder/sms/SmsBuilder.class */
public class SmsBuilder {
    public static final String SMS_CODE = "sms:code:";
    public static final String SMS_PARAM_KEY = "code";
    private final SmsProperties smsProperties;
    private final ISmsService smsService;
    private final BladeRedis bladeRedis;
    private final Map<String, SmsTemplate> templatePool = new ConcurrentHashMap();
    private final Map<String, Sms> smsPool = new ConcurrentHashMap();
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case -1045510480:
                if (implMethodName.equals("getSmsCode")) {
                    z = true;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = false;
                    break;
                }
                break;
            case 803533544:
                if (implMethodName.equals("getStatus")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/mp/base/BaseEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getStatus();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/resource/entity/Sms") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getSmsCode();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public SmsBuilder(SmsProperties smsProperties, ISmsService smsService, BladeRedis bladeRedis) {
        this.smsProperties = smsProperties;
        this.smsService = smsService;
        this.bladeRedis = bladeRedis;
    }
 
    public SmsTemplate template() {
        return template("");
    }
 
    public SmsTemplate template(String code) {
        SmsTemplate template;
        String tenantId = AuthUtil.getTenantId();
        Sms sms = getSms(tenantId, code);
        Sms smsCached = this.smsPool.get(tenantId);
        SmsTemplate template2 = this.templatePool.get(tenantId);
        if (!Func.hasEmpty(new Object[]{template2, smsCached}) && sms.getTemplateId().equals(smsCached.getTemplateId()) && sms.getAccessKey().equals(smsCached.getAccessKey())) {
            return template2;
        }
        synchronized (SmsBuilder.class) {
            template = this.templatePool.get(tenantId);
            if (Func.hasEmpty(new Object[]{template, smsCached}) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
                if (sms.getCategory().intValue() == SmsEnum.YUNPIAN.getCategory()) {
                    template = YunpianSmsBuilder.template(sms, this.bladeRedis);
                } else if (sms.getCategory().intValue() == SmsEnum.QINIU.getCategory()) {
                    template = QiniuSmsBuilder.template(sms, this.bladeRedis);
                } else if (sms.getCategory().intValue() == SmsEnum.ALI.getCategory()) {
                    template = AliSmsBuilder.template(sms, this.bladeRedis);
                } else if (sms.getCategory().intValue() == SmsEnum.TENCENT.getCategory()) {
                    template = TencentSmsBuilder.template(sms, this.bladeRedis);
                }
                this.templatePool.put(tenantId, template);
                this.smsPool.put(tenantId, sms);
            }
        }
        return template;
    }
 
    public Sms getSms(String tenantId, String code) {
        String key = tenantId;
        LambdaQueryWrapper<Sms> lqw = (LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId);
        String smsCode = StringUtil.isBlank(code) ? WebUtil.getParameter("code") : code;
        if (StringUtil.isNotBlank(smsCode)) {
            key = key.concat("-").concat(smsCode);
            lqw.eq((v0) -> {
                return v0.getSmsCode();
            }, smsCode);
        } else {
            lqw.eq((v0) -> {
                return v0.getStatus();
            }, Integer.valueOf(SmsStatusEnum.ENABLE.getNum()));
        }
        Sms sms = (Sms) CacheUtil.get("blade:resource", SMS_CODE, key, () -> {
            Sms s = (Sms) this.smsService.getOne(lqw);
            if (Func.isEmpty(s)) {
                Sms defaultSms = new Sms();
                defaultSms.setId(BladeConstant.TOP_PARENT_ID);
                defaultSms.setTemplateId(this.smsProperties.getTemplateId());
                defaultSms.setRegionId(this.smsProperties.getRegionId());
                defaultSms.setCategory(Integer.valueOf(SmsEnum.of(this.smsProperties.getName()).getCategory()));
                defaultSms.setAccessKey(this.smsProperties.getAccessKey());
                defaultSms.setSecretKey(this.smsProperties.getSecretKey());
                defaultSms.setSignName(this.smsProperties.getSignName());
                return defaultSms;
            }
            return s;
        }, ExtCacheConstant.TENANT_MODE);
        if (sms == null || sms.getId() == null) {
            throw new ServiceException("未获取到对应的短信配置");
        }
        return sms;
    }
}