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 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);
            }
          }
        }
      }
    }
  }