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 | 124 +++++++++++++++++++++++++++++++++-------- 1 files changed, 99 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/yssh/controller/WarningAnalyseController.java b/src/main/java/com/yssh/controller/WarningAnalyseController.java index 2e76dad..7032820 100644 --- a/src/main/java/com/yssh/controller/WarningAnalyseController.java +++ b/src/main/java/com/yssh/controller/WarningAnalyseController.java @@ -1,5 +1,9 @@ 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; @@ -14,7 +18,9 @@ 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") @@ -27,48 +33,87 @@ @ApiOperationSupport(order = 1) @ApiOperation(value = "鑾峰彇瀹炴椂鎶ヨ", notes = "鑾峰彇瀹炴椂鎶ヨ鍒嗘瀽鏁版嵁") @GetMapping("/runAlarm") - public Result alarmAnalyse() { - return Result.OK(warningService.getRunTimeAlarmAnalyse()); + 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() { - return Result.OK(warningService.getRunTimeWarningAnalyse()); + 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 = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) { - return Result.OK(warningService.monthCount(null == date ? new 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 ? InitConfig.getDate() : 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) { - Date endDate = null == date ? new Date() : date; - return Result.OK(warningService.everydayCount(endDate)); - } - - @ApiOperationSupport(order = 4) - @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) { - Date endDate = null == date ? new Date() : date; - return Result.OK(warningService.select3Hours(endDate)); - } - - @ApiOperationSupport(order = 4) - @ApiOperation(value = "鑾峰彇鏈湀鐩戞祴澶ф暟鎹珯鐐规渶澶у�糡OP10", notes = "鑾峰彇鏈湀鐩戞祴澶ф暟鎹珯鐐规渶澶у�糡OP10鏁伴噺鍒楄〃") - @GetMapping("/monthTop10") - public Result monthTop10() { - return Result.ok(warningService.selectMonthTop10()); + 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( @@ -83,6 +128,35 @@ end = tmp; } - return Result.OK(warningService.getAlarmAndWarnByTime(begin, end)); + //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