houzhongjian
2025-01-21 49148428d71415ad2b5449cb6ea2e83f1fbb6c18
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
package com.iailab.module.model.api.controller.admin;
 
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mcs.dto.*;
import com.iailab.module.model.api.mdk.dto.StScheduleRecordVO;
import com.iailab.module.model.common.utils.ApiSecurityUtils;
import com.iailab.module.model.common.utils.ExcelUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年11月14日
 */
@Slf4j
@RestController
@RequestMapping("/model/api/mcs")
@Tag(name = "数据")
public class McsApiController {
 
    @Resource
    private ApiSecurityUtils apiSecurityUtils;
 
    @Autowired
    private McsApi mcsApi;
 
    @GetMapping("/predict-item/tree")
    @Operation(summary = "预测项树")
    public CommonResult<List<PredictItemTreeDTO>> getPredictItemTree(HttpServletResponse response, HttpServletRequest
            request) throws Exception {
        apiSecurityUtils.validate(request);
        List<PredictItemTreeDTO> list = mcsApi.getPredictItemTree();
        return CommonResult.success(list);
    }
 
    @PostMapping("/predict-data/charts")
    @Operation(summary = "预测数据图表")
    public CommonResult<PreDataBarLineRespVO> getPreDataCharts(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataBarLineReqVO reqVO) throws Exception {
        apiSecurityUtils.validate(request);
        PreDataBarLineRespVO respVO = new PreDataBarLineRespVO();
        try {
            respVO = mcsApi.getPreDataCharts(reqVO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CommonResult.success(respVO);
    }
 
    @PostMapping("/predict-data/item-chart")
    @Operation(summary = "预测数据图表")
    public CommonResult<PreDataItemChartRespVO> getPreDataItemChart(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataItemChartReqVO reqVO) throws Exception {
        apiSecurityUtils.validate(request);
        PreDataItemChartRespVO respVO = mcsApi.getPreDataItemChart(reqVO);
        return CommonResult.success(respVO);
    }
 
    @PostMapping("/predict-data/single-chart")
    @Operation(summary = "预测数据图表")
    public CommonResult<PreDataSingleChartRespVO> getPreDataSingleChart(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception {
        apiSecurityUtils.validate(request);
        PreDataSingleChartRespVO respVO = mcsApi.getPreDataSingleChart(reqVO);
        return CommonResult.success(respVO);
    }
 
    @PostMapping("/plan-data/single-chart")
    @Operation(summary = "预测数据图表")
    public CommonResult<PlanDataSingleChartRespVO> getPlanDataSingleChart(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception {
        apiSecurityUtils.validate(request);
        PlanDataSingleChartRespVO respVO = mcsApi.getPlanDataSingleChart(reqVO);
        return CommonResult.success(respVO);
    }
 
    @PostMapping("/predict-data/cur")
    @Operation(summary = "获取当前预测数据")
    public CommonResult<Map<String, List<Object[]>>> getPreDataCur(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataJsonReqVO reqVO)throws Exception {
        apiSecurityUtils.validate(request);
        reqVO.setPredictTime(new Date());
        Map<String, List<Object[]>> map = mcsApi.getPreDataCur(reqVO);
        return CommonResult.success(map);
    }
 
    @GetMapping("/predict-data/exportValue")
    @Operation(summary = "导出预测数据")
    public void exportPointValue(@RequestParam("itemId") String itemId,
                                 @RequestParam("startTime") String startTime,
                                 @RequestParam("endTime") String endTime,
                                 HttpServletResponse response) throws IOException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        PreDataItemChartReqVO reqVO = new PreDataItemChartReqVO();
        reqVO.setItemId(itemId);
        try {
            if (startTime == "") {
                reqVO.setStartTime(new Date((new Date()).getTime() - 60 * 60 * 1000));
            } else {
                reqVO.setStartTime(formatter.parse(startTime));
 
            }
            if (endTime == "") {
                reqVO.setEndTime(new Date((new Date()).getTime() + 60 * 60 * 1000));
            } else {
                reqVO.setEndTime(formatter.parse(endTime));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        PreDataItemChartRespVO respVO = mcsApi.getPreDataItemChart(reqVO);
        try {
            String sheetTitle = "sheet1";
            ExcelUtil.exportchart(sheetTitle, respVO, response);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
    @GetMapping("/alarm-message/last-one")
    @Operation(summary = "根据监控对象获取最新预警信息")
    public CommonResult<AlarmMessageRespDTO> getLastAlarmMessage(HttpServletResponse response, HttpServletRequest
            request, @RequestParam("alarmObj") String alarmObj) {
        AlarmMessageRespDTO data = mcsApi.getLastAlarmMessage(alarmObj);
        return CommonResult.success(data);
    }
 
    @GetMapping("/schedule-suggest/last-limit")
    @Operation(summary = "根据监控对象获取最新预警信息")
    public CommonResult<List<ScheduleSuggestRespDTO>> getLastLimitScheduleSuggest(HttpServletResponse response, HttpServletRequest
            request, @RequestParam("scheduleObj") String scheduleObj, @RequestParam("limit") Integer limit) {
        List<ScheduleSuggestRespDTO> data = mcsApi.getLastLimitScheduleSuggest(scheduleObj, limit);
        return CommonResult.success(data);
    }
 
    @PostMapping("/alarm-suggest/page")
    @Operation(summary = "获取预警信息和调度建议分页列表")
    public CommonResult<PageResult<StAlarmAndSuggestRespVO>> getAlarmAndSuggestPage(@RequestBody StAlarmAndSuggestPageReqVO reqVO) {
        PageResult<StAlarmAndSuggestRespVO> page = mcsApi.getAlarmAndSuggestPage(reqVO);
        return success(BeanUtils.toBean(page, StAlarmAndSuggestRespVO.class));
    }
 
    @GetMapping("/chart/param/list")
    @Operation(summary = "图表配置列表")
    public CommonResult<List<ChartParamDTO>> getChartParamList(@RequestParam("chartCode") String chartCode) {
        List<ChartParamDTO> chartParamList = mcsApi.getChartParamList(chartCode);
        return CommonResult.success(chartParamList);
    }
 
    @PostMapping("/predict-data/doubleValue")
    @Operation(summary = "获取多个预测项Double类型数据")
    public CommonResult<Map<String, Map<String,Double>>> getPreDoubleData(@RequestBody PreDoubleDataReqVO reqVO) {
        Map<String, Map<String,Double>> map = mcsApi.getPreDoubleData(reqVO);
        return CommonResult.success(map);
    }
 
    @PostMapping("/predict-data/last-value")
    @Operation(summary = "获取最后预测值")
    public CommonResult<Map<String, BigDecimal>> getPredictLastValue(@RequestBody PredictLastValueReqVO reqVO) {
        Map<String, BigDecimal> data = mcsApi.getPredictLastValue(reqVO);
        return CommonResult.success(data);
    }
 
    @GetMapping("/predict-data/electric")
    @Operation(summary = "电力功率因数预测结果查询")
    public CommonResult<Map<String,List<Object[]>>> getElectricPredictData(@RequestParam String itemCode) {
        Map<String,List<Object[]>> data = mcsApi.getElectricPredictData(itemCode);
        return CommonResult.success(data);
    }
    @GetMapping("/schedule-data/last")
    @Operation(summary = "调度模型最新结果查询")
    public CommonResult<List<StScheduleRecordVO>> getLastScheduleData(@RequestParam String scheduleCode, @RequestParam Integer limit) {
        if (null == limit) {
            limit = 1;
        }
        return CommonResult.success(mcsApi.getLastScheduleData(scheduleCode,limit));
    }
 
    @PostMapping("/schedule-data/last/more")
    @Operation(summary = "多个调度模型最新结果查询")
    public CommonResult<Map<String,List<StScheduleRecordVO>>> getMoreLastScheduleData(@RequestBody Map<String,Object> params) {
        if (!params.containsKey("scheduleCodes")) {
            return success(new HashMap<>());
        }
        Set<String> scheduleCodes = new HashSet<>(((List<String>) params.get("scheduleCodes")));
        if (CollectionUtils.isEmpty(scheduleCodes)) {
            return success(new HashMap<>());
        }
        Integer limit = 1;
        if (params.containsKey("limit")) {
            limit = Integer.parseInt(params.get("limit").toString());
        }
 
        Map<String,List<StScheduleRecordVO>> result = new HashMap<>(scheduleCodes.size());
        for (String scheduleCode : scheduleCodes) {
            result.put(scheduleCode,mcsApi.getLastScheduleData(scheduleCode, limit));
        }
        return CommonResult.success(result);
    }
 
    @PostMapping("/machineRealTimeStatus")
    @Operation(summary = "发电机组实时状态查询")
    CommonResult<List<Map<String, Object>>> getRealTimeStatus(@RequestBody List<Map<String, Object>> machines) {
        return CommonResult.success(mcsApi.getRealTimeStatus(machines));
    }
 
    @PostMapping("/predict-data/itemNo")
    @Operation(summary = "查询时间范围内预测结果")
    CommonResult<Map<String,List<Object[]>>> getPredictDataItemNo(@RequestBody PreDataItemNoReqVO reqVO) {
        return CommonResult.success(mcsApi.getPredictDataItemNo(reqVO));
    }
}