From 74e3485e6bae63e73f5d3be8b36c671e30aa389d Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 20 十一月 2024 10:31:21 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/service/WarningAnalyseService.java |  643 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 332 insertions(+), 311 deletions(-)

diff --git a/src/main/java/com/yssh/service/WarningAnalyseService.java b/src/main/java/com/yssh/service/WarningAnalyseService.java
index 7a9d6d2..0a0aece 100644
--- a/src/main/java/com/yssh/service/WarningAnalyseService.java
+++ b/src/main/java/com/yssh/service/WarningAnalyseService.java
@@ -1,13 +1,6 @@
 package com.yssh.service;
 
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.CountDownLatch;
 
 import com.yssh.entity.*;
@@ -15,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;
@@ -24,7 +18,6 @@
 import org.springframework.stereotype.Service;
 
 import com.google.common.collect.Lists;
-import com.yssh.entity.WarningVo;
 
 import javax.annotation.Resource;
 
@@ -33,28 +26,34 @@
     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;
 
-    private SimpleDateFormat ym = new SimpleDateFormat("yyyyMM%");
+    @Resource
+    VocValsService vocValsService;
+
+    @Resource
+    SuYuanService suYuanService;
+
+    private static HashMap<String, String> filterMap = new HashMap<>();
 
     @Async("threadPoolTaskExecutor")
     public void insertWarningDetails(List<WarningDetail> warning) throws Exception {
-        //鎻掑叆鏁版嵁
+        // 鎻掑叆鏁版嵁
         List<List<WarningDetail>> list = Lists.partition(warning, AsyncService.BATCH_INSERT_NUMBER);
         CountDownLatch countDownLatch = new CountDownLatch(list.size());
         for (List<WarningDetail> corpReserveList : list) {
@@ -63,66 +62,313 @@
         countDownLatch.await();
     }
 
-    public List<WarningVo> getRunTimeAlarmAnalyse() {
-        List<WarningVo> result = new ArrayList<>();
-        Date nowDate = DateUtils.getNowDate();
-        //String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate);
-        //DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
-        //if (StringUtils.isNull(dictRecord)) {
-        //	nowDate = DateUtils.getAPeriodOfTime(nowDate, -1, Calendar.HOUR_OF_DAY);
-        //}
-        //List<WarningDetail> list = alarmAnalyseOperation(nowDate);
-
-        List<WarningDetail> list = new ArrayList<>();
-        Calendar calendar = getCalendar(nowDate);
-        for (int i = 0; i < 6; i++) {
-            calendar.add(Calendar.HOUR, -1);
-            List<WarningDetail> rs = getAlarmWarnAnalyse(calendar.getTime(), false);
-            if (null != rs && rs.size() > 0) {
-                list.addAll(rs);
-            }
+    /**
+     * 鑾峰彇瀹炴椂鎶ヨ
+     */
+    public List<Qxsh> getRunTimeAlarmAnalyse(Integer start, Integer end) {
+        //List<Qxsh> list = qxshMapper.selectAlarmByBeginAndEnd(start, end);
+        String key = "qxshMapper.selectAlarmByBeginAndEnd." + start + "." + end;
+        List<Qxsh> list = CacheUtils.getListByKey(key);
+        if (null == list) {
+            list = qxshMapper.selectAlarmByBeginAndEnd(start, end);
+            copeHasSuYuan(list);
+            CacheUtils.putListByKey(key, list);
         }
-        list.forEach(s -> {
-            String time = DateUtils.getYyyyMmDdHh(s.getCreateTime());
-            result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time));
-        });
+
+        return list;
+    }
+
+    /**
+     * 鑾峰彇瀹炴椂棰勮
+     */
+    public List<Qxsh> getRunTimeWarningAnalyse(Integer start, Integer end) {
+        //List<Qxsh> list = qxshMapper.selectWarnByBeginAndEnd(start, end);
+        String key = "qxshMapper.selectWarnByBeginAndEnd." + start + "." + end;
+        List<Qxsh> list = CacheUtils.getListByKey(key);
+        if (null == list) {
+            list = qxshMapper.selectWarnByBeginAndEnd(start, end);
+            copeHasSuYuan(list);
+            CacheUtils.putListByKey(key, list);
+        }
+
+        return list;
+    }
+
+    /**
+     * 鏈湀棰勮鎶ヨ缁熻
+     */
+    public Map<String, Integer> monthCount(Date date) {
+        Date startDate = DateUtils.getMonthStart(date);
+        Date endDate = DateUtils.getMonthEnd(date);
+        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;
     }
 
-    private Calendar getCalendar(Date nowDate) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(nowDate);
-        calendar.add(Calendar.HOUR, 1);
+    /**
+     * 姣忔棩棰勮銆佹姤璀︽暟閲忓彉鍖栬秼鍔�
+     */
+    public Map<String, List<Map<String, Object>>> everydayCount(Date endDate) {
+        Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate));
+        Date startDate = DateUtils.getAPeriodOfTime(endDate, -6, Calendar.DATE);
+        Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate));
 
