|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.apache.commons.collections.CollectionUtils; | 
|---|
|  |  |  | import org.apache.commons.collections.MapUtils; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.apache.commons.net.ftp.FTPClient; | 
|---|
|  |  |  | import org.apache.log4j.Logger; | 
|---|
|  |  |  | import org.dom4j.Document; | 
|---|
|  |  |  | 
|---|
|  |  |  | parameters.put("sensors", Arrays.asList(sensorKeys)); | 
|---|
|  |  |  | parameters.put("sensors2", s); | 
|---|
|  |  |  | List<Map<String, Object>> monitorList = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); | 
|---|
|  |  |  | for (Map<String, Object> monitorMap : monitorList) { | 
|---|
|  |  |  | String time = monitorMap.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | monitorMap.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer maxTime = 0; | 
|---|
|  |  |  | Integer max1 = 0; | 
|---|
|  |  |  | if (monitorList.size() != 0) { | 
|---|
|  |  |  | Map<String, Object> monitorMap = monitorList.get(monitorList.size() - 1); | 
|---|
|  |  |  | max1 = Integer.valueOf(monitorMap.get("time").toString()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | max1 = 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String type = parameters.get("type").toString(); | 
|---|
|  |  |  | ArrayList<Map<String, Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | String sensorKey1 = s; | 
|---|
|  |  |  | switch (s) { | 
|---|
|  |  |  | case "e1": | 
|---|
|  |  |  | 
|---|
|  |  |  | areaList = historyMinutelyService.getAreaAvgDataByAreaCode(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> areaMap : areaList) { | 
|---|
|  |  |  | String time = areaMap.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | areaMap.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ArrayList<Map<String, Object>> resultList = new ArrayList<>(); | 
|---|
|  |  |  | if (areaList.isEmpty()) { | 
|---|
|  |  |  | if (areaList.isEmpty() && monitorList.isEmpty()) { | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(resultList); | 
|---|
|  |  |  | } else if (areaList.isEmpty()) { | 
|---|
|  |  |  | resultList.addAll(monitorList); | 
|---|
|  |  |  | for (Map<String, Object> map : monitorList) { | 
|---|
|  |  |  | ArrayList<String> values = new ArrayList<>(); | 
|---|
|  |  |  | values.add(null); | 
|---|
|  |  |  | values.add(map.remove(s).toString()); | 
|---|
|  |  |  | map.put("values", values); | 
|---|
|  |  |  | for (Map<String, Object> resultMap : resultList) { | 
|---|
|  |  |  | String time = resultMap.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | resultMap.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  | List<String> values = new ArrayList<>(); | 
|---|
|  |  |  | values.add(""); | 
|---|
|  |  |  | values.add(resultMap.remove(s).toString()); | 
|---|
|  |  |  | resultMap.put("values", values); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(resultList); | 
|---|
|  |  |  | } else if (monitorList.isEmpty()) { | 
|---|
|  |  |  | resultList.addAll(areaList); | 
|---|
|  |  |  | for (Map<String, Object> resultMap : resultList) { | 
|---|
|  |  |  | String time = resultMap.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | resultMap.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  | List<String> values = new ArrayList<>(); | 
|---|
|  |  |  | values.add(resultMap.remove(s).toString()); | 
|---|
|  |  |  | values.add(""); | 
|---|
|  |  |  | resultMap.put("values", values); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(resultList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> map : areaList) { | 
|---|
|  |  |  | String time = map.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | map.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer max = 0; | 
|---|
|  |  |  | if (areaList.size() != 0) { | 
|---|
|  |  |  | Map<String, Object> areaMap = areaList.get(areaList.size() - 1); | 
|---|
|  |  |  | max = Integer.valueOf(areaMap.get("time").toString()); | 
|---|
|  |  |  | for (Map<String, Object> m : monitorList) { | 
|---|
|  |  |  | String time = m.get("time").toString(); | 
|---|
|  |  |  | time = time.substring(time.length() - 2); | 
|---|
|  |  |  | m.put("time", Integer.valueOf(time)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer maxTime = 0; | 
|---|
|  |  |  | Map<String, Object> areaMap = areaList.get(areaList.size() - 1); | 
|---|
|  |  |  | Integer areaMax = Integer.valueOf(areaMap.get("time").toString()); | 
|---|
|  |  |  | Map<String, Object> monitorMap = monitorList.get(monitorList.size() - 1); | 
|---|
|  |  |  | Integer monitorMax = Integer.valueOf(monitorMap.get("time").toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (type.equals("day")) { | 
|---|
|  |  |  | if (areaMax >= monitorMax) { | 
|---|
|  |  |  | maxTime = areaMax + 1; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | maxTime = monitorMax + 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | max = 0; | 
|---|
|  |  |  | if (areaMax >= monitorMax) { | 
|---|
|  |  |  | maxTime = areaMax; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | maxTime = monitorMax; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (max1 >= max) { | 
|---|
|  |  |  | maxTime = max1; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | maxTime = max; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int i = 0; i <= maxTime; i++) { | 
|---|
|  |  |  | for (int i = 0; i < maxTime; i++) { | 
|---|
|  |  |  | resultList.add(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> areaMap : areaList) { | 
|---|
|  |  |  | Integer time = Integer.valueOf(areaMap.get("time").toString()); | 
|---|
|  |  |  | resultList.set(time, areaMap); | 
|---|
|  |  |  | for (Map<String, Object> map : areaList) { | 
|---|
|  |  |  | Integer time = Integer.valueOf(map.get("time").toString()); | 
|---|
|  |  |  | if (type.equals("day")) { | 
|---|
|  |  |  | resultList.set(time, map); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | resultList.set(time - 1, map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> resultMap : resultList) { | 
|---|
|  |  |  | for (Map<String, Object> monitorMap : monitorList) { | 
|---|
|  |  |  | ArrayList<String> values = new ArrayList<>(); | 
|---|
|  |  |  | String monitorTime = monitorMap.get("time").toString(); | 
|---|
|  |  |  | if (resultMap != null) { | 
|---|
|  |  |  | String resultTime = resultMap.get("time").toString(); | 
|---|
|  |  |  | if (resultTime.equals(monitorTime)) { | 
|---|
|  |  |  | String value = resultMap.remove(s).toString(); | 
|---|
|  |  |  | String value1 = monitorMap.get(s).toString(); | 
|---|
|  |  |  | values.add(value); | 
|---|
|  |  |  | values.add(value1); | 
|---|
|  |  |  | resultMap.put("values", values); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | String value1 = monitorMap.get(s).toString(); | 
|---|
|  |  |  | values.add(null); | 
|---|
|  |  |  | values.add(value1); | 
|---|
|  |  |  | if (type.equals("day")) { | 
|---|
|  |  |  | for (int i = 0; i < resultList.size(); i++) { | 
|---|
|  |  |  | if (resultList.get(i) == null) { | 
|---|
|  |  |  | Map<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("time", i); | 
|---|
|  |  |  | hashMap.put(s, ""); | 
|---|
|  |  |  | resultList.set(i, hashMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | for (int i = 0; i < resultList.size(); i++) { | 
|---|
|  |  |  | if (resultList.get(i) == null) { | 
|---|
|  |  |  | Map<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("time", i + 1); | 
|---|
|  |  |  | hashMap.put(s, ""); | 
|---|
|  |  |  | resultList.set(i, hashMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | resultList.removeAll(Collections.singleton(null)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> resultMap : resultList) { | 
|---|
|  |  |  | if (resultMap.containsKey(s)) { | 
|---|
|  |  |  | ArrayList<String> values = new ArrayList<>(); | 
|---|
|  |  |  | values.add(resultMap.remove(s).toString()); | 
|---|
|  |  |  | values.add(null); | 
|---|
|  |  |  | resultMap.put("values", values); | 
|---|
|  |  |  | for (Map<String, Object> map : resultList) { | 
|---|
|  |  |  | List<Object> values = new ArrayList<>(); | 
|---|
|  |  |  | for (Map<String, Object> map1 : monitorList) { | 
|---|
|  |  |  | if (map.get("time").toString().equals(map1.get("time").toString())) { | 
|---|
|  |  |  | values.add(map.remove(s)); | 
|---|
|  |  |  | values.add(map1.remove(s)); | 
|---|
|  |  |  | map.put("values", values); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(resultList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> map : resultList) { | 
|---|
|  |  |  | List<Object> values = new ArrayList<>(); | 
|---|
|  |  |  | if (map.containsKey(s)) { | 
|---|
|  |  |  | values.add(map.remove(s)); | 
|---|
|  |  |  | values.add(""); | 
|---|
|  |  |  | map.put("values", values); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> mapList = new ArrayList<>(); | 
|---|
|  |  |  | for (Map<String, Object> map : resultList) { | 
|---|
|  |  |  | String values = map.get("values").toString(); | 
|---|
|  |  |  | String string = StringUtils.strip(values, "[]"); | 
|---|
|  |  |  | String[] strings = string.split(","); | 
|---|
|  |  |  | if (!strings[0].equals("") || !strings[1].equals(" ")) { | 
|---|
|  |  |  | mapList.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new ResultBean<List<Map<String, Object>>>(mapList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("getmpoint-byid") | 
|---|