mirror of https://gitee.com/stylefeng/roses
【8.3.3】【role】增加接口:获取用户指定机构下的公司角色树
parent
a1a391f691
commit
6c8db77e2b
|
@ -58,10 +58,22 @@ public class NewRoleAssignController {
|
|||
* @author fengshuonan
|
||||
* @since 2025/1/24 14:33
|
||||
*/
|
||||
@GetResource(name = "获取用户指定公司下的业务角色树", path = "/sysRoleAssign/v2/getCompanyBusinessRoleTree")
|
||||
@GetResource(name = "获取用户指定机构下的业务角色树", path = "/sysRoleAssign/v2/getCompanyBusinessRoleTree")
|
||||
public ResponseData<List<SysRoleTreeDTO>> getCompanyBusinessRoleTree(@RequestParam("userId") Long userId, @RequestParam("orgId") Long orgId) {
|
||||
List<SysRoleTreeDTO> list = sysRoleAssignV2Service.getCompanyBusinessRoleTree(userId, orgId);
|
||||
return new SuccessResponseData<>(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户指定机构公司角色树
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/24 15:40
|
||||
*/
|
||||
@GetResource(name = "获取用户指定机构下的公司角色树", path = "/sysRoleAssign/v2/getCompanyRoleTree")
|
||||
public ResponseData<List<SysRoleTreeDTO>> getCompanyRoleTree(@RequestParam("userId") Long userId, @RequestParam("orgId") Long orgId) {
|
||||
List<SysRoleTreeDTO> list = sysRoleAssignV2Service.getCompanyRoleTree(userId, orgId);
|
||||
return new SuccessResponseData<>(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,4 +22,12 @@ public interface SysRoleAssignV2Service {
|
|||
*/
|
||||
List<SysRoleTreeDTO> getCompanyBusinessRoleTree(Long userId, Long orgId);
|
||||
|
||||
/**
|
||||
* 获取用户指定机构下的公司角色树(包含角色分类和角色)
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/24 15:45
|
||||
*/
|
||||
List<SysRoleTreeDTO> getCompanyRoleTree(Long userId, Long orgId);
|
||||
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.OrganizationServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.role.RoleTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.org.CompanyDeptDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.role.SysRoleTreeDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.newrole.UserRoleDTO;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.user.factory.RoleAssignV2Factory;
|
||||
|
@ -11,6 +13,7 @@ import cn.stylefeng.roses.kernel.sys.modular.user.service.SysUserRoleService;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -29,23 +32,54 @@ public class SysRoleAssignV2ServiceImpl implements SysRoleAssignV2Service {
|
|||
@Resource
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
@Resource
|
||||
private OrganizationServiceApi organizationServiceApi;
|
||||
|
||||
@Override
|
||||
public List<SysRoleTreeDTO> getCompanyBusinessRoleTree(Long userId, Long orgId) {
|
||||
|
||||
// 1. 获取系统中所有业务角色的树(业务角色分类 + 业务角色)
|
||||
List<SysRoleTreeDTO> totalBusinessRoleTree = sysRoleServiceApi.roleCategoryAndRoleTreeList(RoleTypeEnum.BUSINESS_ROLE.getCode(), null);
|
||||
|
||||
// 2. 获改用户,指定的机构,已经绑定的了哪些业务角色
|
||||
// 2. 获取用户绑定的角色,并挂载到树中
|
||||
return getUserBindRoleAndCombine(totalBusinessRoleTree, userId, orgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleTreeDTO> getCompanyRoleTree(Long userId, Long orgId) {
|
||||
|
||||
// 1. 获取机构的对应的公司
|
||||
CompanyDeptDTO orgCompanyInfo = organizationServiceApi.getOrgCompanyInfo(orgId);
|
||||
if (orgCompanyInfo == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 2. 获取系统中所有业务角色的树(业务角色分类 + 业务角色)
|
||||
List<SysRoleTreeDTO> totalCompanyRoleTree = sysRoleServiceApi.roleCategoryAndRoleTreeList(RoleTypeEnum.COMPANY_ROLE.getCode(), orgCompanyInfo.getCompanyId());
|
||||
|
||||
// 3. 获取用户绑定的角色,并挂载到树中
|
||||
return getUserBindRoleAndCombine(totalCompanyRoleTree, userId, orgId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户绑定的角色,并挂载到树中
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/24 15:51
|
||||
*/
|
||||
private List<SysRoleTreeDTO> getUserBindRoleAndCombine(List<SysRoleTreeDTO> totalRoleTree, Long userId, Long orgId) {
|
||||
|
||||
// 1. 获取用户,指定的机构,已经绑定的了哪些业务角色
|
||||
List<UserRoleDTO> userLinkedOrgRoleList = sysUserRoleService.getUserLinkedOrgRoleList(userId);
|
||||
if (ObjectUtil.isEmpty(userLinkedOrgRoleList)) {
|
||||
return totalBusinessRoleTree;
|
||||
return totalRoleTree;
|
||||
}
|
||||
userLinkedOrgRoleList = userLinkedOrgRoleList.stream().filter(item -> orgId.equals(item.getRoleOrgId())).collect(Collectors.toList());
|
||||
|
||||
// 3. 将用户绑定的角色,挂载到角色树中,赋值checked选项
|
||||
RoleAssignV2Factory.mountBusinessRole(totalBusinessRoleTree, userLinkedOrgRoleList);
|
||||
// 2. 将用户绑定的角色,挂载到角色树中,赋值checked选项
|
||||
RoleAssignV2Factory.mountBusinessRole(totalRoleTree, userLinkedOrgRoleList);
|
||||
|
||||
return totalBusinessRoleTree;
|
||||
return totalRoleTree;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue