燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-07-27 093a6b0549f5f1ed921d7bc4cfb5d43619c148ae
src/main/java/com/yssh/service/WarningAnalyseService.java
@@ -1,6 +1,5 @@
package com.yssh.service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@@ -9,6 +8,7 @@
import com.yssh.mapper.QxshMapper;
import com.yssh.mapper.SuYuanMapper;
import com.yssh.mapper.WarningDetailMapper;
import com.yssh.utils.CacheUtils;
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.DateUtils;
import com.yssh.utils.StringUtils;
@@ -26,25 +26,28 @@
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private WarningDetailMapper warningDetailMapper;
    WarningDetailMapper warningDetailMapper;
    @Resource
    private CommonService commonService;
    CommonService commonService;
    @Resource
    private SuYuanMapper suYuanMapper;
    SuYuanMapper suYuanMapper;
    @Resource
    private DictRecordMapper dictRecordMapper;
    DictRecordMapper dictRecordMapper;
    @Resource
    private AsyncService asyncService;
    AsyncService asyncService;
    @Resource
    private QxshMapper qxshMapper;
    QxshMapper qxshMapper;
    @Resource
    private VocValsService vocValsService;
    VocValsService vocValsService;
    @Resource
    SuYuanService suYuanService;
    private static HashMap<String, String> filterMap = new HashMap<>();
@@ -63,14 +66,18 @@
     * 获取实时报警
     */
    public List<Qxsh> getRunTimeAlarmAnalyse(Integer start, Integer end) {
        return qxshMapper.selectAlarmByBeginAndEnd(start, end);
        List<Qxsh> list = qxshMapper.selectAlarmByBeginAndEnd(start, end);
        return copeHasSuYuan(list);
    }
    /**
     * 获取实时预警
     */
    public List<Qxsh> getRunTimeWarningAnalyse(Integer start, Integer end) {
        return qxshMapper.selectWarnByBeginAndEnd(start, end);
        List<Qxsh> list = qxshMapper.selectWarnByBeginAndEnd(start, end);
        return copeHasSuYuan(list);
    }
    /**
@@ -82,12 +89,20 @@
        Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate));
        Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate));
        String key = "WAS.monthCount." + start + "." + end;
        Object obj = CacheUtils.get(key);
        if (obj instanceof Map<?, ?>) {
            return (Map<String, Integer>) obj;
        }
        Map<String, Integer> result = new HashMap<>();
        Integer warnNum = qxshMapper.countMonthForWarn(start, end);
        result.put("warningNumber", null == warnNum ? 0 : warnNum);
        Integer alarmNum = qxshMapper.countMonthForAlarm(start, end);
        result.put("alarmNumber", null == alarmNum ? 0 : alarmNum);
        CacheUtils.put(key, result);
        return result;
    }
@@ -101,10 +116,22 @@
        Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate));
        Map<String, List<Map<String, Object>>> result = new HashMap<>();
        List<Map<String, Object>> warnList = qxshMapper.count7DayForWarn(start, end);
        //List<Map<String, Object>> warnList = qxshMapper.count7DayForWarn(start, end);
        String key = "qxshMapper.count7DayForWarn." + start + "." + end;
        List<Map<String, Object>> warnList = CacheUtils.getListByKey(key);
        if (null == warnList) {
            warnList = qxshMapper.count7DayForWarn(start, end);
            CacheUtils.putListByKey(key, warnList);
        }
        result.put("warningDayCount", warnList);
        List<Map<String, Object>> alarmList = qxshMapper.count7DayForAlarm(start, end);
        //List<Map<String, Object>> alarmList = qxshMapper.count7DayForAlarm(start, end);
        String key2 = "qxshMapper.count7DayForAlarm." + start + "." + end;
        List<Map<String, Object>> alarmList = CacheUtils.getListByKey(key2);
        if (null == alarmList) {
            alarmList = qxshMapper.count7DayForAlarm(start, end);
            CacheUtils.putListByKey(key2, alarmList);
        }
        result.put("alarmDayCount", alarmList);
        return result;
@@ -119,9 +146,16 @@
        Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate));
        //  List<String> times = DateUtils.get3Hours();
        List<Qxsh> list = qxshMapper.select3Hours(start, end);
        if (null == list || list.isEmpty()) {
            return null;
        //List<Qxsh> list = qxshMapper.select3Hours(start, end);
        //if (null == list || list.isEmpty()) {
        //    return null;
        //}
        String key = "qxshMapper.select3Hours." + start + "." + end;
        List<Qxsh> list = CacheUtils.getListByKey(key);
        if (null == list) {
            list = qxshMapper.select3Hours(start, end);
            CacheUtils.putListByKey(key, list);
        }
        /* Map<String, List<Double>> map = new LinkedHashMap<>();
@@ -139,7 +173,14 @@
     */
    public List<Qxsh> selectMonthTop10() {
        String time = DateUtils.getYyyyMm(new Date());
        List<Qxsh> list = qxshMapper.selectMonthTop10(time + "%");
        //List<Qxsh> list = qxshMapper.selectMonthTop10(time + "%");
        String key = "qxshMapper.selectMonthTop10." + time;
        List<Qxsh> list = CacheUtils.getListByKey(key);
        if (null == list) {
            list = qxshMapper.selectMonthTop10(time + "%");
            CacheUtils.putListByKey(key, list);
        }
        return list;
    }
