【8.0】【sys】【role】权限限制绑定:绑定菜单功能

pull/57/head
fengshuonan 2023-09-08 16:28:08 +08:00
parent 6af917f7b4
commit 007ea60454
2 changed files with 83 additions and 29 deletions

View File

@ -0,0 +1,82 @@
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleBindLimitAction;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleLimit;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenuOptions;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.PermissionNodeTypeEnum;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.RoleLimitTypeEnum;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleLimitService;
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuOptionsService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
*
*
* @author fengshuonan
* @since 2023/9/8 16:12
*/
@Service
public class RoleBindOptionImpl implements RoleAssignOperateAction, RoleBindLimitAction {
@Resource
private SysRoleMenuOptionsService sysRoleMenuOptionsService;
@Resource
private SysRoleLimitService sysRoleLimitService;
@Override
public PermissionNodeTypeEnum getNodeType() {
return PermissionNodeTypeEnum.OPTIONS;
}
@Override
public void doOperateAction(RoleBindPermissionRequest roleBindPermissionRequest) {
Long roleId = roleBindPermissionRequest.getRoleId();
Long menuOptionId = roleBindPermissionRequest.getNodeId();
if (roleBindPermissionRequest.getChecked()) {
SysRoleMenuOptions sysRoleMenuOptions = new SysRoleMenuOptions();
sysRoleMenuOptions.setRoleId(roleId);
sysRoleMenuOptions.setMenuOptionId(menuOptionId);
this.sysRoleMenuOptionsService.save(sysRoleMenuOptions);
} else {
LambdaUpdateWrapper<SysRoleMenuOptions> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(SysRoleMenuOptions::getRoleId, roleId);
wrapper.eq(SysRoleMenuOptions::getMenuOptionId, menuOptionId);
this.sysRoleMenuOptionsService.remove(wrapper);
}
}
@Override
public PermissionNodeTypeEnum getRoleBindLimitNodeType() {
return this.getNodeType();
}
@Override
public void doRoleBindLimitAction(RoleBindPermissionRequest roleBindPermissionRequest) {
Long roleId = roleBindPermissionRequest.getRoleId();
Long menuOptionId = roleBindPermissionRequest.getNodeId();
if (roleBindPermissionRequest.getChecked()) {
SysRoleLimit sysRoleLimit = new SysRoleLimit();
sysRoleLimit.setRoleId(roleId);
sysRoleLimit.setLimitType(RoleLimitTypeEnum.MENU_OPTIONS.getCode());
sysRoleLimit.setBusinessId(menuOptionId);
this.sysRoleLimitService.save(sysRoleLimit);
} else {
LambdaUpdateWrapper<SysRoleLimit> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(SysRoleLimit::getRoleId, roleId);
wrapper.eq(SysRoleLimit::getBusinessId, menuOptionId);
this.sysRoleLimitService.remove(wrapper);
}
}
}

View File

@ -8,14 +8,10 @@ import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenuOptions;
import cn.stylefeng.roses.kernel.sys.modular.role.action.RoleAssignOperateAction;
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleMenuOptions;
import cn.stylefeng.roses.kernel.sys.modular.role.enums.PermissionNodeTypeEnum;
import cn.stylefeng.roses.kernel.sys.modular.role.mapper.SysRoleMenuOptionsMapper;
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuOptionsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -34,7 +30,7 @@ import java.util.stream.Collectors;
*/
@Service
public class SysRoleMenuOptionsServiceImpl extends ServiceImpl<SysRoleMenuOptionsMapper, SysRoleMenuOptions> implements
SysRoleMenuOptionsService, RemoveRoleCallbackApi, RoleAssignOperateAction, RemoveMenuCallbackApi {
SysRoleMenuOptionsService, RemoveRoleCallbackApi, RemoveMenuCallbackApi {
@Resource(name = "roleMenuOptionsCache")
private CacheOperatorApi<List<Long>> roleMenuOptionsCache;
@ -129,30 +125,6 @@ public class SysRoleMenuOptionsServiceImpl extends ServiceImpl<SysRoleMenuOption
this.remove(wrapper);
}
@Override
public PermissionNodeTypeEnum getNodeType() {
return PermissionNodeTypeEnum.OPTIONS;
}
@Override
public void doOperateAction(RoleBindPermissionRequest roleBindPermissionRequest) {
Long roleId = roleBindPermissionRequest.getRoleId();
Long menuOptionId = roleBindPermissionRequest.getNodeId();
if (roleBindPermissionRequest.getChecked()) {
SysRoleMenuOptions sysRoleMenuOptions = new SysRoleMenuOptions();
sysRoleMenuOptions.setRoleId(roleId);
sysRoleMenuOptions.setMenuOptionId(menuOptionId);
this.save(sysRoleMenuOptions);
} else {
LambdaUpdateWrapper<SysRoleMenuOptions> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(SysRoleMenuOptions::getRoleId, roleId);
wrapper.eq(SysRoleMenuOptions::getMenuOptionId, menuOptionId);
this.remove(wrapper);
}
}
@Override
public void removeMenuAction(Set<Long> beRemovedMenuIdList) {
LambdaQueryWrapper<SysRoleMenuOptions> queryWrapper = new LambdaQueryWrapper<>();