コード例 #1
0
  @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;
  }
コード例 #2
0
 @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;
 }
コード例 #3
0
 /**
  * @Description:生成tree html
  *
  * @author:[email protected]
  * @date:2011-9-5
  */
 public void createCategoryTreeHtml(HttpServletRequest request) {
   List<AdminDept> entitys = adminDeptService.findByProperty("parentId", 0);
   String objName = "所有分类";
   StringBuffer sb = new StringBuffer();
   sb.append("<li href='#' id='0'");
   sb.append("<a target='main'>" + objName + "</a><ul>");
   for (AdminDept entity : entitys) {
     List<AdminDept> entitysOne = adminDeptService.findByProperty("parentId", entity.getId());
     if (entitysOne.size() > 0) {
       sb.append(
           "<li href='#' id='"
               + entity.getId()
               + "'><a target='main'>"
               + entity.getName()
               + "</a><ul>");
       for (AdminDept entityOne : entitysOne) {
         //					sb.append("<li href='#' id='" + entityOne.getId()+"'><a target='main'>" +
         // entityOne.getName() + "</a></li>");
         List<AdminDept> entitysTwo =
             adminDeptService.findByProperty("parentId", entityOne.getId());
         if (entitysTwo.size() > 0) {
           sb.append(
               "<li href='#' id='"
                   + entityOne.getId()
                   + "'><a target='main'>"
                   + entityOne.getName()
                   + "</a><ul>");
           for (AdminDept entityTwo : entitysTwo) {
             List<AdminDept> entitysThree =
                 adminDeptService.findByProperty("parentId", entityTwo.getId());
             if (entitysThree.size() > 0) {
               sb.append(
                   "<li href='#' id='"
                       + entityTwo.getId()
                       + "'><a target='main'>"
                       + entityTwo.getName()
                       + "</a><ul>");
               for (AdminDept entityThree : entitysThree) {
                 sb.append(
                     "<li href='#' id='"
                         + entityThree.getId()
                         + "'><a target='main'>"
                         + entityThree.getName()
                         + "</a></li>");
               }
               sb.append("</ul></li>");
             } else {
               sb.append(
                   "<li href='#' id='"
                       + entityTwo.getId()
                       + "'><a target='main'>"
                       + entityTwo.getName()
                       + "</a></li>");
             }
           }
           sb.append("</ul></li>");
         } else {
           sb.append(
               "<li href='#' id='"
                   + entityOne.getId()
                   + "'><a target='main'>"
                   + entityOne.getName()
                   + "</a></li>");
         }
       }
       sb.append("</ul></li>");
     } else {
       sb.append(
           "<li href='#' id='"
               + entity.getId()
               + "'><a target='main'>"
               + entity.getName()
               + "</a></li>");
     }
   }
   sb.append("</ul></li>");
   String htmlFile = getAppRoot(request) + Constants.STATIC_PATH + Constants.TREE_HTML_DEPT;
   FileUtils.writeFile(htmlFile, sb.toString());
 }
コード例 #4
0
 @RequestMapping("/parse_tree")
 @ResponseBody
 public Map<String, Object> parseTree(HttpServletRequest request) {
   Map<String, Object> model = new HashMap<String, Object>();
   List<AdminDept> entitys = adminDeptService.findByProperty("parentId", 0);
   String objName = "所有部门";
   StringBuffer sb = new StringBuffer();
   sb.append("<li id='10000'");
   sb.append("<a href='#' target='main'>" + objName + "</a><ul>");
   for (AdminDept entity : entitys) {
     List<AdminDept> entitysOne = adminDeptService.findByProperty("parentId", entity.getId());
     if (entitysOne.size() > 0) {
       sb.append(
           "<li href='#' id='"
               + entity.getId()
               + "'><a target='main'>"
               + entity.getName()
               + "</a><ul>");
       for (AdminDept entityOne : entitysOne) {
         // sb.append("<li href='#' id='" +
         // entityOne.getId()+"'><a target='main'>" +
         // entityOne.getName() + "</a></li>");
         List<AdminDept> entitysTwo =
             adminDeptService.findByProperty("parentId", entityOne.getId());
         if (entitysTwo.size() > 0) {
           sb.append(
               "<li href='#' id='"
                   + entityOne.getId()
                   + "'><a target='main'>"
                   + entityOne.getName()
                   + "</a><ul>");
           for (AdminDept entityTwo : entitysTwo) {
             sb.append(
                 "<li href='#' id='"
                     + entityTwo.getId()
                     + "'><a target='main'>"
                     + entityTwo.getName()
                     + "</a></li>");
           }
           sb.append("</ul></li>");
         } else {
           sb.append(
               "<li href='#' id='"
                   + entityOne.getId()
                   + "'><a target='main'>"
                   + entityOne.getName()
                   + "</a></li>");
         }
       }
       sb.append("</ul></li>");
     } else {
       sb.append(
           "<li href='#' id='"
               + entity.getId()
               + "'><a target='main'>"
               + entity.getName()
               + "</a></li>");
     }
   }
   sb.append("</ul></li>");
   model.put("tree", sb.toString());
   return model;
 }