Bladeren bron

新增根据deptId获取树形列表接口

tags/v1.1.0^2
wanjing 1 jaar geleden
bovenliggende
commit
019af236ee
4 gewijzigde bestanden met toevoegingen van 118 en 2 verwijderingen
  1. +11
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/DeptController.java
  2. +14
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/DeptServiceImpl.java
  3. +7
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/IDeptService.java
  4. +86
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/query/QueryListTreeByDeptIdService.java

+ 11
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/DeptController.java Bestand weergeven

@@ -36,11 +36,20 @@ public class DeptController {
return deptService.getListTree();
}

/**
* 查询当前部门树形列表
*/
@GetMapping("/list/tree/{deptId}")
public JsonResult getListTree(@PathVariable(value="deptId", required=false) String deptId) {
// log.info("进入获取部门列表接口");
return deptService.getListTreeByDeptId(deptId);
}

/**
* 根据id查询子部门列表
*/
@GetMapping(value= {"/child/list/{id}", "/child/list"})
public JsonResult getChildList(@PathVariable(value="id", required=false) String id ) {
@GetMapping(value= {"/child/list", "/child/list/{id}"})
public JsonResult getChildList(@PathVariable(value="id", required=false) String id) {
// log.info("进入获取子部门分页列表列表接口, id:{}", id);
return deptService.getChildList(id);
}

+ 14
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/DeptServiceImpl.java Bestand weergeven

@@ -9,6 +9,7 @@ import com.tuoheng.admin.service.dept.add.AddDeptService;
import com.tuoheng.admin.service.dept.delete.DeleteDeptService;
import com.tuoheng.admin.service.dept.query.QueryChildListService;
import com.tuoheng.admin.service.dept.query.QueryDeptInfoService;
import com.tuoheng.admin.service.dept.query.QueryListTreeByDeptIdService;
import com.tuoheng.admin.service.dept.query.QueryListTreeService;
import com.tuoheng.admin.service.dept.update.UpdateDeptService;
import com.tuoheng.common.core.utils.JsonResult;
@@ -33,6 +34,9 @@ public class DeptServiceImpl implements IDeptService {
@Autowired
private QueryListTreeService queryListTreeService;
@Autowired
private QueryListTreeByDeptIdService queryListTreeByDeptIdService;
@Autowired
private QueryChildListService queryChildListService;
@@ -58,6 +62,16 @@ public class DeptServiceImpl implements IDeptService {
return queryListTreeService.getListTree();
}
/**
* 查询当前部门树形列表
*
* @return 部门
*/
@Override
public JsonResult getListTreeByDeptId(String deptId) {
return queryListTreeByDeptIdService.getListTree(deptId);
}
/**
* 根据id查询子部门列表
*

+ 7
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/IDeptService.java Bestand weergeven

@@ -32,6 +32,13 @@ public interface IDeptService {
*/
JsonResult getListTree();
/**
* 查询当前部门树形列表
*
* @return 部门集合
*/
JsonResult getListTreeByDeptId(String deptId);
/**
* 根据id查询子部门列表
*

+ 86
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/query/QueryListTreeByDeptIdService.java Bestand weergeven

@@ -0,0 +1,86 @@
package com.tuoheng.admin.service.dept.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.conver.DeptConverMapper;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.code.dept.QueryDeptTreeListCodeEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.admin.vo.dept.DeptTreeVo;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 获取当前部门树形列表业务层处理
*
* @author wanjing
* @team tuoheng
* @date 2022-11-19
*/
@Slf4j
@Service
public class QueryListTreeByDeptIdService {

@Autowired
private DeptMapper deptMapper;

/**
* 获取部门树形列表
*
* @return
*/
public JsonResult getListTree(String deptId) {
List<DeptTreeVo> deptTreeVoList = new ArrayList<>();
User user = CurrentUserUtil.getUserInfo();
// 查询当前部门下所有有效的部门数据
List<String> deptIdList = deptMapper.selectAllChildListById(user.getDeptId());
List<Dept> deptList = deptMapper.selectListByIdList(deptIdList);
// 找出当前部门
Dept currentDept = deptList.stream()
.filter(item -> deptId.equals(item.getId()))
.findAny()
.orElse(null);
deptList.removeIf(item -> (item.getPid().equals(currentDept.getPid()) && !item.getId().equals(deptId)));

if (CollectionUtil.isEmpty(deptList)) {
log.info("获取部门列表为空");
return JsonResult.error(QueryDeptTreeListCodeEnum.DEPT_LIST_IS_NULL.getCode(), QueryDeptTreeListCodeEnum.DEPT_LIST_IS_NULL.getMsg());
}
List<DeptTreeVo> deptTreeVoListTmp = DeptConverMapper.INSTANCE.deptListToDeptVoList(deptList);
Map<String, DeptTreeVo> deptVoMap = new HashMap<>();
for (DeptTreeVo deptTreeVo : deptTreeVoListTmp) {
deptVoMap.put(deptTreeVo.getId(), deptTreeVo);
}
for (DeptTreeVo deptTreeVo : deptTreeVoListTmp) {
DeptTreeVo child = deptTreeVo;
if (currentDept.getId().equals(child.getId())) {
deptTreeVoList.add(deptTreeVo);
} else {
DeptTreeVo parent = deptVoMap.get(child.getPid());
if (ObjectUtil.isNotNull(parent)) {
deptTreeVo.setPname(parent.getName());
parent.getChildren().add(child);
}
}
}
if (ObjectUtil.isNotNull(currentDept)) {
// 从list中移除上级部门
Dept finalCurrentDept = currentDept;
deptTreeVoList.removeIf(item -> item.getId().equals(finalCurrentDept.getPid()));
}
return JsonResult.success(deptTreeVoList);
}

}

Laden…
Annuleren
Opslaan