|
|
@@ -1,26 +1,43 @@
|
|
|
package cn.com.ctop.job.bytedance.config;
|
|
|
|
|
|
-import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.DianZhongMapper;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@Configuration
|
|
|
-@ConfigurationProperties(prefix = "dianzhong.client")
|
|
|
public class DianZhongConfig {
|
|
|
+ @Autowired
|
|
|
+ private DianZhongMapper dianZhongMapper;
|
|
|
private static List<DZConfig> dzConfig;
|
|
|
private static final Map<String, String> tokenMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
+
|
|
|
public List<DZConfig> getDzConfig() {
|
|
|
+ dzConfig = new ArrayList<>();
|
|
|
+ List<JSONObject> arr = dianZhongMapper.getAccountConfig();
|
|
|
+ for (JSONObject jsonObject : arr) {
|
|
|
+ String clientId = jsonObject.getString("account_id");
|
|
|
+ String token = jsonObject.getString("token");
|
|
|
+ String businessMethod = jsonObject.getString("business_method");
|
|
|
+ DZConfig config = new DZConfig(clientId, token, businessMethod);
|
|
|
+ dzConfig.add(config);
|
|
|
+ tokenMap.put(clientId, token);
|
|
|
+ }
|
|
|
return dzConfig;
|
|
|
}
|
|
|
|
|
|
public String getToken(String clientId) {
|
|
|
- if (tokenMap.isEmpty()) {
|
|
|
- for (DZConfig config : dzConfig) {
|
|
|
- tokenMap.put(config.getClientId(), config.getToken());
|
|
|
+ if (!tokenMap.containsKey(clientId)) {
|
|
|
+ String token = dianZhongMapper.getAccountToken(clientId);
|
|
|
+ if (StringUtils.isNotBlank(token)) {
|
|
|
+ tokenMap.put(clientId, token);
|
|
|
}
|
|
|
}
|
|
|
return tokenMap.get(clientId);
|
|
|
@@ -35,6 +52,15 @@ public class DianZhongConfig {
|
|
|
private String token;
|
|
|
private String type;
|
|
|
|
|
|
+ public DZConfig() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public DZConfig(String clientId, String token, String type) {
|
|
|
+ this.clientId = clientId;
|
|
|
+ this.token = token;
|
|
|
+ this.type = type;
|
|
|
+ }
|
|
|
+
|
|
|
public String getClientId() {
|
|
|
return clientId;
|
|
|
}
|