部门列表

pull/1/head
杨世强 1 year ago
parent d708dcf73b
commit ea749f59e7

@ -131,19 +131,10 @@ public class DeptController {
//将Dept转化为简单的Dept
List<DeptSimpleRespVO> simpleDeptList = new ArrayList<>();
simpleDeptList.addAll(DeptConvert.INSTANCE.convertList02(deptDOList));
deptDOList.forEach(deptDO -> {
List<AdminUserDO> adminUserList = userService.getUserListByDeptIds(Collections.singleton(deptDO.getId()));
for (AdminUserDO adminUserDO : adminUserList){
DeptSimpleRespVO deptSimpleRespVO = new DeptSimpleRespVO();
deptSimpleRespVO.setId(adminUserDO.getId());
deptSimpleRespVO.setParentId(adminUserDO.getDeptId());
deptSimpleRespVO.setName(adminUserDO.getNickname());
simpleDeptList.add(deptSimpleRespVO);
}
});
//将list转为树状
// List<DeptSimpleRespVO> list = deptService.buildTree(simpleDeptList,0);
return success(simpleDeptList);
List<DeptSimpleRespVO> list = deptService.buildTree(simpleDeptList,0);
List<DeptSimpleRespVO> result = deptService.setBuildTree(list,0);
return success(result);
}
}

@ -24,5 +24,8 @@ public class DeptSimpleRespVO {
@Schema(description = "父部门 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long parentId;
@Schema(description = "子集" )
private List<DeptSimpleRespVO> children;
}

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.yunxi.scm.framework.common.enums.CommonStatusEnum;
import com.yunxi.scm.framework.tenant.core.db.TenantBaseDO;
import com.yunxi.scm.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
import com.yunxi.scm.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
import com.yunxi.scm.module.system.dal.dataobject.user.AdminUserDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
@ -71,8 +72,8 @@ public class DeptDO extends TenantBaseDO {
*/
private Long enterpriseId;
// @TableField(exist = false)
// private List children;
@TableField(exist = false)
private List<DeptSimpleRespVO> children;
}

@ -107,5 +107,7 @@ public interface DeptService {
*
*
*/
// List<DeptSimpleRespVO> buildTree(List<DeptSimpleRespVO> deptDOList, long pid);
List<DeptSimpleRespVO> buildTree(List<DeptSimpleRespVO> deptDOList, long pid);
List<DeptSimpleRespVO> setBuildTree(List<DeptSimpleRespVO> deptDOList, long pid);
}

@ -19,6 +19,7 @@ import com.yunxi.scm.module.system.service.user.AdminUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -41,6 +42,9 @@ public class DeptServiceImpl implements DeptService {
@Resource
private DeptMapper deptMapper;
@Resource
@Lazy
private AdminUserService userService;
@Override
@CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST,
@ -205,17 +209,38 @@ public class DeptServiceImpl implements DeptService {
});
}
// @Override
// public List<DeptSimpleRespVO> buildTree(List<DeptSimpleRespVO> deptDOList, long pid) {
// List<DeptSimpleRespVO> treeList = new ArrayList<>();
// for (DeptSimpleRespVO dept : deptDOList) {
// if (dept.getParentId() == pid) {
// dept.setChildren(buildTree(deptDOList, dept.getId()));
// treeList.add(dept);
// }
// }
// return treeList;
// }
@Override
public List<DeptSimpleRespVO> buildTree(List<DeptSimpleRespVO> deptDOList, long pid) {
List<DeptSimpleRespVO> treeList = new ArrayList<>();
for (DeptSimpleRespVO dept : deptDOList) {
if (dept.getParentId() == pid) {
dept.setChildren(buildTree(deptDOList, dept.getId()));
treeList.add(dept);
}
}
return treeList;
}
@Override
public List<DeptSimpleRespVO> setBuildTree(List<DeptSimpleRespVO> deptDOList, long pid) {
for (DeptSimpleRespVO dept : deptDOList) {
if (dept.getChildren() != null && dept.getChildren().size() > 0) {
setBuildTree(dept.getChildren(), dept.getId());
} else {
List<AdminUserDO> adminUserList = userService.getUserListByDeptIds(Collections.singleton(dept.getId()));
List<DeptSimpleRespVO> simpleDeptList = new ArrayList<>();
for (AdminUserDO adminUserDO : adminUserList) {
DeptSimpleRespVO deptSimpleRespVO = new DeptSimpleRespVO();
deptSimpleRespVO.setId(adminUserDO.getId());
deptSimpleRespVO.setParentId(adminUserDO.getDeptId());
deptSimpleRespVO.setName(adminUserDO.getNickname());
simpleDeptList.add(deptSimpleRespVO);
}
dept.setChildren(simpleDeptList);
}
}
return deptDOList;
}
}

Loading…
Cancel
Save