燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-04-26 659abe57f755e128e68d0a56bfc473e0baa4260b
src/main/java/com/yssh/service/impl/WarningAnalyseServiceImpl.java
@@ -57,7 +57,9 @@
   @Autowired
   private IAsyncService asyncService;
   private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
   private SimpleDateFormat ymdh = new SimpleDateFormat("yyyyMMddHH");
   private SimpleDateFormat ymdhms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   @Override
   @Async("threadPoolTaskExecutor")
@@ -75,12 +77,11 @@
   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);
      }
      //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<>();
@@ -92,7 +93,6 @@
            list.addAll(rs);
         }
      }
      list.forEach(s -> {
         result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue()));
      });
@@ -111,13 +111,13 @@
   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);
      }
      //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 < 3; i++) {
@@ -127,7 +127,6 @@
            list.addAll(rs);
         }
      }
      list.forEach(s -> {
         result.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue()));
      });
@@ -135,36 +134,55 @@
   }
   public List<WarningDetail> alarmAnalyseOperation(Date date) {
      List<WarningDetail> result = new ArrayList<WarningDetail>();
      List<WarningDetail> result = new ArrayList<>();
      String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
      List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d());
      if (ids.size() == 0) {
         return result;
      }
      DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
      if (StringUtils.isNull(dictRecord)) {
      if (null == dictRecord) {
         return result;
      }
      String tableName = dictRecord.getTableName();
      if (suYuanMapper.isTableExists(tableName) == 0) {
         return result;
      }
      List<SuYuan2d> list = suYuanMapper.getAlarmsAnalyse(tableName, ids);
      list.forEach(s -> {
         String locationName = commonService.select3dCheckPointById(s.getId()).getName();
         result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 0, s.getValue()));
      });
      if (null != list && list.size() > 0) {
         for (SuYuan2d s : list) {
            String locationName = commonService.select3dCheckPointById(s.getId()).getName();
            result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 0, s.getValue()));
         }
      }
      return result;
   }
   public List<WarningDetail> warningAnalyseOperation(Date date) {
      List<WarningDetail> result = new ArrayList<WarningDetail>();
      List<WarningDetail> result = new ArrayList<>();
      String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
      List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d());
      if (ids.size() == 0) {
         return result;
      }
      DictRecord dictRecord = dictRecordMapper.selectByCreateTime(Long.parseLong(time));
      if (StringUtils.isNull(dictRecord)) {
      if (null == dictRecord) {
         return result;
      }
      String tableName = dictRecord.getTableName();
      if (suYuanMapper.isTableExists(tableName) == 0) {
         return result;
      }
      List<SuYuan2d> list = suYuanMapper.getWarningAnalyse(tableName, ids);
      list.forEach(s -> {
         String locationName = commonService.select3dCheckPointById(s.getId()).getName();
         result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 1, s.getValue()));
      });
      if (null != list && list.size() > 0) {
         for (SuYuan2d s : list) {
            String locationName = commonService.select3dCheckPointById(s.getId()).getName();
            result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 1, s.getValue()));
         }
      }
      return result;
   }
@@ -192,7 +210,7 @@
   @Override
   public Map<String, Integer> countThisMonthAlarmAndWarning() {
      Map<String, Integer> result = new HashMap<>();
      Map<String, Object> param = new HashMap<String, Object>();
      Map<String, Object> param = new HashMap<>();
      param.put("type", 0);
      param.put("startTime", DateUtils.getMonthStart());
      param.put("endTime", DateUtils.getMonthEnd());
@@ -229,7 +247,7 @@
   @Override
   public Map<String, List<Double>> selectEachLocationDataChange() {
      Map<String, List<Double>> result = new LinkedHashMap<>();
      /*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));
@@ -249,12 +267,41 @@
            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;
   }
   @Override
   public List<Map<String, Object>> selectThisMonthLocationValueDataTop10() {
      List<Map<String, Object>> result = new ArrayList<>();
      /*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()));
@@ -272,7 +319,101 @@
         }
         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()));
      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) {
         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");
         }
         result.add(map);
      }
      return CalculateUtils.sort(result, "value", true).subList(0, 10);
   }
   @Override
   public List<WarningVo> getAlarmAndWarnByTime(Date begin, Date end) {
      List<WarningVo> list = new ArrayList<>();
      List<String> ids = CalculateUtils.assembleId(commonService.getCheckPoints3d());
      if (ids.size() == 0) {
         return list;
      }
      List<DictRecord> dictList = dictRecordMapper.selectByTime(ymdhms.format(begin), ymdhms.format(end));
      if (null == dictList || dictList.isEmpty()) {
         return list;
      }
      List<String> tables = new ArrayList<>();
      for (DictRecord dr : dictList) {
         tables.add(dr.getTableName());
      }
      for (String tab : tables) {
         List<WarningDetail> alarmList = getAlarmByTime(tab, ids);
         for (WarningDetail s : alarmList) {
            list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue()));
         }
      }
      for (String tab : tables) {
         List<WarningDetail> warnList = getWarnByTime(tab, ids);
         for (WarningDetail s : warnList) {
            list.add(new WarningVo(s.getLocationName(), s.getSuYuanId(), 0.0, 0.0, s.getValue()));
         }
      }
      return list;
   }
   private List<WarningDetail> getAlarmByTime(String tableName, List<String> ids) {
      List<WarningDetail> result = new ArrayList<>();
      List<SuYuan2d> list = suYuanMapper.getAlarmsAnalyse(tableName, ids);
      if (null != list && list.size() > 0) {
         Date date = getDateByTabName(tableName);
         for (SuYuan2d s : list) {
            String locationName = commonService.select3dCheckPointById(s.getId()).getName();
            result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 0, s.getValue()));
         }
      }
      return result;
   }
   private List<WarningDetail> getWarnByTime(String tableName, List<String> ids) {
      List<WarningDetail> result = new ArrayList<>();
      List<SuYuan2d> list = suYuanMapper.getWarningAnalyse(tableName, ids);
      if (null != list && list.size() > 0) {
         Date date = getDateByTabName(tableName);
         for (SuYuan2d s : list) {
            String locationName = commonService.select3dCheckPointById(s.getId()).getName();
            result.add(new WarningDetail(0L, tableName, s.getId(), locationName, date, 1, s.getValue()));
         }
      }
      return result;
   }
   private Date getDateByTabName(String tab) {
      try {
         return ymdh.parse(tab.replace("su_yuan_", ""));
      } catch (Exception e) {
         return new Date();
      }
   }
}