Authored by menglingjie

add

@@ -28,23 +28,38 @@ public class AppDegradeController { @@ -28,23 +28,38 @@ public class AppDegradeController {
28 28
29 @RequestMapping("/getList") 29 @RequestMapping("/getList")
30 @ResponseBody 30 @ResponseBody
31 - public BaseResponse<PageResponse<AppDegradeConfig>> getDegradeConfigList(@RequestBody AppDegradeInfoReq req){ 31 + public BaseResponse<PageResponse<AppDegradeConfig>> getDegradeConfigList(@RequestBody AppDegradeInfoReq req) {
32 PageResponse<AppDegradeConfig> pageResponse = appDegradeService.getAppDegradeConfigList(req); 32 PageResponse<AppDegradeConfig> pageResponse = appDegradeService.getAppDegradeConfigList(req);
33 return new BaseResponse<>(pageResponse); 33 return new BaseResponse<>(pageResponse);
34 } 34 }
35 35
36 @RequestMapping("/change") 36 @RequestMapping("/change")
37 @ResponseBody 37 @ResponseBody
38 - public BaseResponse addDegradeConfig(@RequestBody AppDegradeInfoReq req){ 38 + public BaseResponse addDegradeConfig(@RequestBody AppDegradeInfoReq req) {
39 BaseResponse<Integer> baseResponse = new BaseResponse<>(); 39 BaseResponse<Integer> baseResponse = new BaseResponse<>();
40 - if (req.getId()>0) { 40 + if (req.getId() > 0) {
41 baseResponse.setData(appDegradeService.updateAppDegradeConfig(req)); 41 baseResponse.setData(appDegradeService.updateAppDegradeConfig(req));
42 - } else {  
43 - baseResponse.setData(appDegradeService.addAppDegradeConfig(req));  
44 } 42 }
45 -  
46 return baseResponse; 43 return baseResponse;
47 } 44 }
48 45
  46 + @RequestMapping("/sync")
  47 + @ResponseBody
  48 + public BaseResponse sync() {
  49 + BaseResponse<Integer> baseResponse = new BaseResponse<>();
  50 + try {
  51 + int sync = appDegradeService.sync();
  52 + if (sync == 200) {
  53 + baseResponse.setMessage("同步成功");
  54 + } else {
  55 + baseResponse.setMessage("同步失败");
  56 + }
  57 + return baseResponse;
  58 + } catch (Exception e) {
  59 + baseResponse.setCode(201);
  60 + baseResponse.setMessage("同步失败");
  61 + return baseResponse;
  62 + }
49 63
  64 + }
50 } 65 }
@@ -14,5 +14,5 @@ public interface AppDegradeService { @@ -14,5 +14,5 @@ public interface AppDegradeService {
14 14
15 int updateAppDegradeConfig(AppDegradeInfoReq req); 15 int updateAppDegradeConfig(AppDegradeInfoReq req);
16 16
17 - int addAppDegradeConfig(AppDegradeInfoReq req); 17 + int sync();
18 } 18 }
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 }