-        return calendar;
-    }
-
-    public List<WarningVo> getRunTimeWarningAnalyse() {
-        List<WarningVo> result = new ArrayList<>();
-        Date nowDate = DateUtils.getNowDate();
-        //String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate);
-        //DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
-        //if (StringUtils.isNull(dictRecord)) {
-        //	nowDate = DateUtils.getAPeriodOfTime(nowDate, -1, Calendar.HOUR_OF_DAY);
-        //}
-        //List<WarningDetail> list = warningAnalyseOperation(nowDate);
-
-        List<WarningDetail> list = new ArrayList<>();
-        Calendar calendar = getCalendar(nowDate);
-        for (int i = 0; i < 6; i++) {
-            calendar.add(Calendar.HOUR, -1);
-            List<WarningDetail> rs = getAlarmWarnAnalyse(calendar.getTime(), true);
-            if (null != rs && rs.size() > 0) {
-                list.addAll(rs);
-            }
+        Map<String, List<Map<String, Object>>> result = new HashMap<>();
+        //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);
         }
-        list.forEach(s -> {
-            String time = DateUtils.getYyyyMmDdHh(s.getCreateTime());
-            result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue(), time));
-        });
+        result.put("warningDayCount", warnList);
+
+        //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;
     }
 
+    /**
+     * 涓夊皬鏃剁洃娴嬬珯鐐规暟鎹彉鍖栬秼鍔�
+     */
+    public Object select3Hours(Date endDate) {
+        Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate));
+        Date startDate = DateUtils.getAPeriodOfTime(endDate, -2, Calendar.HOUR_OF_DAY);
+        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;
+        //}
+
+        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<>();
+        for (Qxsh qxsh : list) {
+            String name = qxsh.getName();
+            List<Double> values = map.computeIfAbsent(name, k -> new ArrayList<>());
+            values.add(qxsh.getValue());
+        }*/
+
+        return list;
+    }
+
+    /**
+     * 鑾峰彇鏈湀鐩戞祴绔欑偣鏈�澶у�糡OP10
+     */
+    public List<Qxsh> selectMonthTop10() {
+        String time = DateUtils.getYyyyMm(new Date());
+        //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;
+    }
+
+    /**
+     * 鑾峰彇鏈懆鐩戞祴绔欑偣鏈�澶у�糡OP10
+     */
+    public List<Qxsh> selectWeekTop10() {
+        Date now = new Date();
+        int weekOfYear = DateUtils.getWeekOfYear(now);
+        int year = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYY, now));
+        Date lastSun = DateUtils.getWeekOfYearForSun(year, weekOfYear);
+        Date mon = DateUtils.getAPeriodOfTime(lastSun, 1, Calendar.DATE);
+        Date sun = DateUtils.getAPeriodOfTime(lastSun, 7, Calendar.DATE);
+        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);
+        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;
+    }
+
+    /**
+     * 鑾峰彇鏈棩鐩戞祴绔欑偣鏈�澶у�糡OP10
+     */
+    public List<Qxsh> selectDayTop10() {
+        String time = DateUtils.getYyyyMmDd(new Date());
+        //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;
+    }
+
+    /**
+     * 鏍规嵁鏃堕棿鑾峰彇鎶ヨ鍜岄璀︿俊鎭�
+     */
+    public List<Report> getAlarmAndWarnByTime(Date beginDate, Date endDate) {
+        String strStart = DateUtils.getYyyyMmDdHh(beginDate);
+        String strEnd = DateUtils.getYyyyMmDdHh(endDate);
+        Integer start = Integer.parseInt(strStart);
+        Integer end = Integer.parseInt(strEnd);
+
+        List<Qxsh> rsList = qxshMapper.selectForReport(start, end);
+        if (null == rsList || rsList.isEmpty()) return null;
+
+        Hashtable<String, Boolean> dict = getExistTabDict(rsList);
+        List<Report> list = new ArrayList<>();
+        for (Qxsh qxsh : rsList) {
+            String tab = "su_yuan_" + qxsh.getTime();
+            if (!dict.get(tab)) continue;
+
+            MonitorPointPosition point = commonService.select3dCheckPointByName(qxsh.getName());
+            String suYuanId = point.getId().substring(0, point.getId().lastIndexOf("_") + 1) + "0";
+            Double lastVal = qxshMapper.selectLastYearVal(Integer.parseInt(qxsh.getTime()) - 1000000, qxsh.getName());
+
+            WarningDetail wd = new WarningDetail(0L, tab, suYuanId, qxsh.getName(), null, 0, qxsh.getValue());
+            DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(tab, suYuanId);
+            if (null == suYuan) {
+                String[] strs = suYuanId.split("_");
+                suYuan = new DistanceSuYuan(null, null, 0.0, suYuanId, Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), 0, 0, null, 0.0, 0.0, 0.0, 0.0);
+            }
+            //List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50);
+            //DistanceSuYuan suMax = suYuanMapper.getSuYuan500Max(tab, ids3d);
+
+            //String filter = CalculateUtils.getFilterByExtend(point, 50);
+            String filter = getFilterByPoint(point, 50);
+            DistanceSuYuan suMax = suYuanMapper.getSuYuan500MaxByFilter(tab, filter);
+            if (null == suMax) {
+                String[] strs = suYuanId.split("_");
+                suMax = new DistanceSuYuan(null, null, 0.0, suYuanId, Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), 0, 0, null, 0.0, 0.0, 0.0, 0.0);
+            }
+            suMax.setAddr(getAddr(suMax.getId()));
+
+            Report report = Report.calcReport(wd, suYuan, suMax);
+            report.setLastVal(lastVal);
+
+            SuYuan700 su = suYuanMapper.selectSuYuan46ById(suYuanId, qxsh.getTime().substring(0, 4) + "-" + qxsh.getTime().substring(4, 6) + "-" + qxsh.getTime().substring(6, 8) + " " + qxsh.getTime().substring(8, 10) + ":00:00");
+            report.setSu(su);
+
+            list.add(report);
+        }
+
+        return list;
+    }
+
+    public static String getFilterByPoint(MonitorPointPosition point, int range) {
+        String key = String.format("%d_%d_%d", point.getX(), point.getY(), range);
+        if (filterMap.containsKey(key)) {
+            return filterMap.get(key);
+        }
+
+        List<String> ids = CalculateUtils.aloneCrosswiseExtend(point, range);
+        for (int i = 0, c = ids.size(); i < c; i++) {
+            ids.set(i, "'" + ids.get(i) + "'");
+        }
+
+        String filter = "id in (" + StringUtils.join(ids, ",") + ")";
+        if (!filterMap.containsKey(key)) {
+            filterMap.put(key, filter);
+        }
+
+        return filter;
+    }
+
+    private Hashtable<String, Boolean> getExistTabDict(List<Qxsh> rsList) {
+        Hashtable<String, Boolean> dict = new Hashtable<>();
+        for (Qxsh qxsh : rsList) {
+            String tab = "su_yuan_" + qxsh.getTime();
+            if (dict.containsKey(tab)) {
+                continue;
+            }
+
+            Boolean b = suYuanMapper.isTableExists(tab) > 0;
+            dict.put(tab, b);
+        }
+
+        return dict;
+    }
+
+    private String getAddr(String id) {
+        String[] strs = id.split("_");
+        int x = Integer.parseInt(strs[0]) / 10;
+        int y = Integer.parseInt(strs[1]) / 10;
+
+        List<VocCoords> list = vocValsService.selectCoords(x, y);
+        for (VocCoords vc : list) {
+            if (null != vc.getAddr() && vc.getAddr().length() > 0) {
+                return vc.getAddr();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 瀛樺偍鍛婅/棰勮淇℃伅
+     */
+    public void warningOperationStorage(Date date) {
+        List<WarningDetail> allData = new ArrayList<>();
+        List<WarningDetail> alarms = this.getAlarmWarnAnalyse(date, false);
+        if (StringUtils.isNotEmpty(alarms)) {
+            allData.addAll(alarms);
+        }
+
+        List<WarningDetail> warnings = this.getAlarmWarnAnalyse(date, true);
+        if (StringUtils.isNotEmpty(warnings)) {
+            allData.addAll(warnings);
+        }
+
+        if (StringUtils.isNotEmpty(allData)) {
+            try {
+                insertWarningDetails(allData);
+            } catch (Exception e) {
+                logger.error("鎵归噺鎻掑叆鍛婅鏁版嵁鍑虹幇寮傚父锛侊紒锛�", e);
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鍛婅/棰勮鍒嗘瀽
+     */
     private List<WarningDetail> getAlarmWarnAnalyse(Date date, boolean isWarn) {
         List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d());
 
@@ -148,259 +394,34 @@
         return result;
     }
 
-    public void warningOperationStorage(Date date) {
-        List<WarningDetail> allData = new ArrayList<>();
-        List<WarningDetail> alarms = this.getAlarmWarnAnalyse(date, false);
-        if (StringUtils.isNotEmpty(alarms)) {
-            allData.addAll(alarms);
-        }
-
-        List<WarningDetail> warnings = this.getAlarmWarnAnalyse(date, true);
-        if (StringUtils.isNotEmpty(warnings)) {
-            allData.addAll(warnings);
-        }
-
-        if (StringUtils.isNotEmpty(allData)) {
-            try {
-                insertWarningDetails(allData);
-            } catch (Exception e) {
-                logger.error("鎵归噺鎻掑叆鍛婅鏁版嵁鍑虹幇寮傚父锛侊紒锛�", e);
-                e.printStackTrace();
-            }
-        }
-    }
-
-    public Map<String, Integer> countThisMonthAlarmAndWarning() {
-        Map<String, Integer> result = new HashMap<>();
-        Map<String, Object> param = new HashMap<>();
-        param.put("startTime", DateUtils.getYyyyMmDdHhMmSs(DateUtils.getMonthStart()));
-        param.put("endTime", DateUtils.getYyyyMmDdHhMmSs(DateUtils.getMonthEnd()));
-
-        /*param.put("type", 0);
-        List<WarningVo> alarms = warningDetailMapper.selectWarningDetailByMap(param);
-        if (StringUtils.isNull(alarms)) {
-            alarms = new ArrayList<>();
-        }
-        result.put("alarmNumber", alarms.size());*/
-        Integer alarmNum = warningDetailMapper.countAlarmByMap(param);
-        result.put("alarmNumber", null == alarmNum ? 0 : alarmNum);
-
-        param.put("type", 1);
-        /*List<WarningVo> warnings = warningDetailMapper.selectWarningDetailByMap(param);
-        if (StringUtils.isNull(warnings)) {
-            warnings = new ArrayList<>();
-        }
-        result.put("warningNumber", warnings.size());*/
-        Integer warnNum = warningDetailMapper.countWarnByMap(param);
-        result.put("warningNumber", null == warnNum ? 0 : warnNum);
-
-        return result;
-    }
-
-    public Map<String, List<Map<String, Object>>> countEverydayAlarmAndWarning() {
-        Map<String, List<Map<String, Object>>> result = new HashMap<>();
-
-        Map<String, Object> param = new HashMap<String, Object>();
-        Date now = new Date();
-        Date last = DateUtils.getAPeriodOfTime(now, -7, Calendar.DATE); // 涓婂懆鐨勪粖澶�
-        param.put("startTime", DateUtils.getYyyyMmDdHhMmSs(last));
-        param.put("endTime", DateUtils.getYyyyMmDdHhMmSs(now));
-
-        param.put("type", 0);
-        List<Map<String, Object>> alarmDayCount = warningDetailMapper.selectWarningDayCountByMap(param);
-        result.put("alarmDayCount", alarmDayCount);
-
-        param.put("type", 1);
-        List<Map<String, Object>> warningDayCount = warningDetailMapper.selectWarningDayCountByMap(param);
-        result.put("warningDayCount", warningDayCount);
-
-        return result;
-    }
-
-    public Map<String, List<Double>> selectEachLocationDataChange() {
-		/*Map<String, List<Double>> result = new LinkedHashMap<>();
-		List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d();
-		Date nowDate = DateUtils.getNowDate();
-		Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate));
-		Long startTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getAPeriodOfTime(nowDate, -3, Calendar.HOUR_OF_DAY)));
-		List<DictRecord> recordList = dictRecordMapper.selectByTimeDictRecordList(startTime, endTime);
-		checkPoints.forEach(c -> {
-			List<String> tableNames = new ArrayList<>();
-			recordList.forEach(r -> {
-				tableNames.add(r.getTableName());
-			});
-			List<Double> values = new ArrayList<>();
-			if (StringUtils.isNotNull(tableNames)) {
-				List<SuYuanMonitorData> data = suYuanMapper.getMonitorData(tableNames, c.getId());
-				data.forEach(v -> {
-					values.add(v.getValue());
-				});
-				result.put(c.getName(), values);
-			}
-		});
-		return result;*/
-
-        Map<String, List<Double>> result = new LinkedHashMap<>();
-        List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d();
-        Date nowDate = DateUtils.getNowDate();
-        Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, nowDate));
-        Long startTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getAPeriodOfTime(nowDate, -3, Calendar.HOUR_OF_DAY)));
-        List<DictRecord> recordList = dictRecordMapper.selectByTimeDictRecordList(startTime, endTime);
-
-        List<String> tableNames = new ArrayList<>();
-        for (DictRecord dr : recordList) {
-            if (suYuanMapper.isTableExists(dr.getTableName()) > 0) {
-                tableNames.add(dr.getTableName());
-            }
-        }
-        if (tableNames.isEmpty()) {
-            return result;
-        }
-
-        for (MonitorPointPosition c : checkPoints) {
-            List<Double> values = new ArrayList<>();
-            List<SuYuanMonitorData> data = suYuanMapper.getMonitorData(tableNames, c.getId());
-            if (null != data && data.size() > 0) {
-                for (SuYuanMonitorData v : data) {
-                    values.add(v.getValue());
-                }
-            }
-            result.put(c.getName(), values);
-        }
-        return result;
-    }
-
-    public List<Map<String, Object>> selectThisMonthLocationValueDataTop10() {
-		/*List<Map<String, Object>> result = new ArrayList<>();
-		List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d();
-		Long startTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getMonthStart()));
-		Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getMonthEnd()));
-		List<DictRecord> recordList = dictRecordMapper.selectByTimeDictRecordList(startTime, endTime);
-		checkPoints.forEach(c -> {
-			List<String> tableNames = new ArrayList<>();
-			recordList.forEach(r -> {
-				tableNames.add(r.getTableName());
-			});
-			Map<String, Object> map = suYuanMapper.getMonthValueDataMax(tableNames, c.getId());
-			if (StringUtils.isNotNull(map) && StringUtils.isNotEmpty(map)) {
-				String suYuanId = map.get("id").toString();
-				map.put("name", commonService.select3dCheckPointById(suYuanId).getName());
-				map.remove("id");
-			}
-			result.add(map);
-		});
-		return CalculateUtils.sort(result, "value", true).subList(0, 10);*/
-
-        List<Map<String, Object>> result = new ArrayList<>();
-        List<MonitorPointPosition> checkPoints = commonService.getCheckPoints3d();
-        Long startTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getMonthStart()));
-        Long endTime = Long.parseLong(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, DateUtils.getMonthEnd()));
-        //startTime = 2023040100L;
-        //endTime = 2023043023L;
-
-        List<DictRecord> recordList = dictRecordMapper.selectByTimeDictRecordList(startTime, endTime);
-
-        List<String> tableNames = new ArrayList<>();
-        for (DictRecord dr : recordList) {
-            if (suYuanMapper.isTableExists(dr.getTableName()) > 0) {
-                tableNames.add(dr.getTableName());
-            }
-        }
-        if (tableNames.isEmpty()) {
-            return result;
-        }
-
-        /*List<String> idList = new ArrayList<>();
-        for (MonitorPointPosition c : checkPoints) {
-            idList.add("'" + c.getId() + "'");
-        }
-        String ids = String.join(",", idList);*/
-
-        for (MonitorPointPosition c : checkPoints) {
-            Map<String, Object> map = suYuanMapper.getMonthValueDataMax(tableNames, c.getId());
-            if (null != map && map.size() > 0) {
-                //String suYuanId = map.get("id").toString();
-                //map.put("name", commonService.select3dCheckPointById(suYuanId).getName());
-                //map.remove("id");
-                map.put("name", c.getName());
-                result.add(map);
-            }
-        }
-
-        return CalculateUtils.sort(result, "value", true).subList(0, 10);
-    }
-
-    public List<Qxsh> selectMonthTop10() {
-        String time = DateUtils.getYyyyMm(new Date());
-
-        List<Qxsh> list = qxshMapper.selectMonthTop10(time + "%");
-
-        return list;
-    }
-
-    public Map<String, List<Double>> select3Hours() {
-        Map<String, List<Double>> map = new LinkedHashMap<>();
-
-        List<String> times = DateUtils.get3Hours();
-        List<Qxsh> list = qxshMapper.select3Hours(times);
+    /**
+     * 澶勭悊鏄惁鍚湁婧簮淇℃伅
+     */
+    private List<Qxsh> copeHasSuYuan(List<Qxsh> list) {
         if (null == list || list.isEmpty()) {
-            return map;
+            return null;
         }
 
+        Map<String, Integer> tabs = new HashMap<>();
         for (Qxsh qxsh : list) {
-            String name = qxsh.getName();
-            List<Double> values = map.computeIfAbsent(name, k -> new ArrayList<>());
-            values.add(qxsh.getValue());
-        }
+            String tab = "su_yuan_" + qxsh.getTime();
+            if (!tabs.containsKey(tab)) {
+                tabs.put(tab, suYuanMapper.isTableExists(tab));
+            }
 
-        return map;
-    }
-
-    public List<Report> getAlarmAndWarnByTime(Date begin, Date end) {
-        String startTime = DateUtils.getYyyyMmDdHhMmSs(begin);
-        String endTime = DateUtils.getYyyyMmDdHhMmSs(end);
-
-        List<WarningDetail> rs = new ArrayList<>();
-        List<WarningDetail> rsYj = warningDetailMapper.selectByTimeForYj(startTime, endTime);
-        if (null != rsYj && rsYj.size() > 0) rs.addAll(rsYj);
-
-        List<WarningDetail> rsBj = warningDetailMapper.selectByTimeForBj(startTime, endTime);
-        if (null != rsBj && rsBj.size() > 0) rs.addAll(rsBj);
-
-        List<Report> list = new ArrayList<>();
-        for (WarningDetail wd : rs) {
-            //String time = ymdh.format(wd.getCreateTime());
-            //list.add(new WarningVo(wd.getLocationName(), wd.getSuYuanId(), 0.0, 0.0, wd.getValue(), time));
-
-            /*DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(wd.getTableName(), wd.getSuYuanId());
-            Double lastVal = warningDetailMapper.getLastYearVal(wd.getId());
-
-            int rows = suYuanMapper.isTableExists(wd.getTableName());
-            DistanceSuYuan suMax = null;
-            if (rows > 0) {
-                MonitorPointPosition point = commonService.select3dCheckPointByName(wd.getLocationName());
-                List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50);
-                suMax = suYuanMapper.getSuYuan500Max(wd.getTableName(), ids3d);
-            } else {
-                suMax = suYuan;
-            }*/
-
-            int rows = suYuanMapper.isTableExists(wd.getTableName());
-            if (rows == 0) {
+            int rows = tabs.get(tab);
+            if (0 == rows) {
                 continue;
             }
 
-            DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(wd.getTableName(), wd.getSuYuanId());
-            Double lastVal = warningDetailMapper.getLastYearVal(wd.getId());
+            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";
 
-            MonitorPointPosition point = commonService.select3dCheckPointByName(wd.getLocationName());
-            List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50);
-            DistanceSuYuan suMax = suYuanMapper.getSuYuan500Max(wd.getTableName(), ids3d);
+            Integer isSuYuan = qxshMapper.hasSuYuan(suYuanId, createTime);
+            qxsh.setIsSuYuan(isSuYuan);
 
-            Report report = Report.calcReport(wd, suYuan, suMax);
-            report.setLastVal(lastVal);
-
-            list.add(report);
+            Integer isFast = qxshMapper.countFastSuYuan(suYuanId, createTime);
+            qxsh.setIsFast(isFast);
         }
 
         return list;

--
Gitblit v1.9.3