kaiyu
2021-07-16 3b29244703787dda85386167dca4126b5b0f150c
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
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@Slf4j
@Api(tags = {"web端接口"})
@RestController
@RequestMapping("/web")
public class WebController {
 
    @Autowired
    private HistoryHourlyService historyHourlyService;
 
    @Autowired
    private HistoryDailyService historyDailyService;
 
    @GetMapping("getHourlyAqi")
    @ApiOperation(value = "获取一小时AQI", notes = "获取一小时AQI")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getHourlyAqi(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> result = historyHourlyService.getHourlyAqiByMac(params.get("mac").toString());
        return ResultMessage.ok(result);
    }
 
    @GetMapping("getMonthAvg")
    @ApiOperation(value = "获取某设备某因子本月均值", notes = "获取某设备某因子本月均值")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getMonthAvg(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("sensorCode")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> result = historyDailyService.getMonthAvg(params);
        return ResultMessage.ok(result);
    }
 
}