首页 > 其他分享 >ReportQueryHelper

ReportQueryHelper

时间:2022-10-31 21:14:00浏览次数:44  
标签:return ReportQueryHelper List item static new public

  1 package com.-.it.regioc.service.util;
  2 
  3 import com.alibaba.fastjson.JSONObject;
  4 import lombok.extern.slf4j.Slf4j;
  5 import org.springframework.beans.factory.annotation.Value;
  6 import org.springframework.util.CollectionUtils;
  7 import javax.ws.rs.core.HttpHeaders;
  8 import javax.ws.rs.core.MediaType;
  9 import java.util.ArrayList;
 10 import java.util.HashMap;
 11 import java.util.List;
 12 import java.util.Map;
 13 
 14 @Slf4j
 15 public class ReportQueryHelper {
 16     @Value("${request.application.appId}")
 17     private String appId;
 18 
 19     @Value("${request.appSecret}")
 20     private String appSecret;
 21 
 22     /**
 23      * 构建查询参数
 24      */
 25     public static PercentageParam buildParameter(Condition condition) {
 26         Region region = condition.getRegion();
 27         return new PercentageParam(condition.getTime(), region.getRegionOrg(), region.getRepOffice(), region.getCounty());
 28     }
 29 
 30     /**
 31      * 构建查询参数
 32      */
 33     public static Map<String, String> buildParameterMap(Condition condition) {
 34         Map<String, String> map = new HashMap<>();
 35         map.put("time", condition.getTime());
 36 
 37         List<Filter> filters = condition.getFilters();
 38         if (CollectionUtils.isEmpty(filters)) {
 39             log.info("动态感知地区维度为空:{}", filters);
 40             return map;
 41         }
 42         for (Filter filter : filters) {
 43             map.put(filter.getFilterName(), filter.getFilterValue());
 44         }
 45         return map;
 46     }
 47 
 48     public static List<ApiParameter> buildApiParameters(Map<String, String> parameterMap, List<PreferItem> preferItems) {
 49         Map<String, ApiParameter> map = new HashMap<>();
 50         // API配置在一起
 51         List<ApiParameter> apiParameters = new ArrayList<>();
 52         for (PreferItem item : preferItems) {
 53             ApiParameter apiParameter = map.get(item.getId());
 54             apiParameter.buildParam(parameterMap, item);
 55             apiParameters.add(apiParameter);
 56         }
 57         return apiParameters;
 58     }
 59 
 60     /**
 61      * 要考虑PercentageParam 的参数是否一致,目前是一致的。
 62      */
 63     public static List<ApiParameter> buildProbeApiParameters(PercentageParam param, List<PreferProbeItem> preferProbeItems) {
 64         // API配置在一起
 65         List<ApiParameter> apiParameters = new ArrayList<>();
 66         for (PreferProbeItem item : preferProbeItems) {
 67             ApiParameter apiParam = new ApiParameter(item.getApiName(), "POST", item.getApiUrl(), param);
 68             apiParameters.add(apiParam);
 69         }
 70         return apiParameters;
 71     }
 72 
 73     public static List<ApiParameter> buildProbeWarningParameters(Map<String, String> parameterMap, List<PreferProbeItem> preferProbeItems, List<ProbeCriterion> probeCriteria) {
 74         Map<String, ApiParameter> map = new HashMap<>();
 75         // API配置在一起
 76         List<ApiParameter> apiParameters = new ArrayList<>();
 77         for (PreferProbeItem item : preferProbeItems) {
 78             ApiParameter apiParameter = map.get(item.getId());
 79             apiParameter.buildParam(parameterMap, item);
 80             apiParameters.add(apiParameter);
 81         }
 82         return apiParameters;
 83     }
 84 
 85     public static ResultCollection processKpiCollections(List<JSONObject> results) {
 86         return new ResultCollection();
 87     }
 88 
 89     public static List<WarningItem> processWarningCollections(List<JSONObject> results) {
 90 
 91         return new ArrayList<>();
 92     }
 93 
 94     public static ResultCollection processProbeCollections(List<JSONObject> results) {
 95         List<ProbeMap> probeMap = new ArrayList<>();
 96         List<ProbeSituation> probeSituation = new ArrayList<>();
 97         // 封装成json对象,逻辑较麻烦
 98         for (JSONObject item : results) {
 99             // 获得探针或绩效ID
100             String id = item.getString("id");
101             if ("probe01".equals(id)) {
102                 System.err.println(id);
103             }
104         }
105         return new ResultCollection();
106     }
107 
108     /**
109      * 创建任务列表
110      */
111     public static List<ProbeQueryTask> buildTasks(List<ApiParameter> apiParams, Map<String, String> headerMap) {
112         ArrayList<ProbeQueryTask> tasks = new ArrayList<>();
113         for (ApiParameter apiParam : apiParams) {
114             ProbeQueryTask task = new ProbeQueryTask(apiParam, headerMap);
115             tasks.add(task);
116         }
117         return tasks;
118     }
119 
120     public static Map<String, String> getHeaderMap(String appId, String appSecret) {
121         Map<String, String> headerMap = new HashMap<>();
122         headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
123         headerMap.put("X-HW-ID", appId);
124         headerMap.put("X-HW-APPKEY", appSecret);
125         return headerMap;
126     }
127 }

 

标签:return,ReportQueryHelper,List,item,static,new,public
From: https://www.cnblogs.com/mingruifeng/p/16845796.html

相关文章