//选择评估人-树形结构 @RequestMapping(value = "chooseAssessorTree")//这里不要指定请求方式 public void chooseAssessorTree(HttpServletRequest req,HttpServletResponse res){ //每次点击节点的时候会传入一个节点ID值<br data-filtered="filtered"> String id = req.getParameter("id"); //第一次加载树时选择的区域 String groupId = req.getParameter("groupId"); List<Map<String,Object>> list=userService.queryJSAssessor(id,groupId); BuildJSON.printToClient(req, res, arrayBuilder(list)); } //获得树值 private JSONArray arrayBuilder(List<Map<String,Object>> list) { JSONArray arr = new JSONArray(); if (list != null && list.size() > 0) { for (int i=0;i<list.size();i++) { JSONObject obj = new JSONObject(); Map map=list.get(i); String userImg=map.get("userImg").toString(); if (userImg.equals("1")) {//表示到了叶子节点,选择出人 obj.put("id", map.get("loginName")); obj.put("text", map.get("displayName")); obj.put("state", "open"); //obj.put("iconCls", "icon-user2-gj"); }else{ obj.put("id", map.get("groupId")); obj.put("text", map.get("groupName")); obj.put("state", "closed"); } arr.add(obj); } } return arr; }
dao查询方法
/**查询树结构的人员以及部门数据 * @param parentGroupId * @param groupId 第一次加载树查询的 区域 例如是成都分公司,则查询出成都分公司下面的部门以及人员 * @return */ List<Map<String, Object>> queryJSAssessor(@Param("parentGroupId") String parentGroupId, @Param("groupId")String groupId);
对应的xml
<select resultType="Map" parameterType="String"> SELECT e.loginName, e.displayName, e.groupId, e.groupCode, e.groupName, e.disOrder, e.userImg FROM (SELECT s.loginName,s.displayName,s.groupId,s.groupCode,s.groupName,s.disOrder,s.userImg FROM (SELECT '0' loginName, '0' displayName, fg.ID groupId, fg.CODE groupCode, fg.NAME groupName, fg.DISPLAY_ORDER disOrder, isnull((select count(id) FROM FND_GROUP where PARENT_ID=fg.ID),0) groupLeaf, (select COUNT(1) from FND_USER_GROUP fug, FND_USER fu where fug.USER_ID = fu.ID and fug.GROUP_ID = fg.ID) userLeaf, 0 userImg FROM FND_GROUP fg WHERE fg.ENABLE_FLAG = 'Y' <if test="parentGroupId != null and '' != parentGroupId"> AND fg.PARENT_ID = #{parentGroupId} </if> <if test="parentGroupId == null or '' == parentGroupId"> <if test="groupId!=null and '' !=groupId"> AND fg.PARENT_ID = #{groupId} </if> <if test="groupId==null or ''==groupId"> AND fg.GROUP_LEVEL = 0 </if> </if> )s WHERE s.groupLeaf>0 OR s.userLeaf>0 UNION ALL SELECT fu.LOGIN_NAME loginName, fu.DISPLAY_NAME displayName, fg.ID groupId, fg.CODE groupCode, fg.NAME groupName, fg.DISPLAY_ORDER disOrder, 1 userImg FROM FND_USER fu LEFT JOIN FND_USER_GROUP fug ON fu.ID=fug.USER_ID LEFT JOIN FND_GROUP fg ON fug.GROUP_ID=fg.ID WHERE fu.ENABLE_FLAG = 'Y' AND fug.PRIMARY_FLAG='Y' AND fg.NAME!='' AND fu.LOGIN_NAME!='' AND fu.DISPLAY_NAME!='' AND fu.MOBILE!='' <if test="parentGroupId != null and '' != parentGroupId"> AND fug.GROUP_ID = #{parentGroupId} </if> <if test="parentGroupId == null or '' == parentGroupId"> <if test="groupId!=null and '' !=groupId"> AND fug.GROUP_ID = #{groupId} </if> <if test="groupId==null or ''==groupId"> AND fg.GROUP_LEVEL = 0 </if> </if> )e ORDER BY userImg, CAST(disOrder AS int) </select>
最后再附上一个使用实例的 jsp