| | |
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collection;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.concurrent.ExecutorCompletionService;
|
| | | import java.util.concurrent.ExecutorService;
|
| | | import java.util.concurrent.Executors;
|
| | | import java.util.stream.Collector;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | @Override
|
| | | public Map<String, List<Object>> getCompareReport(Map<String, Object> parameters) throws Exception {
|
| | | Map<String, List<Object>> resultMap = new HashMap<String, List<Object>>();
|
| | | List<Map<String, Object>> list = JSON.parseObject((String)parameters.get("items"), new TypeReference<List<Map<String, Object>>>() {});
|
| | | parameters.remove("items");
|
| | | Map<String, Object> timeType = JSON.parseObject((String)parameters.get("timeType"), new TypeReference<Map<String, Object>>() {});
|
| | | parameters.remove("timeType");
|
| | | List<Map<String, Object>> list = JSON.parseObject((String)parameters.remove("items"), new TypeReference<List<Map<String, Object>>>() {});
|
| | | Map<String, Object> timeType = JSON.parseObject((String)parameters.remove("timeType"), new TypeReference<Map<String, Object>>() {});
|
| | | parameters.putAll(timeType);
|
| | | parameters.put("type", parameters.remove("value"));
|
| | |
|
| | | ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | CompletionService<Map<String, List<Object>>> cs = new ExecutorCompletionService<Map<String, List<Object>>>(threadPool);
|
| | |
| | | if (ObjectUtils.isEmpty(map.get("mac"))) {
|
| | | map.remove("mac");
|
| | | }
|
| | | map.put("time", map.get("formatTime"));
|
| | | map.remove("formatTime");
|
| | | map.put("time", map.remove("formatTime"));
|
| | | map.putAll(parameters);
|
| | | cs.submit(new Callable<Map<String, List<Object>>>() {
|
| | | @Override
|
| | |
| | | List<Object> timeList = (List<Object>) parameters.get("timeList");
|
| | |
|
| | | List<Object> dataList = new ArrayList<Object>();
|
| | | Set<String> sensors ;
|
| | | if (parameters.containsKey("sensorKey")) {
|
| | | String sensorKey = (String) parameters.get("sensorKey");
|
| | | Sensor sensor = new Sensor();
|
| | | sensor.setSensorKey(sensorKey);
|
| | | sensor = sensorMapper.selectOne(sensor );
|
| | | sensors = new HashSet<String>();
|
| | | sensors.add(sensorKey + "-" + sensor.getName() + "-" + sensor.getUnit());
|
| | | } else {
|
| | | sensors = new TreeSet<String>(new Comparator<String>() {
|
| | | @Override
|
| | | public int compare(String o1, String o2) {
|
| | | return Integer.compare(Integer.valueOf(o1.split("-")[0].replace("e", "")), Integer.valueOf(o2.split("-")[0].replace("e", "")));
|
| | | }
|
| | | });
|
| | | sensors.addAll((Set<String>)parameters.get("sensors"));
|
| | | }
|
| | | Set<String> sensors = new TreeSet<String>(new Comparator<String>() {
|
| | | @Override
|
| | | public int compare(String o1, String o2) {
|
| | | return Integer.compare(Integer.valueOf(o1.split("-")[0].replace("e", "")), Integer.valueOf(o2.split("-")[0].replace("e", "")));
|
| | | }
|
| | | });
|
| | | sensors.addAll((Set<String>)parameters.get("sensors"));
|
| | | Map<String, Double[]> doubleMap = new LinkedHashMap<String, Double[]>();
|
| | | for (Map<String, Object> map : resultList) {
|
| | | String time = map.get("time").toString();
|
| | |
| | | parameters.put("end", end);
|
| | |
|
| | | if (parameters.containsKey("sensorKey")) {
|
| | | String sensorKey = (String) parameters.get("sensorKey");
|
| | | String sensorKeyColumn = "AVG(json -> '$." + sensorKey + "[0]') " + sensorKey;
|
| | | List<String> sensors;
|
| | | try {
|
| | | sensors = JSON.parseObject((String)parameters.get("sensors"), new TypeReference<List<String>>() {});
|
| | | parameters.put("sensors", new HashSet<String>(sensors));
|
| | | } catch (Exception e) {
|
| | | sensors = new ArrayList<String>();
|
| | | sensors.add((String)parameters.get("sensorKey"));
|
| | | }
|
| | | String sensorKeyColumn = "";
|
| | | for (int i = 0; i < sensors.size(); i++) {
|
| | | String sensorKey = sensors.get(i).split("-")[0];
|
| | | sensorKeyColumn += "AVG(json -> '$." + sensorKey + "[0]') " + sensorKey;
|
| | | if (i != sensors.size() - 1) {
|
| | | sensorKeyColumn += " ,";
|
| | | } |
| | | |
| | | }
|
| | | parameters.put("sensorKeyColumn", sensorKeyColumn);
|
| | | }
|
| | |
|
| | |
| | | // 监控点平均值
|
| | | if (!parameters.containsKey("mac")) {
|
| | | resultList = new ArrayList<Map<String,Object>>();
|
| | | Integer monitorPointId = Integer.valueOf(parameters.get("monitorPoint").toString());
|
| | | Integer monitorPointId = Integer.valueOf(parameters.get("monitorPointId").toString());
|
| | | List<Map<String, Object>> deviceVersions = deviceMapper.getDeviceVersionIdByMonitorPoint(monitorPointId);
|
| | | ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | CompletionService<List<Map<String, Object>>> cs = new ExecutorCompletionService<List<Map<String, Object>>>(threadPool);
|
| | |
| | | }
|
| | | Map<String, Map<String, Number[]>> result = new LinkedHashMap<String, Map<String, Number[]>>();
|
| | | for (Map<String, Object> map : list) {
|
| | | time = (String) map.get("time");
|
| | | map.remove("time");
|
| | | time = (String) map.remove("time");
|
| | | Map<String, Number[]> times = new HashMap<String, Number[]>();
|
| | | if (result.containsKey(time)) {
|
| | | times = (Map<String, Number[]>) result.get(time);
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<List<PairData>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria){
|
| | | String sensorKey = lineChartCriteria.getSensorKey();
|
| | | TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
|
| | | List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
|
| | | List<List<PairData>> list = new ArrayList<>();
|
| | | dataConditionList.forEach(item -> {
|
| | | List<PairData> pairDataList = queryOneLineChartDateByCrieria(sensorKey,timePeriod,item);
|
| | | list.add(pairDataList);
|
| | | });
|
| | | return list;
|
| | | public Map<String, List<List<PairData>>> queryLineChartDateByCrieria(LineChartCriteria lineChartCriteria){
|
| | | Map<String,List<List<PairData>>> listMap = new HashMap<>();
|
| | | for(String sensorKey:lineChartCriteria.getSensorKeys()){
|
| | | TimePeriod timePeriod = lineChartCriteria.getTimePeriod();
|
| | | List<DataCondition> dataConditionList = lineChartCriteria.getDataConditions();
|
| | | List<List<PairData>> list = new ArrayList<>();
|
| | | dataConditionList.forEach(item -> {
|
| | | List<PairData> pairDataList = queryOneLineChartDateByCrieria(sensorKey,timePeriod,item);
|
| | | list.add(pairDataList);
|
| | | });
|
| | | listMap.put(sensorKey,list);
|
| | | }
|
| | |
|
| | | return listMap;
|
| | | }
|
| | |
|
| | | /**
|