From 007ea604548969ffe1c9e986d23a6a5ff75098be Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Fri, 8 Sep 2023 16:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.0=E3=80=91=E3=80=90sys=E3=80=91?= =?UTF-8?q?=E3=80=90role=E3=80=91=E6=9D=83=E9=99=90=E9=99=90=E5=88=B6?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=EF=BC=9A=E7=BB=91=E5=AE=9A=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../role/service/impl/RoleBindOptionImpl.java | 82 +++++++++++++++++++ .../impl/SysRoleMenuOptionsServiceImpl.java | 30 +------ 2 files changed, 83 insertions(+), 29 deletions(-) create mode 100644 kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindOptionImpl.java diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindOptionImpl.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindOptionImpl.java new file mode 100644 index 000000000..0b4a8eb93 --- /dev/null +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/RoleBindOptionImpl.java @@ -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 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 wrapper = new LambdaUpdateWrapper<>(); + wrapper.eq(SysRoleLimit::getRoleId, roleId); + wrapper.eq(SysRoleLimit::getBusinessId, menuOptionId); + this.sysRoleLimitService.remove(wrapper); + } + + } + +} diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuOptionsServiceImpl.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuOptionsServiceImpl.java index 6fb344e6a..f7b8e507e 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuOptionsServiceImpl.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleMenuOptionsServiceImpl.java @@ -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 implements - SysRoleMenuOptionsService, RemoveRoleCallbackApi, RoleAssignOperateAction, RemoveMenuCallbackApi { + SysRoleMenuOptionsService, RemoveRoleCallbackApi, RemoveMenuCallbackApi { @Resource(name = "roleMenuOptionsCache") private CacheOperatorApi> roleMenuOptionsCache; @@ -129,30 +125,6 @@ public class SysRoleMenuOptionsServiceImpl extends ServiceImpl wrapper = new LambdaUpdateWrapper<>(); - wrapper.eq(SysRoleMenuOptions::getRoleId, roleId); - wrapper.eq(SysRoleMenuOptions::getMenuOptionId, menuOptionId); - this.remove(wrapper); - } - } - @Override public void removeMenuAction(Set beRemovedMenuIdList) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();