private String assemblyCurSubDeptTree(List<Department> subDeptList) { StringBuffer strBuf = new StringBuffer(); for (Department department : subDeptList) { strBuf.append("{\"text\" : \"" + department.getDeptName() + "\","); strBuf.append("\"id\" : \"" + department.getId() + "\","); strBuf.append("\"deptType\" : \"" + department.getDeptType() + "\","); HashMap<String, Integer> nameMap = new HashMap<String, Integer>(); nameMap.put("parentId", department.getId()); List<Department> list = entityDao.getDepartmentList(nameMap); if (list != null && list.size() > 0) { strBuf.append("\"leaf\" : false ,"); strBuf.append("\"cls\" :\"fold\""); } else { strBuf.append("\"cls\" :'file',"); strBuf.append("\"leaf\" : true"); } strBuf.append("},"); } if (strBuf.length() > 0) { strBuf.delete(strBuf.length() - 1, strBuf.length()); } return strBuf.toString(); }
public String assimblyDepartName(Integer id) { int i = 1; StringBuffer sb = new StringBuffer(); List<Department> list = getParentDeptList(id); for (Department department : list) { sb.append(department.getId()); if (i < list.size()) sb.append(","); i = i + 1; } return sb.toString(); }
private String getSubDeptDepartment(List<Department> subDeptList) { StringBuffer strBuf = new StringBuffer(); for (Department deparment : subDeptList) { strBuf.append("id:" + deparment.getId()); List<Department> list = getCurSubDepartmentList(deparment.getId()); if (list != null && list.size() > 0) { strBuf.append(getSubDeptDepartment(list)); } } return strBuf.toString(); }
public String deleteDepartment(Department o) { String message = ""; if (this.getCurSubDeptUserList(o.getId()).size() > 0) { message = "该部门下有用户不能删除该部门!"; } else if (this.getSubDepartmentList(o.getId()).size() > 0) { message = "该部门下有子部门,不能删除该部门!"; } else { entityDao.remove(o); } return message; }
public List<User> getSubDeptUserList(Integer id) { List<User> userList = new ArrayList<User>(); List<Department> list = getSubDepartmentList(id); for (Department dept : list) { HashMap<String, String> nameMap = new HashMap<String, String>(); nameMap.put("deptId", dept.getId().toString()); List<User> userTempList = userDao.getUserList(nameMap); for (User tempUser : userTempList) { userList.add(tempUser); } } return userList; }
/** * 一次访问数据库 获取 ext 树 * * @param nodeId * @return * @create 2012-1-11 上午10:06:05 jinrey * @history */ public String getDepartmentByNodeId(String deptType) { // 执行查询,取得所有记录 Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("deptType", deptType); List<Department> list = entityDao.getDeptList(paramMap); // map Map<Integer, Department> map = new HashMap<Integer, Department>(); Department root = null; // 根结点 // 第一次循环,将结果集放到一个"Map键-值对"结构中,方便取出指定元素 for (Department treeNode : list) { map.put(treeNode.getId(), treeNode); if (treeNode.getParentId() == 1) { root = treeNode; } } // 第二次循环所有结点,将每个结点的子结点存入一个TreeSet中。*/ for (Department treeNode : list) { if (treeNode.getParentId() != 1) { map.get(treeNode.getParentId()).addChild(treeNode); } } // 递归方法toJsonString() 生成树字符串 String treeStr = "[" + root.toJsonString() + "]"; return treeStr; }
@SuppressWarnings("unchecked") public List<Department> getParentDeptList(Integer id) { List tempList = new ArrayList(); while (true) { // id 为 顶级部门 (父节点)为0 if (id.intValue() == Department.rootNode.intValue()) { break; } Department dept = entityDao.queryByDepartmentId(id); tempList.add(dept); if (dept.getParentId().intValue() != Department.rootNode.intValue()) { dept = entityDao.queryByDepartmentId(dept.getParentId()); tempList.add(dept); } id = dept.getParentId(); } return tempList; }
private String assemblyParentDeptTree(List<Department> subDeptList) { StringBuffer strBuf = new StringBuffer(); for (int i = subDeptList.size() - 1; i >= 0; i--) { Department department = subDeptList.get(i); if (i > 0) { if (i == subDeptList.size() - 1) { strBuf.append("{\"text\" : \"" + department.getDeptName() + "\","); strBuf.append("\"id\" : \"" + department.getId() + "\","); strBuf.append("\"deptType\" : \"" + department.getDeptType() + "\","); strBuf.append("\"leaf\" : false ,"); strBuf.append("\"cls\" :\"fold\","); strBuf.append("\"children\" :["); } else { strBuf.append("{\"text\" : \"" + department.getDeptName() + "\","); strBuf.append("\"id\" : \"" + department.getId() + "\","); strBuf.append("\"deptType\" : \"" + department.getDeptType() + "\","); strBuf.append("\"leaf\" : false ,"); strBuf.append("\"cls\" :\"fold\","); strBuf.append("\"children\" :["); } } else { strBuf.append("{\"text\" : \"" + department.getDeptName() + "\","); strBuf.append("\"id\" : \"" + department.getId() + "\","); strBuf.append("\"deptType\" : \"" + department.getDeptType() + "\","); strBuf.append("\"cls\" :'file',"); strBuf.append("\"leaf\" : true"); for (int j = subDeptList.size() - 1; j >= 0; j--) { strBuf.append("}"); strBuf.append("]"); } } } if (strBuf.length() > 0) { strBuf.delete(strBuf.length() - 1, strBuf.length()); } return strBuf.toString(); }
public void insertDepartment(Department o) { try { if (o.getParentId() == 0) { o.setParentId(Department.rootNode); // o.setParentName(o.getDeptName()); entityDao.insert(o); } else { Department dept = this.getDepartmentId(o.getParentId()); dept.setIsLeaf("n"); entityDao.update(dept); String idPath = dept.getFullIdPath() == null ? "" : dept.getFullIdPath(); String namePath = dept.getFullNamePath() == null ? "" : dept.getFullNamePath(); // id全路径格式:/1/2/ o.setFullIdPath(idPath + dept.getId() + "/"); o.setFullNamePath(namePath + dept.getDeptName() + "/"); o.setOrgLever(Integer.valueOf((dept.getOrgLever().intValue() + 1))); // o.setParentName(dept.getDeptName()); entityDao.insert(o); } } finally { } }
public String getDepartmentById(String deptId) { Department department = this.entityDao.get(Long.valueOf(deptId)); String deptName = department.getDeptName(); return deptName; }
public String assemblyCurParentDeptTree(Integer id) { Department dept = entityDao.get(id); dept = entityDao.get(dept.getParentId()); return assemblyCurSubDeptTree(dept.getId()); }