yangys
2024-03-29 4b479381a65bd3ef526cb92631d3550f2aa17459
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.qianwen.smartman.modules.sync.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.notify.service.INotifyConfigService;
import com.qianwen.smartman.modules.sync.constant.DingConstant;
import com.qianwen.smartman.modules.sync.constant.OuterAppConfigConstant;
import com.qianwen.smartman.modules.sync.constant.QyWechatConstant;
import com.qianwen.smartman.modules.sync.convert.OuterAppConfigConvert;
import com.qianwen.smartman.modules.sync.entity.OuterAppConfig;
import com.qianwen.smartman.modules.sync.mapper.OuterAppConfigMapper;
import com.qianwen.smartman.modules.sync.service.IOuterAppConfigService;
import com.qianwen.smartman.modules.sync.vo.OuterAppConfigVO;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/sync/service/impl/OuterAppConfigServiceImpl.class */
public class OuterAppConfigServiceImpl extends BaseServiceImpl<OuterAppConfigMapper, OuterAppConfig> implements IOuterAppConfigService {
    private final BladeRedis bladeRedis;
    private final IUserOauthService userOauthService;
    private final INotifyConfigService notifyConfigService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case 242925765:
                if (implMethodName.equals("getAppType")) {
                    z = true;
                    break;
                }
                break;
            case 799509265:
                if (implMethodName.equals("getSource")) {
                    z = false;
                    break;
                }
                break;
            case 803533544:
                if (implMethodName.equals("getStatus")) {
                    z = true;
                    break;
                }
                break;
            case 859984188:
                if (implMethodName.equals("getUserId")) {
                    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/modules/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getSource();
                    };
                }
                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/system/entity/UserOauth") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
                    return (v0) -> {
                        return v0.getUserId();
                    };
                }
                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/sync/entity/OuterAppConfig") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getAppType();
                    };
                }
                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/sync/entity/OuterAppConfig") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getAppType();
                    };
                }
                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/sync/entity/OuterAppConfig") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
                    return (v0) -> {
                        return v0.getAppType();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public OuterAppConfigServiceImpl(BladeRedis bladeRedis, IUserOauthService userOauthService, @Lazy INotifyConfigService notifyConfigService) {
        this.bladeRedis = bladeRedis;
        this.userOauthService = userOauthService;
        this.notifyConfigService = notifyConfigService;
    }
 
    @Override // org.springblade.modules.sync.service.IOuterAppConfigService
    public OuterAppConfig getAppConfig(Integer appType) {
        Object configObj = this.bladeRedis.get(OuterAppConfigConstant.OUTER_APP_CONFIG + appType);
        if (Func.isNotEmpty(configObj)) {
            return (OuterAppConfig) Func.convert(configObj, OuterAppConfig.class);
        }
        OuterAppConfig dingAppConfig = (OuterAppConfig) getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getAppType();
        }, appType));
        this.bladeRedis.setEx(OuterAppConfigConstant.OUTER_APP_CONFIG + appType, dingAppConfig, Duration.ofDays(7L));
        return dingAppConfig;
    }
 
    @Override // org.springblade.modules.sync.service.IOuterAppConfigService
    @Transactional
    public Boolean unbind(Integer type) {
        this.bladeRedis.del(OuterAppConfigConstant.OUTER_APP_CONFIG + type);
        this.userOauthService.update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
            return v0.getSource();
        }, type.equals(OuterAppConfigConstant.QY_WECHAT) ? QyWechatConstant.QY_SOURCE : DingConstant.DING_AUTH_KEY)).set((v0) -> {
            return v0.getUserId();
        }, (Object) null));
        return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().eq((v0) -> {
            return v0.getAppType();
        }, type)).set((v0) -> {
            return v0.getStatus();
        }, CommonConstant.DEACTIVATE)));
    }
 
    @Override // org.springblade.modules.sync.service.IOuterAppConfigService
    public OuterAppConfigVO submit(OuterAppConfigVO outerAppConfigVO) {
        OuterAppConfig dingAppConfig = (OuterAppConfig) getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getAppType();
        }, outerAppConfigVO.getAppType().equals(OuterAppConfigConstant.QY_WECHAT) ? OuterAppConfigConstant.DING : OuterAppConfigConstant.QY_WECHAT));
        if (Func.isNotEmpty(dingAppConfig) && dingAppConfig.getStatus().equals(CommonConstant.ENABLE)) {
            throw new ServiceException(MessageUtils.message("sys.outer.config.is.bind", new Object[0]));
        }
        OuterAppConfig outerAppConfig = OuterAppConfigConvert.INSTANCE.convert(outerAppConfigVO);
        outerAppConfig.setStatus(CommonConstant.ENABLE);
        saveOrUpdate(outerAppConfig);
        this.bladeRedis.del(OuterAppConfigConstant.OUTER_APP_CONFIG + outerAppConfigVO.getAppType());
        this.bladeRedis.del(new String[]{QyWechatConstant.TOKEN_KEY + QyWechatConstant.QY_APP_TYPE, QyWechatConstant.TOKEN_KEY + QyWechatConstant.BOOK_TYPE, DingConstant.DING_ACCESSTOKEN_REDIS_CACHE});
        this.notifyConfigService.updateServerConfig(outerAppConfig);
        return OuterAppConfigConvert.INSTANCE.convert(outerAppConfig);
    }
 
    @Override // org.springblade.modules.sync.service.IOuterAppConfigService
    public List<OuterAppConfigVO> getConfigs(Map<String, Object> params) {
        List<OuterAppConfig> list = list(Condition.getQueryWrapper(params, OuterAppConfig.class));
        Map<Long, OuterAppConfig> configMap = (Map) list.parallelStream().collect(Collectors.toMap((v0) -> {
            return v0.getId();
        }, config -> {
            return config;
        }));
        List<OuterAppConfigVO> configVOS = OuterAppConfigConvert.INSTANCE.convert(list);
        configVOS.forEach(config2 -> {
            OuterAppConfig appConfig = (OuterAppConfig) configMap.get(config2.getId());
            if (!Objects.isNull(appConfig) && appConfig.getAppType().equals(OuterAppConfigConstant.QY_WECHAT)) {
                config2.setWxDomain(appConfig.getDomainUrl());
            } else if (!Objects.isNull(appConfig) && appConfig.getAppType().equals(OuterAppConfigConstant.DING)) {
                config2.setDingDomain(appConfig.getDomainUrl());
            }
        });
        return configVOS;
    }
}