1
|
package com.monitor.other.degrade.service.impl;
|
1
|
package com.monitor.other.degrade.service.impl;
|
2
|
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
3
|
import com.monitor.common.util.HttpClientUtil;
|
5
|
import com.monitor.common.util.HttpClientUtil;
|
4
|
import com.monitor.model.domain.AppDegradeConfig;
|
6
|
import com.monitor.model.domain.AppDegradeConfig;
|
5
|
import com.monitor.model.request.AppDegradeInfoReq;
|
7
|
import com.monitor.model.request.AppDegradeInfoReq;
|
|
@@ -8,6 +10,7 @@ import com.monitor.mysql.mapper.AppDegradeConfigMapper; |
|
@@ -8,6 +10,7 @@ import com.monitor.mysql.mapper.AppDegradeConfigMapper; |
8
|
import com.monitor.other.degrade.service.AppDegradeService;
|
10
|
import com.monitor.other.degrade.service.AppDegradeService;
|
9
|
import com.yoho.core.common.utils.MD5;
|
11
|
import com.yoho.core.common.utils.MD5;
|
10
|
import org.apache.commons.collections.CollectionUtils;
|
12
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
13
|
+import org.apache.commons.lang3.StringUtils;
|
11
|
import org.springframework.stereotype.Service;
|
14
|
import org.springframework.stereotype.Service;
|
12
|
|
15
|
|
13
|
import javax.annotation.Resource;
|
16
|
import javax.annotation.Resource;
|
|
@@ -38,37 +41,37 @@ public class AppDegradeServiceImpl implements AppDegradeService { |
|
@@ -38,37 +41,37 @@ public class AppDegradeServiceImpl implements AppDegradeService { |
38
|
|
41
|
|
39
|
@Override
|
42
|
@Override
|
40
|
public int updateAppDegradeConfig(AppDegradeInfoReq req) {
|
43
|
public int updateAppDegradeConfig(AppDegradeInfoReq req) {
|
41
|
- int result = appDegradeConfigMapper.updateByPrimaryKeySelective(req);
|
|
|
42
|
- if (result == 1) {
|
|
|
43
|
- List<AppDegradeConfig> list = appDegradeConfigMapper.getAllDegradeApi();
|
|
|
44
|
- StringBuffer sb = new StringBuffer();
|
|
|
45
|
- if (CollectionUtils.isNotEmpty(list)) {
|
|
|
46
|
- for (AppDegradeConfig appDegradeConfig : list) {
|
|
|
47
|
- sb.append(appDegradeConfig.getApiCode()).append(",");
|
|
|
48
|
- }
|
|
|
49
|
- sb.append(";");
|
|
|
50
|
- }
|
|
|
51
|
- SortedMap<String, String> param = new TreeMap<>();
|
|
|
52
|
- param.put("client_type", "iphone");
|
|
|
53
|
- param.put("private_key", "a85bb0674e08986c6b115d5e3a4884fa");
|
|
|
54
|
- param.put("app_version", "9.9.9");
|
|
|
55
|
- param.put("config_key", "demoteapi");
|
|
|
56
|
- param.put("method", "resources.config.syncAppDegrade");
|
|
|
57
|
- param.put("config_value", sb.toString().replace(",;", "").replace(";", ""));
|
|
|
58
|
- String cs = getClientSecret(param);
|
|
|
59
|
- param.put("client_secret", cs);
|
|
|
60
|
- param.remove("private_key");
|
|
|
61
|
- HttpClientUtil.doget("http://api.yoho.cn", param, null);
|
|
|
62
|
- }
|
|
|
63
|
- return result;
|
44
|
+ return appDegradeConfigMapper.updateByPrimaryKeySelective(req);
|
64
|
}
|
45
|
}
|
65
|
|
46
|
|
66
|
@Override
|
47
|
@Override
|
67
|
- public int addAppDegradeConfig(AppDegradeInfoReq req) {
|
|
|
68
|
- return 0;
|
48
|
+ public int sync() {
|
|
|
49
|
+ List<AppDegradeConfig> list = appDegradeConfigMapper.getAllDegradeApi();
|
|
|
50
|
+ StringBuffer sb = new StringBuffer();
|
|
|
51
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
52
|
+ for (AppDegradeConfig appDegradeConfig : list) {
|
|
|
53
|
+ sb.append(appDegradeConfig.getApiCode()).append(",");
|
|
|
54
|
+ }
|
|
|
55
|
+ sb.append(";");
|
|
|
56
|
+ }
|
|
|
57
|
+ SortedMap<String, String> param = new TreeMap<>();
|
|
|
58
|
+ param.put("client_type", "iphone");
|
|
|
59
|
+ param.put("private_key", "a85bb0674e08986c6b115d5e3a4884fa");
|
|
|
60
|
+ param.put("app_version", "9.9.9");
|
|
|
61
|
+ param.put("config_key", "demoteapi");
|
|
|
62
|
+ param.put("method", "resources.config.syncAppDegrade");
|
|
|
63
|
+ param.put("config_value", sb.toString().replace(",;", "").replace(";", ""));
|
|
|
64
|
+ String cs = getClientSecret(param);
|
|
|
65
|
+ param.put("client_secret", cs);
|
|
|
66
|
+ param.remove("private_key");
|
|
|
67
|
+ String result = HttpClientUtil.doget("http://api.yoho.cn", param, null);
|
|
|
68
|
+ if (StringUtils.isNotEmpty(result)) {
|
|
|
69
|
+ JSONObject json = JSON.parseObject(result);
|
|
|
70
|
+ return json.getIntValue("code");
|
|
|
71
|
+ }
|
|
|
72
|
+ return 201;
|
69
|
}
|
73
|
}
|
70
|
|
74
|
|
71
|
-
|
|
|
72
|
public String getClientSecret(SortedMap<String, String> filtedMap) {
|
75
|
public String getClientSecret(SortedMap<String, String> filtedMap) {
|
73
|
filtedMap.remove("client_secret");
|
76
|
filtedMap.remove("client_secret");
|
74
|
List<String> array = new LinkedList<>();
|
77
|
List<String> array = new LinkedList<>();
|
|
@@ -80,4 +83,6 @@ public class AppDegradeServiceImpl implements AppDegradeService { |
|
@@ -80,4 +83,6 @@ public class AppDegradeServiceImpl implements AppDegradeService { |
80
|
String sign = MD5.md5(signStr);
|
83
|
String sign = MD5.md5(signStr);
|
81
|
return sign;
|
84
|
return sign;
|
82
|
}
|
85
|
}
|
|
|
86
|
+
|
|
|
87
|
+
|
83
|
} |
88
|
} |