燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-07-31 2a4e0a1c07d0d109d80d1d0cbcdd6b7be40c8bbc
src/main/java/com/yssh/controller/WarningAnalyseController.java
@@ -1,5 +1,6 @@
package com.yssh.controller;
import com.yssh.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -14,6 +15,7 @@
import com.yssh.utils.Result;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
@Api(tags = "告警分析")
@@ -27,28 +29,76 @@
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取实时报警", notes = "获取实时报警分析数据")
    @GetMapping("/runAlarm")
    public Result alarmAnalyse(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
        return Result.OK(warningService.getRunTimeAlarmAnalyse(null == date ? new Date() : date));
    public Result alarmAnalyse(@RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                               @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
        Integer startTime = getStartTime(start, end);
        Integer endTime = getEndTime(start, end);
        return Result.OK(warningService.getRunTimeAlarmAnalyse(startTime, endTime));
    }
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取实时预警", notes = "获取实时预警分析数据")
    @GetMapping("/runWarning")
    public Result warningAnalyse(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
        return Result.OK(warningService.getRunTimeWarningAnalyse(null == date ? new Date() : date));
    public Result warningAnalyse(@RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                                 @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
        Integer startTime = getStartTime(start, end);
        Integer endTime = getEndTime(start, end);
        return Result.OK(warningService.getRunTimeWarningAnalyse(startTime, endTime));
    }
    private Integer getStartTime(Date start, Date end) {
        do {
            if (null == start && null == end) {
                start = DateUtils.getAPeriodOfTime(new Date(), -5, Calendar.HOUR_OF_DAY);
                break;
            }
            if (null != start && null == end) {
                break;
            }
            if (null == start) {
                start = DateUtils.getAPeriodOfTime(end, -5, Calendar.HOUR_OF_DAY);
                break;
            }
            start = start.getTime() > end.getTime() ? end : start;
        } while (false);
        return Integer.parseInt(DateUtils.getYyyyMmDdHh(start));
    }
    private Integer getEndTime(Date start, Date end) {
        do {
            if (null == start && null == end) {
                end = new Date();
                break;
            }
            if (null != start && null == end) {
                end = DateUtils.getAPeriodOfTime(start, 5, Calendar.HOUR_OF_DAY);
                break;
            }
            if (null == start) {
                break;
            }
            end = start.getTime() < end.getTime() ? end : start;
        } while (false);
        return Integer.parseInt(DateUtils.getYyyyMmDdHh(end));
    }
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "本月预警报警统计", notes = "本月预警报警统计,返回参数alarmNumber对应值为本月报警数据量,参数warningNumber对应值为本月预警数据量")
    @GetMapping("/monthCount")
    public Result thisMonthCount(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
    public Result thisMonthCount(@RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
        return Result.OK(warningService.monthCount(null == date ? new Date() : date));
    }
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "一周预警报警数量变化趋势", notes = "一周预警报警数量变化趋势,返回参数alarmDayCount为一周每日报警统计数量列表,参数warningDayCount为一周每日预警统计数量列表")
    @GetMapping("/everydayCount")
    public Result everydayCount(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
    public Result everydayCount(@RequestParam(value = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
        return Result.OK(warningService.everydayCount(null == date ? new Date() : date));
    }