public void deleteTask(String taskId) {
    if (StringUtils.isBlank(taskId)) {
      throw new BusinessException("taskId", ErrorCode.PARAMETER_NOT_FOUND);
    }
    try {
      // 删除巡检计划时先删除EP_TASK_STEP表记录
      EpTaskStepExample TaskStepExample = new EpTaskStepExample();
      EpTaskStepExample.Criteria criteria = TaskStepExample.createCriteria();
      criteria.andTaskIdEqualTo(taskId);
      epTaskStepDAO.deleteByExample(TaskStepExample);
      // 删除巡检计划时先删除关系表记录
      EpRTaskstepMonitorExample epRTaskstepMonitorExample = new EpRTaskstepMonitorExample();
      EpRTaskstepMonitorExample.Criteria epRTaskstepMonitorCriteria =
          epRTaskstepMonitorExample.createCriteria();
      epRTaskstepMonitorCriteria.andTaskIdEqualTo(taskId);
      epRTaskstepMonitorDao.deleteByExample(epRTaskstepMonitorExample);

      epTaskDAO.deleteByPrimaryKey(taskId);
    } catch (Exception e) {
      throw new BusinessException("resourceBeUsed", ErrorCode.RESOURCE_BE_USED);
    }
  }
  public Map listTaskDetail(String taskId) {
    if (StringUtils.isBlank(taskId)) {
      throw new BusinessException("taskId", ErrorCode.PARAMETER_NOT_FOUND);
    }
    EpTask epTask = epTaskDAO.selectByPrimaryKey(taskId);
    Map map = new HashMap();
    if (epTask != null) {
      map.put("id", epTask.getId());
      map.put("taskName", epTask.getName());
      map.put("taskType", epTask.getType());
      map.put("organId", epTask.getOrganId());
      map.put("taskNote", epTask.getNote());
      map.put("branchId", epTask.getBranchId());
      EpTaskStepExample stepexample = new EpTaskStepExample();
      String orderByClause = "seq";
      stepexample.setOrderByClause(orderByClause);
      EpTaskStepExample.Criteria criteria = stepexample.createCriteria();
      criteria.andTaskIdEqualTo(taskId);
      List<EpTaskStep> list = epTaskStepDAO.selectByExample(stepexample);
      // System.out.println("list:"+list.size());
      List stepList = new ArrayList();
      if (list.size() > 0) {
        for (EpTaskStep epTaskStep : list) {
          EpTaskStepVO epTaskStepVO = new EpTaskStepVO();
          epTaskStepVO.setId(epTaskStep.getId());
          epTaskStepVO.setDeviceType(epTaskStep.getDeviceType());
          epTaskStepVO.setStepName(epTaskStep.getName());
          epTaskStepVO.setStepNote(epTaskStep.getNote());
          epTaskStepVO.setSequence(epTaskStep.getSeq() + "");
          epTaskStepVO.setTaskId(epTaskStep.getTaskId());
          List<EpRTaskstepMonitor> monitorList =
              epRTaskstepMonitorDao.listEpRTaskstepMonitor(epTaskStep.getId());
          System.out.println("1:" + epTaskStep.getId());
          List probersList = new ArrayList();
          List vicList = new ArrayList();
          String lastMonitorId = null;
          // System.out.println("monitorList:"+monitorList.size());
          if (monitorList.size() > 0) {
            for (EpRTaskstepMonitor monitor : monitorList) {
              Map mMap = new HashMap();
              if (monitor.getMonitorType().equals(new BigDecimal(2))) {
                EpRTaskstepMonitorVO vo = new EpRTaskstepMonitorVO();
                vo.setId(monitor.getMonitorId());
                probersList.add(vo);
              }
              /*
               * System.out .println("lastMonitorId:" +
               * lastMonitorId);
               * System.out.println("monitor.getMonitorId():" +
               * monitor.getMonitorId()); System.out
               * .println("lastMonitorId!=monitor.getMonitorId():"
               * + lastMonitorId != monitor .getMonitorId());
               * System.out
               * .println("lastMonitorId!=monitor.getMonitorId():"
               * + monitor.getMonitorId().equals( lastMonitorId));
               * System.out.println(monitor.getMonitorId().equals(
               * lastMonitorId));
               */
              if (monitor.getMonitorType().equals(new BigDecimal(1))
                  && !monitor.getMonitorId().equals(lastMonitorId)) {

                ListEpRTaskstepMonitorVO vo = new ListEpRTaskstepMonitorVO();
                vo.setId(monitor.getMonitorId());
                List viclist = new ArrayList();
                for (EpRTaskstepMonitor vmonitor : monitorList) {
                  if (monitor.getMonitorId().equals(vmonitor.getMonitorId())) {
                    EpRTaskstepMonitorVO visvo = new EpRTaskstepMonitorVO();
                    visvo.setId(vmonitor.getPresetId());
                    EpPreset epPreset = epPresetDAO.selectByPrimaryKey(vmonitor.getPresetId());
                    if (epPreset != null) {
                      viclist.add(epPreset);
                    }
                  }
                }
                vo.setPresets(viclist);
                vicList.add(vo);
              }

              lastMonitorId = monitor.getMonitorId();
            }
          }
          epTaskStepVO.setProbers(probersList);
          epTaskStepVO.setVics(vicList);
          stepList.add(epTaskStepVO);
        }
        map.put("steps", stepList);
      }
    }
    return map;
  }
  public void updateEpTask(String jsonString) throws JSONException {
    JSONObject jsonObj = new JSONObject(jsonString);
    String taskName = jsonObj.getString("taskName");
    String taskType = jsonObj.getString("taskType");
    String organId = jsonObj.getString("organId");
    String id = jsonObj.getString("id");
    if (StringUtils.isBlank(id)) {
      throw new BusinessException("id", ErrorCode.PARAMETER_NOT_FOUND);
    }
    String taskNote = jsonObj.getString("taskNote");
    String branchId = jsonObj.getString("branchId");

    /*
     * EpTaskExample example = new EpTaskExample(); EpTaskExample.Criteria
     * criteria = example.createCriteria();
     * criteria.andNameEqualTo(taskName); List<EpTask> list =
     * epTaskDAO.selectByExample(example); System.out.println(list.size());
     * if (list.size() > 1 && list.get(0).getId() != id) { throw new
     * BusinessException("taskName", ErrorCode.NAME_EXIST); }
     */
    Long time = System.currentTimeMillis();
    EpTask epTask = new EpTask();
    epTask.setId(id);
    epTask.setCreateTime(new BigDecimal(time));
    epTask.setName(taskName);
    epTask.setType(new BigDecimal(taskType));
    epTask.setOrganId(organId);
    epTask.setNote(taskNote);
    epTask.setBranchId(branchId);
    // 更新task表
    epTaskDAO.updateByPrimaryKeySelective(epTask);
    // 删除EpTaskStep
    EpTaskStepExample TaskStepExample = new EpTaskStepExample();
    EpTaskStepExample.Criteria EpTaskStepcriteria = TaskStepExample.createCriteria();
    EpTaskStepcriteria.andTaskIdEqualTo(id);
    epTaskStepDAO.deleteByExample(TaskStepExample);
    // 删除EpTaskStepMonitor
    EpRTaskstepMonitorExample epRTaskstepMonitorExample = new EpRTaskstepMonitorExample();
    EpRTaskstepMonitorExample.Criteria epRTaskstepMonitorCriteria =
        epRTaskstepMonitorExample.createCriteria();
    epRTaskstepMonitorCriteria.andTaskIdEqualTo(id);
    epRTaskstepMonitorDao.deleteByExample(epRTaskstepMonitorExample);

    JSONArray jsonArray = jsonObj.getJSONArray("steps");
    if (jsonArray.length() > 0) {
      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonSteps = new JSONObject(jsonArray.getString(i));
        String sequence = jsonSteps.getString("sequence");
        String stepName = jsonSteps.getString("stepName");
        String stepNote = jsonSteps.getString("stepNote");
        String deviceType = jsonSteps.getString("deviceType");
        if (StringUtils.isBlank(sequence)) {
          throw new BusinessException("sequence", ErrorCode.PARAMETER_NOT_FOUND);
        }
        if (StringUtils.isBlank(stepName)) {
          throw new BusinessException("stepName", ErrorCode.PARAMETER_NOT_FOUND);
        }
        String stepId = sequenceDAO.getEpTaskStepSeq();
        EpTaskStep epts = new EpTaskStep();
        epts.setSeq(Integer.parseInt(sequence));
        epts.setName(stepName);
        epts.setNote(stepNote);
        epts.setTaskId(id);
        epts.setDeviceType(deviceType);
        epts.setId(stepId);
        epTaskStepDAO.insert(epts);
        JSONArray probers = jsonSteps.getJSONArray("probers");
        if (probers.length() > 0) {
          for (int j = 0; j < probers.length(); j++) {
            JSONObject jsonprobers = new JSONObject(probers.getString(j));
            String monitorId = jsonprobers.getString("id");
            if (StringUtils.isBlank(monitorId)) {
              throw new BusinessException("id", ErrorCode.PARAMETER_NOT_FOUND);
            }
            String epRTaskStepMonitorId = sequenceDAO.getEpRTaskStepMonitorSeq();
            EpRTaskstepMonitor ertsm = new EpRTaskstepMonitor();
            ertsm.setId(epRTaskStepMonitorId);
            ertsm.setMonitorId(monitorId);
            ertsm.setStepId(stepId);
            ertsm.setTaskId(id);
            ertsm.setMonitorType(new BigDecimal(2));
            epRTaskstepMonitorDao.insert(ertsm);
          }
        }
        JSONArray vics = jsonSteps.getJSONArray("vics");
        if (vics.length() > 0) {
          for (int k = 0; k < vics.length(); k++) {
            JSONObject jsonvics = new JSONObject(vics.getString(k));
            String monitorId = jsonvics.getString("id");
            JSONArray presetsnum = jsonvics.getJSONArray("presets");
            if (presetsnum.length() > 0) {
              for (int l = 0; l < presetsnum.length(); l++) {
                JSONObject jsonpresets = new JSONObject(presetsnum.getString(l));
                String presetsnumid = jsonpresets.getString("id");
                if (StringUtils.isBlank(monitorId)) {
                  throw new BusinessException("id", ErrorCode.PARAMETER_NOT_FOUND);
                }
                String epRTaskStepMonitorId = sequenceDAO.getEpRTaskStepMonitorSeq();
                EpRTaskstepMonitor ertsm = new EpRTaskstepMonitor();
                ertsm.setPresetId(presetsnumid);
                ertsm.setId(epRTaskStepMonitorId);
                ertsm.setMonitorId(monitorId);
                ertsm.setStepId(stepId);
                ertsm.setTaskId(id);
                ertsm.setMonitorType(new BigDecimal(1));
                epRTaskstepMonitorDao.insert(ertsm);
              }
            } else {
              String epRTaskStepMonitorId = sequenceDAO.getEpRTaskStepMonitorSeq();
              EpRTaskstepMonitor ertsm = new EpRTaskstepMonitor();
              ertsm.setId(epRTaskStepMonitorId);
              ertsm.setMonitorId(monitorId);
              ertsm.setStepId(stepId);
              ertsm.setTaskId(id);
              ertsm.setMonitorType(new BigDecimal(1));
              epRTaskstepMonitorDao.insert(ertsm);
            }
          }
        }
      }
    }
  }