oa小程序 - 通讯录查询部门添加新接口。用于显示部门

This commit is contained in:
Echo 2025-07-07 17:18:10 +08:00
parent 90b1d55c25
commit f0009fee14
6 changed files with 91 additions and 5 deletions

View File

@ -25,10 +25,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -128,6 +125,48 @@ public class DeptController {
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
}
@GetMapping(value = {"/address-book-list"})
@Operation(summary = "获取通讯录部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
public CommonResult<List<DeptSimpleRespVO>> getAddressBookDeptList(@RequestParam("id") Long id) {
List<DeptDO> list = deptService.getDeptList(
new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
// 获得所有得虚机构部门信息
List<DeptDO> virtuallyDeptId = list.stream()
.filter(dept -> dept.getVirtuallyStatus() == 1)
.collect(Collectors.toList());
virtuallyDeptId.forEach(data -> {
// 将虚机构的子部门父部门设置为虚机构的父部门
list.stream().filter(dept -> dept.getParentId().equals(data.getId()))
.map(dept -> dept.setParentId(data.getParentId()))
.collect(Collectors.toList());
});
// 移除虚机构不展示
list.removeIf(dept -> dept.getVirtuallyStatus() == 1);
//根据当前用户的部门ID查询部门信息 -- 这里需要一个不用数据权限查询部门信息的方法
DeptDO userDept = deptService.getDeptNoPermission(id);
//部门类型
String type = userDept.getType() ;
//
List<DeptDO> list1 = deptService.getDeptListByType(
new DeptListReqVO().setType(type).setStatus(CommonStatusEnum.ENABLE.getStatus()));
// 合并list和list1根据ID去重
Set<Long> existingIds = list.stream().map(DeptDO::getId).collect(Collectors.toSet());
List<DeptDO> combinedList = new ArrayList<>(list); // 初始化为list的副本
// 添加list1中不重复的部门
list1.stream()
.filter(dept -> !existingIds.contains(dept.getId()))
.forEach(combinedList::add);
return success(BeanUtils.toBean(combinedList, DeptSimpleRespVO.class));
}
@GetMapping(value = {"/list-all-simple", "/simple-list"})
@Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() {

View File

@ -18,4 +18,7 @@ public class DeptListReqVO {
@Schema(description = "是否为虚机构 | 0否 1是")
private Integer virtuallyStatus;
@Schema(description = "部门类型")
private String type;
}

View File

@ -145,7 +145,7 @@ public class UserController {
@GetMapping("/page-permission")
@Operation(summary = "获得用户分页列表 | 无数据权限接口")
@PreAuthorize("@ss.hasPermission('system:user:list')")
// @PreAuthorize("@ss.hasPermission('system:user:list')")
@DataPermission(enable = false)
public CommonResult<PageResult<UserRespVO>> getUserPageNoPermission(@Valid UserPageReqVO pageReqVO) {
// 获得用户分页列表

View File

@ -16,6 +16,13 @@ import java.util.List;
@Mapper
public interface DeptMapper extends BaseMapperX<DeptDO> {
default List<DeptDO> selectListByType(DeptListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<DeptDO>()
.eqIfPresent(DeptDO::getType, reqVO.getType())
.eqIfPresent(DeptDO::getStatus, reqVO.getStatus()));
}
default List<DeptDO> selectList(DeptListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<DeptDO>()
.likeIfPresent(DeptDO::getName, reqVO.getName())

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.service.dept;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptApiDTO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
@ -53,6 +54,10 @@ public interface DeptService {
*/
DeptDO getDept(Long id);
@DataPermission(enable = false)
DeptDO getDeptNoPermission(Long id);
List<DeptDO> getDeptListNoPermission(Collection<Long> ids);
/**
* 获得部门信息数组
*
@ -69,6 +74,15 @@ public interface DeptService {
*/
List<DeptDO> getDeptList(DeptListReqVO reqVO);
/**
* 根据部门类型筛选部门列表
*
* @param reqVO 筛选条件请求 VO
* @return 部门列表
*/
@DataPermission(enable = false)
List<DeptDO> getDeptListByType(DeptListReqVO reqVO);
/**
* 获得指定编号的部门 Map
*

View File

@ -234,6 +234,21 @@ public class DeptServiceImpl implements DeptService {
return deptMapper.selectById(id);
}
@DataPermission(enable = false)
@Override
public DeptDO getDeptNoPermission(Long id) {
return deptMapper.selectById(id);
}
@DataPermission(enable = false)
@Override
public List<DeptDO> getDeptListNoPermission(Collection<Long> ids){
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return deptMapper.selectBatchIds(ids);
}
@Override
public List<DeptDO> getDeptList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
@ -249,6 +264,14 @@ public class DeptServiceImpl implements DeptService {
return list;
}
@Override
@DataPermission(enable = false)
public List<DeptDO> getDeptListByType(DeptListReqVO reqVO) {
List<DeptDO> list = deptMapper.selectListByType(reqVO);
list.sort(Comparator.comparing(DeptDO::getSort));
return list;
}
@Override
public List<DeptDO> getChildDeptList(Long id) {
List<DeptDO> children = new LinkedList<>();