| | |
| | | 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.beans.factory.annotation.Autowired; |
| | | 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.RestController; |
| | | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import com.yssh.service.IWarningAnalyseService; |
| | | import com.yssh.service.WarningAnalyseService; |
| | | import com.yssh.utils.Result; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import javax.annotation.Resource; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Api(tags = "告警分析") |
| | | @RequestMapping("/warning") |
| | | @RestController |
| | | @SuppressWarnings("rawtypes") |
| | | public class WarningAnalyseController { |
| | | @Resource |
| | | private WarningAnalyseService warningService; |
| | | |
| | | @Autowired |
| | | private IWarningAnalyseService warningService; |
| | | |
| | | private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | | * 2.筛选大于yssh_bjyj中的jcbj字段的值 返回id+经纬度+value |
| | | */ |
| | | @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)); |
| | | } |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | | * 2.筛选大于yssh_bjyj中的jcyj字段的值 返回id+经纬度+value |
| | | */ |
| | | @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(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对应值为本月预警数据量") |
| | | @ApiOperation(value = "本月预警报警统计", notes = "本月预警报警统计,返回参数alarmNumber对应值为本月报警数据量,参数warningNumber对应值为本月预警数据量") |
| | | @GetMapping("/monthCount") |
| | | public Result thisMonthCount() { |
| | | return Result.OK(warningService.countThisMonthAlarmAndWarning()); |
| | | 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为一周每日预警统计数量列表") |
| | | @ApiOperation(value = "一周预警报警数量变化趋势", notes = "一周预警报警数量变化趋势,返回参数alarmDayCount为一周每日报警统计数量列表,参数warningDayCount为一周每日预警统计数量列表") |
| | | @GetMapping("/everydayCount") |
| | | public Result everydayCount() { |
| | | return Result.OK(warningService.countEverydayAlarmAndWarning()); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiOperation(value = "三小时监测站点数据变化趋势", notes = "返回值为三小时监测站点监测数据,返回值为map集合,其中key为站点名称,value为list集合,保存每天监测数值数据") |
| | | @GetMapping("/locationDataChange") |
| | | public Result locationDataChange() { |
| | | //return Result.OK(warningService.selectEachLocationDataChange()); |
| | | |
| | | String key = dateFormat.format(new Date()) + "_local"; |
| | | Object obj = CacheUtils.get(key); |
| | | Map<String, List<Double>> map; |
| | | |
| | | if (null != obj) { |
| | | map = (Map<String, List<Double>>) obj; |
| | | } else { |
| | | map = warningService.selectEachLocationDataChange(); |
| | | if (null != map && map.size() > 0) { |
| | | CacheUtils.put(key, map); |
| | | } |
| | | } |
| | | |
| | | return Result.ok(map); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 4) |
| | | @ApiOperation(value = "获取本月监测大数据站点最大值TOP10", notes = "获取本月监测大数据站点最大值TOP10数量列表") |
| | | @GetMapping("/monthTop10") |
| | | public Result monthTop10() { |
| | | //return Result.OK(warningService.selectThisMonthLocationValueDataTop10()); |
| | | |
| | | String key = dateFormat.format(new Date()) + "_top10"; |
| | | Object obj = CacheUtils.get(key); |
| | | List<Map<String, Object>> list; |
| | | |
| | | if (null != obj) { |
| | | list = (List<Map<String, Object>>) obj; |
| | | } else { |
| | | list = warningService.selectThisMonthLocationValueDataTop10(); |
| | | if (null != list && list.size() > 0) { |
| | | CacheUtils.put(key, list); |
| | | } |
| | | } |
| | | |
| | | return Result.ok(list); |
| | | 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", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date begin, |
| | | @RequestParam(value = "end", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) { |
| | | @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 = end; |
| | | Date tmp = begin; |
| | | begin = end; |
| | | 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 = "获取本月监测站点最大值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()); |
| | | } |
| | | } |