¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yssh.controller; |
| | | |
| | | 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(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 = "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 = "date", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) { |
| | | return Result.OK(warningService.everydayCount(null == date ? new Date() : date)); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "ä¸å°æ¶çæµç«ç¹æ°æ®ååè¶å¿", notes = "è¿åå¼ä¸ºä¸å°æ¶çæµç«ç¹çæµæ°æ®ï¼è¿åå¼ä¸ºmapéåï¼å
¶ä¸key为ç«ç¹åç§°ï¼value为listéåï¼ä¿åæ¯å¤©çæµæ°å¼æ°æ®") |
| | | @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 ? new Date() : 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 = "è·åæ¬æçæµç«ç¹æå¤§å¼Top10", notes = "è·åæ¬æçæµç«ç¹æå¤§å¼Top10æ°éå表") |
| | | @GetMapping("/monthTop10") |
| | | public Result monthTop10() { |
| | | return Result.OK(warningService.selectMonthTop10()); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 8) |
| | | @ApiOperation(value = "è·åæ¬å¨çæµç«ç¹æå¤§å¼Top10", notes = "è·åæ¬å¨çæµç«ç¹æå¤§å¼Top10") |
| | | @GetMapping("/weekTop10") |
| | | public Result weekTop10() { |
| | | return Result.OK(warningService.selectWeekTop10()); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 9) |
| | | @ApiOperation(value = "è·åæ¬æ¥çæµç«ç¹æå¤§å¼Top10", notes = "è·åæ¬æ¥çæµç«ç¹æå¤§å¼Top10") |
| | | @GetMapping("/dayTop10") |
| | | public Result dayTop10() { |
| | | return Result.OK(warningService.selectDayTop10()); |
| | | } |
| | | } |