@@ -157,7 +198,13 @@
        Integer intMon = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, mon) + "00"); // 2023080700
        Integer intSun = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, sun) + "23"); // 2023081323
        List<Qxsh> list = qxshMapper.selectWeekTop10(intMon, intSun);
        //List<Qxsh> list = qxshMapper.selectWeekTop10(intMon, intSun);
        String key = "qxshMapper.selectWeekTop10." + intMon + "." + intSun;
        List<Qxsh> list = CacheUtils.getListByKey(key);
        if (null == list) {
            list = qxshMapper.selectWeekTop10(intMon, intSun);
            CacheUtils.putListByKey(key, list);
        }
        return list;
    }
@@ -167,7 +214,14 @@
     */
    public List<Qxsh> selectDayTop10() {
        String time = DateUtils.getYyyyMmDd(new Date());
        List<Qxsh> list = qxshMapper.selectDayTop10(time + "%");
        //List<Qxsh> list = qxshMapper.selectDayTop10(time + "%");
        String key = "qxshMapper.selectDayTop10." + time;
        List<Qxsh> list = CacheUtils.getListByKey(key);
        if (null == list) {
            list = qxshMapper.selectDayTop10(time + "%");
            CacheUtils.putListByKey(key, list);
        }
        return list;
    }
@@ -317,4 +371,37 @@
        return result;
    }
    /**
     * 处理是否含有溯源信息
     */
    private List<Qxsh> copeHasSuYuan(List<Qxsh> list) {
        if (null == list || list.isEmpty()) {
            return null;
        }
        Map<String, Integer> tabs = new HashMap<>();
        for (Qxsh qxsh : list) {
            String tab = "su_yuan_" + qxsh.getTime();
            if (!tabs.containsKey(tab)) {
                tabs.put(tab, suYuanMapper.isTableExists(tab));
            }
            int rows = tabs.get(tab);
            if (0 == rows) {
                continue;
            }
            String suYuanId = suYuanService.selectSuYuanIdByName(qxsh.getName());
            String createTime = qxsh.getTime().substring(0, 4) + "-" + qxsh.getTime().substring(4, 6) + "-" + qxsh.getTime().substring(6, 8) + " " + qxsh.getTime().substring(8, 10) + ":00:00";
            Integer isSuYuan = qxshMapper.hasSuYuan(suYuanId, createTime);
            qxsh.setIsSuYuan(isSuYuan);
            Integer isFast = qxshMapper.countFastSuYuan(suYuanId, createTime);
            qxsh.setIsFast(isFast);
        }
        return list;
    }
}