Ejemplo n.º 1
0
  @Override
  public PageInfo byMonitorCode(SiteBO siteBO) {
    try {
      PageHelper.startPage(siteBO.getPage(), siteBO.getRows());

      Long t1 = System.currentTimeMillis();
      Map<String, Object> re = Bean2Map.trans(siteBO);
      System.out.println(System.currentTimeMillis() - t1 + " : " + re);
      if ("-1".equals(siteBO.getMonitorCode())) {
        List<String> codes = ShiroCustomUtils.getMonitors();
        if (codes.size() > 0) {
          re.put("monitorCode", codes.get(0));
        } else {
          re.remove("monitorCode");
        }
      }
      List<Site> list = siteDao.byMonitorCode(re);

      List<SiteBO> sbl = new ArrayList<>();
      try {
        // TODO 连接REDIS获取实时统计数据
        for (Site m : list) {
          SiteBO sb = new SiteBO();
          BeanUtils.copyProperties(sb, m);
          Map<String, String> site = redisBasicService.getSiteHash(m.getSiteCode());
          BeanUtils.populate(sb, site);
          Long counts = alarmHistoryService.getCountByCode(sb.getSiteCode());
          sb.setTotalAlarm(counts);
          TerminalBO tb = terminalLogService.getSiteTerminalInfo(sb.getSiteCode());
          if (tb != null) {
            if (tb.getSiteTerminalTotalNum() != null && tb.getSiteTerminalUnknowNum() != null) {
              int usingNum = tb.getSiteTerminalTotalNum();
              int unKnownNum = tb.getSiteTerminalUnknowNum();
              if (usingNum != 0 || unKnownNum != 0) {
                double rate = (usingNum + 0.0) / (unKnownNum + usingNum + 0.0);
                sb.setInstallationRate(String.format("%.2f", rate * 100) + "%");
              } else {
                sb.setInstallationRate("0.0%");
              }
            }
          }
          sbl.add(sb);
        }
      } catch (Exception e) {
        Map<String, SiteLiveData> liveLatest = siteLiveDataService.getAllLatest();
        for (Site s : list) {
          SiteBO sb = new SiteBO();
          BeanUtils.copyProperties(sb, s);
          if (liveLatest.containsKey(s.getSiteCode())) {
            BeanUtils.copyProperties(sb, liveLatest.get(s.getSiteCode()));
          }
          sbl.add(sb);
        }
      }
      return PageInfo.clone(list, sbl);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Ejemplo n.º 2
0
  @Override
  public PageInfo getSiteOnLine(SiteBO siteBO) {
    try {
      PageHelper.startPage(siteBO.getPage(), siteBO.getRows());

      Map<String, Object> re = Bean2Map.trans(siteBO);
      List list = siteDao.getSiteOnLine(re);
      return PageInfo.clone(list);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }