77import com .didiglobal .logi .security .common .dto .config .ConfigDTO ;
88import com .didiglobal .logi .security .service .ConfigService ;
99import com .xiaojukeji .know .streaming .km .biz .version .VersionControlManager ;
10+ import com .xiaojukeji .know .streaming .km .common .bean .dto .metrices .MetricDetailDTO ;
1011import com .xiaojukeji .know .streaming .km .common .bean .dto .metrices .UserMetricConfigDTO ;
1112import com .xiaojukeji .know .streaming .km .common .bean .entity .config .metric .UserMetricConfig ;
1213import com .xiaojukeji .know .streaming .km .common .bean .entity .result .Result ;
1314import com .xiaojukeji .know .streaming .km .common .bean .entity .version .VersionControlItem ;
1415import com .xiaojukeji .know .streaming .km .common .bean .vo .config .metric .UserMetricConfigVO ;
1516import com .xiaojukeji .know .streaming .km .common .bean .vo .version .VersionItemVO ;
17+ import com .xiaojukeji .know .streaming .km .common .constant .Constant ;
1618import com .xiaojukeji .know .streaming .km .common .enums .version .VersionEnum ;
1719import com .xiaojukeji .know .streaming .km .common .utils .ConvertUtil ;
1820import com .xiaojukeji .know .streaming .km .common .utils .VersionUtil ;
@@ -159,6 +161,9 @@ public Result<List<UserMetricConfigVO>> listUserMetricItem(Long clusterId, Integ
159161
160162 UserMetricConfig umc = userMetricConfigMap .get (itemType + "@" + metric );
161163 userMetricConfigVO .setSet (null != umc && umc .isSet ());
164+ if (umc != null ) {
165+ userMetricConfigVO .setRank (umc .getRank ());
166+ }
162167 userMetricConfigVO .setName (itemVO .getName ());
163168 userMetricConfigVO .setType (itemVO .getType ());
164169 userMetricConfigVO .setDesc (itemVO .getDesc ());
@@ -178,13 +183,30 @@ public Result<List<UserMetricConfigVO>> listUserMetricItem(Long clusterId, Integ
178183 @ Override
179184 public Result <Void > updateUserMetricItem (Long clusterId , Integer type , UserMetricConfigDTO dto , String operator ) {
180185 Map <String , Boolean > metricsSetMap = dto .getMetricsSet ();
181- if (null == metricsSetMap || metricsSetMap .isEmpty ()){
186+
187+ //转换metricDetailDTOList
188+ List <MetricDetailDTO > metricDetailDTOList = dto .getMetricDetailDTOList ();
189+ Map <String , MetricDetailDTO > metricDetailMap = new HashMap <>();
190+ if (metricDetailDTOList != null && !metricDetailDTOList .isEmpty ()) {
191+ metricDetailMap = metricDetailDTOList .stream ().collect (Collectors .toMap (MetricDetailDTO ::getMetric , Function .identity ()));
192+ }
193+
194+ //转换metricsSetMap
195+ if (metricsSetMap != null && !metricsSetMap .isEmpty ()) {
196+ for (Map .Entry <String , Boolean > metricAndShowEntry : metricsSetMap .entrySet ()) {
197+ if (metricDetailMap .containsKey (metricAndShowEntry .getKey ())) continue ;
198+ metricDetailMap .put (metricAndShowEntry .getKey (), new MetricDetailDTO (metricAndShowEntry .getKey (), metricAndShowEntry .getValue (), null ));
199+ }
200+ }
201+
202+ if (metricDetailMap .isEmpty ()) {
182203 return Result .buildSuc ();
183204 }
184205
206+
185207 Set <UserMetricConfig > userMetricConfigs = getUserMetricConfig (operator );
186208 for (Map .Entry <String , Boolean > metricAndShowEntry : metricsSetMap .entrySet ()){
187- UserMetricConfig userMetricConfig = new UserMetricConfig (type , metricAndShowEntry .getKey (), metricAndShowEntry .getValue ());
209+ UserMetricConfig userMetricConfig = new UserMetricConfig (type , metricAndShowEntry .getKey (), metricAndShowEntry .getValue (), metricDetailMap . get ( metricAndShowEntry . getKey ()). getRank () );
188210 userMetricConfigs .remove (userMetricConfig );
189211 userMetricConfigs .add (userMetricConfig );
190212 }
@@ -228,7 +250,15 @@ private Set<UserMetricConfig> getUserMetricConfig(String operator){
228250 return defaultMetrics ;
229251 }
230252
231- return JSON .parseObject (value , new TypeReference <Set <UserMetricConfig >>(){});
253+ Set <UserMetricConfig > userMetricConfigs = JSON .parseObject (value , new TypeReference <Set <UserMetricConfig >>() {});
254+
255+ //补充rank不存在情况
256+ for (UserMetricConfig userMetricConfig : userMetricConfigs ) {
257+ if (userMetricConfig .getRank () == 0 ) {
258+ userMetricConfig .setRank (Constant .DEFAULT_METRIC_RANK );
259+ }
260+ }
261+ return userMetricConfigs ;
232262 }
233263
234264 public static void main (String [] args ){
0 commit comments