feat(permission): 重构权限系统实现对象级别权限控制
- 在PermissionService中新增getScopedMenusByRoleId和getScopedPermissionsByRoleId方法 - 实现getScopedMenusByRoleId方法用于获取角色的对象范围菜单列表 - 实现getScopedPermissionsByRoleId方法用于获取角色的对象范围权限集合 - 添加getEnabledScopedRole私有方法确保只处理启用状态的角色对象 - 在ProductMemberServiceImpl中替换SystemRoleMapper为ObjectPermissionApi调用 - 将验证产品角色的方法改为调用远程权限接口验证 - 更新ProductObjectPermissionService使用远程权限接口替代本地查询 - 修改ProductServiceImpl中权限获取逻辑使用新的对象权限API - 移除原有的系统菜单和角色相关的数据对象依赖 - 在测试类中更新模拟对象和断言逻辑适配新的权限接口调用
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.dataobject.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.rdms.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 对象菜单表
|
||||
*/
|
||||
@TableName("system_menu")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SystemMenuDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String permission;
|
||||
|
||||
private String scopeType;
|
||||
|
||||
private String objectType;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private Long parentId;
|
||||
|
||||
private String path;
|
||||
|
||||
private String icon;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Boolean visible;
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.dataobject.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.rdms.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 角色信息表
|
||||
*/
|
||||
@TableName("system_role")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SystemRoleDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 作用域类型
|
||||
*/
|
||||
private String scopeType;
|
||||
/**
|
||||
* 对象类型
|
||||
*/
|
||||
private String objectType;
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 角色状态
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 角色类型
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.dataobject.permission;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.rdms.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 对象角色菜单关联表
|
||||
*/
|
||||
@TableName("system_role_menu")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SystemRoleMenuDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long menuId;
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.mysql.permission;
|
||||
|
||||
import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemMenuDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SystemMenuMapper extends BaseMapperX<SystemMenuDO> {
|
||||
|
||||
default List<SystemMenuDO> selectListByIdsAndScopeAndObjectType(Collection<Long> ids,
|
||||
String scopeType,
|
||||
String objectType) {
|
||||
return selectList(new LambdaQueryWrapperX<SystemMenuDO>()
|
||||
.inIfPresent(SystemMenuDO::getId, ids)
|
||||
.eq(SystemMenuDO::getScopeType, scopeType)
|
||||
.eq(SystemMenuDO::getObjectType, objectType));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.mysql.permission;
|
||||
|
||||
import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.rdms.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SystemRoleMapper extends BaseMapperX<SystemRoleDO> {
|
||||
|
||||
default SystemRoleDO selectByIdAndScopeAndObjectType(Long id, String scopeType, String objectType) {
|
||||
return selectOne(new LambdaQueryWrapperX<SystemRoleDO>()
|
||||
.eq(SystemRoleDO::getId, id)
|
||||
.eq(SystemRoleDO::getScopeType, scopeType)
|
||||
.eq(SystemRoleDO::getObjectType, objectType)
|
||||
.eq(SystemRoleDO::getStatus, 0));
|
||||
}
|
||||
|
||||
default List<SystemRoleDO> selectListByIdsAndScopeAndObjectType(Collection<Long> ids,
|
||||
String scopeType,
|
||||
String objectType) {
|
||||
return selectList(new LambdaQueryWrapperX<SystemRoleDO>()
|
||||
.inIfPresent(SystemRoleDO::getId, ids)
|
||||
.eq(SystemRoleDO::getScopeType, scopeType)
|
||||
.eq(SystemRoleDO::getObjectType, objectType)
|
||||
.eq(SystemRoleDO::getStatus, 0));
|
||||
}
|
||||
|
||||
default SystemRoleDO selectByScopeAndObjectTypeAndCode(String scopeType, String objectType, String code) {
|
||||
return selectOne(new LambdaQueryWrapperX<SystemRoleDO>()
|
||||
.eq(SystemRoleDO::getScopeType, scopeType)
|
||||
.eq(SystemRoleDO::getObjectType, objectType)
|
||||
.eq(SystemRoleDO::getCode, code)
|
||||
.eq(SystemRoleDO::getStatus, 0));
|
||||
}
|
||||
|
||||
default SystemRoleDO selectByScopeAndObjectTypeAndName(String scopeType, String objectType, String name) {
|
||||
return selectOne(new LambdaQueryWrapperX<SystemRoleDO>()
|
||||
.eq(SystemRoleDO::getScopeType, scopeType)
|
||||
.eq(SystemRoleDO::getObjectType, objectType)
|
||||
.eq(SystemRoleDO::getName, name)
|
||||
.eq(SystemRoleDO::getStatus, 0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.njcn.rdms.module.project.dal.mysql.permission;
|
||||
|
||||
import com.njcn.rdms.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleMenuDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SystemRoleMenuMapper extends BaseMapperX<SystemRoleMenuDO> {
|
||||
|
||||
default List<SystemRoleMenuDO> selectListByRoleId(Long roleId) {
|
||||
return selectList(SystemRoleMenuDO::getRoleId, roleId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.rdms.module.project.framework.rpc.config;
|
||||
|
||||
import com.njcn.rdms.module.system.api.permission.ObjectPermissionApi;
|
||||
import com.njcn.rdms.module.system.api.user.AdminUserApi;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -8,6 +9,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
* Project 模块的 RPC 配置
|
||||
*/
|
||||
@Configuration(value = "projectRpcConfiguration", proxyBeanMethods = false)
|
||||
@EnableFeignClients(clients = {AdminUserApi.class})
|
||||
@EnableFeignClients(clients = {AdminUserApi.class, ObjectPermissionApi.class})
|
||||
public class RpcConfiguration {
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ package com.njcn.rdms.module.project.framework.security.service;
|
||||
|
||||
import com.njcn.rdms.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.member.UserObjectRoleDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemMenuDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleMenuDO;
|
||||
import com.njcn.rdms.module.project.dal.mysql.member.UserObjectRoleMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemMenuMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemRoleMenuMapper;
|
||||
import com.njcn.rdms.module.project.enums.ErrorCodeConstants;
|
||||
import com.njcn.rdms.module.system.api.permission.ObjectPermissionApi;
|
||||
import com.njcn.rdms.module.system.enums.permission.PermissionScopeTypeEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -15,7 +12,6 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -34,9 +30,7 @@ public class ProductObjectPermissionService implements ObjectPermissionService {
|
||||
@Resource
|
||||
private UserObjectRoleMapper userObjectRoleMapper;
|
||||
@Resource
|
||||
private SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
@Resource
|
||||
private SystemMenuMapper systemMenuMapper;
|
||||
private ObjectPermissionApi objectPermissionApi;
|
||||
|
||||
@Override
|
||||
public String getObjectType() {
|
||||
@@ -65,26 +59,13 @@ public class ProductObjectPermissionService implements ObjectPermissionService {
|
||||
}
|
||||
|
||||
private Set<String> getRolePermissions(Long roleId) {
|
||||
List<SystemRoleMenuDO> roleMenus = systemRoleMenuMapper.selectListByRoleId(roleId);
|
||||
if (roleMenus == null || roleMenus.isEmpty()) {
|
||||
Set<String> permissions = objectPermissionApi
|
||||
.getObjectRolePermissions(roleId, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE)
|
||||
.getCheckedData();
|
||||
if (permissions == null || permissions.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<Long> menuIds = roleMenus.stream()
|
||||
.map(SystemRoleMenuDO::getMenuId)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (menuIds.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
List<SystemMenuDO> menus = systemMenuMapper.selectListByIdsAndScopeAndObjectType(
|
||||
menuIds, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE);
|
||||
if (menus == null || menus.isEmpty()) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return menus.stream()
|
||||
.filter(menu -> ROLE_SCOPE_OBJECT.equals(menu.getScopeType()))
|
||||
.filter(menu -> PRODUCT_OBJECT_TYPE.equals(menu.getObjectType()))
|
||||
.filter(menu -> Integer.valueOf(0).equals(menu.getStatus()))
|
||||
.map(SystemMenuDO::getPermission)
|
||||
return permissions.stream()
|
||||
.filter(StringUtils::hasText)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
@@ -9,13 +9,13 @@ import com.njcn.rdms.module.project.controller.admin.product.vo.member.ProductMe
|
||||
import com.njcn.rdms.module.project.framework.security.annotation.CheckObjectPermission;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.audit.BizAuditLogDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.member.UserObjectRoleDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.product.ProductDO;
|
||||
import com.njcn.rdms.module.project.dal.mysql.audit.BizAuditLogMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.member.UserObjectRoleMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemRoleMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.product.ProductMapper;
|
||||
import com.njcn.rdms.module.project.enums.ErrorCodeConstants;
|
||||
import com.njcn.rdms.module.system.api.permission.ObjectPermissionApi;
|
||||
import com.njcn.rdms.module.system.api.permission.dto.ObjectRoleRespDTO;
|
||||
import com.njcn.rdms.module.system.api.user.AdminUserApi;
|
||||
import com.njcn.rdms.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -63,7 +63,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
@Resource
|
||||
private UserObjectRoleMapper userObjectRoleMapper;
|
||||
@Resource
|
||||
private SystemRoleMapper systemRoleMapper;
|
||||
private ObjectPermissionApi objectPermissionApi;
|
||||
@Resource
|
||||
private BizAuditLogMapper bizAuditLogMapper;
|
||||
@Resource
|
||||
@@ -75,7 +75,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
public List<ProductMemberRespVO> getProductMemberList(Long productId) {
|
||||
ProductDO product = validateProductExists(productId);
|
||||
List<UserObjectRoleDO> members = userObjectRoleMapper.selectListByObject(PRODUCT_OBJECT_TYPE, productId);
|
||||
Map<Long, SystemRoleDO> roleMap = getRoleMap(members.stream().map(UserObjectRoleDO::getRoleId).collect(Collectors.toSet()));
|
||||
Map<Long, ObjectRoleRespDTO> roleMap = getRoleMap(members.stream().map(UserObjectRoleDO::getRoleId).collect(Collectors.toSet()));
|
||||
Map<Long, AdminUserRespDTO> userMap = getUserMap(members.stream().map(UserObjectRoleDO::getUserId).collect(Collectors.toSet()));
|
||||
return members.stream().map(member -> {
|
||||
ProductMemberRespVO respVO = new ProductMemberRespVO();
|
||||
@@ -84,7 +84,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
AdminUserRespDTO user = userMap.get(member.getUserId());
|
||||
respVO.setUserNickname(user == null ? null : user.getNickname());
|
||||
respVO.setRoleId(member.getRoleId());
|
||||
SystemRoleDO role = roleMap.get(member.getRoleId());
|
||||
ObjectRoleRespDTO role = roleMap.get(member.getRoleId());
|
||||
respVO.setRoleName(role == null ? null : role.getName());
|
||||
respVO.setRoleCode(role == null ? null : role.getCode());
|
||||
respVO.setManagerFlag(Objects.equals(member.getUserId(), product.getManagerUserId())
|
||||
@@ -103,7 +103,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
permission = PRODUCT_UPDATE_PERMISSION)
|
||||
public Long createProductMember(Long productId, ProductMemberSaveReqVO reqVO) {
|
||||
ProductDO product = validateProductExists(productId);
|
||||
SystemRoleDO targetRole = validateProductRole(reqVO.getRoleId());
|
||||
ObjectRoleRespDTO targetRole = validateProductRole(reqVO.getRoleId());
|
||||
UserObjectRoleDO existingMember = userObjectRoleMapper
|
||||
.selectByObjectAndUserId(PRODUCT_OBJECT_TYPE, productId, reqVO.getUserId());
|
||||
if (existingMember != null && Objects.equals(existingMember.getStatus(), MEMBER_STATUS_ACTIVE)) {
|
||||
@@ -153,7 +153,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
throw exception(ErrorCodeConstants.PRODUCT_MEMBER_NOT_ACTIVE);
|
||||
}
|
||||
|
||||
SystemRoleDO targetRole = validateProductRole(reqVO.getRoleId());
|
||||
ObjectRoleRespDTO targetRole = validateProductRole(reqVO.getRoleId());
|
||||
UserObjectRoleDO before = cloneMember(member);
|
||||
member.setRemark(normalizeNullableText(reqVO.getRemark()));
|
||||
|
||||
@@ -215,8 +215,10 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
return member;
|
||||
}
|
||||
|
||||
private SystemRoleDO validateProductRole(Long roleId) {
|
||||
SystemRoleDO role = systemRoleMapper.selectByIdAndScopeAndObjectType(roleId, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE);
|
||||
private ObjectRoleRespDTO validateProductRole(Long roleId) {
|
||||
ObjectRoleRespDTO role = objectPermissionApi
|
||||
.getObjectRoleById(roleId, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE)
|
||||
.getCheckedData();
|
||||
if (role == null) {
|
||||
throw exception(ErrorCodeConstants.PRODUCT_MEMBER_ROLE_INVALID);
|
||||
}
|
||||
@@ -236,7 +238,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
return;
|
||||
}
|
||||
|
||||
SystemRoleDO previousManagerRole = validatePreviousManagerTransfer(currentManagerUserId,
|
||||
ObjectRoleRespDTO previousManagerRole = validatePreviousManagerTransfer(currentManagerUserId,
|
||||
previousManagerUserId, previousManagerRoleId);
|
||||
transferPreviousManager(product.getId(), previousManagerUserId, previousManagerRole.getId(), reason);
|
||||
|
||||
@@ -245,9 +247,9 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
writeManagerChangeAuditLog(product.getId(), currentManagerUserId, targetManagerUserId, reason);
|
||||
}
|
||||
|
||||
private SystemRoleDO validatePreviousManagerTransfer(Long currentManagerUserId,
|
||||
Long previousManagerUserId,
|
||||
Long previousManagerRoleId) {
|
||||
private ObjectRoleRespDTO validatePreviousManagerTransfer(Long currentManagerUserId,
|
||||
Long previousManagerUserId,
|
||||
Long previousManagerRoleId) {
|
||||
if (currentManagerUserId == null
|
||||
|| previousManagerUserId == null
|
||||
|| previousManagerRoleId == null) {
|
||||
@@ -256,7 +258,7 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
if (!Objects.equals(currentManagerUserId, previousManagerUserId)) {
|
||||
throw exception(ErrorCodeConstants.PRODUCT_MANAGER_TRANSFER_SOURCE_INVALID);
|
||||
}
|
||||
SystemRoleDO previousManagerRole = validateProductRole(previousManagerRoleId);
|
||||
ObjectRoleRespDTO previousManagerRole = validateProductRole(previousManagerRoleId);
|
||||
if (isManagerRole(previousManagerRole)) {
|
||||
throw exception(ErrorCodeConstants.PRODUCT_MANAGER_TRANSFER_ROLE_INVALID);
|
||||
}
|
||||
@@ -298,17 +300,21 @@ public class ProductMemberServiceImpl implements ProductMemberService {
|
||||
writeMemberAuditLog(member, actionType, before, member, reason);
|
||||
}
|
||||
|
||||
private boolean isManagerRole(SystemRoleDO role) {
|
||||
private boolean isManagerRole(ObjectRoleRespDTO role) {
|
||||
return Objects.equals(PRODUCT_MANAGER_ROLE_CODE, role.getCode());
|
||||
}
|
||||
|
||||
private Map<Long, SystemRoleDO> getRoleMap(Set<Long> roleIds) {
|
||||
private Map<Long, ObjectRoleRespDTO> getRoleMap(Set<Long> roleIds) {
|
||||
if (roleIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<SystemRoleDO> roles = systemRoleMapper
|
||||
.selectListByIdsAndScopeAndObjectType(roleIds, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE);
|
||||
return roles.stream().collect(Collectors.toMap(SystemRoleDO::getId, Function.identity()));
|
||||
List<ObjectRoleRespDTO> roles = objectPermissionApi
|
||||
.getObjectRoleList(roleIds, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE)
|
||||
.getCheckedData();
|
||||
if (roles == null || roles.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return roles.stream().collect(Collectors.toMap(ObjectRoleRespDTO::getId, Function.identity()));
|
||||
}
|
||||
|
||||
private Map<Long, AdminUserRespDTO> getUserMap(Set<Long> userIds) {
|
||||
|
||||
@@ -17,21 +17,19 @@ import com.njcn.rdms.module.project.controller.admin.product.vo.setting.ProductS
|
||||
import com.njcn.rdms.module.project.framework.security.annotation.CheckObjectPermission;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.audit.BizAuditLogDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.member.UserObjectRoleDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemMenuDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.permission.SystemRoleMenuDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.product.ProductDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.product.ProductStatusLogDO;
|
||||
import com.njcn.rdms.module.project.dal.dataobject.status.ObjectStatusTransitionDO;
|
||||
import com.njcn.rdms.module.project.dal.mysql.audit.BizAuditLogMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.member.UserObjectRoleMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemMenuMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemRoleMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.permission.SystemRoleMenuMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.product.ProductMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.product.ProductStatusLogMapper;
|
||||
import com.njcn.rdms.module.project.dal.mysql.status.ObjectStatusTransitionMapper;
|
||||
import com.njcn.rdms.module.project.enums.ErrorCodeConstants;
|
||||
import com.njcn.rdms.module.system.api.permission.ObjectPermissionApi;
|
||||
import com.njcn.rdms.module.system.api.permission.dto.ObjectMenuRespDTO;
|
||||
import com.njcn.rdms.module.system.api.permission.dto.ObjectRolePermissionRespDTO;
|
||||
import com.njcn.rdms.module.system.api.permission.dto.ObjectRoleRespDTO;
|
||||
import com.njcn.rdms.module.system.api.user.AdminUserApi;
|
||||
import com.njcn.rdms.module.system.enums.permission.MenuTypeEnum;
|
||||
import com.njcn.rdms.module.system.enums.permission.PermissionScopeTypeEnum;
|
||||
@@ -45,7 +43,6 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -99,11 +96,7 @@ public class ProductServiceImpl implements ProductService {
|
||||
@Resource
|
||||
private UserObjectRoleMapper userObjectRoleMapper;
|
||||
@Resource
|
||||
private SystemRoleMapper systemRoleMapper;
|
||||
@Resource
|
||||
private SystemRoleMenuMapper systemRoleMenuMapper;
|
||||
@Resource
|
||||
private SystemMenuMapper systemMenuMapper;
|
||||
private ObjectPermissionApi objectPermissionApi;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@@ -174,23 +167,14 @@ public class ProductServiceImpl implements ProductService {
|
||||
return respVO;
|
||||
}
|
||||
|
||||
SystemRoleDO currentRole = systemRoleMapper
|
||||
.selectByIdAndScopeAndObjectType(currentMember.getRoleId(), ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE);
|
||||
ObjectRolePermissionRespDTO permissionDetail = objectPermissionApi
|
||||
.getObjectRolePermissionDetail(currentMember.getRoleId(), ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE)
|
||||
.getCheckedData();
|
||||
ObjectRoleRespDTO currentRole = permissionDetail == null ? null : permissionDetail.getCurrentRole();
|
||||
List<ObjectMenuRespDTO> menus = permissionDetail == null || permissionDetail.getMenus() == null
|
||||
? Collections.emptyList()
|
||||
: permissionDetail.getMenus();
|
||||
respVO.setCurrentRole(buildCurrentRole(currentMember, currentRole));
|
||||
|
||||
List<SystemRoleMenuDO> roleMenus = systemRoleMenuMapper.selectListByRoleId(currentMember.getRoleId());
|
||||
if (roleMenus.isEmpty()) {
|
||||
respVO.setNavs(Collections.emptyList());
|
||||
respVO.setButtons(Collections.emptyList());
|
||||
return respVO;
|
||||
}
|
||||
|
||||
Set<Long> menuIds = roleMenus.stream()
|
||||
.map(SystemRoleMenuDO::getMenuId)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
List<SystemMenuDO> menus = filterEnableProductObjectMenus(
|
||||
systemMenuMapper.selectListByIdsAndScopeAndObjectType(menuIds, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE));
|
||||
|
||||
respVO.setNavs(buildContextNavs(menus));
|
||||
respVO.setButtons(buildContextButtons(menus));
|
||||
return respVO;
|
||||
@@ -386,8 +370,9 @@ public class ProductServiceImpl implements ProductService {
|
||||
}
|
||||
|
||||
private void initManagerMemberRelation(ProductDO product) {
|
||||
SystemRoleDO managerRole = systemRoleMapper
|
||||
.selectByScopeAndObjectTypeAndCode(ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE, PRODUCT_MANAGER_ROLE_CODE);
|
||||
ObjectRoleRespDTO managerRole = objectPermissionApi
|
||||
.getObjectRoleByCode(PRODUCT_MANAGER_ROLE_CODE, ROLE_SCOPE_OBJECT, PRODUCT_OBJECT_TYPE)
|
||||
.getCheckedData();
|
||||
if (managerRole == null) {
|
||||
throw invalidParamException("未找到产品经理对象角色配置:{}", PRODUCT_MANAGER_ROLE_CODE);
|
||||
}
|
||||
@@ -406,22 +391,11 @@ public class ProductServiceImpl implements ProductService {
|
||||
writeManagerInitAuditLog(product.getId(), product.getManagerUserId());
|
||||
}
|
||||
|
||||
private List<SystemMenuDO> filterEnableProductObjectMenus(List<SystemMenuDO> menus) {
|
||||
if (menus == null || menus.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return menus.stream()
|
||||
.filter(menu -> Objects.equals(ROLE_SCOPE_OBJECT, menu.getScopeType()))
|
||||
.filter(menu -> Objects.equals(PRODUCT_OBJECT_TYPE, menu.getObjectType()))
|
||||
.filter(menu -> Objects.equals(0, menu.getStatus()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private ProductContextProductRespVO buildCurrentProduct(ProductDO product) {
|
||||
return BeanUtils.toBean(product, ProductContextProductRespVO.class);
|
||||
}
|
||||
|
||||
private ProductContextRoleRespVO buildCurrentRole(UserObjectRoleDO currentMember, SystemRoleDO currentRole) {
|
||||
private ProductContextRoleRespVO buildCurrentRole(UserObjectRoleDO currentMember, ObjectRoleRespDTO currentRole) {
|
||||
ProductContextRoleRespVO roleRespVO = new ProductContextRoleRespVO();
|
||||
roleRespVO.setRoleId(currentMember.getRoleId());
|
||||
if (currentRole != null) {
|
||||
@@ -431,7 +405,7 @@ public class ProductServiceImpl implements ProductService {
|
||||
return roleRespVO;
|
||||
}
|
||||
|
||||
private List<ProductContextNavRespVO> buildContextNavs(List<SystemMenuDO> menus) {
|
||||
private List<ProductContextNavRespVO> buildContextNavs(List<ObjectMenuRespDTO> menus) {
|
||||
if (menus.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -455,13 +429,13 @@ public class ProductServiceImpl implements ProductService {
|
||||
return navs;
|
||||
}
|
||||
|
||||
private List<String> buildContextButtons(List<SystemMenuDO> menus) {
|
||||
private List<String> buildContextButtons(List<ObjectMenuRespDTO> menus) {
|
||||
if (menus.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return menus.stream()
|
||||
.filter(menu -> MenuTypeEnum.BUTTON.getType().equals(menu.getType()))
|
||||
.map(SystemMenuDO::getPermission)
|
||||
.map(ObjectMenuRespDTO::getPermission)
|
||||
.filter(StringUtils::hasText)
|
||||
.map(String::trim)
|
||||
.distinct()
|
||||
|
||||
Reference in New Issue
Block a user