Пример #1
0
 /**
  * 获取树的节点数据
  *
  * @param req 请求参数
  * @return
  */
 @RequestMapping(value = "/PositionController!getTreeData", method = RequestMethod.GET)
 @ResponseBody
 public String getTreeData(HttpServletRequest req) {
   DbContextHolder.clearDbType();
   HashMap<String, String> map = new HashMap<String, String>();
   List<Position> treeDataByCode = new ArrayList<Position>();
   String path = req.getContextPath();
   String basePath = path + "/";
   String uid = req.getParameter("userid");
   // 通过用户取
   Account acc = (Account) req.getSession().getAttribute("user");
   if (uid != null && !"".equals(uid)) {
     HashMap<String, Object> args = new HashMap<String, Object>();
     args.put("id", uid);
     List<Account> accounts = accountService.getAccount(args);
     if (accounts != null && accounts.size() > 0) {
       acc = accounts.get(0);
     }
   }
   if ((acc.getParent_userid() == null || acc.getParent_userid() == 0)) {
     map.put("parent_code", "0");
     treeDataByCode = positionService.getAddrTree(map);
     for (Position position : treeDataByCode) {
       if (position != null) {
         // 看看是省、市、区
         setIcon(basePath, position);
       }
     }
   } else {
     treeDataByCode = positionService.getPositionByUserid(acc.getId().toString());
     for (Position position : treeDataByCode) {
       if (position != null) {
         setIcon(basePath, position);
       }
     }
     List<AccountDistrictRel> adRel = accountService.queryAccountDistrictRel(acc);
     for (int i = 0; i < adRel.size(); i++) {
       AccountDistrictRel ar = adRel.get(i);
       Position p = new Position();
       p.setId(ar.getCode());
       p.setLeaf(0);
       p.setLevels(0);
       p.setName(ar.getName());
       p.setExpand(true);
       p.setpId(ar.getParent_code());
       // 看看是省、市、区
       setIcon(basePath, p);
       treeDataByCode.add(p);
     }
   }
   JSONArray treeNodes = new JSONArray();
   treeNodes.addAll(treeDataByCode);
   return treeNodes.toString();
 }
Пример #2
0
  /**
   * 根据树节点的ID获取该节点的字节点的数据
   *
   * @param req 请求参数
   * @return
   */
  @RequestMapping(value = "/PositionController!getTreeDataById", method = RequestMethod.GET)
  @ResponseBody
  public String getTreeDataById(HttpServletRequest req) {
    DbContextHolder.clearDbType();
    String path = req.getContextPath();
    String basePath = path + "/";
    String id = req.getParameter("id");
    List<Position> treeDataByCode = null;
    // 检查USER
    Account user = (Account) req.getSession().getAttribute("user");
    if (user.getLevel() != 0) {
      // 市级用户
      if (id.matches("[1-9][0-9][0]{4}")) {
        //
        treeDataByCode = positionService.getPositionByUserid(user.getId().toString());
        for (Position position : treeDataByCode) {
          if (position != null) {
            setIcon(basePath, position);
          }
        }
        List<AccountDistrictRel> adRel = accountService.queryAccountDistrictRel(user);
        for (int i = 0; i < adRel.size(); i++) {
          AccountDistrictRel ar = adRel.get(i);
          Position p = new Position();
          p.setId(ar.getCode());
          p.setLeaf(0);
          p.setLevels(0);
          p.setName(ar.getName());
          p.setExpand(true);
          p.setpId(ar.getParent_code());
          // 看看是省、市、区
          setIcon(basePath, p);
          treeDataByCode.add(p);
        }
        JSONArray treeNodes = new JSONArray();
        treeNodes.addAll(treeDataByCode);
        return treeNodes.toString();
      }
    }

    Map<String, String> arguments = new HashMap<String, String>();
    arguments.put("parent_code", id);
    treeDataByCode = positionService.getAddrTree(arguments);
    for (Position position : treeDataByCode) {
      if (position != null) {
        setIcon(basePath, position);
      }
    }
    JSONArray treeNodes = new JSONArray();
    treeNodes.addAll(treeDataByCode);
    return treeNodes.toString();
  }