From 8185e5cdc2bbdf7fb4ca46a10864106893a01ed3 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 20 十一月 2024 15:30:12 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/controller/WarningAnalyseController.java |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/yssh/controller/WarningAnalyseController.java b/src/main/java/com/yssh/controller/WarningAnalyseController.java
new file mode 100644
index 0000000..7032820
--- /dev/null
+++ b/src/main/java/com/yssh/controller/WarningAnalyseController.java
@@ -0,0 +1,162 @@
+package com.yssh.controller;
+
+import com.yssh.config.InitConfig;
+import com.yssh.entity.Report;
+import com.yssh.utils.CacheUtils;
+import com.yssh.utils.DateUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.yssh.service.WarningAnalyseService;
+import com.yssh.utils.Result;
+
+import javax.annotation.Resource;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Api(tags = "鍛婅鍒嗘瀽")
+@RequestMapping("/warning")
+@RestController
+@SuppressWarnings("rawtypes")
+public class WarningAnalyseController {
+    @Resource
+    private WarningAnalyseService warningService;
+
+    @ApiOperationSupport(order = 1)
+    @ApiOperation(value = "鑾峰彇瀹炴椂鎶ヨ", notes = "鑾峰彇瀹炴椂鎶ヨ鍒嗘瀽鏁版嵁")
+    @GetMapping("/runAlarm")
+    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 = "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(InitConfig.getDate(), -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 = InitConfig.getDate();
+                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 = "鏈湀棰勮鎶ヨ缁熻锛岃繑鍥炲弬鏁癮larmNumber瀵瑰簲鍊间负鏈湀鎶ヨ鏁版嵁閲忥紝鍙傛暟warningNumber瀵瑰簲鍊间负鏈湀棰勮鏁版嵁閲�")
+    @GetMapping("/monthCount")
+    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 ? InitConfig.getDate() : date));
+    }
+
+    @ApiOperationSupport(order = 4)
+    @ApiOperation(value = "涓�鍛ㄩ璀︽姤璀︽暟閲忓彉鍖栬秼鍔�", notes = "涓�鍛ㄩ璀︽姤璀︽暟閲忓彉鍖栬秼鍔匡紝杩斿洖鍙傛暟alarmDayCount涓轰竴鍛ㄦ瘡鏃ユ姤璀︾粺璁℃暟閲忓垪琛紝鍙傛暟warningDayCount涓轰竴鍛ㄦ瘡鏃ラ璀︾粺璁℃暟閲忓垪琛�")
+    @GetMapping("/everydayCount")
+    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 ? InitConfig.getDate() : date));
+    }
+
+    @ApiOperationSupport(order = 5)
+    @ApiOperation(value = "涓夊皬鏃剁洃娴嬬珯鐐规暟鎹彉鍖栬秼鍔�", notes = "杩斿洖鍊间负涓夊皬鏃剁洃娴嬬珯鐐圭洃娴嬫暟鎹紝杩斿洖鍊间负map闆嗗悎锛屽叾涓璳ey涓虹珯鐐瑰悕绉帮紝value涓簂ist闆嗗悎锛屼繚瀛樻瘡澶╃洃娴嬫暟鍊兼暟鎹�")
+    @GetMapping("/locationDataChange")
+    public Result locationDataChange(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
+        return Result.OK(warningService.select3Hours(null == date ? InitConfig.getDate() : date));
+    }
+
+    @ApiOperationSupport(order = 6)
+    @ApiOperation(value = "鏍规嵁鏃堕棿鑾峰彇鎶ヨ鍜岄璀︿俊鎭�", notes = "鏍规嵁鏃堕棿鑾峰彇鎶ヨ鍜岄璀︿俊鎭�")
+    @GetMapping("/getAlarmAndWarnByTime")
+    public Result getAlarmAndWarnByTime(
+            @RequestParam(value = "begin") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date begin,
+            @RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
+        if (null == begin || null == end) {
+            return Result.error(null);
+        }
+        if (begin.getTime() > end.getTime()) {
+            Date tmp = begin;
+            begin = end;
+            end = tmp;
+        }
+
+        //List<Report> list = warningService.getAlarmAndWarnByTime(begin, end);
+        String key = "getAlarmAndWarnByTime." + DateUtils.getYyyyMmDdHh(begin) + "." + DateUtils.getYyyyMmDdHh(end);
+        List<Report> list = CacheUtils.getListByKey(key);
+        if (null == list) {
+            list = warningService.getAlarmAndWarnByTime(begin, end);
+            CacheUtils.putListByKey(key, list);
+        }
+
+        return Result.OK(list);
+    }
+
+    @ApiOperationSupport(order = 7)
+    @ApiOperation(value = "鑾峰彇鏈湀鐩戞祴绔欑偣鏈�澶у�糡op10", notes = "鑾峰彇鏈湀鐩戞祴绔欑偣鏈�澶у�糡op10鏁伴噺鍒楄〃")
+    @GetMapping("/monthTop10")
+    public Result monthTop10() {
+        return Result.OK(warningService.selectMonthTop10());
+    }
+
+    @ApiOperationSupport(order = 8)
+    @ApiOperation(value = "鑾峰彇鏈懆鐩戞祴绔欑偣鏈�澶у�糡op10", notes = "鑾峰彇鏈懆鐩戞祴绔欑偣鏈�澶у�糡op10")
+    @GetMapping("/weekTop10")
+    public Result weekTop10() {
+        return Result.OK(warningService.selectWeekTop10());
+    }
+
+    @ApiOperationSupport(order = 9)
+    @ApiOperation(value = "鑾峰彇鏈棩鐩戞祴绔欑偣鏈�澶у�糡op10", notes = "鑾峰彇鏈棩鐩戞祴绔欑偣鏈�澶у�糡op10")
+    @GetMapping("/dayTop10")
+    public Result dayTop10() {
+        return Result.OK(warningService.selectDayTop10());
+    }
+}

--
Gitblit v1.9.3