Authored by zhaoqi

降级服务后台接口

@@ -24,4 +24,16 @@ public class DegradeConfig { @@ -24,4 +24,16 @@ public class DegradeConfig {
24 24
25 private String functionPointName; 25 private String functionPointName;
26 26
  27 + // 一级页面
  28 + private String level1Page;
  29 +
  30 + // 二级页面
  31 + private String level2Page;
  32 +
  33 + // 接口名称
  34 + private String apiName;
  35 +
  36 + // 客户端类型
  37 + private String clientType;
  38 +
27 } 39 }
@@ -9,19 +9,38 @@ import lombok.Data; @@ -9,19 +9,38 @@ import lombok.Data;
9 @Data 9 @Data
10 public class DegradeInfoReq extends PageRequest { 10 public class DegradeInfoReq extends PageRequest {
11 11
  12 + // 集群 qq/aws/gray
12 private String cloudType; 13 private String cloudType;
13 14
  15 + // 配置名称 eg. a.b.c
14 private String configName; 16 private String configName;
15 17
  18 + // 配置中文名称 eg. 商品详情页评论降级
16 private String configShowName; 19 private String configShowName;
17 20
  21 + // 等级
18 private Integer level; 22 private Integer level;
19 23
  24 + // 开关
20 private String switchOn; 25 private String switchOn;
21 26
22 private int id; 27 private int id;
23 28
  29 + // 配置描述
24 private String configDesc; 30 private String configDesc;
25 31
  32 + // 功能点
26 private String functionPointName; 33 private String functionPointName;
  34 +
  35 + // 一级页面
  36 + private String level1Page;
  37 +
  38 + // 二级页面
  39 + private String level2Page;
  40 +
  41 + // 接口名称
  42 + private String apiName;
  43 +
  44 + // 客户端类型
  45 + private String clientType;
27 } 46 }
@@ -20,5 +20,5 @@ public interface DegradeConfigMapper { @@ -20,5 +20,5 @@ public interface DegradeConfigMapper {
20 20
21 List<DegradeConfig> selectByCondition(DegradeInfoReq req); 21 List<DegradeConfig> selectByCondition(DegradeInfoReq req);
22 22
23 - List<String> selectAllFunction(); 23 + List<DegradeConfig> selectInitInfo();
24 } 24 }
@@ -10,9 +10,13 @@ @@ -10,9 +10,13 @@
10 <result column="level" property="level" jdbcType="TINYINT" /> 10 <result column="level" property="level" jdbcType="TINYINT" />
11 <result column="img_url" property="imgUrl" jdbcType="VARCHAR" /> 11 <result column="img_url" property="imgUrl" jdbcType="VARCHAR" />
12 <result column="function_point_name" property="functionPointName" jdbcType="VARCHAR" /> 12 <result column="function_point_name" property="functionPointName" jdbcType="VARCHAR" />
  13 + <result column="level1_page" property="level1Page" jdbcType="VARCHAR" />
  14 + <result column="level2_page" property="level2Page" jdbcType="VARCHAR" />
  15 + <result column="api_name" property="apiName" jdbcType="VARCHAR" />
  16 + <result column="client_type" property="clientType" jdbcType="VARCHAR" />
13 </resultMap> 17 </resultMap>
14 <sql id="Base_Column_List" > 18 <sql id="Base_Column_List" >
15 - id, config_name, config_show_name, switch_on, config_desc, level, img_url,function_point_name 19 + id, config_name, config_show_name, switch_on, config_desc, level, img_url,function_point_name,level1_page,level2_page,api_name,client_type
16 </sql> 20 </sql>
17 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 21 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
18 select 22 select
@@ -31,11 +35,20 @@ @@ -31,11 +35,20 @@
31 <if test="level != null &amp;&amp; level != '' " > 35 <if test="level != null &amp;&amp; level != '' " >
32 and level = #{level} 36 and level = #{level}
33 </if> 37 </if>
  38 + <if test="level1Page != null &amp;&amp; level1Page != '' " >
  39 + and level1_page = #{level1Page}
  40 + </if>
  41 + <if test="level2Page != null &amp;&amp; level2Page != '' " >
  42 + and level2_page = #{level2Page}
  43 + </if>
  44 + <if test="clientType != null &amp;&amp; clientType != '' &amp;&amp;clientType != '全部' " >
  45 + and client_type = #{clientType}
  46 + </if>
