dongyukun
7 天以前 e88fba9645a57535d858ce48da8e9d9a3dc84adc
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/controller/admin/McsApiController.java
@@ -4,6 +4,7 @@
import com.iailab.module.model.api.mcs.McsApi;
import com.iailab.module.model.api.mcs.dto.*;
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;
@@ -11,10 +12,13 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author PanZhibao
@@ -33,7 +37,6 @@
    @Autowired
    private McsApi mcsApi;
    @PermitAll
    @GetMapping("/predict-item/tree")
    @Operation(summary = "预测项树")
    public CommonResult<List<PredictItemTreeDTO>> getPredictItemTree(HttpServletResponse response, HttpServletRequest
@@ -43,17 +46,20 @@
        return CommonResult.success(list);
    }
    @PermitAll
    @PostMapping("/predict-data/charts")
    @Operation(summary = "预测数据图表")
    public CommonResult<PreDataBarLineRespVO> getPreDataCharts(HttpServletResponse response, HttpServletRequest
            request, @RequestBody PreDataBarLineReqVO reqVO) throws Exception {
        apiSecurityUtils.validate(request);
        PreDataBarLineRespVO respVO = mcsApi.getPreDataCharts(reqVO);
        PreDataBarLineRespVO respVO = new PreDataBarLineRespVO();
        try {
            respVO = mcsApi.getPreDataCharts(reqVO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CommonResult.success(respVO);
    }
    @PermitAll
    @PostMapping("/predict-data/item-chart")
    @Operation(summary = "预测数据图表")
    public CommonResult<PreDataItemChartRespVO> getPreDataItemChart(HttpServletResponse response, HttpServletRequest
@@ -62,4 +68,81 @@
        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);
    }
}