mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 03:42:07 +08:00
后端增加指标摆放顺序功能
This commit is contained in:
@@ -7,12 +7,14 @@ import com.didiglobal.logi.log.LogFactory;
|
|||||||
import com.didiglobal.logi.security.common.dto.config.ConfigDTO;
|
import com.didiglobal.logi.security.common.dto.config.ConfigDTO;
|
||||||
import com.didiglobal.logi.security.service.ConfigService;
|
import com.didiglobal.logi.security.service.ConfigService;
|
||||||
import com.xiaojukeji.know.streaming.km.biz.version.VersionControlManager;
|
import com.xiaojukeji.know.streaming.km.biz.version.VersionControlManager;
|
||||||
|
import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.MetricDetailDTO;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.UserMetricConfigDTO;
|
import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.UserMetricConfigDTO;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.metric.UserMetricConfig;
|
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.metric.UserMetricConfig;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
|
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.entity.version.VersionControlItem;
|
import com.xiaojukeji.know.streaming.km.common.bean.entity.version.VersionControlItem;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.vo.config.metric.UserMetricConfigVO;
|
import com.xiaojukeji.know.streaming.km.common.bean.vo.config.metric.UserMetricConfigVO;
|
||||||
import com.xiaojukeji.know.streaming.km.common.bean.vo.version.VersionItemVO;
|
import com.xiaojukeji.know.streaming.km.common.bean.vo.version.VersionItemVO;
|
||||||
|
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
|
||||||
import com.xiaojukeji.know.streaming.km.common.enums.version.VersionEnum;
|
import com.xiaojukeji.know.streaming.km.common.enums.version.VersionEnum;
|
||||||
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
|
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
|
||||||
import com.xiaojukeji.know.streaming.km.common.utils.VersionUtil;
|
import com.xiaojukeji.know.streaming.km.common.utils.VersionUtil;
|
||||||
@@ -159,6 +161,9 @@ public class VersionControlManagerImpl implements VersionControlManager {
|
|||||||
|
|
||||||
UserMetricConfig umc = userMetricConfigMap.get(itemType + "@" + metric);
|
UserMetricConfig umc = userMetricConfigMap.get(itemType + "@" + metric);
|
||||||
userMetricConfigVO.setSet(null != umc && umc.isSet());
|
userMetricConfigVO.setSet(null != umc && umc.isSet());
|
||||||
|
if (umc != null) {
|
||||||
|
userMetricConfigVO.setRank(umc.getRank());
|
||||||
|
}
|
||||||
userMetricConfigVO.setName(itemVO.getName());
|
userMetricConfigVO.setName(itemVO.getName());
|
||||||
userMetricConfigVO.setType(itemVO.getType());
|
userMetricConfigVO.setType(itemVO.getType());
|
||||||
userMetricConfigVO.setDesc(itemVO.getDesc());
|
userMetricConfigVO.setDesc(itemVO.getDesc());
|
||||||
@@ -178,13 +183,30 @@ public class VersionControlManagerImpl implements VersionControlManager {
|
|||||||
@Override
|
@Override
|
||||||
public Result<Void> updateUserMetricItem(Long clusterId, Integer type, UserMetricConfigDTO dto, String operator) {
|
public Result<Void> updateUserMetricItem(Long clusterId, Integer type, UserMetricConfigDTO dto, String operator) {
|
||||||
Map<String, Boolean> metricsSetMap = dto.getMetricsSet();
|
Map<String, Boolean> metricsSetMap = dto.getMetricsSet();
|
||||||
if(null == metricsSetMap || metricsSetMap.isEmpty()){
|
|
||||||
|
//转换metricDetailDTOList
|
||||||
|
List<MetricDetailDTO> metricDetailDTOList = dto.getMetricDetailDTOList();
|
||||||
|
Map<String, MetricDetailDTO> metricDetailMap = new HashMap<>();
|
||||||
|
if (metricDetailDTOList != null && !metricDetailDTOList.isEmpty()) {
|
||||||
|
metricDetailMap = metricDetailDTOList.stream().collect(Collectors.toMap(MetricDetailDTO::getMetric, Function.identity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//转换metricsSetMap
|
||||||
|
if (metricsSetMap != null && !metricsSetMap.isEmpty()) {
|
||||||
|
for (Map.Entry<String, Boolean> metricAndShowEntry : metricsSetMap.entrySet()) {
|
||||||
|
if (metricDetailMap.containsKey(metricAndShowEntry.getKey())) continue;
|
||||||
|
metricDetailMap.put(metricAndShowEntry.getKey(), new MetricDetailDTO(metricAndShowEntry.getKey(), metricAndShowEntry.getValue(), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metricDetailMap.isEmpty()) {
|
||||||
return Result.buildSuc();
|
return Result.buildSuc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Set<UserMetricConfig> userMetricConfigs = getUserMetricConfig(operator);
|
Set<UserMetricConfig> userMetricConfigs = getUserMetricConfig(operator);
|
||||||
for(Map.Entry<String, Boolean> metricAndShowEntry : metricsSetMap.entrySet()){
|
for(Map.Entry<String, Boolean> metricAndShowEntry : metricsSetMap.entrySet()){
|
||||||
UserMetricConfig userMetricConfig = new UserMetricConfig(type, metricAndShowEntry.getKey(), metricAndShowEntry.getValue());
|
UserMetricConfig userMetricConfig = new UserMetricConfig(type, metricAndShowEntry.getKey(), metricAndShowEntry.getValue(), metricDetailMap.get(metricAndShowEntry.getKey()).getRank());
|
||||||
userMetricConfigs.remove(userMetricConfig);
|
userMetricConfigs.remove(userMetricConfig);
|
||||||
userMetricConfigs.add(userMetricConfig);
|
userMetricConfigs.add(userMetricConfig);
|
||||||
}
|
}
|
||||||
@@ -228,7 +250,15 @@ public class VersionControlManagerImpl implements VersionControlManager {
|
|||||||
return defaultMetrics;
|
return defaultMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.parseObject(value, new TypeReference<Set<UserMetricConfig>>(){});
|
Set<UserMetricConfig> userMetricConfigs = JSON.parseObject(value, new TypeReference<Set<UserMetricConfig>>() {});
|
||||||
|
|
||||||
|
//补充rank不存在情况
|
||||||
|
for (UserMetricConfig userMetricConfig : userMetricConfigs) {
|
||||||
|
if (userMetricConfig.getRank() == 0) {
|
||||||
|
userMetricConfig.setRank(Constant.DEFAULT_METRIC_RANK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return userMetricConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.xiaojukeji.know.streaming.km.common.bean.dto.metrices;
|
||||||
|
|
||||||
|
import com.xiaojukeji.know.streaming.km.common.bean.dto.BaseDTO;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author didi
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@ApiModel(description = "指标详细属性信息")
|
||||||
|
public class MetricDetailDTO extends BaseDTO {
|
||||||
|
|
||||||
|
@ApiModelProperty("指标名称")
|
||||||
|
private String metric;
|
||||||
|
|
||||||
|
@ApiModelProperty("指标是否显示")
|
||||||
|
private Boolean set;
|
||||||
|
|
||||||
|
@ApiModelProperty("指标优先级")
|
||||||
|
private Integer rank;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@@ -17,4 +18,7 @@ import java.util.Map;
|
|||||||
public class UserMetricConfigDTO extends BaseDTO {
|
public class UserMetricConfigDTO extends BaseDTO {
|
||||||
@ApiModelProperty("指标展示设置项,key:指标名;value:是否展现(true展现/false不展现)")
|
@ApiModelProperty("指标展示设置项,key:指标名;value:是否展现(true展现/false不展现)")
|
||||||
private Map<String, Boolean> metricsSet;
|
private Map<String, Boolean> metricsSet;
|
||||||
|
|
||||||
|
@ApiModelProperty("指标自定义属性列表")
|
||||||
|
private List<MetricDetailDTO> metricDetailDTOList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.xiaojukeji.know.streaming.km.common.bean.entity.config.metric;
|
package com.xiaojukeji.know.streaming.km.common.bean.entity.config.metric;
|
||||||
|
|
||||||
|
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserMetricConfig {
|
public class UserMetricConfig {
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
@@ -15,6 +15,22 @@ public class UserMetricConfig {
|
|||||||
|
|
||||||
private boolean set;
|
private boolean set;
|
||||||
|
|
||||||
|
private int rank;
|
||||||
|
|
||||||
|
public UserMetricConfig(int type, String metric, boolean set, Integer rank) {
|
||||||
|
this.type = type;
|
||||||
|
this.metric = metric;
|
||||||
|
this.set = set;
|
||||||
|
this.rank = rank == null ? Constant.DEFAULT_METRIC_RANK : rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserMetricConfig(int type, String metric, boolean set) {
|
||||||
|
this.type = type;
|
||||||
|
this.metric = metric;
|
||||||
|
this.set = set;
|
||||||
|
this.rank = Constant.DEFAULT_METRIC_RANK;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode(){
|
public int hashCode(){
|
||||||
return metric.hashCode() << 1 + type;
|
return metric.hashCode() << 1 + type;
|
||||||
|
|||||||
@@ -14,4 +14,7 @@ import lombok.NoArgsConstructor;
|
|||||||
public class UserMetricConfigVO extends VersionItemVO {
|
public class UserMetricConfigVO extends VersionItemVO {
|
||||||
@ApiModelProperty(value = "该指标用户是否设置展现", example = "true")
|
@ApiModelProperty(value = "该指标用户是否设置展现", example = "true")
|
||||||
private Boolean set;
|
private Boolean set;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "该指标展示优先级", example = "1")
|
||||||
|
private Integer rank;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ public class Constant {
|
|||||||
*/
|
*/
|
||||||
public static final Integer DEFAULT_CLUSTER_HEALTH_SCORE = 90;
|
public static final Integer DEFAULT_CLUSTER_HEALTH_SCORE = 90;
|
||||||
|
|
||||||
|
public static final Integer DEFAULT_METRIC_RANK = 10000;
|
||||||
|
|
||||||
public static final String DEFAULT_USER_NAME = "know-streaming-app";
|
public static final String DEFAULT_USER_NAME = "know-streaming-app";
|
||||||
|
|
||||||
public static final int INVALID_CODE = -1;
|
public static final int INVALID_CODE = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user