diff --git a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyDataPermissionHandler.java b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyDataPermissionHandler.java index 361b8aa973643fdc7e52957cd5a0024edb9c85aa..12aaeb343399e357cf4934af8481b79441488aa1 100644 --- a/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyDataPermissionHandler.java +++ b/youlai-common/common-mybatis/src/main/java/com/youlai/common/mybatis/handler/MyDataPermissionHandler.java @@ -56,6 +56,7 @@ public class MyDataPermissionHandler implements DataPermissionHandler { * @param where 当前查询条件 * @return 构建后查询条件 */ + @SneakyThrows public static Expression dataScopeFilter(String deptAlias, String userAlias, Expression where) { @@ -69,20 +70,15 @@ public class MyDataPermissionHandler implements DataPermissionHandler { userColumnName = userAlias + "." + USER_ID_COLUMN_NAME; } - // 获取当前用户的数据权限 Integer dataScope = SecurityUtils.getDataScope(); - DataScopeEnum dataScopeEnum = IBaseEnum.getEnumByValue(dataScope, DataScopeEnum.class); - Long deptId = null, userId = null; + Long deptId, userId; String appendSqlStr = null; - switch (dataScopeEnum) { - case DEPT_AND_SUB: - deptId = SecurityUtils.getDeptId(); - appendSqlStr = deptColumnName + " IN ( SELECT id FROM sys_dept WHERE id = " + deptId + " or find_in_set( " + deptId + " , tree_path ) )"; + case ALL: break; case DEPT: deptId = SecurityUtils.getDeptId(); @@ -92,15 +88,16 @@ public class MyDataPermissionHandler implements DataPermissionHandler { userId = SecurityUtils.getUserId(); appendSqlStr = userColumnName + "=" + userId; break; + // 默认部门及子部门数据权限 + default: + deptId = SecurityUtils.getDeptId(); + appendSqlStr = deptColumnName + " IN ( SELECT id FROM sys_dept WHERE id = " + deptId + " or find_in_set( " + deptId + " , tree_path ) )"; + break; } Expression appendExpression = null; if (StrUtil.isNotBlank(appendSqlStr)) { - try { - appendExpression = CCJSqlParserUtil.parseCondExpression(appendSqlStr); - } catch (JSQLParserException e) { - throw new RuntimeException(e); - } + appendExpression = CCJSqlParserUtil.parseCondExpression(appendSqlStr); } if (appendExpression == null) { diff --git a/youlai-system/system-api/src/main/java/com/youlai/system/dto/UserAuthInfo.java b/youlai-system/system-api/src/main/java/com/youlai/system/dto/UserAuthInfo.java index 13a2bad797bf3ddae97b930831dc455e1f1ca3d8..eccbe120a3600f1a11c3712c2c51e1d00baa3c5b 100644 --- a/youlai-system/system-api/src/main/java/com/youlai/system/dto/UserAuthInfo.java +++ b/youlai-system/system-api/src/main/java/com/youlai/system/dto/UserAuthInfo.java @@ -52,6 +52,6 @@ public class UserAuthInfo { /** * 数据权限范围 */ - private Set dataScopes; + private Integer dataScope; } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/pojo/service/impl/SysUserServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/pojo/service/impl/SysUserServiceImpl.java index 0fbe3fb1ca3424638f109d6389febbdd8f3a7443..bbf009b9a8841d9099d711021c12f85f8fd4b422 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/pojo/service/impl/SysUserServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/pojo/service/impl/SysUserServiceImpl.java @@ -26,6 +26,7 @@ import com.youlai.system.pojo.bo.UserFormBO; import com.youlai.system.pojo.bo.UserBO; import com.youlai.system.pojo.query.UserPageQuery; import com.youlai.system.pojo.service.SysMenuService; +import com.youlai.system.pojo.service.SysRoleService; import com.youlai.system.pojo.service.SysUserRoleService; import com.youlai.system.pojo.vo.user.UserLoginVO; import com.youlai.system.pojo.vo.user.UserExportVO; @@ -61,8 +62,10 @@ public class SysUserServiceImpl extends ServiceImpl impl private final SysUserRoleService userRoleService; private final UserImportListener userImportListener; private final UserConverter userConverter; - private final SysMenuService menuService; + + private final SysRoleService roleService; + /** * 获取用户分页列表 * @@ -212,6 +215,13 @@ public class SysUserServiceImpl extends ServiceImpl impl if(CollectionUtil.isNotEmpty(roles)){ Set perms = menuService.listRolePerms(roles); userAuthInfo.setPerms(perms); + + // 根据角色获取范围最大的数据权限 + + Integer dataScope= + + + } return userAuthInfo; } diff --git a/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml b/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml index b45dd762658f7fc4ab3f0b9c31410844c4dea054..b841abe0721f94830fabf9f8ad487d25653626da 100644 --- a/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml +++ b/youlai-system/system-boot/src/main/resources/mapper/SysUserMapper.xml @@ -86,9 +86,6 @@ - - - @@ -100,8 +97,7 @@ t1.PASSWORD, t1.STATUS, t1.dept_id deptId, - t3.CODE roleCode, - t3.data_scope dataScope + t3.CODE roleCode FROM sys_user t1 LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id