| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.HistoryFiveMinutely; |
| | | import com.moral.api.entity.MonitorPoint; |
| | |
| | | import com.moral.api.service.MonitorPointService; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import io.lettuce.core.GeoCoordinates; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Autowired |
| | | MonitorPointService monitorPointService; |
| | | |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private HistoryFiveMinutelyMapper historyFiveMinutelyMapper; |
| | | HistoryFiveMinutelyMapper historyFiveMinutelyMapper; |
| | | |
| | | @Override |
| | | public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { |
| | |
| | | for (Device device : devices) { |
| | | DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO(); |
| | | String mac = device.getMac(); |
| | | //从缓存中获取 |
| | | Map<String, Object> sensorValues = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_FIVE_MINUTES, mac); |
| | | Map<String, Object> value = new HashMap<>(); |
| | | if (sensorValues != null && sensorValues.get(sensorCode) != null) |
| | | value.put(sensorCode, sensorValues.get(sensorCode)); |
| | | //如果没有数据从数据库查询 |
| | | HistoryFiveMinutely dbHistoryFiveMinutely = queryLastDataByMac(mac); |
| | | String dbDataStr = dbHistoryFiveMinutely.getValue(); |
| | | sensorValues = JSON.parseObject(dbDataStr, HashMap.class); |
| | | Map<String,Object> sensorValue = new HashMap<>(); |
| | | if (sensorValues!=null&&sensorValues.get(sensorCode) != null) |
| | | sensorValue.put(sensorCode,sensorValues.get(sensorCode)); |
| | | else |
| | | value.put(sensorCode, null); |
| | | sensorValue.put(sensorCode,null); |
| | | dto.setDevice(device); |
| | | dto.setSensorValue(value); |
| | | dto.setSensorValue(sensorValue); |
| | | dtos.add(dto); |
| | | } |
| | | return dtos; |
| | | } |
| | | |
| | | @Override |
| | | public HistoryFiveMinutely queryLastDataByMac(String mac) { |
| | | QueryWrapper<HistoryFiveMinutely> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("mac",mac); |
| | | queryWrapper.orderByDesc("time"); |
| | | queryWrapper.last("limit 0,1"); |
| | | List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyMapper.selectList(queryWrapper); |
| | | if(ObjectUtils.isEmpty(historyFiveMinutelies)) |
| | | return null; |
| | | return historyFiveMinutelies.get(0); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Object> getAreaWindData(Map<String, Object> params) { |
| | |
| | | list.add(laLaMap); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |