public String createEpRTaskEmployee(
     String taskId,
     String employeeId,
     String userId,
     String allotUserId,
     String executeTime,
     BigDecimal executeTimeType,
     BigDecimal taskType,
     String supportEmployee) {
   if (StringUtils.isBlank(taskId)) {
     throw new BusinessException("taskId", ErrorCode.PARAMETER_NOT_FOUND);
   }
   if (StringUtils.isBlank(employeeId)) {
     throw new BusinessException("employeeId", ErrorCode.PARAMETER_NOT_FOUND);
   }
   if (StringUtils.isBlank(allotUserId)) {
     throw new BusinessException("allotUserId", ErrorCode.PARAMETER_NOT_FOUND);
   }
   if (StringUtils.isBlank(executeTime)) {
     throw new BusinessException("executeTime", ErrorCode.PARAMETER_NOT_FOUND);
   }
   String id = sequenceDAO.getEpRTaskEmployeeSeq();
   EpRTaskEmployee erte = new EpRTaskEmployee();
   erte.setId(id);
   erte.setTaskId(taskId);
   erte.setEmployeeId(employeeId);
   erte.setUserId(userId);
   erte.setAllotUserId(allotUserId);
   erte.setExecuteTime(executeTime);
   erte.setExecuteTimeType(executeTimeType);
   erte.setTaskType(taskType);
   erte.setSupportEmployee(supportEmployee);
   epRTaskEmployeeDAO.insert(erte);
   return id;
 }
  public String addEpPreset(String name, short presetNumber, String vicId, BigDecimal setFlag)
      throws BusinessException {
    // 同一个摄像头的预置点名称不能重复
    EpPresetExample example = new EpPresetExample();
    EpPresetExample.Criteria criteria = example.createCriteria();
    criteria.andNameEqualTo(name);
    criteria.andVicIdEqualTo(vicId);
    List<EpPreset> list = epPresetDAO.selectByExample(example);
    if (list.size() > 0) {
      throw new BusinessException(name, ErrorCode.NAME_EXIST);
    }

    EpPreset epPreset = new EpPreset();
    String id = sequenceDAO.getEpPresetSeq();
    epPreset.setId(id);
    epPreset.setVicId(vicId);
    epPreset.setName(name);
    epPreset.setPresetNumber(presetNumber);
    epPreset.setSetFlag(setFlag);
    epPresetDAO.insert(epPreset);
    return id;
  }
 public void addOrUpdateEpPreset(String jsonString) throws JSONException {
   if (StringUtils.isBlank(jsonString)) {
     throw new BusinessException("jsonString", ErrorCode.PARAMETER_NOT_FOUND);
   }
   JSONObject jsonObject = new JSONObject(jsonString);
   String vicId = jsonObject.getString("vicId");
   epPresetDAO.deleteByvicId(vicId);
   JSONArray jsonArray = jsonObject.getJSONArray("presets");
   if (jsonArray.length() > 0) {
     for (int i = 0; i < jsonArray.length(); i++) {
       JSONObject jsonObj = new JSONObject(jsonArray.getString(i));
       String name = jsonObj.getString("name");
       String note = jsonObj.getString("note");
       String presetNumberstr = jsonObj.getString("presetNumber");
       Short presetNumber;
       try {
         presetNumber = Short.valueOf(presetNumberstr);
       } catch (Exception e) {
         throw new BusinessException("presetNumber", ErrorCode.AC_PARAMETER_INVALID);
       }
       String setFlagstr = jsonObj.getString("setFlag");
       BigDecimal setFlag;
       try {
         setFlag = new BigDecimal(setFlagstr);
       } catch (Exception e) {
         throw new BusinessException("setFlag", ErrorCode.AC_PARAMETER_INVALID);
       }
       EpPreset epPreset = new EpPreset();
       String id = sequenceDAO.getEpPresetSeq();
       epPreset.setId(id);
       epPreset.setVicId(vicId);
       epPreset.setName(name);
       epPreset.setNote(note);
       epPreset.setPresetNumber(Short.valueOf(presetNumber));
       epPreset.setSetFlag(setFlag);
       epPresetDAO.insert(epPreset);
     }
   }
 }
 public void operateEpTaskInspection(String jsonString) throws JSONException {
   EpTaskInspectionExample example = new EpTaskInspectionExample();
   EpTaskInspectionExample.Criteria criteria = example.createCriteria();
   epTaskInspectionDAO.deleteByExample(example);
   JSONArray jsonArray = new JSONArray(jsonString);
   if (jsonArray.length() > 0) {
     for (int i = 0; i < jsonArray.length(); i++) {
       JSONObject jsonObject = new JSONObject(jsonArray.get(i).toString());
       EpTaskInspection epTaskInspection = new EpTaskInspection();
       String id = sequenceDAO.getEpTaskInstanceSeq();
       String item = jsonObject.getString("item");
       String seq = jsonObject.getString("seq");
       String standard = jsonObject.getString("standard");
       String type = jsonObject.getString("type");
       epTaskInspection.setId(id);
       epTaskInspection.setItem(item);
       epTaskInspection.setSeq(new BigDecimal(seq));
       epTaskInspection.setStandard(standard);
       epTaskInspection.setType(type);
       epTaskInspectionDAO.insert(epTaskInspection);
     }
   }
 }
  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 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);
            }
          }
        }
      }
    }
  }