34 </select> 47 </select>
35 48
36 - <select id="selectAllFunction" resultType="java.lang.String">  
37 - select function_point_name  
38 - from degrade_info WHERE function_point_name IS NOT NULL AND function_point_name !='' group by function_point_name 49 + <select id="selectInitInfo" resultMap="BaseResultMap">
  50 + select DISTINCT function_point_name,level1_page,level2_page
  51 + from degrade_info
39 </select> 52 </select>
40 53
41 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > 54 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
@@ -44,10 +57,11 @@ @@ -44,10 +57,11 @@
44 </delete> 57 </delete>
45 <insert id="insert" parameterType="com.monitor.model.domain.DegradeConfig" > 58 <insert id="insert" parameterType="com.monitor.model.domain.DegradeConfig" >
46 insert into degrade_info (id, config_name, config_show_name, switch_on, 59 insert into degrade_info (id, config_name, config_show_name, switch_on,
47 - config_desc, level, img_url,function_point_name 60 + config_desc, level, img_url,function_point_name,level1_page,level2_page,api_name,client_type
48 ) 61 )
49 values (#{id,jdbcType=INTEGER}, #{configName,jdbcType=VARCHAR}, #{configShowName,jdbcType=VARCHAR}, #{switchOn,jdbcType=CHAR}, 62 values (#{id,jdbcType=INTEGER}, #{configName,jdbcType=VARCHAR}, #{configShowName,jdbcType=VARCHAR}, #{switchOn,jdbcType=CHAR},
50 - #{configDesc,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}, #{imgUrl,jdbcType=VARCHAR},#{functionPointName,jdbcType=VARCHAR} 63 + #{configDesc,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}, #{imgUrl,jdbcType=VARCHAR},#{functionPointName,jdbcType=VARCHAR},
  64 + #{level1Page,jdbcType=VARCHAR},#{level2Page,jdbcType=VARCHAR},#{apiName,jdbcType=VARCHAR},#{clientType,jdbcType=VARCHAR}
51 ) 65 )
52 </insert> 66 </insert>
53 <insert id="insertSelective" parameterType="com.monitor.model.domain.DegradeConfig" > 67 <insert id="insertSelective" parameterType="com.monitor.model.domain.DegradeConfig" >
@@ -74,6 +88,18 @@ @@ -74,6 +88,18 @@
74 <if test="functionPointName != null" > 88 <if test="functionPointName != null" >
75 function_point_name, 89 function_point_name,
76 </if> 90 </if>
  91 + <if test="level1Page != null" >
  92 + level1_page,
  93 + </if>
  94 + <if test="level2Page != null" >
  95 + level2_page,
  96 + </if>
  97 + <if test="apiName != null" >
  98 + api_name,
  99 + </if>
  100 + <if test="clientType != null" >
  101 + client_type,
  102 + </if>
77 </trim> 103 </trim>
78 <trim prefix="values (" suffix=")" suffixOverrides="," > 104 <trim prefix="values (" suffix=")" suffixOverrides="," >
79 <if test="configName != null" > 105 <if test="configName != null" >
@@ -97,6 +123,18 @@ @@ -97,6 +123,18 @@
97 <if test="functionPointName != null" > 123 <if test="functionPointName != null" >
98 #{functionPointName,jdbcType=VARCHAR}, 124 #{functionPointName,jdbcType=VARCHAR},
99 </if> 125 </if>
  126 + <if test="level1Page != null" >
  127 + #{level1Page,jdbcType=VARCHAR},
  128 + </if>
  129 + <if test="level2Page != null" >
  130 + #{level2Page,jdbcType=VARCHAR},
  131 + </if>
  132 + <if test="apiName != null" >
  133 + #{apiName,jdbcType=VARCHAR},
  134 + </if>
  135 + <if test="clientType != null" >
  136 + #{clientType,jdbcType=VARCHAR},
  137 + </if>
100 </trim> 138 </trim>
101 </insert> 139 </insert>
102 <update id="updateByPrimaryKeySelective" parameterType="com.monitor.model.domain.DegradeConfig" > 140 <update id="updateByPrimaryKeySelective" parameterType="com.monitor.model.domain.DegradeConfig" >
@@ -120,6 +158,18 @@ @@ -120,6 +158,18 @@
120 <if test="functionPointName != null" > 158 <if test="functionPointName != null" >
121 function_point_name = #{functionPointName,jdbcType=VARCHAR}, 159 function_point_name = #{functionPointName,jdbcType=VARCHAR},
122 </if> 160 </if>
  161 + <if test="level1Page != null" >
  162 + level1_page = #{level1Page,jdbcType=VARCHAR},
  163 + </if>
  164 + <if test="level2Page != null" >
  165 + level2_page = #{level2Page,jdbcType=VARCHAR},
  166 + </if>
  167 + <if test="apiName != null" >
  168 + api_name = #{apiName,jdbcType=VARCHAR},
  169 + </if>
  170 + <if test="clientType != null" >
  171 + client_type = #{clientType,jdbcType=VARCHAR},
  172 + </if>
