cjl
2023-09-06 921eca0d6be75b8a634abb33185b7d9b2fcddfd4
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package com.moral.api.controller;
 
import com.moral.api.dto.MonitoringStationDTO;
import com.moral.api.dto.MonitoringStationDTOResult;
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.api.utils.EasyExcelUtils;
import com.moral.api.utils.NoModelWriteData;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * @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,false);
 
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), vo);
    }
 
    @GetMapping("queryMonitorPointsState")
    public ResultMessage queryMonitorPointsState(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,true);
 
        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 monitorPoint = params.remove("monitorPointIds").toString();
        /*if(monitorPoint.contains("")){
 
        }*/
        String[] monitorPointIds = monitorPoint.split(",");
        if (monitorPointIds.length > 3) {
            return ResultMessage.ok();
        }
 
        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);
    }
 
    /**
     * 监测站点数据导出
     *
     * @param params
     * @return
     */
    @PostMapping("getHourlyDataExcel")
    public ResultMessage getHourlyDataExcel(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("macs") || !params.containsKey("sensors") || !params.containsKey("times") || !params.containsKey("type")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> resList = monitorPointService.getHourlyDataDataV3(params);
        return ResultMessage.ok(resList);
    }
 
 
    @PostMapping("getHourlyDataExcelNew")
    public ResultMessage getHourlyDataExcelNew(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("macs") || !params.containsKey("sensors") || !params.containsKey("times") || !params.containsKey("type")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> resList = monitorPointService.getHourlyDataDataV3Excel(params);
        return ResultMessage.ok(resList);
    }
 
    @PostMapping("/exlOut")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    public void exlOut(HttpServletResponse response,@RequestBody Map<String, Object> params) {
        //导出字段集合
        // List<ExcelHeader> excelHeaders = Arrays.asList(new ExcelHeader("phone", "手机号"), new ExcelHeader("sexStr", "性别"));
       /* Map<String, Object> params = new HashMap<>();
        params.put("macs", Arrays.asList("p5dnd7a0245446", "p5dnd7a0745450"));
        params.put("sensors", "a34004,a34002");
        params.put("type", "hours");
        params.put("times", Arrays.asList("2023-07-01 00", "2023-07-02 00"));*/
        if (!params.containsKey("macs") || !params.containsKey("sensors") || !params.containsKey("times") || !params.containsKey("type")) {
            return;
        }
        //数据集合
        List<Map<String, Object>> resList = monitorPointService.getHourlyDataDataV3Excel(params);
        if (CollectionUtils.isEmpty(resList)) {
            return;
        }
        Map<String, Object> map = resList.get(0);
        List<String> list = new ArrayList<>();
        for (String key : map.keySet()) {
            list.add(key);
        }
        String[] s2 = new String[list.size()];
        list.toArray(s2);
        NoModelWriteData d = new NoModelWriteData();
        d.setFileName("数据导出");
        d.setHeadMap(s2);
        d.setDataStrMap(s2);
        d.setDataList(resList);
        try {
            EasyExcelUtils easyExcelUtils = new EasyExcelUtils();
            easyExcelUtils.noModleWrite(d, response);
        } catch (Exception e) {
            int i = 0;
        }
 
    }
    @PostMapping("listMonitoring")
    public ResultMessage listMonitoring(@RequestBody Map<String, Object> params) {
 
        /*@RequestParam @ApiParam(value = "mac",name = "mac号") List<String> mac,
        @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
        @RequestParam @ApiParam(value = "reportType",name = "type") int reportType,
        @RequestParam @ApiParam(value = "endTime",name = "结束时间") String endTime*/
        List<MonitoringStationDTO> resList = monitorPointService.listMonitoringStationDTO(params,Integer.parseInt(params.get("reportType").toString()),params.get("startTime").toString(),params.get("endTime").toString());
        /*List<MonitoringStationDTOResult> list = new ArrayList<>();
        for(MonitoringStationDTO m : resList){
            MonitoringStationDTOResult result = new MonitoringStationDTOResult();
            result.setName(m.getName());
            result.setMac(m.getMac());
            result.setPM25(m.getPM25().compareTo(BigDecimal.ZERO)==0?"-":m.getPM25().toString());
            result.setPM25Num(m.getPM25Num()==0?"-":String.valueOf(m.getPM25Num()));
            result.setO3(m.getO3().compareTo(BigDecimal.ZERO)==0?"-":m.getO3().toString());
            result.setO3Num(m.getO3Num()==0?"-":String.valueOf(m.getO3Num()));
            result.setTovc(m.getTovc().compareTo(BigDecimal.ZERO)==0?"-":m.getTovc().toString());
            result.setTOVCNum(m.getTOVCNum()==0?"-":String.valueOf(m.getTOVCNum()));
            result.setComposite(m.getComposite().compareTo(BigDecimal.ZERO)==0?"-":m.getComposite().toString());
            result.setCompositeNum(m.getCompositeNum()==0?"-":String.valueOf(m.getCompositeNum()));
            result.setSO2(m.getSO2().compareTo(BigDecimal.ZERO)==0?"-":m.getSO2().toString());
            result.setSO2Num(m.getSO2Num()==0?"-":String.valueOf(m.getSO2Num()));
            result.setNO2(m.getNO2().compareTo(BigDecimal.ZERO)==0?"-":m.getNO2().toString());
            result.setNO2Num(m.getNO2Num()==0?"-":String.valueOf(m.getNO2Num()));
            result.setPM10(m.getPM10().compareTo(BigDecimal.ZERO)==0?"-":m.getPM10().toString());
            result.setPM10Num(m.getPM10Num()==0?"-":String.valueOf(m.getPM10Num()));
            result.setCO(m.getCO().compareTo(BigDecimal.ZERO)==0?"-":m.getCO().toString());
            result.setCONum(m.getCONum()==0?"-":String.valueOf(m.getCONum()));
            list.add(result);
        }*/
        return ResultMessage.ok(resList);
    }
}