chen_xi
2022-10-27 2c86b47f500aa16ce7c142361fe4c3ffab45c1f6
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
package com.moral.api.controller;
 
import com.moral.api.entity.MonitorPoint;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.pojo.vo.monitorPoint.MonitorPointsVO;
import com.moral.api.service.HistoryFiveMinutelyService;
import com.moral.api.service.MonitorPointService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
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.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.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @ClassName DeviceController
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 9:24
 * @Version TODO
 **/
@Slf4j
@Api(tags = {"设备数据"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/monitorPoint")
public class MonitorPointController {
 
    @Autowired
    MonitorPointService monitorPointService;
 
    @Autowired
    private HistoryFiveMinutelyService historyFiveMinutelyService;
 
    @GetMapping("queryMonitorPoints")
    public ResultMessage queryMonitorPointsAndDevices(MonitorPointQueryForm form) {
        //判断是否缺少参数
        if (!form.valid())
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
                    ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        //处理查询业务
        List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(form);
 
        //转换前端参数
        MonitorPointsVO vo = MonitorPointsVO.convert(monitorPoints);
 
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), vo);
    }
 
    /**
    * @Description: 查询组织下所有的站点id以及name
            * @Param: [organizationId]
            * @return: com.moral.constant.ResultMessage
            * @Author: 陈凯裕
            * @Date: 2021/9/26
            */
    @GetMapping("queryAllMonitorPoints")
    public ResultMessage queryAllMonitorPoints(Integer organizationId){
        //处理查询业务
        List<MonitorPoint> monitorPoints = monitorPointService.queryAllMonitorPoints(organizationId);
        //返回数据
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), monitorPoints);
    }
 
 
    /**
     * @param request 请求信息
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("getWindData")
    @ApiOperation(value = "获取风场数据", notes = "获取风场数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointIds", value = "站点id", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getWindData(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("monitorPointIds")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        String[] monitorPointIds = params.remove("monitorPointIds").toString().split(",");
        params.put("monitorPointIds", monitorPointIds);
        List<Object> response = historyFiveMinutelyService.getAreaWindData(params);
        return ResultMessage.ok(response);
    }
 
    /**
      *@Description: 监测站点数据显示导出
      *@Param: [request]
      *@return: com.moral.constant.ResultMessage 
      *@Author: lizijie
      *@Date: 2022-10-10 14:00
     **/
    @GetMapping("getHourlyDataByMonitorPoint")
    public ResultMessage getHourlyDataByMonitorPoint(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("monitorPointId") || !params.containsKey("sensors") || !params.containsKey("startTime") || !params.containsKey("endTime")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> resultList = monitorPointService.getHourlyDataByMonitorPoint(params);
        return ResultMessage.ok(resultList);
    }
 
}