jinpengyong
2021-09-01 7607bab6e868a51609164ce111c9d5e1046cd11f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.moral.api.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.moral.api.mapper.HistoryHourlyMapper;
import com.moral.api.service.HistoryHourlyService;
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;
import java.util.Map;
 
/**
 * <p>
 * 已校准小时表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-07-14
 */
@Service
public class HistoryHourlyServiceImpl implements HistoryHourlyService {
 
    @Autowired
    private HistoryHourlyMapper historyHourlyMapper;
 
    @Override
    public Map<String, Object> getHourlyAqiByMac(String mac) {
        Date now = new Date();
        String time = DateUtils.dateToDateString(now, DateUtils.yyyy_MM_dd_HH_EN) + ":00:00";
        //获取小时数据
        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 (ObjectUtils.isEmpty(value)) {
            result.put("AQI", Constants.NULL_VALUE);
            return result;
        }
        Map<String, Object> data = JSONObject.parseObject(value, Map.class);
        result.put("AQI", AQIUtils.hourlyAqi(data));
        return result;
    }
}