123 </set> 173 </set>
124 where id = #{id,jdbcType=INTEGER} 174 where id = #{id,jdbcType=INTEGER}
125 </update> 175 </update>
@@ -131,7 +181,11 @@ @@ -131,7 +181,11 @@
131 config_desc = #{configDesc,jdbcType=VARCHAR}, 181 config_desc = #{configDesc,jdbcType=VARCHAR},
132 level = #{level,jdbcType=TINYINT}, 182 level = #{level,jdbcType=TINYINT},
133 img_url = #{imgUrl,jdbcType=VARCHAR}, 183 img_url = #{imgUrl,jdbcType=VARCHAR},
134 - function_point_name = #{functionPointName,jdbcType=VARCHAR} 184 + function_point_name = #{functionPointName,jdbcType=VARCHAR},
  185 + level1_page = #{level1Page,jdbcType=VARCHAR},
  186 + level2_page = #{level2Page,jdbcType=VARCHAR},
  187 + api_name = #{apiName,jdbcType=VARCHAR},
  188 + client_type = #{clientType,jdbcType=VARCHAR}
135 where id = #{id,jdbcType=INTEGER} 189 where id = #{id,jdbcType=INTEGER}
136 </update> 190 </update>
137 </mapper> 191 </mapper>
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
12 12
13 import javax.annotation.Resource; 13 import javax.annotation.Resource;
14 import java.util.List; 14 import java.util.List;
  15 +import java.util.Map;
