Authored by zhaoqi

降级服务后台接口

... ... @@ -24,4 +24,16 @@ public class DegradeConfig {
private String functionPointName;
// 一级页面
private String level1Page;
// 二级页面
private String level2Page;
// 接口名称
private String apiName;
// 客户端类型
private String clientType;
}
... ...
... ... @@ -9,19 +9,38 @@ import lombok.Data;
@Data
public class DegradeInfoReq extends PageRequest {
// 集群 qq/aws/gray
private String cloudType;
// 配置名称 eg. a.b.c
private String configName;
// 配置中文名称 eg. 商品详情页评论降级
private String configShowName;
// 等级
private Integer level;
// 开关
private String switchOn;
private int id;
// 配置描述
private String configDesc;
// 功能点
private String functionPointName;
// 一级页面
private String level1Page;
// 二级页面
private String level2Page;
// 接口名称
private String apiName;
// 客户端类型
private String clientType;
}
... ...
... ... @@ -20,5 +20,5 @@ public interface DegradeConfigMapper {
List<DegradeConfig> selectByCondition(DegradeInfoReq req);
List<String> selectAllFunction();
List<DegradeConfig> selectInitInfo();
}
\ No newline at end of file
... ...
... ... @@ -10,9 +10,13 @@
<result column="level" property="level" jdbcType="TINYINT" />
<result column="img_url" property="imgUrl" jdbcType="VARCHAR" />
<result column="function_point_name" property="functionPointName" jdbcType="VARCHAR" />
<result column="level1_page" property="level1Page" jdbcType="VARCHAR" />
<result column="level2_page" property="level2Page" jdbcType="VARCHAR" />
<result column="api_name" property="apiName" jdbcType="VARCHAR" />
<result column="client_type" property="clientType" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, config_name, config_show_name, switch_on, config_desc, level, img_url,function_point_name
id, config_name, config_show_name, switch_on, config_desc, level, img_url,function_point_name,level1_page,level2_page,api_name,client_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -31,11 +35,20 @@
<if test="level != null &amp;&amp; level != '' " >
and level = #{level}
</if>
<if test="level1Page != null &amp;&amp; level1Page != '' " >
and level1_page = #{level1Page}
</if>
<if test="level2Page != null &amp;&amp; level2Page != '' " >
and level2_page = #{level2Page}
</if>
<if test="clientType != null &amp;&amp; clientType != '' &amp;&amp;clientType != '全部' " >
and client_type = #{clientType}
</if>
</select>
<select id="selectAllFunction" resultType="java.lang.String">
select function_point_name
from degrade_info WHERE function_point_name IS NOT NULL AND function_point_name !='' group by function_point_name
<select id="selectInitInfo" resultMap="BaseResultMap">
select DISTINCT function_point_name,level1_page,level2_page
from degrade_info
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
... ... @@ -44,10 +57,11 @@
</delete>
<insert id="insert" parameterType="com.monitor.model.domain.DegradeConfig" >
insert into degrade_info (id, config_name, config_show_name, switch_on,
config_desc, level, img_url,function_point_name
config_desc, level, img_url,function_point_name,level1_page,level2_page,api_name,client_type
)
values (#{id,jdbcType=INTEGER}, #{configName,jdbcType=VARCHAR}, #{configShowName,jdbcType=VARCHAR}, #{switchOn,jdbcType=CHAR},
#{configDesc,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}, #{imgUrl,jdbcType=VARCHAR},#{functionPointName,jdbcType=VARCHAR}
#{configDesc,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}, #{imgUrl,jdbcType=VARCHAR},#{functionPointName,jdbcType=VARCHAR},
#{level1Page,jdbcType=VARCHAR},#{level2Page,jdbcType=VARCHAR},#{apiName,jdbcType=VARCHAR},#{clientType,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.monitor.model.domain.DegradeConfig" >
... ... @@ -74,6 +88,18 @@
<if test="functionPointName != null" >
function_point_name,
</if>
<if test="level1Page != null" >
level1_page,
</if>
<if test="level2Page != null" >
level2_page,
</if>
<if test="apiName != null" >
api_name,
</if>
<if test="clientType != null" >
client_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="configName != null" >
... ... @@ -97,6 +123,18 @@
<if test="functionPointName != null" >
#{functionPointName,jdbcType=VARCHAR},
</if>
<if test="level1Page != null" >
#{level1Page,jdbcType=VARCHAR},
</if>
<if test="level2Page != null" >
#{level2Page,jdbcType=VARCHAR},
</if>
<if test="apiName != null" >
#{apiName,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
#{clientType,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.monitor.model.domain.DegradeConfig" >
... ... @@ -120,6 +158,18 @@
<if test="functionPointName != null" >
function_point_name = #{functionPointName,jdbcType=VARCHAR},
</if>
<if test="level1Page != null" >
level1_page = #{level1Page,jdbcType=VARCHAR},
</if>
<if test="level2Page != null" >
level2_page = #{level2Page,jdbcType=VARCHAR},
</if>
<if test="apiName != null" >
api_name = #{apiName,jdbcType=VARCHAR},
</if>
<if test="clientType != null" >
client_type = #{clientType,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
... ... @@ -131,7 +181,11 @@
config_desc = #{configDesc,jdbcType=VARCHAR},
level = #{level,jdbcType=TINYINT},
img_url = #{imgUrl,jdbcType=VARCHAR},
function_point_name = #{functionPointName,jdbcType=VARCHAR}
function_point_name = #{functionPointName,jdbcType=VARCHAR},
level1_page = #{level1Page,jdbcType=VARCHAR},
level2_page = #{level2Page,jdbcType=VARCHAR},
api_name = #{apiName,jdbcType=VARCHAR},
client_type = #{clientType,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
* Created by zhaoqi on 2016/8/26 0026.
... ... @@ -44,12 +45,11 @@ public class DegradeController {
return baseResponse;
}
@RequestMapping("/getFunction")
@RequestMapping("/getInitInfo")
@ResponseBody
public BaseResponse getFunction(){
BaseResponse<List> baseResponse = new BaseResponse<>();
List<String> functions = degradeService.getFunction();
baseResponse.setData(functions);
public BaseResponse getInitInfo(){
BaseResponse<Map> baseResponse = new BaseResponse<>();
baseResponse.setData(degradeService.getInitInfo());
return baseResponse;
}
... ...
... ... @@ -5,6 +5,8 @@ import com.monitor.model.response.PageResponse;
import com.monitor.model.request.DegradeInfoReq;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by zhaoqi on 2016/8/26 0026.
... ... @@ -17,5 +19,5 @@ public interface DegradeService {
int updateDegradeConfig(DegradeInfoReq config);
List<String> getFunction();
Map<String,Set<String>> getInitInfo();
}
... ...
... ... @@ -35,6 +35,8 @@ public class DegradeServiceImpl implements DegradeService {
private static String QQ = "zookeeper_qq";
private static String GRAY = "gray_qq";
// 测试用
// private static String TEST205 = "zookeeper_205";
// private static String TEST211 = "zookeeper_211";
... ... @@ -71,8 +73,23 @@ public class DegradeServiceImpl implements DegradeService {
}
@Override
public List<String> getFunction() {
return degradeConfigMapper.selectAllFunction();
public Map<String,Set<String>> getInitInfo() {
List<DegradeConfig> degradeConfigs = degradeConfigMapper.selectInitInfo();
Set<String> functionSet = new HashSet<>();
Set<String> level1PageSet = new HashSet<>();
Set<String> level2PageSet = new HashSet<>();
for (DegradeConfig degradeConfig : degradeConfigs) {
if (StringUtils.isNotBlank(degradeConfig.getFunctionPointName())) {
functionSet.add(degradeConfig.getFunctionPointName());
}
if (StringUtils.isNotBlank(degradeConfig.getLevel1Page())) {
level1PageSet.add(degradeConfig.getLevel1Page());
}
if (StringUtils.isNotBlank(degradeConfig.getLevel2Page())) {
level2PageSet.add(degradeConfig.getLevel2Page());
}
}
return new HashMap<String,Set<String>>(){{put("function",functionSet);put("level1",level1PageSet);put("level2",level2PageSet);}};
}
private void modifyZkConfig(DegradeInfoReq req) {
... ... @@ -91,7 +108,7 @@ public class DegradeServiceImpl implements DegradeService {
}
zkTreeAllReq.setIp(req.getCloudType());
// // test
// test
// if (req.getCloudType().equals(AWS)) {
// zkTreeAllReq.setIp(TEST205);
// } else {
... ... @@ -121,7 +138,11 @@ public class DegradeServiceImpl implements DegradeService {
config.setImgUrl(configDb.getImgUrl());
config.setId(configDb.getId());
config.setLevel(configDb.getLevel());
config.setLevel1Page(configDb.getLevel1Page());
config.setLevel2Page(configDb.getLevel2Page());
config.setApiName(configDb.getApiName());
config.setFunctionPointName(configDb.getFunctionPointName());
config.setClientType(configDb.getClientType());
break;
}
}
... ... @@ -164,6 +185,26 @@ public class DegradeServiceImpl implements DegradeService {
continue;
}
}
if (StringUtils.isNotBlank(req.getLevel1Page())) {
if (!Objects.equals(degradeConfig.getLevel1Page(), req.getLevel1Page())) {
continue;
}
}
if (StringUtils.isNotBlank(req.getLevel2Page())) {
if (!Objects.equals(degradeConfig.getLevel2Page(), req.getLevel2Page())) {
continue;
}
}
if (StringUtils.isNotBlank(req.getClientType()) && !"全部".equals(req.getClientType())) {
if (!Objects.equals(degradeConfig.getClientType(), req.getClientType())) {
continue;
}
}
if (StringUtils.isNotBlank(req.getApiName())) {
if (!findByRegex(req.getApiName(),degradeConfig.getApiName())) {
continue;
}
}
// 名称没有degrade的配置也不要
if (!degradeConfig.getConfigName().contains("degrade")) {
continue;
... ...