| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.HistoryHourly; |
| | | import com.moral.api.mapper.HistoryHourlyMapper; |
| | | import com.moral.api.service.HistoryHourlyService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.AQIUtils; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | |
| | | * @since 2021-07-14 |
| | | */ |
| | | @Service |
| | | public class HistoryHourlyServiceImpl extends ServiceImpl<HistoryHourlyMapper, HistoryHourly> implements HistoryHourlyService { |
| | | public class HistoryHourlyServiceImpl implements HistoryHourlyService { |
| | | |
| | | @Autowired |
| | | private HistoryHourlyMapper historyHourlyMapper; |
| | | |
| | | @Override |
| | | public Map<String, Object> getHourlyAqiByMac(String mac) { |
| | | QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>(); |
| | | String time = DateUtils.dateToDateString(new Date(), DateUtils.yyyy_MM_dd_HH_EN) + ":00:00"; |
| | | queryWrapper.eq("time", time).eq("mac", mac); |
| | | Date now = new Date(); |
| | | String time = DateUtils.dateToDateString(now, DateUtils.yyyy_MM_dd_HH_EN) + ":00:00"; |
| | | //获取小时数据 |
| | | HistoryHourly historyHourly = historyHourlyMapper.selectOne(queryWrapper); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("timeUnits", DateUtils.dateToDateString(now, DateUtils.yyyyMM_EN)); |
| | | params.put("mac", mac); |
| | | params.put("time", time); |
| | | String value = historyHourlyMapper.selectHourlyData(params); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | if (historyHourly == null) { |
| | | if (ObjectUtils.isEmpty(value)) { |
| | | result.put("AQI", Constants.NULL_VALUE); |
| | | return result; |
| | | } |
| | | Map<String, Object> data = JSONObject.parseObject(historyHourly.getValue(), Map.class); |
| | | Map<String, Object> data = JSONObject.parseObject(value, Map.class); |
| | | result.put("AQI", AQIUtils.hourlyAqi(data)); |
| | | return result; |
| | | } |