Skip to content

Commit

Permalink
1.用户管理,点击部门筛选,同时显示子部门用户
Browse files Browse the repository at this point in the history
  • Loading branch information
lcg0124 committed Nov 15, 2018
1 parent e650240 commit 5d7b07e
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public interface DeptService {
Tree<DeptDO> getTree();

boolean checkDeptHasUser(Long deptId);

List<Long> listChildrenIds(Long parentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,90 @@
import com.bootdo.system.service.DeptService;



@Service
public class DeptServiceImpl implements DeptService {
@Autowired
private DeptDao sysDeptMapper;

@Override
public DeptDO get(Long deptId){
return sysDeptMapper.get(deptId);
}

@Override
public List<DeptDO> list(Map<String, Object> map){
return sysDeptMapper.list(map);
}

@Override
public int count(Map<String, Object> map){
return sysDeptMapper.count(map);
}

@Override
public int save(DeptDO sysDept){
return sysDeptMapper.save(sysDept);
}

@Override
public int update(DeptDO sysDept){
return sysDeptMapper.update(sysDept);
}

@Override
public int remove(Long deptId){
return sysDeptMapper.remove(deptId);
}

@Override
public int batchRemove(Long[] deptIds){
return sysDeptMapper.batchRemove(deptIds);
}

@Override
public Tree<DeptDO> getTree() {
List<Tree<DeptDO>> trees = new ArrayList<Tree<DeptDO>>();
List<DeptDO> sysDepts = sysDeptMapper.list(new HashMap<String,Object>(16));
for (DeptDO sysDept : sysDepts) {
Tree<DeptDO> tree = new Tree<DeptDO>();
tree.setId(sysDept.getDeptId().toString());
tree.setParentId(sysDept.getParentId().toString());
tree.setText(sysDept.getName());
Map<String, Object> state = new HashMap<>(16);
state.put("opened", true);
tree.setState(state);
trees.add(tree);
}
// 默认顶级菜单为0,根据数据库实际情况调整
Tree<DeptDO> t = BuildTree.build(trees);
return t;
}

@Override
public boolean checkDeptHasUser(Long deptId) {
// TODO Auto-generated method stub
//查询部门以及此部门的下级部门
int result = sysDeptMapper.getDeptUserNumber(deptId);
return result==0?true:false;
}
@Autowired
private DeptDao sysDeptMapper;

@Override
public DeptDO get(Long deptId) {
return sysDeptMapper.get(deptId);
}

@Override
public List<DeptDO> list(Map<String, Object> map) {
return sysDeptMapper.list(map);
}

@Override
public int count(Map<String, Object> map) {
return sysDeptMapper.count(map);
}

@Override
public int save(DeptDO sysDept) {
return sysDeptMapper.save(sysDept);
}

@Override
public int update(DeptDO sysDept) {
return sysDeptMapper.update(sysDept);
}

@Override
public int remove(Long deptId) {
return sysDeptMapper.remove(deptId);
}

@Override
public int batchRemove(Long[] deptIds) {
return sysDeptMapper.batchRemove(deptIds);
}

@Override
public Tree<DeptDO> getTree() {
List<Tree<DeptDO>> trees = new ArrayList<Tree<DeptDO>>();
List<DeptDO> sysDepts = sysDeptMapper.list(new HashMap<String, Object>(16));
for (DeptDO sysDept : sysDepts) {
Tree<DeptDO> tree = new Tree<DeptDO>();
tree.setId(sysDept.getDeptId().toString());
tree.setParentId(sysDept.getParentId().toString());
tree.setText(sysDept.getName());
Map<String, Object> state = new HashMap<>(16);
state.put("opened", true);
tree.setState(state);
trees.add(tree);
}
// 默认顶级菜单为0,根据数据库实际情况调整
Tree<DeptDO> t = BuildTree.build(trees);
return t;
}

@Override
public boolean checkDeptHasUser(Long deptId) {
// TODO Auto-generated method stub
//查询部门以及此部门的下级部门
int result = sysDeptMapper.getDeptUserNumber(deptId);
return result == 0 ? true : false;
}

@Override
public List<Long> listChildrenIds(Long parentId) {
List<DeptDO> deptDOS = list(null);
return treeMenuList(deptDOS, parentId);
}

List<Long> treeMenuList(List<DeptDO> menuList, long pid) {
List<Long> childIds = new ArrayList<>();
for (DeptDO mu : menuList) {
//遍历出父id等于参数的id,add进子节点集合
if (mu.getParentId() == pid) {
//递归遍历下一级
treeMenuList(menuList, mu.getDeptId());
childIds.add(mu.getDeptId());
}
}
return childIds;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.bootdo.common.domain.FileDO;
import com.bootdo.common.service.FileService;
import com.bootdo.common.utils.*;
import com.bootdo.system.service.DeptService;
import com.bootdo.system.vo.UserVO;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class UserServiceImpl implements UserService {
private FileService sysFileService;
@Autowired
private BootdoConfig bootdoConfig;
@Autowired
DeptService deptService;
private static final Logger logger = LoggerFactory.getLogger(UserService.class);

@Override
Expand All @@ -58,6 +61,14 @@ public UserDO get(Long id) {

@Override
public List<UserDO> list(Map<String, Object> map) {
String deptId = map.get("deptId").toString();
if (StringUtils.isNotBlank(deptId)) {
Long deptIdl = Long.valueOf(deptId);
List<Long> childIds = deptService.listChildrenIds(deptIdl);
childIds.add(deptIdl);
map.put("deptId", null);
map.put("deptIds",childIds);
}
return userMapper.list(map);
}

Expand Down Expand Up @@ -105,7 +116,7 @@ public int update(UserDO user) {
return r;
}

// @CacheEvict(value = "user")
// @CacheEvict(value = "user")
@Override
public int remove(Long userId) {
userRoleMapper.removeByUserId(userId);
Expand Down
Loading

0 comments on commit 5d7b07e

Please sign in to comment.