| | |
| | | package com.yssh.controller; |
| | | |
| | | import com.yssh.entity.Qxsh; |
| | | import com.yssh.utils.CacheUtils; |
| | | 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.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | @Api(tags="告警分析") |
| | | @Api(tags = "告警分析") |
| | | @RequestMapping("/warning") |
| | | @RestController |
| | | @SuppressWarnings("rawtypes") |
| | |
| | | @Autowired |
| | | private IWarningAnalyseService warningService; |
| | | |
| | | private static ConcurrentHashMap<String, Object> cache = new ConcurrentHashMap<>(5); |
| | | |
| | | private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); |
| | | |
| | | public static final long CACHE_HOLD_TIME_24H = 24 * 60 * 60 * 1000L; |
| | | |
| | | //报警分析 |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | |
| | | public Result alarmAnalyse() { |
| | | return Result.OK(warningService.getRunTimeAlarmAnalyse()); |
| | | } |
| | | |
| | | //预警分析 |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | |
| | | //return Result.OK(warningService.selectEachLocationDataChange()); |
| | | |
| | | String key = dateFormat.format(new Date()) + "_local"; |
| | | Object obj = CacheUtils.get(key); |
| | | Map<String, List<Double>> map; |
| | | if (cache.containsKey(key)) { |
| | | map = (Map<String, List<Double>>) cache.get(key); |
| | | } else { |
| | | map = warningService.selectEachLocationDataChange(); |
| | | if (null != map && map.size() > 0) { |
| | | cache.put(key, map); |
| | | } |
| | | } |
| | | |
| | | //if (null != obj) { |
| | | // map = (Map<String, List<Double>>) obj; |
| | | //} else { |
| | | //map = warningService.selectEachLocationDataChange(); |
| | | map = warningService.select3Hours(); |
| | | // if (null != map && map.size() > 0) { |
| | | // CacheUtils.put(key, map); |
| | | // } |
| | | //} |
| | | |
| | | return Result.ok(map); |
| | | } |
| | |
| | | public Result monthTop10() { |
| | | //return Result.OK(warningService.selectThisMonthLocationValueDataTop10()); |
| | | |
| | | String key = dateFormat.format(new Date()) + "_top10"; |
| | | List<Map<String, Object>> list; |
| | | if (cache.containsKey(key)) { |
| | | list = (List<Map<String, Object>>) cache.get(key); |
| | | } else { |
| | | list = warningService.selectThisMonthLocationValueDataTop10(); |
| | | if (null != list && list.size() > 0) { |
| | | cache.put(key, list); |
| | | } |
| | | //String key = dateFormat.format(new Date()) + "_top10"; |
| | | //Object obj = CacheUtils.get(key); |
| | | List<Qxsh> list; |
| | | |
| | | //if (null != obj) { |
| | | // list = (List<Qxsh>) obj; |
| | | //} else { |
| | | //list = warningService.selectThisMonthLocationValueDataTop10(); |
| | | list = warningService.selectMonthTop10(); |
| | | // if (null != list && list.size() > 0) { |
| | | // CacheUtils.put(key, list); |
| | | // } |
| | | //} |
| | | |
| | | return Result.ok(list); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 5) |
| | | @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) { |
| | | if (null == begin || null == end) { |
| | | return Result.error(null); |
| | | } |
| | | |
| | | return Result.OK(list); |
| | | if (begin.getTime() > end.getTime()) { |
| | | Date tmp = end; |
| | | begin = end; |
| | | end = tmp; |
| | | } |
| | | |
| | | return Result.OK(warningService.getAlarmAndWarnByTime(begin, end)); |
| | | } |
| | | } |