Authored by menglingjie

add

... ... @@ -28,23 +28,38 @@ public class AppDegradeController {
@RequestMapping("/getList")
@ResponseBody
public BaseResponse<PageResponse<AppDegradeConfig>> getDegradeConfigList(@RequestBody AppDegradeInfoReq req){
public BaseResponse<PageResponse<AppDegradeConfig>> getDegradeConfigList(@RequestBody AppDegradeInfoReq req) {
PageResponse<AppDegradeConfig> pageResponse = appDegradeService.getAppDegradeConfigList(req);
return new BaseResponse<>(pageResponse);
}
@RequestMapping("/change")
@ResponseBody
public BaseResponse addDegradeConfig(@RequestBody AppDegradeInfoReq req){
public BaseResponse addDegradeConfig(@RequestBody AppDegradeInfoReq req) {
BaseResponse<Integer> baseResponse = new BaseResponse<>();
if (req.getId()>0) {
if (req.getId() > 0) {
baseResponse.setData(appDegradeService.updateAppDegradeConfig(req));
} else {
baseResponse.setData(appDegradeService.addAppDegradeConfig(req));
}
return baseResponse;
}
@RequestMapping("/sync")
@ResponseBody
public BaseResponse sync() {
BaseResponse<Integer> baseResponse = new BaseResponse<>();
try {
int sync = appDegradeService.sync();
if (sync == 200) {
baseResponse.setMessage("同步成功");
} else {
baseResponse.setMessage("同步失败");
}
return baseResponse;
} catch (Exception e) {
baseResponse.setCode(201);
baseResponse.setMessage("同步失败");
return baseResponse;
}
}
}
... ...
... ... @@ -14,5 +14,5 @@ public interface AppDegradeService {
int updateAppDegradeConfig(AppDegradeInfoReq req);
int addAppDegradeConfig(AppDegradeInfoReq req);
int sync();
}
... ...
package com.monitor.other.degrade.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.monitor.common.util.HttpClientUtil;
import com.monitor.model.domain.AppDegradeConfig;
import com.monitor.model.request.AppDegradeInfoReq;
... ... @@ -8,6 +10,7 @@ import com.monitor.mysql.mapper.AppDegradeConfigMapper;
import com.monitor.other.degrade.service.AppDegradeService;
import com.yoho.core.common.utils.MD5;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -38,37 +41,37 @@ public class AppDegradeServiceImpl implements AppDegradeService {
@Override
public int updateAppDegradeConfig(AppDegradeInfoReq req) {
int result = appDegradeConfigMapper.updateByPrimaryKeySelective(req);
if (result == 1) {
List<AppDegradeConfig> list = appDegradeConfigMapper.getAllDegradeApi();
StringBuffer sb = new StringBuffer();
if (CollectionUtils.isNotEmpty(list)) {
for (AppDegradeConfig appDegradeConfig : list) {
sb.append(appDegradeConfig.getApiCode()).append(",");
}
sb.append(";");
}
SortedMap<String, String> param = new TreeMap<>();
param.put("client_type", "iphone");
param.put("private_key", "a85bb0674e08986c6b115d5e3a4884fa");
param.put("app_version", "9.9.9");
param.put("config_key", "demoteapi");
param.put("method", "resources.config.syncAppDegrade");
param.put("config_value", sb.toString().replace(",;", "").replace(";", ""));
String cs = getClientSecret(param);
param.put("client_secret", cs);
param.remove("private_key");
HttpClientUtil.doget("http://api.yoho.cn", param, null);
}
return result;
return appDegradeConfigMapper.updateByPrimaryKeySelective(req);
}
@Override
public int addAppDegradeConfig(AppDegradeInfoReq req) {
return 0;
public int sync() {
List<AppDegradeConfig> list = appDegradeConfigMapper.getAllDegradeApi();
StringBuffer sb = new StringBuffer();
if (CollectionUtils.isNotEmpty(list)) {
for (AppDegradeConfig appDegradeConfig : list) {
sb.append(appDegradeConfig.getApiCode()).append(",");
}
sb.append(";");
}
SortedMap<String, String> param = new TreeMap<>();
param.put("client_type", "iphone");
param.put("private_key", "a85bb0674e08986c6b115d5e3a4884fa");
param.put("app_version", "9.9.9");
param.put("config_key", "demoteapi");
param.put("method", "resources.config.syncAppDegrade");
param.put("config_value", sb.toString().replace(",;", "").replace(";", ""));
String cs = getClientSecret(param);
param.put("client_secret", cs);
param.remove("private_key");
String result = HttpClientUtil.doget("http://api.yoho.cn", param, null);
if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result);
return json.getIntValue("code");
}
return 201;
}
public String getClientSecret(SortedMap<String, String> filtedMap) {
filtedMap.remove("client_secret");
List<String> array = new LinkedList<>();
... ... @@ -80,4 +83,6 @@ public class AppDegradeServiceImpl implements AppDegradeService {
String sign = MD5.md5(signStr);
return sign;
}
}
... ...