1. 优化用户全局公司与部门选择的体验

2. 新增规则引擎模块
This commit is contained in:
chenbowen
2025-09-21 21:48:54 +08:00
parent f8c984d627
commit 516ca4aefd
31 changed files with 2241 additions and 13 deletions

View File

@@ -80,6 +80,14 @@ public class DeptController {
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
}
@GetMapping(value = {"/simple-user-dept-list"})
@Operation(summary = "获取当前用户归属部门精简信息列表", description = "只包含当前用户归属的启用部门,主要用于前端的下拉选项")
@Parameter(name = "companyId", description = "公司ID可选参数用于过滤指定公司下的部门", required = false, example = "1")
public CommonResult<List<DeptSimpleRespVO>> getCurrentUserDeptList(@RequestParam(value = "companyId", required = false) Long companyId) {
List<DeptDO> list = deptService.getCurrentUserDeptList(companyId);
return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
}
@GetMapping(value = {"/list-company-simple", "/simple-company-list"})
@Operation(summary = "获取用户所属公司精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项")
public CommonResult<List<DeptSimpleRespVO>> getSimpleCompanyList() {

View File

@@ -117,6 +117,15 @@ public interface DeptService {
List<DeptDO> getUserCompanyList();
/**
* 获取当前用户归属的部门列表
* 只返回当前登录用户归属的启用部门
*
* @param companyId 可选的公司ID用于过滤指定公司下的部门
* @return 当前用户归属的部门列表
*/
List<DeptDO> getCurrentUserDeptList(Long companyId);
Set<CompanyDeptInfo> getCompanyDeptInfoListByUserId(Long userId);
/**

View File

@@ -292,6 +292,65 @@ public class DeptServiceImpl implements DeptService {
return getDeptList(companyIds);
}
/**
* 获取当前用户归属的部门列表
* 只返回当前登录用户归属的启用部门
*
* @return 当前用户归属的部门列表
*/
@Override
public List<DeptDO> getCurrentUserDeptList(Long companyId) {
Set<Long> deptIds = userDeptMapper.selectValidListByUserIds(singleton(getLoginUserId()))
.stream()
.map(UserDeptDO::getDeptId)
.collect(Collectors.toSet());
if (CollUtil.isEmpty(deptIds)) {
return Collections.emptyList();
}
// 获取部门信息并过滤启用的部门
List<DeptDO> deptList = getDeptList(deptIds).stream()
.filter(dept -> CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus()))
.collect(Collectors.toList());
// 如果指定了公司ID则进一步过滤属于该公司的部门
if (companyId != null) {
return deptList.stream()
.filter(dept -> isUnderCompany(dept, companyId))
.collect(Collectors.toList());
}
return deptList;
}
/**
* 判断部门是否属于指定公司
*
* @param dept 部门
* @param companyId 公司ID
* @return 是否属于指定公司
*/
private boolean isUnderCompany(DeptDO dept, Long companyId) {
if (dept == null || companyId == null) {
return false;
}
// 如果部门本身就是指定的公司
if (dept.getId().equals(companyId) && Boolean.TRUE.equals(dept.getIsCompany())) {
return true;
}
// 向上递归查找,看是否有祖先部门是指定的公司
DeptDO current = dept;
while (current != null && current.getParentId() != null && !DeptDO.PARENT_ID_ROOT.equals(current.getParentId())) {
current = getDept(current.getParentId());
if (current != null && current.getId().equals(companyId) && Boolean.TRUE.equals(current.getIsCompany())) {
return true;
}
}
return false;
}
/**
* 根据用户ID查询其归属公司及直属部门关系列表不递归下级公司
*/