private String findParentId(Integer parentId, String parents) { SysGroups sysGroup = this.getCurrentDAO().get(parentId); if (sysGroup != null && sysGroup.getGroupParentId() != -1) { parents += findParentId(sysGroup.getGroupParentId(), parents) + ","; } parents += sysGroup.getId(); return parents; }
@Override public List<SysUsers> findSysUsersInGroups( String groupIds, int roleCategory, List<SysGroups> lstGroups) { List<Object> gIds = new ArrayList<Object>(); if (groupIds != null && !groupIds.equals("") && groupIds.contains(",")) { String[] arr = groupIds.split(","); for (int i = 0; i < arr.length; i++) { gIds.add(Integer.parseInt(arr[i])); } } else if (groupIds != null && !groupIds.equals("") && !groupIds.contains(",")) { gIds.add(Integer.parseInt(groupIds)); } if (roleCategory != 1) { StringBuffer hql = new StringBuffer("from SysGroups where id in ("); for (int i = 0; i < gIds.size(); i++) { if (i == 0) { hql.append("?"); } else { hql.append(",?"); } } hql.append(")"); List<SysGroups> lst = this.getCurrentDAO().find(hql.toString(), gIds.toArray()); gIds = new ArrayList<Object>(); if (lst != null && !lst.isEmpty()) { for (SysGroups givenGroup : lstGroups) { // 当前登录用户所在的群组 for (SysGroups group : lst) { if (roleCategory == 2) { // 校区助理角色 if (givenGroup.getGroupCategory() == 0) { // 所在群组为校区时,应取校区群组ID和校区下班级ID if (group.getId() == givenGroup.getId() || group.getGroupParentId() == givenGroup.getId()) { gIds.add(group.getId()); } } else if (givenGroup.getGroupCategory() == 1) { // 所在群组为班级时,应只取班级ID if (group.getId() == givenGroup.getId()) { gIds.add(group.getId()); } } } else if (roleCategory == 3) { // 教师角色 if (givenGroup.getGroupCategory() == 1) { // 所在群组为班级时,应只取班级ID if (group.getId() == givenGroup.getId()) { gIds.add(group.getId()); } } } } } } } return this.sysUsersManagementDAO.findSysUsersInGroups(gIds); }
@Override public List<Map<String, Object>> findGroupsForTree(Map<String, Object> parameters) { List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); Object[] param = null; StringBuffer hql = new StringBuffer("From SysGroups sgs where 1=1"); if (parameters != null && !parameters.isEmpty()) { param = new Object[parameters.size()]; int ind = 0; for (String key : parameters.keySet()) { hql.append(" and "); hql.append(key); hql.append(" = ?"); param[ind++] = parameters.get(key); } } hql.append(" order by groupParentId , id"); List<SysGroups> lst = this.getCurrentDAO().find(hql.toString(), param); if (lst != null && !lst.isEmpty()) { Map<String, Object> map = null; for (SysGroups sysGroup : lst) { map = new HashMap<String, Object>(); map.put("id", sysGroup.getId()); map.put("text", sysGroup.getGroupName()); map.put("parent", sysGroup.getGroupParentId() == -1 ? "#" : sysGroup.getGroupParentId()); if (sysGroup.getGroupParentId() == -1) { Map<String, Object> state = new HashMap<String, Object>(); state.put("opened", true); state.put("selected", true); map.put("state", state); } result.add(map); } } return result; }
@Override public List<Map<String, Object>> findGroupsForTree(List<Map<String, Integer>> parameters) { StringBuffer hql = new StringBuffer(); StringBuffer strIds = new StringBuffer(); List<Integer> parameterIds = new ArrayList<Integer>(); // 记录班级的group_id List<Integer> parentIds = new ArrayList<Integer>(); // 记录班级的group_parent_id,现阶段的数据结构group_parent_id就是校区的id for (Map<String, Integer> map : parameters) { parameterIds.add(map.get("groupId")); if (map.get("groupCategory") == 0) { // 校区 parentIds.add(map.get("groupId")); } else if (map.get("groupCategory") == 1) { // 班级 if (strIds.length() > 0) { strIds.append(","); } strIds.append(this.findParentId(map.get("groupId"), strIds.toString())); } } if (strIds.length() != 0) { for (String tmp : strIds.toString().split(",")) { if (tmp != null && !tmp.equals("")) { parameterIds.add(Integer.parseInt(tmp)); } } } List<Object> param = new ArrayList<Object>(); // = ? or sgs.groupParentId = ? or sgs.groupParentId = -1 order by groupParentId , id hql.append("from SysGroups sgs where "); if (parameterIds.size() > 0) { hql.append("sgs.id in ("); for (int i = 0; i < parameterIds.size(); i++) { if (i != 0) { hql.append(" , "); } hql.append("?"); param.add(parameterIds.get(i)); } hql.append(")"); } if (parentIds.size() > 0) { if (parameterIds.size() > 0) { hql.append(" or "); } hql.append("sgs.groupParentId in ("); for (int i = 0; i < parentIds.size(); i++) { if (i != 0) { hql.append(" , "); } hql.append("?"); param.add(parentIds.get(i)); } hql.append(")"); } hql.append("or sgs.groupParentId = -1 order by groupParentId , id"); List<SysGroups> lst = this.getCurrentDAO().find(hql.toString(), param.toArray()); Map<String, Object> mapTemp = null; List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); if (lst != null && !lst.isEmpty()) { for (SysGroups sysGroup : lst) { mapTemp = new HashMap<String, Object>(); mapTemp.put("id", sysGroup.getId()); mapTemp.put("text", sysGroup.getGroupName()); mapTemp.put( "parent", sysGroup.getGroupParentId() == -1 ? "#" : sysGroup.getGroupParentId()); if (sysGroup.getGroupParentId() == -1) { Map<String, Object> state = new HashMap<String, Object>(); state.put("opened", true); state.put("selected", true); mapTemp.put("state", state); } result.add(mapTemp); } } return result; }