| | |
| | | package com.qianwen.smartman.modules.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import java.lang.invoke.SerializedLambda; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import com.qianwen.smartman.common.cache.RegionCache; |
| | | import com.qianwen.smartman.common.constant.CommonConstant; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.qianwen.core.log.exception.ServiceException; |
| | | import com.qianwen.core.secure.utils.AuthUtil; |
| | | import com.qianwen.core.tool.constant.BladeConstant; |
| | | import com.qianwen.core.tool.node.ForestNodeMerger; |
| | | import com.qianwen.core.tool.utils.CollectionUtil; |
| | | import com.qianwen.core.tool.utils.Func; |
| | | import com.qianwen.smartman.common.constant.CommonConstant; |
| | | import com.qianwen.smartman.modules.system.entity.Role; |
| | | import com.qianwen.smartman.modules.system.entity.RoleMenu; |
| | | import com.qianwen.smartman.modules.system.entity.RoleScope; |
| | |
| | | import com.qianwen.smartman.modules.system.service.IRoleService; |
| | | import com.qianwen.smartman.modules.system.vo.RoleVO; |
| | | import com.qianwen.smartman.modules.system.wrapper.RoleWrapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | @Service |
| | | @Validated |
| | |
| | | public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService { |
| | | private final IRoleMenuService roleMenuService; |
| | | private final IRoleScopeService roleScopeService; |
| | | |
| | | private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) { |
| | | String implMethodName = lambda.getImplMethodName(); |
| | | boolean z = true; |
| | | switch (implMethodName.hashCode()) { |
| | | case -1041904421: |
| | | if (implMethodName.equals("getParentId")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case -787052612: |
| | | if (implMethodName.equals("getScopeCategory")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 98245393: |
| | | if (implMethodName.equals("getId")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 298479812: |
| | | if (implMethodName.equals("getRoleAlias")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 618292688: |
| | | if (implMethodName.equals("getMenuId")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 770598695: |
| | | if (implMethodName.equals("getRoleId")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 771206363: |
| | | if (implMethodName.equals("getTenantId")) { |
| | | z = true; |
| | | break; |
| | | } |
| | | break; |
| | | case 1811120535: |
| | | if (implMethodName.equals("getRoleName")) { |
| | | z = false; |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | switch (z) { |
| | | case false: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleName(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleName(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleMenu") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleMenu") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleMenu") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleScope") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleScope") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleId(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getId(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleMenu") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getMenuId(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleScope") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) { |
| | | return (v0) -> { |
| | | return v0.getScopeCategory(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/RoleScope") && lambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) { |
| | | return (v0) -> { |
| | | return v0.getScopeCategory(); |
| | | }; |
| | | } |
| | | break; |
| | | case RegionCache.VILLAGE_LEVEL /* 5 */: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) { |
| | | return (v0) -> { |
| | | return v0.getTenantId(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleAlias(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) { |
| | | return (v0) -> { |
| | | return v0.getRoleAlias(); |
| | | }; |
| | | } |
| | | break; |
| | | case true: |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getParentId(); |
| | | }; |
| | | } |
| | | if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/system/entity/Role") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) { |
| | | return (v0) -> { |
| | | return v0.getParentId(); |
| | | }; |
| | | } |
| | | break; |
| | | } |
| | | throw new IllegalArgumentException("Invalid lambda deserialization"); |
| | | } |
| | | |
| | | public RoleServiceImpl(final IRoleMenuService roleMenuService, final IRoleScopeService roleScopeService) { |
| | | this.roleMenuService = roleMenuService; |
| | |
| | | } |
| | | |
| | | private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) { |
| | | Long administratorCount = this.baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, "administrator").in(Role::getId, roleIds)); |
| | | /* |
| | | Long administratorCount = ((RoleMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { |
| | | return v0.getRoleAlias(); |
| | | }, "administrator")).in((v0) -> { |
| | | return v0.getId(); |
| | | }, roleIds)); |
| | | }, roleIds));*/ |
| | | if (!AuthUtil.isAdministrator() && administratorCount.longValue() > 0) { |
| | | throw new ServiceException("无权配置超管角色!"); |
| | | } |
| | | Long adminCount = this.baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, "admin").in(Role::getId, roleIds)); |
| | | /* |
| | | Long adminCount = ((RoleMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { |
| | | return v0.getRoleAlias(); |
| | | }, "admin")).in((v0) -> { |
| | | return v0.getId(); |
| | | }, roleIds)); |
| | | }, roleIds));*/ |
| | | if (!AuthUtil.isAdmin() && adminCount.longValue() > 0) { |
| | | throw new ServiceException("无权配置管理员角色!"); |
| | | } |
| | | this.roleMenuService.remove(Wrappers.<RoleMenu>update().lambda().in(RoleMenu::getRoleId, roleIds)); |
| | | /* |
| | | this.roleMenuService.remove((Wrapper) Wrappers.update().lambda().in((v0) -> { |
| | | return v0.getRoleId(); |
| | | }, roleIds)); |
| | | }, roleIds));*/ |
| | | List<RoleMenu> roleMenus = new ArrayList<>(); |
| | | roleIds.forEach(roleId -> { |
| | | menuIds.forEach(menuId -> { |
| | |
| | | } |
| | | |
| | | private void recursionRoleMenu(List<Long> roleIds, List<Long> menuIds) { |
| | | //Role::getParentId RoleMenu::getRoleId RoleMenu::getMenuId |
| | | roleIds.forEach(roleId -> { |
| | | ((RoleMapper) this.baseMapper).selectList((Wrapper) Wrappers.query().lambda().eq((v0) -> { |
| | | return v0.getParentId(); |
| | | }, roleId)).forEach(role -> { |
| | | List<RoleMenu> roleMenuList = this.roleMenuService.list((Wrapper) Wrappers.query().lambda().eq((v0) -> { |
| | | return v0.getRoleId(); |
| | | }, role.getId())); |
| | | List<Long> collectRoleMenuIds = (List) roleMenuList.stream().map((v0) -> { |
| | | return v0.getMenuId(); |
| | | }).filter(menuId -> { |
| | | return !menuIds.contains(menuId); |
| | | }).collect(Collectors.toList()); |
| | | if (collectRoleMenuIds.size() > 0) { |
| | | this.roleMenuService.remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> { |
| | | return v0.getRoleId(); |
| | | }, role.getId())).in((v0) -> { |
| | | return v0.getMenuId(); |
| | | }, collectRoleMenuIds)); |
| | | recursionRoleMenu(Collections.singletonList(role.getId()), menuIds); |
| | | } |
| | | this.baseMapper.selectList( Wrappers.<Role>query().lambda().eq(Role::getParentId, roleId)).forEach(role -> { |
| | | List<RoleMenu> roleMenuList = this.roleMenuService.list(Wrappers.<RoleMenu>query().lambda().eq(RoleMenu::getRoleId, role.getId())); |
| | | List<Long> collectRoleMenuIds = roleMenuList.stream().map((v0) -> { |
| | | return v0.getMenuId(); |
| | | }).filter(menuId -> { |
| | | return !menuIds.contains(menuId); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | if (collectRoleMenuIds.size() > 0) { |
| | | this.roleMenuService.remove(Wrappers.<RoleMenu>update().lambda().eq(RoleMenu::getRoleId, role.getId()).in(RoleMenu::getMenuId, collectRoleMenuIds)); |
| | | recursionRoleMenu(Collections.singletonList(role.getId()), menuIds); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | private boolean grantDataScope(List<Long> roleIds, List<Long> dataScopeIds) { |
| | | this.roleScopeService.remove(Wrappers.<RoleScope>update().lambda() |
| | | .eq(RoleScope::getScopeCategory, CommonConstant.DATA_SCOPE_CATEGORY).in(RoleScope::getRoleId, roleIds)); |
| | | /* |
| | | this.roleScopeService.remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> { |
| | | return v0.getScopeCategory(); |
| | | }, CommonConstant.DATA_SCOPE_CATEGORY)).in((v0) -> { |
| | | return v0.getRoleId(); |
| | | }, roleIds)); |
| | | }, roleIds));*/ |
| | | List<RoleScope> roleDataScopes = new ArrayList<>(); |
| | | roleIds.forEach(roleId -> { |
| | | dataScopeIds.forEach(scopeId -> { |
| | |
| | | } |
| | | |
| | | private boolean grantApiScope(List<Long> roleIds, List<Long> apiScopeIds) { |
| | | this.roleScopeService.remove(Wrappers.<RoleScope>update().lambda() |
| | | .eq(RoleScope::getScopeCategory, CommonConstant.API_SCOPE_CATEGORY).in(RoleScope::getRoleId, roleIds)); |
| | | /* |
| | | this.roleScopeService.remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> { |
| | | return v0.getScopeCategory(); |
| | | }, CommonConstant.API_SCOPE_CATEGORY)).in((v0) -> { |
| | | return v0.getRoleId(); |
| | | }, roleIds)); |
| | | }, roleIds));*/ |
| | | List<RoleScope> roleApiScopes = new ArrayList<>(); |
| | | roleIds.forEach(roleId -> { |
| | | apiScopeIds.forEach(scopeId -> { |
| | |
| | | |
| | | @Override // org.springblade.modules.system.service.IRoleService |
| | | public String getRoleIds(String tenantId, String roleNames) { |
| | | List<Role> roleList = this.baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getTenantId, tenantId).in(Role::getRoleName, Func.toStrList(roleNames))); |
| | | |
| | | /* |
| | | List<Role> roleList = ((RoleMapper) this.baseMapper).selectList((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { |
| | | return v0.getTenantId(); |
| | | }, tenantId)).in((v0) -> { |
| | | return v0.getRoleName(); |
| | | }, Func.toStrList(roleNames))); |
| | | }, Func.toStrList(roleNames)));*/ |
| | | if (roleList != null && roleList.size() > 0) { |
| | | return (String) roleList.stream().map(role -> { |
| | | return Func.toStr(role.getId()); |
| | |
| | | |
| | | @Override // org.springblade.modules.system.service.IRoleService |
| | | public List<RoleVO> search(String roleName, Long parentId) { |
| | | Wrapper lambda = Wrappers.query().lambda(); |
| | | LambdaQueryWrapper<Role> lambda = Wrappers.<Role>query().lambda(); |
| | | |
| | | //Wrapper lambda = Wrappers.query().lambda(); |
| | | if (Func.isNotEmpty(roleName)) { |
| | | lambda.like((v0) -> { |
| | | return v0.getRoleName(); |