| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.time.Instant;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.ZoneId;
|
| | | import java.time.ZoneOffset;
|
| | | import java.time.temporal.ChronoUnit;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | return values;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getActualDataByRegion(Map<String, Object> parameters) {
|
| | | Object sensorKey = parameters.get("sensorKey");
|
| | | ValidateUtil.notNull(sensorKey, "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
|
| | | ValidateUtil.notNull(parameters.get("interval"), "param.is.null");
|
| | | Integer interval = Integer.valueOf(parameters.get("interval").toString());
|
| | | LocalDateTime start, end;
|
| | | if (!parameters.containsKey("time")) {
|
| | | end = LocalDateTime.now();
|
| | | int second = end.getSecond() / interval * interval;
|
| | | end = end.truncatedTo(ChronoUnit.MINUTES).plusSeconds(second);
|
| | | start = end.minusSeconds(interval);
|
| | | } else {
|
| | | //start = LocalDateTime.ofEpochSecond(Long.valueOf(parameters.get("time").toString()) / 1000, 0, ZoneOffset.ofHours(8));
|
| | | start = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.valueOf(parameters.get("time").toString())),ZoneId.of("+8"));
|
| | | end = start.plusSeconds(interval);
|
| | | }
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | | parameters.put("sensorKeys", Arrays.asList(((String) sensorKey).split(",")));
|
| | | accountService.setOrgIdsByAccount(parameters);
|
| | | Map<String, Object> result = historyMapper.getActualDataByRegion(parameters);
|
| | | if (ObjectUtils.isEmpty(result)) {
|
| | | result = new HashMap<String, Object>();
|
| | | }
|
| | | result.put("time", end.toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
| | | return result;
|
| | | }
|
| | |
|
| | | }
|