예제 #1
0
 /**
  * 设置树节点的图片
  *
  * @param basePath
  * @param position
  */
 private void setIcon(String basePath, Position position) {
   if (position.getId().matches("[1-9][0-9]{1}[0]{4}")) {
     // 省
     position.setIcon(basePath + "source" + "/" + "images" + "/" + "province.png");
     position.setIsParent(true);
   } else if (position.getId().matches("[1-9][0-9][1-9][0-9][0]{2}|[1-9][0-9][0-9][1-9][0]{2}")) {
     // 市
     position.setIcon(basePath + "source" + "/" + "images" + "/" + "city.png");
     position.setIsParent(true);
   } else if (position.getId().matches("[0-9]{4}[1-9][0-9]|[0-9]{4}[0-9][1-9]")) {
     // 区
     position.setIcon(basePath + "source" + "/" + "images" + "/" + "district.png");
     position.setIsParent(false);
   }
 }
예제 #2
0
 /**
  * 获取树的节点数据
  *
  * @param req 请求参数
  * @return
  */
 @RequestMapping(value = "/euTreeData!getTreeData", method = RequestMethod.GET)
 @ResponseBody
 public JSONArray getEasyUiTreeData(HttpServletRequest req) {
   DbContextHolder.clearDbType();
   HashMap<String, String> map = new HashMap<String, String>();
   List<Position> treeDataByCode = new ArrayList<Position>();
   Account user = (Account) req.getSession().getAttribute("user");
   List<AccountDistrictRel> adRel = new ArrayList<AccountDistrictRel>();
   if (user.getParent_userid() == 0) {
     // 管理员查询所有
     map.put("parent_code", "0");
     treeDataByCode = positionService.getAddrTree(map);
     for (Position position : treeDataByCode) {
       if (position != null) {
         if (position.getLeaf() != 2) {
           position.setIsParent(true);
         }
       }
     }
     user.setLevel(-1);
   } else {
     treeDataByCode = positionService.getPositionByUserid(user.getId().toString());
     adRel = accountService.queryAccountDistrictRel(user);
   }
   Map<String, EasyUiTreeData> treeDatas =
       new HashMap<String, PositionController.EasyUiTreeData>();
   List<PositionController.EasyUiTreeData> mp = new ArrayList<PositionController.EasyUiTreeData>();
   for (AccountDistrictRel ad : adRel) {
     EasyUiTreeData data = new EasyUiTreeData();
     data.setText(ad.getName());
     data.setId(ad.getCode());
     Map<String, String> attributes = new HashMap<String, String>();
     attributes.put("level", user.getLevel().toString());
     attributes.put("pid", ad.getParent_code());
     data.setAttributes(attributes);
     treeDatas.put(ad.getCode(), data);
   }
   for (Position position : treeDataByCode) {
     EasyUiTreeData data = new EasyUiTreeData();
     if (position != null) {
       data.setId(position.getId());
       data.setText(position.getName());
       Map<String, String> attributes = new HashMap<String, String>();
       attributes.put("level", String.valueOf((user.getLevel() + 1)));
       attributes.put("pid", position.getpId());
       data.setAttributes(attributes);
       EasyUiTreeData easyUiTreeData = treeDatas.get(position.getpId());
       if (easyUiTreeData != null) {
         easyUiTreeData.getChildren().add(data);
       } else {
         mp.add(data);
       }
       //				mp.add(data);
     }
   }
   mp.addAll(treeDatas.values());
   JSONArray treeNodes = new JSONArray();
   treeNodes.addAll(mp);
   return treeNodes;
 }