/**
  * 今天的利用率 罗盘
  *
  * @param osId
  * @return
  */
 @Post("getUtilzation/{osId}")
 public Reply getUtilzation(@Param("osId") String osId) {
   Date currentTime = new Date();
   Map<String, Double> map = new HashMap<String, Double>();
   map = osViewHandle.creatUtilZationView(osId, currentTime);
   return Replys.with(map).as(Json.class);
 }
 /**
  * 概览页面CPU 与内存曲线
  *
  * @param osId
  * @return
  */
 @Post("getCpuAndRam/{osId}")
 public Reply getCpuAndRam(@Param("osId") String osId) {
   Date currentTime = new Date();
   Map<String, List<List<?>>> oneOsCpuAndMem =
       osViewHandle.createOneOsCpuAndMemline(osId, currentTime, 3);
   return Replys.with(oneOsCpuAndMem).as(Json.class);
 }
 /**
  * 今天的可用性图饼
  *
  * @param osId
  * @return
  */
 @Post("getUsability/{osId}")
 public Reply getUsability(@Param("osId") String osId) {
   Map<String, Double> map = new HashMap<String, Double>();
   Date currentTime = new Date();
   map = osAvailableViewHandle.creatAvailablePie(osId, currentTime, 1);
   return Replys.with(map).as(Json.class);
 }
 /**
  * @title findRiskDutyAddFeeField
  * @description 查询pd_lmdutypayaddfee表的字段
  * @author 朱超
  * @return
  */
 public Reply findRiskDutyAddFeeField() {
   String tableCode = "PD_LMDutyPayAddFee";
   List<PDBaseField> fields = pdBaseFieldService.findField(tableCode);
   String[] fieldsArr =
       new String[] {
         "id.fieldCode", "fieldName", "fieldType", "officialDesc", "busiDesc", "displayOrder"
       };
   return Replys.with(fields).as(Json.class).includes(fieldsArr);
 }
 /**
  * @title updateDutyPayAddFee
  * @description 更新一条加费记录
  * @author 朱超
  * @return
  */
 public Reply updateDutyPayAddFee(
     @Param("pdlmDutyPayAddFee") PDLMDutyPayAddFee pdlmDutyPayAddFee) {
   PDLMDutyPayAddFee pdlmDutyPayAddFeeTarget =
       pdlmDutyPayAddFeeService.updateDutyPayAddFee(pdlmDutyPayAddFee);
   List<PDLMDutyPayAddFee> pdlmDutyPayAddFees = new ArrayList<PDLMDutyPayAddFee>();
   pdlmDutyPayAddFees.add(pdlmDutyPayAddFeeTarget);
   String[] show =
       new String[] {
         "id.riskCode",
         "id.dutyCode",
         "id.addFeeType",
         "id.addFeeObject",
         "addFeeCalCode",
         "addPointLimit"
       };
   return Replys.with(pdlmDutyPayAddFees).as(Json.class).includes(show);
 }
  @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);
  }
 /**
  * 概览页面CPU分解信息曲线 cpu利用率曲线(内存CPU表格下面的曲线)
  *
  * @param osId
  * @return
  */
 @Post("getCpuInfo/{osId}")
 public Reply getCpuInfo(@Param("osId") String osId) {
   Date currentTime = new Date();
   Map<String, List<List<?>>> lineMap = osViewHandle.createOneCpuResolveView(osId, currentTime, 3);
   return Replys.with(lineMap).as(Json.class);
 }
 /**
  * @title deleteDutyPayAddFee
  * @description 删除一条加费记录
  * @author 朱超
  * @return
  */
 public Reply deleteDutyPayAddFee(
     @Param("pdlmDutyPayAddFee") PDLMDutyPayAddFee pdlmDutyPayAddFee) {
   String flag = pdlmDutyPayAddFeeService.deleteDutyPayAddFee(pdlmDutyPayAddFee);
   return Replys.with(flag).as(Text.class);
 }
 public Reply findByPK(@Param("id") PDLMDutyPayAddFeeId id) {
   PDLMDutyPayAddFee resultDutyPayAddFee = pdlmDutyPayAddFeeService.findByPK(id);
   List<PDLMDutyPayAddFee> list = new ArrayList<PDLMDutyPayAddFee>();
   list.add(resultDutyPayAddFee);
   return Replys.with(list).as(Json.class);
 }