From 669c02c03d01f1b32b669bd6eaa7139aafaa2b53 Mon Sep 17 00:00:00 2001 From: OTTO <731554297@qq.com> Date: Tue, 23 Jan 2024 16:03:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9F=BA=E7=A1=80=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA):=20=E6=94=B9=E9=80=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、菜单表和角色表增加组织类型字段,用于隔离特色专区和项目管理 2、用户仅能查看到相同组织类型下的角色及菜单 --- .../com/ruoyi/system/api/domain/SysRole.java | 5 + .../datascope/aspect/DataScopeAspect.java | 10 +- .../java/com/ruoyi/system/domain/SysMenu.java | 172 +----- .../ruoyi/system/mapper/SysMenuMapper.java | 10 +- .../service/impl/SysMenuServiceImpl.java | 5 + .../service/impl/SysRoleServiceImpl.java | 6 + .../resources/mapper/system/SysMenuMapper.xml | 539 ++++++++++-------- .../resources/mapper/system/SysRoleMapper.xml | 7 +- ...144403_alert_role_and_menu_add_dept_id.sql | 19 + 9 files changed, 362 insertions(+), 411 deletions(-) create mode 100644 sql/update/20240123144403_alert_role_and_menu_add_dept_id.sql diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java index 5f342cfd3..5435623df 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysRole.java @@ -62,6 +62,11 @@ public class SysRole extends BaseEntity /** 部门组(数据权限) */ private Long[] deptIds; + /** + * 组织类型 + */ + private Integer deptType; + /** 角色菜单权限 */ private Set permissions; diff --git a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java index c8924a8e0..93ccb3214 100644 --- a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java +++ b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java @@ -148,22 +148,24 @@ public class DataScopeAspect */ public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, SysUserDeptRole userIdentify, String deptAlias, String userAlias, String permission) { StringBuilder sqlString = new StringBuilder(); + boolean openDataScopeJoin = false; SysRole sysRole = userIdentify.getSysRole(); if (sysRole != null) { - if (DATA_SCOPE_DEPT_AND_CHILD.equals(sysRole.getDataScope()) && StringUtils.isNotEmpty(deptAlias)) { + if (StringUtils.isNotEmpty(deptAlias)) { //用户所在组织应该为当前登录身份的组织 Long deptId = userIdentify.getDeptId(); //获取当前登录身份所在组织及组织以下数据权限 sqlString.append(StringUtils.format( " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, deptId, deptId)); - execSql(joinPoint, sqlString, false); - } else if (DATA_SCOPE_SELF.equals(sysRole.getDataScope()) && StringUtils.isNotEmpty(userAlias)) { + } + if (DATA_SCOPE_SELF.equals(sysRole.getDataScope()) && StringUtils.isNotEmpty(userAlias)) { sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); - execSql(joinPoint, sqlString, true); + openDataScopeJoin = true; } } + execSql(joinPoint, sqlString, openDataScopeJoin); } private static void execSql(JoinPoint joinPoint, StringBuilder sqlString, Boolean openDataScopeJoin) { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMenu.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMenu.java index 0d674d769..69060c21b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMenu.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysMenu.java @@ -1,19 +1,21 @@ package com.ruoyi.system.domain; -import java.util.ArrayList; -import java.util.List; +import com.ruoyi.common.core.web.domain.BaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.core.web.domain.BaseEntity; +import java.util.ArrayList; +import java.util.List; /** * 菜单权限表 sys_menu * * @author ruoyi */ +@Data public class SysMenu extends BaseEntity { private static final long serialVersionUID = 1L; @@ -63,19 +65,15 @@ public class SysMenu extends BaseEntity /** 菜单图标 */ private String icon; + /** + * 组织类型 + */ + @ApiModelProperty("组织类型") + private Integer deptType; + /** 子菜单 */ private List children = new ArrayList(); - public Long getMenuId() - { - return menuId; - } - - public void setMenuId(Long menuId) - { - this.menuId = menuId; - } - @NotBlank(message = "菜单名称不能为空") @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符") public String getMenuName() @@ -83,177 +81,33 @@ public class SysMenu extends BaseEntity return menuName; } - public void setMenuName(String menuName) - { - this.menuName = menuName; - } - - public String getParentName() - { - return parentName; - } - - public void setParentName(String parentName) - { - this.parentName = parentName; - } - - public Long getParentId() - { - return parentId; - } - - public void setParentId(Long parentId) - { - this.parentId = parentId; - } - @NotNull(message = "显示顺序不能为空") public Integer getOrderNum() { return orderNum; } - public void setOrderNum(Integer orderNum) - { - this.orderNum = orderNum; - } - @Size(min = 0, max = 200, message = "路由地址不能超过200个字符") public String getPath() { return path; } - public void setPath(String path) - { - this.path = path; - } - @Size(min = 0, max = 200, message = "组件路径不能超过255个字符") public String getComponent() { return component; } - public void setComponent(String component) - { - this.component = component; - } - - public String getQuery() - { - return query; - } - - public void setQuery(String query) - { - this.query = query; - } - - public String getIsFrame() - { - return isFrame; - } - - public void setIsFrame(String isFrame) - { - this.isFrame = isFrame; - } - - public String getIsCache() - { - return isCache; - } - - public void setIsCache(String isCache) - { - this.isCache = isCache; - } - @NotBlank(message = "菜单类型不能为空") public String getMenuType() { return menuType; } - public void setMenuType(String menuType) - { - this.menuType = menuType; - } - - public String getVisible() - { - return visible; - } - - public void setVisible(String visible) - { - this.visible = visible; - } - - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符") public String getPerms() { return perms; } - - public void setPerms(String perms) - { - this.perms = perms; - } - - public String getIcon() - { - return icon; - } - - public void setIcon(String icon) - { - this.icon = icon; - } - - public List getChildren() - { - return children; - } - - public void setChildren(List children) - { - this.children = children; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("menuId", getMenuId()) - .append("menuName", getMenuName()) - .append("parentId", getParentId()) - .append("orderNum", getOrderNum()) - .append("path", getPath()) - .append("component", getComponent()) - .append("isFrame", getIsFrame()) - .append("IsCache", getIsCache()) - .append("menuType", getMenuType()) - .append("visible", getVisible()) - .append("status ", getStatus()) - .append("perms", getPerms()) - .append("icon", getIcon()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .toString(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 795fd06d1..f1b6e0505 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -16,7 +16,7 @@ public interface SysMenuMapper { /** * 查询系统菜单列表 - * + * * @param menu 菜单信息 * @return 菜单列表 */ @@ -60,14 +60,6 @@ public interface SysMenuMapper */ public List selectMenuTreeAll(); - /** - * 根据用户ID查询菜单 - * - * @param userId 用户ID - * @return 菜单列表 - */ - public List selectMenuTreeByUserId(Long userId); - /** * 根据角色ID查询菜单树信息 * diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 70be260fd..2140e7ec4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -69,6 +69,11 @@ public class SysMenuServiceImpl implements ISysMenuService } else { + // 根据用户当前身份获取组织类型 + SysUserDeptRole userIdentify = SecurityUtils.getUserIdentity(); + if (userIdentify != null && userIdentify.getSysDept() != null) { + menu.setDeptType(userIdentify.getSysDept().getDeptType()); + } menu.getParams().put("userId", userId); menuList = menuMapper.selectMenuListByUserId(menu); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index d308b9c90..96230c990 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -8,6 +8,7 @@ import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysRole; import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.domain.SysUserDeptRole; import com.ruoyi.system.domain.SysRoleMenu; import com.ruoyi.system.mapper.SysDeptRoleMapper; import com.ruoyi.system.mapper.SysRoleMapper; @@ -49,6 +50,11 @@ public class SysRoleServiceImpl implements ISysRoleService { @Override public List selectRoleList(SysRole role) { + // 根据用户当前身份获取组织类型 + SysUserDeptRole userIdentify = SecurityUtils.getUserIdentity(); + if (userIdentify != null && userIdentify.getSysDept() != null) { + role.setDeptType(userIdentify.getSysDept().getDeptType()); + } return roleMapper.selectRoleList(role); } diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index bb2f4b4f0..05d72792a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -1,252 +1,317 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time - from sys_menu + + select menu_id, + menu_name, + parent_id, + order_num, + path, + component, + `query`, + is_frame, + is_cache, + menu_type, + visible, + status, + ifnull(perms, '') as perms, + icon, + create_time, + dept_type + from sys_menu - + + + select sm.menu_id, + sm.menu_name, + sm.parent_id, + sm.order_num, + sm.path, + sm.component, + sm.`query`, + sm.is_frame, + sm.is_cache, + sm.menu_type, + sm.visible, + sm.status, + ifnull(sm.perms, '') as perms, + sm.icon, + sm.create_time, + sm.dept_type + from sys_menu sm + + - - - - - - - - - - + + AND sm.visible = #{visible} + + + AND sm.status = #{status} + + + AND sm.dept_type = #{deptType} + + + order by sm.parent_id, sm.order_num + - - - - - + - select count(1) - from sys_menu - where parent_id = #{menuId} - + order by m.parent_id, m.order_num + - - + - - update sys_menu - - menu_name = #{menuName}, - parent_id = #{parentId}, - order_num = #{orderNum}, - path = #{path}, - component = #{component}, - `query` = #{query}, - is_frame = #{isFrame}, - is_cache = #{isCache}, - menu_type = #{menuType}, - visible = #{visible}, - status = #{status}, - perms = #{perms}, - icon = #{icon}, - remark = #{remark}, - update_by = #{updateBy}, - update_time = sysdate() - - where menu_id = #{menuId} - + - - insert into sys_menu( - menu_id, - parent_id, - menu_name, - order_num, - path, - component, - `query`, - is_frame, - is_cache, - menu_type, - visible, - status, - perms, - icon, - remark, - create_by, - create_time - )values( - #{menuId}, - #{parentId}, - #{menuName}, - #{orderNum}, - #{path}, - #{component}, - #{query}, - #{isFrame}, - #{isCache}, - #{menuType}, - #{visible}, - #{status}, - #{perms}, - #{icon}, - #{remark}, - #{createBy}, - sysdate() - ) - - - - delete from sys_menu where menu_id = #{menuId} - + + + + + + + + + + + + + + update sys_menu + + menu_name = #{menuName}, + parent_id = #{parentId}, + order_num = #{orderNum}, + path = #{path}, + component = #{component}, + `query` = #{query}, + is_frame = #{isFrame}, + is_cache = #{isCache}, + menu_type = #{menuType}, + visible = #{visible}, + status = #{status}, + perms = #{perms}, + icon = #{icon}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = sysdate() + + where menu_id = #{menuId} + + + + insert into sys_menu( + menu_id, + parent_id, + menu_name, + order_num, + path, + component, + `query`, + is_frame, + is_cache, + menu_type, + visible, + status, + perms, + icon, + remark, + create_by, + create_time + )values( + #{menuId}, + #{parentId}, + #{menuName}, + #{orderNum}, + #{path}, + #{component}, + #{query}, + #{isFrame}, + #{isCache}, + #{menuType}, + #{visible}, + #{status}, + #{perms}, + #{icon}, + #{remark}, + #{createBy}, + sysdate() + ) + + + + delete + from sys_menu + where menu_id = #{menuId} + + \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml index 6a054b373..6acb36468 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -19,6 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -35,6 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" r.create_by, r.update_by, r.update_time, + r.dept_type, r.remark from sys_role r @@ -68,8 +70,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') - - ${params.dataScope} + + AND r.dept_type = #{deptType} + order by r.role_sort diff --git a/sql/update/20240123144403_alert_role_and_menu_add_dept_id.sql b/sql/update/20240123144403_alert_role_and_menu_add_dept_id.sql new file mode 100644 index 000000000..c8584c145 --- /dev/null +++ b/sql/update/20240123144403_alert_role_and_menu_add_dept_id.sql @@ -0,0 +1,19 @@ +-- 菜单表和角色表增加组织Id字段,用于数据权限判断 +SET FOREIGN_KEY_CHECKS = 0; + +ALTER TABLE `sys_menu` + ADD COLUMN `dept_type` tinyint(4) NULL DEFAULT NULL COMMENT '组织类型'; + +ALTER TABLE `sys_role` + ADD COLUMN `dept_type` tinyint(4) NULL DEFAULT NULL COMMENT '组织类型'; +-- 当前菜单的组织类型均设置为特色专区 +UPDATE sys_menu +SET dept_type = 1; +-- 设置pms相关角色为项目管理、除admin外角色设置为特色专区 +UPDATE sys_role +SET dept_type = 1 +WHERE role_key != 'admin'; +UPDATE sys_role +SET dept_type = 2 +WHERE role_key LIKE 'pms%'; +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file