| | |
| | | |
| | | @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) { |
| | |
| | | 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); |
| | | /** |
| | | * 获取实时报警 |
| | | */ |
| | | public List<Qxsh> getRunTimeAlarmAnalyse(Date endDate) { |
| | | Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate)); |
| | | Date startDate = DateUtils.getAPeriodOfTime(endDate, -5, Calendar.HOUR_OF_DAY); |
| | | Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate)); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | 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 result; |
| | | return qxshMapper.selectAlarmByBeginAndEnd(start, end); |
| | | } |
| | | |
| | | private Calendar getCalendar(Date nowDate) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(nowDate); |
| | | calendar.add(Calendar.HOUR, 1); |
| | | /** |
| | | * 获取实时预警 |
| | | */ |
| | | public List<Qxsh> getRunTimeWarningAnalyse(Date endDate) { |
| | | Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate)); |
| | | Date startDate = DateUtils.getAPeriodOfTime(endDate, -5, Calendar.HOUR_OF_DAY); |
| | | Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate)); |
| | | |
| | | return calendar; |
| | | return qxshMapper.selectWarnByBeginAndEnd(start, end); |
| | | } |
| | | |
| | | 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); |
| | | // 已废弃 * |
| | | 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> 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); |
| | | 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(); |
| | | } |
| | | } |
| | | 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 result; |
| | | } |
| | | |
| | | private List<WarningDetail> getAlarmWarnAnalyse(Date date, boolean isWarn) { |
| | |
| | | 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); |
| | | } |
| | | /** |
| | | * 本月预警报警统计 |
| | | */ |
| | | 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)); |
| | | |
| | | 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); |
| | | 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); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public Map<String, List<Map<String, Object>>> countEverydayAlarmAndWarning() { |
| | | /** |
| | | * 每日预警、报警数量变化趋势 |
| | | */ |
| | | 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)); |
| | | |
| | | Map<String, List<Map<String, Object>>> result = new HashMap<>(); |
| | | List<Map<String, Object>> warnList = qxshMapper.count7DayForWarn(start, end); |
| | | result.put("warningDayCount", warnList); |
| | | |
| | | 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); |
| | | List<Map<String, Object>> alarmList = qxshMapper.count7DayForAlarm(start, end); |
| | | result.put("alarmDayCount", alarmList); |
| | | |
| | | 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;*/ |
| | | /** |
| | | * 三小时监测站点数据变化趋势 |
| | | */ |
| | | 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)); |
| | | |
| | | 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; |
| | | // List<String> times = DateUtils.get3Hours(); |
| | | List<Qxsh> list = qxshMapper.select3Hours(start, end); |
| | | if (null == list || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | 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; |
| | | /* 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; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 获取本月监测大数据站点最大值TOP10 |
| | | */ |
| | | 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); |
| | | if (null == list || list.isEmpty()) { |
| | | return map; |
| | | } |
| | | |
| | | for (Qxsh qxsh : list) { |
| | | String name = qxsh.getName(); |
| | | List<Double> values = map.computeIfAbsent(name, k -> new ArrayList<>()); |
| | | values.add(qxsh.getValue()); |
| | | } |
| | | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 根据时间获取报警和预警信息 |
| | | */ |
| | | 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.selectByBeginAndEnd(start, end); |
| | | List<Qxsh> rsList = qxshMapper.selectForReport(start, end); |
| | | if (null == rsList || rsList.isEmpty()) return null; |
| | | |
| | | Hashtable<String, Boolean> dict = getExistTabDict(rsList); |
| | |
| | | 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 dict; |
| | | } |
| | | |
| | | public List<Report> getAlarmAndWarnByTime2(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); |
| | | |
| | | Hashtable<String, Boolean> dict = new Hashtable<>(); |
| | | List<Report> list = new ArrayList<>(); |
| | | for (WarningDetail wd : rs) { |
| | | /*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; |
| | | }*/ |
| | | if (dict.containsKey(wd.getTableName())) { |
| | | if (!dict.get(wd.getTableName())) continue; |
| | | } else { |
| | | Boolean b = suYuanMapper.isTableExists(wd.getTableName()) > 0; |
| | | dict.put(wd.getTableName(), b); |
| | | if (!b) continue; |
| | | } |
| | | |
| | | DistanceSuYuan suYuan = suYuanMapper.getSuYuanById(wd.getTableName(), wd.getSuYuanId()); |
| | | Double lastVal = warningDetailMapper.getLastYearVal(wd.getId()); |
| | | |
| | | MonitorPointPosition point = commonService.select3dCheckPointByName(wd.getLocationName()); |
| | | List<String> ids3d = CalculateUtils.aloneCrosswiseExtend(point, 50); |
| | | DistanceSuYuan suMax = suYuanMapper.getSuYuan500Max(wd.getTableName(), ids3d); |
| | | suMax.setAddr(getAddr(suMax.getId())); |
| | | |
| | | Report report = Report.calcReport(wd, suYuan, suMax); |
| | | report.setLastVal(lastVal); |
| | | |
| | | list.add(report); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | private String getAddr(String id) { |