kaiyu
2021-12-30 bd9a7f2d97af968d43ccd5516644f6933b42f5b2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.moral.api.controller;
 
import com.moral.api.pojo.dto.cityAQI.CityPollutionLevel;
import com.moral.api.pojo.dto.cityAQI.MonthlyPollutionLevel;
import com.moral.api.pojo.form.aqi.AreaPollutionLevelForm;
import com.moral.api.pojo.vo.cityAQI.BarChartOfPollutionLevelVO;
import com.moral.api.pojo.vo.cityAQI.BarChartTableOfPollutionLevelVO;
import com.moral.api.pojo.vo.cityAQI.PieChartOfPollutionLevelVO;
import com.moral.api.pojo.form.aqi.ChartOfPollutionLevelForm;
import com.moral.api.service.CityAqiDailyService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.*;
 
import javax.servlet.http.HttpServletRequest;
 
import com.moral.api.service.CityAqiService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@RestController
@RequestMapping("/aqi")
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags = {"aqi"})
public class AqiController {
 
    @Autowired
    private CityAqiService cityAqiService;
    @Autowired
    private CityAqiDailyService cityAqiDailyService;
 
    @GetMapping("compareO3")
    @ApiOperation(value = "预测和实测臭氧对比", notes = "预测和实测臭氧对比")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "regionCode", value = "区号", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage measuredCompareForecast(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("regionCode") || !params.containsKey("time")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> response = cityAqiService.measuredCompareForecastOfO3(params);
        return ResultMessage.ok(response);
    }
 
    /**
     * @Description: 查询最新的6参和aqi数据
     * @Param: [regionCode]
     * @return: com.moral.constant.ResultMessage
     * @Author: 陈凯裕
     * @Date: 2021/11/1
     */
    @GetMapping("queryByRegionCode")
    public ResultMessage queryByRegionCode(Integer regionCode) {
        Map<String, Object> value = cityAqiService.queryCityAqiByRegionCode(regionCode);
        return ResultMessage.ok(value);
    }
 
    /**
     * @Description: 查询最近24小时的aqi数据
     * @Param: [regionCode]
     * @return: com.moral.constant.ResultMessage
     * @Author: 陈凯裕
     * @Date: 2021/11/1
     */
    @GetMapping("query24HoursAQI")
    public ResultMessage query24HoursAQIByRegionCode(Integer regionCode) {
        Map<String, Object> datas = cityAqiService.query24HoursAqiByRegionCode(regionCode);
        return ResultMessage.ok(datas);
    }
 
    /**
     * @Description: 查询当天的累计aqi以及主要污染物
     * @Param: [RegionCode]
     * @return: com.moral.constant.ResultMessage
     * @Author: 陈凯裕
     * @Date: 2021/11/2
     */
    @GetMapping("queryTodayAqiAndPollutant")
    public ResultMessage queryTodayAqiAndPollutant(Integer regionCode) {
        Map<String, Object> datas = cityAqiService.queryTodayAqiAndPollutant(regionCode);
        return ResultMessage.ok(datas);
    }
 
    /**
     * @Description: 首页右下角,污染天数占比的饼状图
     * @Param: [regionCode]
     * @return: com.moral.constant.ResultMessage
     * @Author: 陈凯裕
     * @Date: 2021/11/11
     */
    @GetMapping("queryPieChartOfPollutionLevel")
    public ResultMessage queryPieChartOfPollutionLevel(ChartOfPollutionLevelForm form) {
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
 
        PieChartOfPollutionLevelVO VO = cityAqiDailyService.queryPieChartOfPollutionLevels(form);
        return ResultMessage.ok(VO);
    }
 
    /**
    * @Description: 获取城市优良天气占比的柱状图数据
            * @Param: [form]
            * @return: com.moral.constant.ResultMessage
            * @Author: 陈凯裕
            * @Date: 2021/11/22
            */
    @GetMapping("queryBarChartOfPollutionLevel")
    public ResultMessage queryBarChartOfPollutionLevel(ChartOfPollutionLevelForm form){
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        //查询数据
        List<MonthlyPollutionLevel> datas = cityAqiDailyService.queryBarChartOfPollutionLevels(form);
        //数据格式转换
        BarChartOfPollutionLevelVO vo = BarChartOfPollutionLevelVO.convert(datas);
        return ResultMessage.ok(vo);
 
    }
 
    /**
    * @Description: 获取城市优良天气占比的柱状图下的表格数据
            * @Param: [form]
            * @return: com.moral.constant.ResultMessage
            * @Author: 陈凯裕
            * @Date: 2021/11/22
            */
    @GetMapping("queryBarChatTableOfPollutionLevel")
    public ResultMessage queryBarChatTableOfPollutionLevel(ChartOfPollutionLevelForm form){
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        //查询数据
        List<MonthlyPollutionLevel> datas = cityAqiDailyService.queryBarChartOfPollutionLevels(form);
        List<BarChartTableOfPollutionLevelVO> vos = new ArrayList<>();
        for (MonthlyPollutionLevel data : datas) {
            BarChartTableOfPollutionLevelVO vo = BarChartTableOfPollutionLevelVO.convert(data);
            vos.add(vo);
        }
        return ResultMessage.ok(vos);
    }
 
    @GetMapping("provincialRanking")
    @ApiOperation(value = "省内排名", notes = "省内排名")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "regionCode", value = "区号", required = true, paramType = "query", dataType = "Integer")
    })
    public ResultMessage provincialRanking(Integer regionCode) {
        if (ObjectUtils.isEmpty(regionCode)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> response = cityAqiService.provincialRanking(regionCode);
        return ResultMessage.ok(response);
    }
 
    @GetMapping("rankingDetails")
    @ApiOperation(value = "排名详情", notes = "排名详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "regionCode", value = "区号", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "type", value = "排名类型,今日累计:today,小时:hour,日:day,月:month,年:year,自定义:custom", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "时间,排名类型为day,month,year是需传此参", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "start", value = "开始时间,排名类型为custom自定义是传此参,精确到日,如:2021-11-02", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "end", value = "结束时间,排名类型为custom自定义是传此参,精确到日,如:2021-11-03", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "cityType", value = "城市类型,省内城市:province,市区排名:city", required = true, paramType = "query", dataType = "String"),
    })
    public ResultMessage rankingDetails(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("type") || !params.containsKey("cityType") || !params.containsKey("regionCode")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Object type = params.get("type");
        if ("hour".equals(type) || "day".equals(type) || "month".equals(type) || "year".equals(type)) {
            if (!params.containsKey("time")) {
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
        }
        if ("custom".equals(type)) {
            if (!params.containsKey("start") || !params.containsKey("end")) {
                return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
            }
        }
        List<Map<String, Object>> response = cityAqiService.rankingDetails(params);
        return ResultMessage.ok(response);
    }
 
    /**
    * @Description: 查询一个城市所有县级市的优良天气
            * @Param: [regionCode]
            * @return: com.moral.constant.ResultMessage
            * @Author: 陈凯裕
            * @Date: 2021/12/30
            */
    @GetMapping("queryAreaPollutionLevel")
    public ResultMessage queryAreaPollutionLevel(AreaPollutionLevelForm form){
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        //查询业务数据
        List<CityPollutionLevel> datas = cityAqiDailyService.queryAreaPollutionLevel(form);
 
        return ResultMessage.ok(datas);
    }
 
}