liriming
2024-11-28 f96689bddf69ea3d635116cf1dd98bd5e5e0755a
提交 | 用户 | 时间
ead005 1 package com.iailab.module.model.api.controller.admin;
2
179784 3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
ead005 4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.module.model.api.mcs.McsApi;
a4891a 6 import com.iailab.module.model.api.mcs.dto.*;
ead005 7 import com.iailab.module.model.common.utils.ApiSecurityUtils;
179784 8 import com.iailab.module.model.common.utils.ExcelUtil;
ead005 9 import io.swagger.v3.oas.annotations.Operation;
10 import io.swagger.v3.oas.annotations.tags.Tag;
11 import lombok.extern.slf4j.Slf4j;
12 import org.springframework.beans.factory.annotation.Autowired;
a4891a 13 import org.springframework.web.bind.annotation.*;
ead005 14
15 import javax.annotation.Resource;
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
179784 18 import java.io.IOException;
D 19 import java.text.SimpleDateFormat;
20 import java.util.Date;
a4891a 21 import java.util.List;
055765 22
179784 23 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
ead005 24
25 /**
26  * @author PanZhibao
27  * @Description
28  * @createTime 2024年11月14日
29  */
30 @Slf4j
31 @RestController
32 @RequestMapping("/model/api/mcs")
33 @Tag(name = "数据")
34 public class McsApiController {
35
36     @Resource
37     private ApiSecurityUtils apiSecurityUtils;
38
39     @Autowired
40     private McsApi mcsApi;
41
a4891a 42     @GetMapping("/predict-item/tree")
43     @Operation(summary = "预测项树")
44     public CommonResult<List<PredictItemTreeDTO>> getPredictItemTree(HttpServletResponse response, HttpServletRequest
45             request) throws Exception {
46         apiSecurityUtils.validate(request);
47         List<PredictItemTreeDTO> list = mcsApi.getPredictItemTree();
48         return CommonResult.success(list);
49     }
50
ead005 51     @PostMapping("/predict-data/charts")
52     @Operation(summary = "预测数据图表")
53     public CommonResult<PreDataBarLineRespVO> getPreDataCharts(HttpServletResponse response, HttpServletRequest
54             request, @RequestBody PreDataBarLineReqVO reqVO) throws Exception {
55         apiSecurityUtils.validate(request);
9e844c 56         PreDataBarLineRespVO respVO = new PreDataBarLineRespVO();
57         try {
58             respVO = mcsApi.getPreDataCharts(reqVO);
59         } catch (Exception e) {
60             e.printStackTrace();
61         }
ead005 62         return CommonResult.success(respVO);
63     }
64
65     @PostMapping("/predict-data/item-chart")
66     @Operation(summary = "预测数据图表")
67     public CommonResult<PreDataItemChartRespVO> getPreDataItemChart(HttpServletResponse response, HttpServletRequest
68             request, @RequestBody PreDataItemChartReqVO reqVO) throws Exception {
69         apiSecurityUtils.validate(request);
70         PreDataItemChartRespVO respVO = mcsApi.getPreDataItemChart(reqVO);
71         return CommonResult.success(respVO);
72     }
328ef4 73
977edc 74     @PostMapping("/predict-data/single-chart")
328ef4 75     @Operation(summary = "预测数据图表")
91343d 76     public CommonResult<PreDataSingleChartRespVO> getPreDataSingleChart(HttpServletResponse response, HttpServletRequest
328ef4 77             request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception {
78         apiSecurityUtils.validate(request);
91343d 79         PreDataSingleChartRespVO respVO = mcsApi.getPreDataSingleChart(reqVO);
328ef4 80         return CommonResult.success(respVO);
81     }
f0a527 82
8a74e9 83     @PostMapping("/plan-data/single-chart")
84     @Operation(summary = "预测数据图表")
85     public CommonResult<PlanDataSingleChartRespVO> getPlanDataSingleChart(HttpServletResponse response, HttpServletRequest
86             request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception {
87         apiSecurityUtils.validate(request);
88         PlanDataSingleChartRespVO respVO = mcsApi.getPlanDataSingleChart(reqVO);
89         return CommonResult.success(respVO);
90     }
91
179784 92     @GetMapping("/predict-data/exportValue")
D 93     @Operation(summary = "导出预测数据")
94     public void exportPointValue(@RequestParam("itemId") String itemId,
95                                  @RequestParam("startTime") String startTime,
96                                  @RequestParam("endTime") String endTime,
97                                  HttpServletResponse response) throws IOException {
98         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
99         PreDataItemChartReqVO reqVO = new PreDataItemChartReqVO();
100         reqVO.setItemId(itemId);
101         try {
102             if (startTime == "") {
055765 103                 reqVO.setStartTime(new Date((new Date()).getTime() - 60 * 60 * 1000));
179784 104             } else {
D 105                 reqVO.setStartTime(formatter.parse(startTime));
106
107             }
108             if (endTime == "") {
055765 109                 reqVO.setEndTime(new Date((new Date()).getTime() + 60 * 60 * 1000));
179784 110             } else {
D 111                 reqVO.setEndTime(formatter.parse(endTime));
112             }
113         } catch (Exception e) {
114             e.printStackTrace();
115         }
116         PreDataItemChartRespVO respVO = mcsApi.getPreDataItemChart(reqVO);
117         try {
055765 118             String sheetTitle = "sheet1";
179784 119             ExcelUtil.exportchart(sheetTitle, respVO, response);
D 120         } catch (Exception ex) {
121             ex.printStackTrace();
122         }
123     }
055765 124
125     @GetMapping("/alarm-message/last-one")
126     @Operation(summary = "根据监控对象获取最新预警信息")
127     public CommonResult<AlarmMessageRespDTO> getLastAlarmMessage(HttpServletResponse response, HttpServletRequest
128             request, @RequestParam("alarmObj") String alarmObj) {
129         AlarmMessageRespDTO data = mcsApi.getLastAlarmMessage(alarmObj);
130         return CommonResult.success(data);
131     }
132
133     @GetMapping("/schedule-suggest/last-limit")
134     @Operation(summary = "根据监控对象获取最新预警信息")
135     public CommonResult<List<ScheduleSuggestRespDTO>> getLastLimitScheduleSuggest(HttpServletResponse response, HttpServletRequest
136             request, @RequestParam("scheduleObj") String scheduleObj, @RequestParam("limit") Integer limit) {
137         List<ScheduleSuggestRespDTO> data = mcsApi.getLastLimitScheduleSuggest(scheduleObj, limit);
138         return CommonResult.success(data);
139     }
ead005 140 }