/**
   * 生成应用明细告警展示信息
   *
   * @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;
  }
  /**
   * 生成应用饼图展示信息
   *
   * @param applicationId 所属应用ID
   * @return 饼图展示信息
   */
  public ApplicationDetailPieViewModel generatePieViewModel(String applicationId) {
    ApplicationDetailPieViewModel applicationDetailPieViewModel =
        new ApplicationDetailPieViewModel();
    Date startDate = DateUtil.getTodayBeginDate();
    Date endDate = new Date();
    List<HealthStaForMonitor> healthStaForMonitors =
        alarmRepository.selectHealthStaForMonitor(applicationId, startDate, endDate);
    for (HealthStaForMonitor healthStaForMonitor : healthStaForMonitors) {
      if (healthStaForMonitor.getSeverity() == SeverityLevel.CRITICAL) {
        applicationDetailPieViewModel.setCriticalCount(healthStaForMonitor.getCount());
      } else if (healthStaForMonitor.getSeverity() == SeverityLevel.WARNING) {
        applicationDetailPieViewModel.setWarningCount(healthStaForMonitor.getCount());
      } else if (healthStaForMonitor.getSeverity() == SeverityLevel.INFO) {
        applicationDetailPieViewModel.setNormalCount(healthStaForMonitor.getCount());
      }
    }

    return applicationDetailPieViewModel;
  }
  @Post("osInfo/{osId}")
  public Reply osInfo(@Param("osId") String osId) {
    Map<String, String> map = new HashMap<String, String>();
    Date currentTime = new Date();
    // 获取操作系统基本信息】【
    Os os = osService.getOsBasicById(osId);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OsUtil.DATEFORMATE);
    map.put("monitorName", os.getName());
    map.put("health", "1");
    map.put("type", os.getType());
    map.put("osName", os.getIpAddr());
    map.put("os", os.getType());
    // 获取最后一次 响应时间
    OsRespondtime responTime =
        osRespondTimeService.findNealyResponTime(osId, currentTime, os.getIntercycleTime());
    // 获取最后一次轮询时间
    OsAvailabletemp lastSampleTime = osProcessService.getLastSampleTime(osId, currentTime);
    String healthyFlag = "<img src='/monitor/global/images/bussinessY.gif'>&nbsp;&nbsp;健康状态为正常.";
    List<Alarm> alarmList =
        alarmRepository.findAlarmByMonitorId(
            os.getOsInfoId(),
            new DateTime(currentTime).minusMinutes(os.getIntercycleTime()).toDate(),
            currentTime);
    for (Alarm alarm : alarmList) {
      if (alarm.getSeverity().equals(SeverityLevel.INFO)) {
        healthyFlag =
            "<img src='/monitor/global/images/bussinessY.gif'>&nbsp;&nbsp;健康状态为正常.&nbsp;没有出现告警。";
      } else if (alarm.getSeverity().equals(SeverityLevel.WARNING)) {
        healthyFlag =
            "<img src='/monitor/global/images/bussinessY3.gif'>&nbsp;&nbsp;健康状态为警告.&nbsp;出现中等的告警。";
      } else if (alarm.getSeverity().equals(SeverityLevel.CRITICAL)) {
        healthyFlag =
            "<img src='/monitor/global/images/bussinessY2.gif'>&nbsp;&nbsp;健康状态为严重.&nbsp;出现出现严重的告警。";
      } else if (alarm.getSeverity().equals(SeverityLevel.UNKNOW)) {
        healthyFlag =
            "<img src='/monitor/global/images/icon_health_unknown.gif'>&nbsp;&nbsp;健康状态为未知.";
      }
    }
    if (lastSampleTime == null) {
      map.put("lastTime", "未知");
      Calendar c = Calendar.getInstance();
      c.setTime(currentTime);
      c.add(Calendar.MINUTE, os.getIntercycleTime());
      map.put("nextTime", "未知");
    } else {
      if (currentTime.getTime() - lastSampleTime.getSampleDate().getTime()
          > os.getIntercycleTime() * 60 * 1000) {
        map.put("nextTime", "未知");
        healthyFlag = "<img src='/monitor/global/images/bussinessY2.gif'>&nbsp;&nbsp;当前为不可用";
      } else {
        Calendar c = Calendar.getInstance();
        c.setTime(lastSampleTime.getSampleDate());
        c.add(Calendar.MINUTE, os.getIntercycleTime());
        Date nextSampleTime = c.getTime();
        map.put("nextTime", simpleDateFormat.format(nextSampleTime));
      }
      map.put("lastTime", simpleDateFormat.format(lastSampleTime.getSampleDate()));
    }

    map.put("healthy", healthyFlag);
    if (responTime == null) map.put("respondTime", 0 + "毫秒");
    else {
      map.put("respondTime", responTime.getRespondTime() + "毫秒");
    }
    String messageFormat1 = "<span class={0}>{1}</span>";
    return Replys.with(map).as(Json.class);
  }