@RequestMapping(Constants.MV_URI_COMM_ADD) @ResponseBody public Map<String, Object> add(@RequestBody AdminDept bean, HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); try { AdminDept temp = null; if (adminDeptService.findByProperty("name", bean.getName()) != null && adminDeptService.findByProperty("name", bean.getName()).size() > 0) { temp = adminDeptService.findByProperty("name", bean.getName()).get(0); } if (temp != null && temp.getName().equals(bean.getName().trim())) { model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_RENAME); } else { bean.setName(bean.getName().trim()); bean.setAddTime(new Date()); bean.setIsDelete((short) 0); Integer parentId = 1; if (request.getSession().getAttribute(Constants.ONLINE_DEPT_ID) != null) { parentId = Integer.parseInt( request.getSession().getAttribute(Constants.ONLINE_DEPT_ID).toString()); } bean.setParentId(parentId); adminDeptService.save(bean); model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_SUCC); // 生成tree html文件 String htmlFile = getAppRoot(request) + Constants.STATIC_PATH + Constants.TREE_HTML_DEPT; createCategoryTreeHtml(request); } } catch (Exception e) { model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_ERROR); log.error(e); } return model; }
@RequestMapping(Constants.MV_URI_COMM_EDIT) @ResponseBody public Map<String, Object> edit(@RequestBody AdminDept bean, HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); try { AdminDept temp = adminDeptService.findById(bean.getId()); List<AdminDept> temps = adminDeptService.findByProperty("name", bean.getName().trim()); if (temps.size() > 0 && !temps.get(0).getName().equals(temp.getName().trim())) { model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_RENAME); } else { temp.setName(bean.getName().trim()); adminDeptService.update(temp); model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_SUCC); // 生成tree html文件 String htmlFile = getAppRoot(request) + Constants.STATIC_PATH + Constants.TREE_HTML_DEPT; createCategoryTreeHtml(request); } } catch (Exception e) { model.put(Constants.AJAX_MSG_NAME, Constants.AJAX_MSG_ERROR); log.error(e); } return model; }