燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-06-09 498718ad129e8a9010e6f2af2fde2f9d4508fd32
src/main/java/com/yssh/controller/WarningAnalyseController.java
@@ -1,11 +1,15 @@
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;
@@ -18,7 +22,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Api(tags="告警分析")
@Api(tags = "告警分析")
@RequestMapping("/warning")
@RestController
@SuppressWarnings("rawtypes")
@@ -27,11 +31,7 @@
    @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查询即可)
@@ -76,15 +76,18 @@
        //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);
    }
@@ -95,17 +98,39 @@
    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));
    }
}