/**
   * 生成应用明细告警展示信息
   *
   * @param applicationId 所属应用ID
   * @return 告警展示信息
   */
  public ApplicationDetailAlarmViewModel generateAlarmViewModel(String applicationId) {
    Date startDate = DateUtil.getTodayBeginDate();
    Date endDate = new Date();

    Application application = applicationRepository.findApplicationbyId(applicationId);
    int interval = application.getInterval().intValue();
    ApplicationDetailAlarmViewModel applicationDetailAlarmViewModel =
        new ApplicationDetailAlarmViewModel();
    // 获得健康度
    SeverityLevel severityLevel = healthStaService.healthStaForCurrent(applicationId, interval);

    applicationDetailAlarmViewModel.setSeverityLevel(severityLevel);
    int criticalCount = alarmRepository.countCriticalByMonitorId(applicationId, startDate, endDate);

    Pageable pageable = new PageRequest(0, 10, Sort.Direction.DESC, "create_time");
    Page<Alarm> alarmPage =
        alarmRepository.selectCriticalAlarmsByMonitorId(
            pageable, applicationId, startDate, endDate);
    Iterator<Alarm> alarmIterator = alarmPage.iterator();
    while (alarmIterator.hasNext()) {
      applicationDetailAlarmViewModel.addAlarmInfo(alarmIterator.next().getMessage());
    }

    applicationDetailAlarmViewModel.setCriticalCount(criticalCount);
    return applicationDetailAlarmViewModel;
  }
  void execute(Application application) {
    final String appId = application.getId();
    ScheduledFuture scheduledFuture =
        scheduledExecutorService.scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                try {
                  Date startDate = DateUtil.getTodayBeginDate();
                  Date endDate = new Date();
                  List<Url> urls = applicationRepository.selectAllUrlsWithApplicationId(appId);
                  List<UrlResponseTime> urlResponseTimes = new ArrayList<UrlResponseTime>();
                  for (Url url : urls) {
                    UrlResponseTime urlResponseTime =
                        urlResponseTimeRepository.selectUrlResponseTimesForMonitorUrl(
                            url.getId(), startDate, endDate, appId);
                    urlResponseTime =
                        urlResponseTime == null ? new UrlResponseTime() : urlResponseTime;

                    urlResponseTime.setApplicationId(appId);
                    urlResponseTime.setUrlId(url.getId());
                    urlResponseTime.setUrl(url.getUrl());

                    urlResponseTime.initViewValues();

                    urlResponseTimes.add(urlResponseTime);
                  }
                  for (UrlResponseTime urlResponseTime : urlResponseTimes) {
                    urlResponseTime.setHealthBar(
                        healthStaCache.getHealthBar(appId, urlResponseTime.getUrlId()));
                    urlResponseTime.setUrlHref(
                        "<a href='javascript:void(0);' onclick=\"urlDetail('"
                            + appId
                            + "', '"
                            + urlResponseTime.getUrlId()
                            + "')\">"
                            + urlResponseTime.getUrl()
                            + "</a>");
                  }
                  urlResponseTimeCache.put(appId, urlResponseTimes);
                } catch (Throwable t) {
                }
              }
            },
            0,
            27,
            TimeUnit.SECONDS);
    threadHolderMap.put(application.getId(), scheduledFuture);
  }