public void finishTask(String jsonString) throws JSONException {
    JSONObject jsonObj = new JSONObject(jsonString);
    String epRtaskEmployeeId = jsonObj.getString("id");
    String taskResult = jsonObj.getString("result");
    EpRTaskEmployee epRTaskEmployee = epRTaskEmployeeDAO.selectByPrimaryKey(epRtaskEmployeeId);
    EpTask epTask = epTaskDAO.selectByPrimaryKey(epRTaskEmployee.getTaskId());
    EpTaskHistory taskHistory = new EpTaskHistory();
    String historyTaskId = sequenceDAO.getEpTaskHistoryeq();
    taskHistory.setId(historyTaskId);
    taskHistory.setAllotUserId(epRTaskEmployee.getAllotUserId());
    Branch branch = branchDAO.selectByPrimaryKey(epTask.getBranchId());
    String branchName = null;
    if (branch != null) {
      branchName = branch.getName();
    }

    taskHistory.setBranchName(branchName);
    String EmployeeId = epRTaskEmployee.getEmployeeId();
    AcEmployees acEmployees = acEmployeesDAO.selectByPrimaryKey(EmployeeId);
    String employeeName = null;
    if (acEmployees != null) {
      employeeName = acEmployees.getName();
    }
    taskHistory.setEmployeeName(employeeName);
    Long endTime = System.currentTimeMillis();
    taskHistory.setSupportEmployee(epRTaskEmployee.getSupportEmployee());
    taskHistory.setEmployeeId(EmployeeId);
    taskHistory.setEndTime(endTime.toString());
    taskHistory.setExecuteTime(epRTaskEmployee.getExecuteTime());
    taskHistory.setExecuteTimeType(epRTaskEmployee.getExecuteTimeType());
    taskHistory.setNote(epTask.getNote());
    String organName = null;
    Organ organ = organDAO.selectByPrimaryKey(epTask.getOrganId());
    if (organ != null) {
      organName = organ.getName();
    }
    taskHistory.setOrganName(organName);
    taskHistory.setResult(taskResult);
    taskHistory.setTaskId(epRTaskEmployee.getTaskId());
    taskHistory.setTaskName(epTask.getName());
    taskHistory.setTaskType(epTask.getType());
    taskHistory.setType(new BigDecimal(1));
    taskHistory.setUserId(epRTaskEmployee.getUserId());
    JSONArray jsonArray = jsonObj.getJSONArray("steps");
    epTaskHistoryDAO.insert(taskHistory);
    if (jsonArray.length() > 0) {
      for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonSteps = new JSONObject(jsonArray.getString(i));
        String stepId = jsonSteps.getString("stepId");
        String result = jsonSteps.getString("result");
        System.out.println("result:" + result);
        String stepCaptureId = jsonSteps.getString("stepCaptureId");
        EpTaskStepHistory epTaskStepHistory = new EpTaskStepHistory();
        String taskStephistoryId = sequenceDAO.getEpTaskStepHistoryeq();
        EpTaskStep epTaskStep = epTaskStepDAO.selectByPrimaryKey(stepId);
        if (epTaskStep == null) {
          throw new BusinessException("EP_TASK_STEP  STEP_ID", ErrorCode.RESOURCE_NOT_FOUND);
        }
        epTaskStepHistory.setDeviceType(epTaskStep.getDeviceType());
        epTaskStepHistory.setHistoryTaskId(historyTaskId);
        epTaskStepHistory.setId(taskStephistoryId);
        epTaskStepHistory.setResult(result);
        epTaskStepHistory.setSeq(new BigDecimal(epTaskStep.getSeq()));
        epTaskStepHistory.setStepId(stepId);
        epTaskStepHistory.setStepCaptureId(stepCaptureId);
        epTaskStepHistory.setStepName(epTaskStep.getName());
        epTaskStepHistory.setStepNote(epTaskStep.getNote());
        epTaskStepHistoryDAO.insert(epTaskStepHistory);
      }
    }
    epRTaskEmployeeDAO.deleteByPrimaryKey(epRtaskEmployeeId);
  }
  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;
  }