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 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.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.mapper.RoleMapper;
|
import com.qianwen.smartman.modules.system.service.IRoleMenuService;
|
import com.qianwen.smartman.modules.system.service.IRoleScopeService;
|
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
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/RoleServiceImpl.class */
|
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;
|
this.roleScopeService = roleScopeService;
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public IPage<RoleVO> selectRolePage(IPage<RoleVO> page, RoleVO role) {
|
return page.setRecords(((RoleMapper) this.baseMapper).selectRolePage(page, role));
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public List<RoleVO> tree(String tenantId) {
|
String userRole = AuthUtil.getUserRole();
|
String excludeRole = null;
|
if (!CollectionUtil.contains(Func.toStrArray(userRole), "admin") && !CollectionUtil.contains(Func.toStrArray(userRole), "administrator")) {
|
excludeRole = "admin";
|
}
|
return ForestNodeMerger.merge(((RoleMapper) this.baseMapper).tree(tenantId, excludeRole));
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds) {
|
grantRoleMenu(roleIds, menuIds);
|
grantDataScope(roleIds, dataScopeIds);
|
grantApiScope(roleIds, apiScopeIds);
|
return true;
|
}
|
|
private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) {
|
Long administratorCount = ((RoleMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getRoleAlias();
|
}, "administrator")).in((v0) -> {
|
return v0.getId();
|
}, roleIds));
|
if (!AuthUtil.isAdministrator() && administratorCount.longValue() > 0) {
|
throw new ServiceException("无权配置超管角色!");
|
}
|
Long adminCount = ((RoleMapper) this.baseMapper).selectCount((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
|
return v0.getRoleAlias();
|
}, "admin")).in((v0) -> {
|
return v0.getId();
|
}, roleIds));
|
if (!AuthUtil.isAdmin() && adminCount.longValue() > 0) {
|
throw new ServiceException("无权配置管理员角色!");
|
}
|
this.roleMenuService.remove((Wrapper) Wrappers.update().lambda().in((v0) -> {
|
return v0.getRoleId();
|
}, roleIds));
|
List<RoleMenu> roleMenus = new ArrayList<>();
|
roleIds.forEach(roleId -> {
|
menuIds.forEach(menuId -> {
|
RoleMenu roleMenu = new RoleMenu();
|
roleMenu.setRoleId(roleId);
|
roleMenu.setMenuId(menuId);
|
roleMenus.add(roleMenu);
|
});
|
});
|
this.roleMenuService.saveBatch(roleMenus);
|
recursionRoleMenu(roleIds, menuIds);
|
return true;
|
}
|
|
private void recursionRoleMenu(List<Long> roleIds, List<Long> menuIds) {
|
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);
|
}
|
});
|
});
|
}
|
|
private boolean grantDataScope(List<Long> roleIds, List<Long> dataScopeIds) {
|
this.roleScopeService.remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
|
return v0.getScopeCategory();
|
}, CommonConstant.DATA_SCOPE_CATEGORY)).in((v0) -> {
|
return v0.getRoleId();
|
}, roleIds));
|
List<RoleScope> roleDataScopes = new ArrayList<>();
|
roleIds.forEach(roleId -> {
|
dataScopeIds.forEach(scopeId -> {
|
RoleScope roleScope = new RoleScope();
|
roleScope.setScopeCategory(CommonConstant.DATA_SCOPE_CATEGORY);
|
roleScope.setRoleId(roleId);
|
roleScope.setScopeId(scopeId);
|
roleDataScopes.add(roleScope);
|
});
|
});
|
this.roleScopeService.saveBatch(roleDataScopes);
|
return true;
|
}
|
|
private boolean grantApiScope(List<Long> roleIds, List<Long> apiScopeIds) {
|
this.roleScopeService.remove((Wrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().eq((v0) -> {
|
return v0.getScopeCategory();
|
}, CommonConstant.API_SCOPE_CATEGORY)).in((v0) -> {
|
return v0.getRoleId();
|
}, roleIds));
|
List<RoleScope> roleApiScopes = new ArrayList<>();
|
roleIds.forEach(roleId -> {
|
apiScopeIds.forEach(scopeId -> {
|
RoleScope roleScope = new RoleScope();
|
roleScope.setScopeCategory(CommonConstant.API_SCOPE_CATEGORY);
|
roleScope.setScopeId(scopeId);
|
roleScope.setRoleId(roleId);
|
roleApiScopes.add(roleScope);
|
});
|
});
|
this.roleScopeService.saveBatch(roleApiScopes);
|
return true;
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public String getRoleIds(String tenantId, String 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)));
|
if (roleList != null && roleList.size() > 0) {
|
return (String) roleList.stream().map(role -> {
|
return Func.toStr(role.getId());
|
}).distinct().collect(Collectors.joining(","));
|
}
|
return null;
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public List<String> getRoleNames(String roleIds) {
|
return ((RoleMapper) this.baseMapper).getRoleNames(Func.toLongArray(roleIds));
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public List<String> getRoleAliases(String roleIds) {
|
return ((RoleMapper) this.baseMapper).getRoleAliases(Func.toLongArray(roleIds));
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public Role submit(Role role) {
|
if (!AuthUtil.isAdministrator() && Func.toStr(role.getRoleAlias()).equals("administrator")) {
|
throw new ServiceException("无权限创建超管角色!");
|
}
|
if (Func.isEmpty(role.getParentId())) {
|
role.setTenantId(AuthUtil.getTenantId());
|
role.setParentId(BladeConstant.TOP_PARENT_ID);
|
}
|
if (role.getParentId().longValue() > 0) {
|
Role parent = (Role) getById(role.getParentId());
|
if (Func.toLong(role.getParentId()) == Func.toLong(role.getId())) {
|
throw new ServiceException("父节点不可选择自身!");
|
}
|
role.setTenantId(parent.getTenantId());
|
}
|
role.setIsDeleted(0);
|
saveOrUpdate(role);
|
return role;
|
}
|
|
@Override // org.springblade.modules.system.service.IRoleService
|
public List<RoleVO> search(String roleName, Long parentId) {
|
Wrapper lambda = Wrappers.query().lambda();
|
if (Func.isNotEmpty(roleName)) {
|
lambda.like((v0) -> {
|
return v0.getRoleName();
|
}, roleName);
|
}
|
if (Func.isNotEmpty(parentId) && parentId.longValue() > BladeConstant.TOP_PARENT_ID.longValue()) {
|
lambda.eq((v0) -> {
|
return v0.getParentId();
|
}, parentId);
|
}
|
List<Role> roleList = ((RoleMapper) this.baseMapper).selectList(lambda);
|
return RoleWrapper.build().listNodeVO(roleList);
|
}
|
}
|