@RequestMapping(value = "/doSave", method = RequestMethod.POST) public @ResponseBody void doSave( ProjectWizardFormBean formBean, HttpSession session, HttpServletResponse response) throws IOException { JSONObject jsonObject = new JSONObject(); // 檢查是否已經登入系統 // if (!SessionUtils.isLogon(session)) { // jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); // jsonObject.put(JKEY_ERROR_MESSAGE, ErrorMessageEnum.AUTHENTICATION_NOT_LOGON.getDesc()); // // response.setContentType(JKEY_CONTENT_TYPE); // response.getWriter().write(jsonObject.toString()); // return; // } // 檢查欄位值 if (StringUtils.isBlank(formBean.getProjectUuid()) || StringUtils.isBlank(formBean.getName())) { jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); jsonObject.put(JKEY_ERROR_MESSAGE, ErrorMessageEnum.COMMON_DATA_INCORRECT.getDesc()); response.setContentType(JKEY_CONTENT_TYPE); response.getWriter().write(jsonObject.toString()); return; } ProjectPhase projectPhase = new ProjectPhase(); BeanUtils.copyProperties(formBean, projectPhase); String[] toolUuids = StringUtils.split(formBean.getToolUuids(), ","); if (StringUtils.equals(FUNCTION_NAME_INSERT, formBean.getFunctionName())) { // 新增資料 projectPhase.setCreator(SessionUtility.getUserUuid(session)); try { projectPhase = projectWizardService.createProjectPhase(projectPhase, toolUuids); jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_SUCCESS); jsonObject.put(JKEY_UUID, projectPhase.getUuid()); } catch (Exception e) { e.printStackTrace(); jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); jsonObject.put(JKEY_ERROR_MESSAGE, ErrorMessageEnum.COMMON_INSERT_FAILED.getDesc()); } } else if (StringUtils.equals(FUNCTION_NAME_UPDATE, formBean.getFunctionName())) { // 更新資料 try { projectPhase = projectWizardService.updateProjectPhase(projectPhase, toolUuids); jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_SUCCESS); } catch (NoDataFoundException e) { jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); jsonObject.put(JKEY_ERROR_MESSAGE, e.getMessage()); } catch (Exception e) { jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); jsonObject.put(JKEY_ERROR_MESSAGE, ErrorMessageEnum.COMMON_UPDATE_FAILED.getDesc()); } } else { jsonObject.put(JKEY_FUNCTION_STATUS, JVALUE_FUNCTION_FAILED); jsonObject.put(JKEY_ERROR_MESSAGE, ErrorMessageEnum.COMMON_UNKNOWN_FUNCTION.getDesc()); } response.setContentType(JKEY_CONTENT_TYPE); response.getWriter().write(jsonObject.toString()); }