| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.time.LocalDate;
|
| | | import java.time.LocalDateTime;
|
| | | import java.time.format.DateTimeFormatter;
|
| | | import java.time.temporal.TemporalAdjusters;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.apache.commons.collections.CollectionUtils;
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
| | | import com.moral.entity.charts.TimePeriod;
|
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.DeviceMapper;
|
| | | import com.moral.mapper.HistoryMapper;
|
| | | import com.moral.mapper.HistoryMinutelyMapper;
|
| | | import com.moral.mapper.SensorMapper;
|
| | | import com.moral.service.HistoryMinutelyService;
|
| | |
| | |
|
| | | @Resource
|
| | | private HistoryMinutelyMapper historyMinutelyMapper;
|
| | |
|
| | | @Resource
|
| | | private HistoryMapper historyMapper;
|
| | |
|
| | | @Resource
|
| | | private DeviceMapper deviceMapper;
|
| | |
| | | Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
|
| | | return getAQIByDataMap(average);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public Map<String, Object> getHourAQIByDevice(Map<String, Object> parameters) {
|
| | | //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
|
| | | LocalDate localDate = LocalDate.now();
|
| | | System.out.println("localDate:"+localDate);
|
| | | // 昨日00:00:00
|
| | | //parameters.put("start", localDate.minusDays(1));
|
| | | |
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(new Date());
|
| | | calendar.set(Calendar.HOUR,calendar.get(Calendar.HOUR) - 1);
|
| | | System.out.println("++++++"+calendar);
|
| | | int hour = calendar.get(Calendar.HOUR)-1;
|
| | | System.out.println("当前小时减一"+hour);
|
| | | |
| | | // 今日00:00:00
|
| | | parameters.put("end", localDate);
|
| | | parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
|
| | | Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
|
| | | return getAQIByDataMap(average);
|
| | | //ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
|
| | | LocalDate localDate = LocalDate.now();
|
| | | System.out.println("localDate:" + localDate);
|
| | | // 昨日00:00:00
|
| | | //parameters.put("start", localDate.minusDays(1));
|
| | |
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(new Date());
|
| | | calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);
|
| | | System.out.println("++++++" + calendar);
|
| | | int hour = calendar.get(Calendar.HOUR) - 1;
|
| | | System.out.println("当前小时减一" + hour);
|
| | |
|
| | | // 今日00:00:00
|
| | | parameters.put("end", localDate);
|
| | | parameters.put("sensorKeys", Arrays.asList("e1", "e2", "e10", "e11", "e15", "e16"));
|
| | | Map<String, Double> average = historyMinutelyMapper.getSersionAvgByDevice(parameters);
|
| | | return getAQIByDataMap(average);
|
| | | }
|
| | |
|
| | | private Map<String, Object> getAQIByDataMap(Map<String, Double> average) {
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<Map<String, Object>> getSensorData(Map<String, Object> parameters) {
|
| | | parameters.put("sensorKeys",Arrays.asList("e1", "e2", "e3", "e4", "e6", "e7", "e9", "e10", "e11", "e15", "e16", "e17", "e27", "e28", "e76", "e77", "e78", "e79", "e80", "e81"));
|
| | | return historyMinutelyMapper.getSensorData(parameters);
|
| | | public List<List<Map<String, Object>>> getSensorData(Map<String, Object> parameters) {
|
| | | String startTime = parameters.get("startTime").toString();
|
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
| | | LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
|
| | | LocalDate today = LocalDate.now();
|
| | | LocalDate startTimeLocalDate=startTimeLocalDateTime.toLocalDate();
|
| | | Boolean flag=today.isEqual(startTimeLocalDate);
|
| | | List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters);
|
| | | List<String> sensorKeys = new ArrayList<>();
|
| | | for (Sensor sensor : sensors) {
|
| | | sensorKeys.add(sensor.getSensorKey());
|
| | | }
|
| | | parameters.put("sensorKeys", sensorKeys);
|
| | | List<Map<String, Object>> listMap = null;
|
| | | if (flag) {
|
| | | listMap = historyMapper.getSensorDataToday(parameters);
|
| | | } else {
|
| | | listMap = historyMinutelyMapper.getSensorData(parameters);
|
| | | }
|
| | | List<List<Map<String, Object>>> listMaps = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapAvg = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapMin = new ArrayList<>();
|
| | | List<Map<String, Object>> listMapMax = new ArrayList<>();
|
| | | if (CollectionUtils.isNotEmpty(listMap)) {
|
| | | for (Map<String, Object> map : listMap) {
|
| | | Map<String, Object> mapAvg = new LinkedHashMap<>();
|
| | | Map<String, Object> mapMin = new LinkedHashMap<>();
|
| | | Map<String, Object> mapMax = new LinkedHashMap<>();
|
| | | mapAvg.put("time", map.get("time"));
|
| | | mapMin.put("time", map.get("time"));
|
| | | mapMax.put("time", map.get("time"));
|
| | | for (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()).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())) {
|
| | | mapMax.put(entry.getKey().substring(3), new BigDecimal(entry.getValue().toString().replace("\"", "")).stripTrailingZeros().toPlainString());
|
| | | }
|
| | | }
|
| | | }
|
| | | listMapAvg.add(mapAvg);
|
| | | listMapMin.add(mapMin);
|
| | | listMapMax.add(mapMax);
|
| | | }
|
| | | listMaps.add(listMapAvg);
|
| | | listMaps.add(listMapMin);
|
| | | listMaps.add(listMapMax);
|
| | | }
|
| | | return listMaps;
|
| | | }
|
| | |
|
| | | }
|