15 16
16 /** 17 /**
17 * Created by zhaoqi on 2016/8/26 0026. 18 * Created by zhaoqi on 2016/8/26 0026.
@@ -44,12 +45,11 @@ public class DegradeController { @@ -44,12 +45,11 @@ public class DegradeController {
44 return baseResponse; 45 return baseResponse;
45 } 46 }
46 47
47 - @RequestMapping("/getFunction") 48 + @RequestMapping("/getInitInfo")
48 @ResponseBody 49 @ResponseBody
49 - public BaseResponse getFunction(){  
50 - BaseResponse<List> baseResponse = new BaseResponse<>();  
51 - List<String> functions = degradeService.getFunction();  
52 - baseResponse.setData(functions); 50 + public BaseResponse getInitInfo(){
  51 + BaseResponse<Map> baseResponse = new BaseResponse<>();
  52 + baseResponse.setData(degradeService.getInitInfo());
53 return baseResponse; 53 return baseResponse;
54 } 54 }
55 55
@@ -5,6 +5,8 @@ import com.monitor.model.response.PageResponse; @@ -5,6 +5,8 @@ import com.monitor.model.response.PageResponse;
5 import com.monitor.model.request.DegradeInfoReq; 5 import com.monitor.model.request.DegradeInfoReq;
6 6
7 import java.util.List; 7 import java.util.List;
  8 +import java.util.Map;
  9 +import java.util.Set;
8 10
9 /** 11 /**
10 * Created by zhaoqi on 2016/8/26 0026. 12 * Created by zhaoqi on 2016/8/26 0026.
@@ -17,5 +19,5 @@ public interface DegradeService { @@ -17,5 +19,5 @@ public interface DegradeService {
17 19
18 int updateDegradeConfig(DegradeInfoReq config); 20 int updateDegradeConfig(DegradeInfoReq config);
19 21
20 - List<String> getFunction(); 22 + Map<String,Set<String>> getInitInfo();
21 } 23 }
@@ -35,6 +35,8 @@ public class DegradeServiceImpl implements DegradeService { @@ -35,6 +35,8 @@ public class DegradeServiceImpl implements DegradeService {
35 35
36 private static String QQ = "zookeeper_qq"; 36 private static String QQ = "zookeeper_qq";
37 37
  38 + private static String GRAY = "gray_qq";
  39 +
38 // 测试用 40 // 测试用
39 // private static String TEST205 = "zookeeper_205"; 41 // private static String TEST205 = "zookeeper_205";
40 // private static String TEST211 = "zookeeper_211"; 42 // private static String TEST211 = "zookeeper_211";
@@ -71,8 +73,23 @@ public class DegradeServiceImpl implements DegradeService { @@ -71,8 +73,23 @@ public class DegradeServiceImpl implements DegradeService {
71 } 73 }
72 74
73 @Override 75 @Override
74 - public List<String> getFunction() {  
75 - return degradeConfigMapper.selectAllFunction(); 76 + public Map<String,Set<String>> getInitInfo() {
  77 + List<DegradeConfig> degradeConfigs = degradeConfigMapper.selectInitInfo();
  78 + Set<String> functionSet = new HashSet<>();
  79 + Set<String> level1PageSet = new HashSet<>();
  80 + Set<String> level2PageSet = new HashSet<>();
  81 + for (DegradeConfig degradeConfig : degradeConfigs) {
  82 + if (StringUtils.isNotBlank(degradeConfig.getFunctionPointName())) {
  83 + functionSet.add(degradeConfig.getFunctionPointName());
  84 + }
  85 + if (StringUtils.isNotBlank(degradeConfig.getLevel1Page())) {
  86 + level1PageSet.add(degradeConfig.getLevel1Page());
  87 + }
  88 + if (StringUtils.isNotBlank(degradeConfig.getLevel2Page())) {
  89 + level2PageSet.add(degradeConfig.getLevel2Page());
  90 + }
  91 + }
  92 + return new HashMap<String,Set<String>>(){{put("function",functionSet);put("level1",level1PageSet);put("level2",level2PageSet);}};
76 } 93 }
77 94
78 private void modifyZkConfig(DegradeInfoReq req) { 95 private void modifyZkConfig(DegradeInfoReq req) {
@@ -91,7 +108,7 @@ public class DegradeServiceImpl implements DegradeService { @@ -91,7 +108,7 @@ public class DegradeServiceImpl implements DegradeService {
91 } 108 }
92 109
93 zkTreeAllReq.setIp(req.getCloudType()); 110 zkTreeAllReq.setIp(req.getCloudType());
94 -// // test 111 + // test
95 // if (req.getCloudType().equals(AWS)) { 112 // if (req.getCloudType().equals(AWS)) {
96 // zkTreeAllReq.setIp(TEST205); 113 // zkTreeAllReq.setIp(TEST205);
97 // } else { 114 // } else {
@@ -121,7 +138,11 @@ public class DegradeServiceImpl implements DegradeService { @@ -121,7 +138,11 @@ public class DegradeServiceImpl implements DegradeService {
121 config.setImgUrl(configDb.getImgUrl()); 138 config.setImgUrl(configDb.getImgUrl());
122 config.setId(configDb.getId()); 139 config.setId(configDb.getId());
123 config.setLevel(configDb.getLevel()); 140 config.setLevel(configDb.getLevel());
  141 + config.setLevel1Page(configDb.getLevel1Page());
  142 + config.setLevel2Page(configDb.getLevel2Page());
  143 + config.setApiName(configDb.getApiName());
124 config.setFunctionPointName(configDb.getFunctionPointName()); 144 config.setFunctionPointName(configDb.getFunctionPointName());
  145 + config.setClientType(configDb.getClientType());
125 break; 146 break;
126 } 147 }
127 } 148 }
@@ -164,6 +185,26 @@ public class DegradeServiceImpl implements DegradeService { @@ -164,6 +185,26 @@ public class DegradeServiceImpl implements DegradeService {
164 continue; 185 continue;
165 } 186 }
166 } 187 }
  188 + if (StringUtils.isNotBlank(req.getLevel1Page())) {
  189 + if (!Objects.equals(degradeConfig.getLevel1Page(), req.getLevel1Page())) {
  190 + continue;
  191 + }
  192 + }
  193 + if (StringUtils.isNotBlank(req.getLevel2Page())) {
  194 + if (!Objects.equals(degradeConfig.getLevel2Page(), req.getLevel2Page())) {
  195 + continue;
  196 + }
  197 + }
  198 + if (StringUtils.isNotBlank(req.getClientType()) && !"全部".equals(req.getClientType())) {
  199 + if (!Objects.equals(degradeConfig.getClientType(), req.getClientType())) {
  200 + continue;
  201 + }
  202 + }
  203 + if (StringUtils.isNotBlank(req.getApiName())) {
  204 + if (!findByRegex(req.getApiName(),degradeConfig.getApiName())) {
  205 + continue;
  206 + }
  207 + }
167 // 名称没有degrade的配置也不要 208 // 名称没有degrade的配置也不要
168 if (!degradeConfig.getConfigName().contains("degrade")) { 209 if (!degradeConfig.getConfigName().contains("degrade")) {
169 continue; 210 continue;