public String createEpTask(String jsonString) throws JSONException { JSONObject jsonObj = new JSONObject(jsonString); String taskName = jsonObj.getString("taskName"); if (StringUtils.isBlank(taskName)) { throw new BusinessException("taskName", ErrorCode.PARAMETER_NOT_FOUND); } String taskType = jsonObj.getString("taskType"); if (StringUtils.isBlank(taskType)) { throw new BusinessException("taskType", ErrorCode.PARAMETER_NOT_FOUND); } String organId = jsonObj.getString("organId"); if (StringUtils.isBlank(organId)) { throw new BusinessException("organId", 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 list = * epTaskDAO.selectByExample(example); System.out.println(list.size()); * if (list.size() > 0) { throw new BusinessException("taskName", * ErrorCode.NAME_EXIST); } */ Long time = System.currentTimeMillis(); String id = sequenceDAO.getEpTaskSeq(); 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); epTaskDAO.insert(epTask); 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 deviceType = jsonSteps.getString("deviceType"); String stepNote = jsonSteps.getString("stepNote"); 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); } } } } } return id; }