예제 #1
0
  /**
   * 一次访问数据库 获取 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;
  }
예제 #2
0
 private boolean hasMoreDepartment(Integer oldManager) {
   HashMap<String, Integer> nameMap = new HashMap<String, Integer>();
   nameMap.put("deptManager", oldManager);
   List<Department> list = entityDao.getDepartmentList(nameMap);
   if (list.size() > 1) return true;
   else return false;
 }
예제 #3
0
  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();
  }
예제 #4
0
 public Department getDepartmentId(Integer id) {
   Department dept = entityDao.get(id);
   // if (dept.getDeptManager() != null) {
   // User user = userDao.queryByUserId(dept.getDeptManager());
   // dept.setDeptManagerName(user.getUserName());
   // }
   return dept;
 }
예제 #5
0
 @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;
 }
예제 #6
0
  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;
  }
예제 #7
0
  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 {

    }
  }
예제 #8
0
  public List<Department> getSubDepartmentList(Integer id) {
    List<Integer> idList = new ArrayList<Integer>();
    List<Department> deptList = new ArrayList<Department>();
    List<Department> list = getCurSubDepartmentList(id);
    StringTokenizer st = new StringTokenizer(getSubDeptDepartment(list), "id:");
    while (st.hasMoreTokens()) {
      String deptId = st.nextToken();
      idList.add(new Integer(deptId));
    }
    for (Integer tempId : idList) {
      deptList.add(entityDao.queryByDepartmentId(tempId));
    }

    return deptList;
  }
예제 #9
0
 public List<Department> getAll() {
   return entityDao.getAll();
 }
예제 #10
0
 public void updateDepartment(Department o) {
   entityDao.update(o);
 }
예제 #11
0
 public List<Department> getDepartmentListByUser(Integer userId) {
   return entityDao.getDepartmentListByUser(userId);
 }
예제 #12
0
 public String assemblyCurParentDeptTree(Integer id) {
   Department dept = entityDao.get(id);
   dept = entityDao.get(dept.getParentId());
   return assemblyCurSubDeptTree(dept.getId());
 }
예제 #13
0
 public List<Department> getCurSubDepartmentList(Integer id) {
   HashMap<String, Integer> nameMap = new HashMap<String, Integer>();
   nameMap.put("parentId", id);
   return entityDao.getDepartmentList(nameMap);
 }