| | |
| | | Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | LocalDateTime time = LocalDateTime.now();
|
| | | // 当前时间 -10分钟
|
| | | parameters.put("start", time.minusMinutes(10));
|
| | | parameters.put("end", time);
|
| | | // 当前时间 -5分钟
|
| | | parameters.put("end", time.minusMinutes(5));
|
| | | LocalDateTime start = time.minusMinutes(5);
|
| | | parameters.put("start", start);
|
| | | List<Sensor> Sensors = sensorMapper.getSensorsByCriteria(parameters);
|
| | | List<String> sensorKeys = new ArrayList<String>();
|
| | | for (Sensor sensor : Sensors) {
|
| | | sensorKeys.add(sensor.getSensorKey());
|
| | | }
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMM");
|
| | | parameters.put("timeUnits", "five_minutely_" + df.format(time));
|
| | | List<Map<String, Object>> list = historyMapper.getAreaAllDataByAccount(parameters);
|
| | | resultMap.putAll(list.get(0));
|
| | | return resultMap;
|
| | |
| | | List<String> sensorKeys = new ArrayList<String>();
|
| | | sensorKeys.add(macKey.toString());
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | parameters.put("timeUnits", "hourly");
|
| | | List<Map<String, Object>> list = historyMapper.getAreaAllDataByAccount(parameters);
|
| | |
|
| | | for (Map<String, Object> map : list) {
|
| | | result.put((String) map.get("name"), map.get(macKey.toString()));
|
| | | }
|
| | |
| | |
|
| | | @Override
|
| | | public String queryValueByMacAndTime(String mac, Date time) {
|
| | | return historyMapper.selectValueByMacAndTime(mac, time);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| | | String timeUnits = sdf.format(time);
|
| | | return historyMapper.selectValueByMacAndTime(mac, time, timeUnits);
|
| | | }
|
| | |
|
| | | public String getValueByMacAndTime(String mac, String time, String time1) {
|
| | | String timeUnits = time1.substring(0, 10).replace("-", "");
|
| | | return historyMapper.getValueByMacAndTime(mac, time, time1, timeUnits);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | parameters.put("nextLevel", nextLevel);
|
| | |
|
| | | LocalDate localDate = LocalDate.now();
|
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMM");
|
| | | Object timeType = parameters.get("timeType");
|
| | |
|
| | | String table = "history";
|
| | | String column = "value";
|
| | | if ("month".equals(timeType)) {
|
| | | String column = "json";
|
| | | /*if ("month".equals(timeType)) {
|
| | | if (1 != localDate.getDayOfMonth()) {
|
| | | table = "history_daily";
|
| | | column = "json";
|
| | |
| | | parameters.put("start", LocalDateTime.now().truncatedTo(ChronoUnit.HOURS));
|
| | | } else {
|
| | | parameters.put("start", LocalDateTime.now().minusMinutes(5));
|
| | | }*/
|
| | |
|
| | | if ("month".equals(timeType)) {
|
| | | table = "history_daily";
|
| | | parameters.put("start", localDate.with(TemporalAdjusters.firstDayOfMonth()));
|
| | | } else if ("day".equals(timeType)) {
|
| | | table = "history_hourly";
|
| | | parameters.put("start", localDate);
|
| | | } else if ("hour".equals(timeType)) {
|
| | | table = "history_minutely_" + df.format(localDate);
|
| | | parameters.put("start", LocalDateTime.now().truncatedTo(ChronoUnit.HOURS));
|
| | | }
|
| | |
|
| | | parameters.put("table", table);
|
| | | parameters.put("column", column);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | |
|
| | | List<Map<String, Object>> result = historyMapper.getRegionRankingData(parameters);
|
| | | for (Map<String, Object> map : result) {
|
| | | if (ObjectUtils.isEmpty(map.get("avg"))) {
|
| | |
| | | ValidateUtil.notNull(parameters.get("deviceId"), "param.is.null");
|
| | | List<Map<String, Object>> sensors = sensorMapper.getSensorsByDeviceVersionId(parameters);
|
| | | parameters.put("size", 1);
|
| | | Date date = new Date();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| | | String timeUnits = sdf.format(date);
|
| | | parameters.put("timeUnits", timeUnits);
|
| | | List<Map<String, Object>> values = historyMapper.getValueByMacAndSize(parameters);
|
| | | JSONObject map = null;
|
| | | if (!ObjectUtils.isEmpty(values)) {
|
| | |
| | | ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("size"), "param.is.null");
|
| | | parameters.put("size", Integer.valueOf(parameters.remove("size").toString()));
|
| | | Date date = new Date();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| | | String timeUnits = sdf.format(date);
|
| | | parameters.put("timeUnits", timeUnits);
|
| | | List<Map<String, Object>> values = historyMapper.getValueByMacAndSize(parameters);
|
| | | Map<String, Object> sensorUnits = getSensorUnitByDeviceMac(parameters);
|
| | | for (Map<String, Object> value : values) {
|
| | |
| | | parameters.put("end", end);
|
| | | parameters.put("sensorKeys", Arrays.asList(((String) sensorKey).split(",")));
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
|
| | | //从history年月日表获取
|
| | | parameters.put("timeUnits", df.format(start));
|
| | | Map<String, Object> result = historyMapper.getActualDataByRegion(parameters);
|
| | | if (ObjectUtils.isEmpty(result)) {
|
| | | result = new HashMap<String, Object>();
|
| | |
| | | resultMap.put(map.remove("sensor_key").toString(), map);
|
| | | }
|
| | | return resultMap;
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | int startHour = endHour - 1;
|
| | | startTime = localDate + " " + startHour + ":00:00";
|
| | | }
|
| | | Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime);
|
| | | //从不同history日表获取数据
|
| | | String timeUnits = startTime.substring(0, 10).replace("-", "");
|
| | | Map<String, Object> map = historyMapper.getAVGValueByMacAndTimeslot(mac, startTime, endTime, timeUnits);
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | if (map.isEmpty()) {
|
| | | returnMap.put("AQI", "N/V");
|
| | | if (ObjectUtils.isEmpty(map) || map.isEmpty()) {
|
| | | returnMap.put("AQI", "N/V");
|
| | | return returnMap;
|
| | | } else {
|
| | | Map<String, Double> AQIMap = new HashMap<>();
|
| | | for (Map.Entry<String, Object> entry : map.entrySet()) {
|
| | | String key = entry.getKey();
|
| | | Double value = Double.parseDouble(entry.getValue().toString());
|
| | | AQIMap.put(key, value);
|
| | | if (entry.getValue() != null) {
|
| | | Double value = Double.parseDouble(entry.getValue().toString());
|
| | | AQIMap.put(key, value);
|
| | | }
|
| | | }
|
| | | returnMap = AQICalculation.hourlyAQI(AQIMap);
|
| | | }
|
| | |
|
| | | long aqi = Math.round(Double.valueOf(returnMap.get("AQI").toString()));
|
| | | returnMap.put("AQI", aqi);
|
| | | return returnMap;
|
| | | }
|
| | |
|
| | |
| | | Date end = rightNow.getTime();
|
| | | String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(end);
|
| | | String before5Time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(beforeD); // 前五分钟时间
|
| | |
|
| | | String sensor = parameters.get("sensor").toString();
|
| | | List<Map<String, Object>> result = historyMapper.getAVGSensorRankByMonitorPointIdList(sensor, monitorPointIdList, before5Time, endTime);
|
| | | return result;
|
| | | String timeUnits1 = before5Time.substring(0, 10).replace("-", "");
|
| | | List<Map<String, Object>> result1 = historyMapper.getAVGSensorRankByMonitorPointIdList(sensor, monitorPointIdList, before5Time, endTime, timeUnits1);
|
| | | String timeUnits2 = before5Time.substring(0, 10).replace("-", "");
|
| | | List<Map<String, Object>> result2 = historyMapper.getAVGSensorRankByMonitorPointIdList(sensor, monitorPointIdList, before5Time, endTime, timeUnits2);
|
| | | if (result1.isEmpty()) {
|
| | | return result2;
|
| | | } else if (result2.isEmpty()) {
|
| | | return result1;
|
| | | } else {
|
| | | for (Map<String, Object> map1 : result1) {
|
| | | Object name1 = map1.get("name");
|
| | | double value1 = Double.parseDouble(map1.get("sensor").toString());
|
| | | double avg = 0.0;
|
| | | for (Map<String, Object> map2 : result2) {
|
| | | Object name2 = map2.get("name");
|
| | | double value2 = Double.parseDouble(map2.get("sensor").toString());
|
| | | if (name1.equals(name2)) {
|
| | | avg = (value1 + value2) / 2;
|
| | | map1.put("sensor", avg);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return result1;
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | int startHour = endHour - 1;
|
| | | startTime = localDate + " " + startHour + ":00:00";
|
| | | }
|
| | | Map<String, Object> map = historyMapper.getMonitorPointAVGValueByMonitorPointIdAndTimeslot(monitor_point_id, startTime, endTime);
|
| | | //从不同history日表获取数据
|
| | | String timeUnits = startTime.substring(0, 10).replace("-", "");
|
| | |
|
| | | Map<String, Object> map = historyMapper.getMonitorPointAVGValueByMonitorPointIdAndTimeslot(monitor_point_id, startTime, endTime, timeUnits);
|
| | | Map<String, Object> returnMap = new HashMap<>();
|
| | | if (map.isEmpty()) {
|
| | | returnMap.put("AQI", "N/V");
|
| | |
| | | String startTime = parameters.get("startTime").toString();
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
| | | LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
|
| | | LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
| | | LocalDateTime startTimeDay = startTimeLocalDateTime.truncatedTo(ChronoUnit.DAYS);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
|
| | | int format = Integer.parseInt(sdf.format(new Date()));
|
| | | int year = startTimeLocalDateTime.getYear();
|
| | | int month = startTimeLocalDateTime.getMonthValue();
|
| | | String monthStr = month < 10 ? ("0" + month) : month + "";
|
| | |
| | | }
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | List<Map<String, Object>> listMap = null;
|
| | | if (today.compareTo(startTimeDay) == 0) {
|
| | | listMap = historyMapper.listGetSensorData(parameters);
|
| | | }
|
| | | listMap = historyMapper.getCarSensorData(parameters);
|
| | | if (CollectionUtils.isEmpty(listMap)) {
|
| | | listMap = historyMapper.getCarSensorData(parameters);
|
| | | if (CollectionUtils.isEmpty(listMap)) {
|
| | | if (year <= 2019) {
|
| | | listMap = historyMinutelyMapper.getSensorData(parameters);
|
| | | } else {
|
| | | if (year <= 2019) {
|
| | | listMap = historyMinutelyMapper.getSensorData(parameters);
|
| | | } else {
|
| | | if (Integer.parseInt(yearAndMonth) <= format) {
|
| | | parameters.put("yearAndMonth", yearAndMonth);
|
| | | listMap = historyMinutelyMapper.getSensorData2020(parameters);
|
| | | }
|
| | | }
|
| | | }
|
| | | //}
|
| | | List<List<Map<String, Object>>> listMaps = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapAvg = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapMin = new ArrayList<>();
|
| | |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) {
|
| | | for (Sensor sensor : sensors) {
|
| | | if (sensor.getSensorKey().equals(entry.getKey())) {
|
| | | mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString() + sensor.getUnit());
|
| | | if (entry.getValue() != null) {
|
| | | mapAvg.put(entry.getKey(), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString() + sensor.getUnit());
|
| | | }
|
| | | } else if (("min" + sensor.getSensorKey()).equals(entry.getKey())) {
|
| | | mapMin.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
|
| | | } else if (("max" + sensor.getSensorKey()).equals(entry.getKey())) {
|
| | |
| | | }
|
| | | return maxList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String getJsonData(String mac, String time, String table) {
|
| | | return historyMapper.getJsonData(mac, time, table);
|
| | | }
|
| | |
|
| | | }
|