| | |
| | | //从缓存中获取 |
| | | Map<String, Object> sensorValues = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_FIVE_MINUTES, mac); |
| | | //如果没有数据从数据库查询 |
| | | if (ObjectUtils.isEmpty(sensorValues)) { |
| | | HistoryFiveMinutely dbHistoryFiveMinutely = queryLastDataByMac(mac); |
| | | if(ObjectUtils.isEmpty(dbHistoryFiveMinutely)) |
| | | continue; |
| | | String dbDataStr = dbHistoryFiveMinutely.getValue(); |
| | | else |
| | | sensorValues = JSON.parseObject(dbHistoryFiveMinutely.getValue(),Map.class); |
| | | } |
| | | String dbDataStr = JSON.toJSONString(sensorValues); |
| | | sensorValues = JSON.parseObject(dbDataStr, HashMap.class); |
| | | Map<String,Object> sensorValue = new HashMap<>(); |
| | | if (sensorValues!=null&&sensorValues.get(sensorCode) != null) |
| | |
| | | queryWrapper.eq("mac",mac); |
| | | queryWrapper.orderByDesc("time"); |
| | | queryWrapper.last("limit 0,1"); |
| | | List<HistoryFiveMinutely> historyFiveMinutelies = historyFiveMinutelyMapper.selectList(queryWrapper); |
| | | if(ObjectUtils.isEmpty(historyFiveMinutelies)) |
| | | //获取当月的表名 |
| | | Date date = new Date(); |
| | | List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH); |
| | | List<HistoryFiveMinutely> datas = multiTableQuery(queryWrapper, tableNames); |
| | | if (ObjectUtils.isEmpty(datas)) |
| | | return null; |
| | | return historyFiveMinutelies.get(0); |
| | | return datas.get(0); |
| | | } |
| | | |
| | | |
| | |
| | | return datas; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description: 多表查询,传入表名集合,以及条件wrapper,返回数据 |
| | | * @Param: [wrapper, tableNames] |
| | |
| | | List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.selectList(wrapper); |
| | | result.addAll(datas); |
| | | } |
| | | MybatisPlusConfig.tableName.remove(); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |