From a9dba08a8d8bb58829620537f8ecd1c97ee9851e Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Wed, 6 Mar 2024 16:19:51 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=903.6.3=E7=89=88=E6=9C=AC=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E3=80=91=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/api/CommonAPI.java | 4 +- .../org/jeecg/config/shiro/ShiroRealm.java | 4 +- .../jeecg/common/system/api/ISysBaseAPI.java | 22 +--- .../api/fallback/SysBaseAPIFallback.java | 17 +-- .../jeecg/common/system/api/ISysBaseAPI.java | 19 +-- .../api/controller/SystemApiController.java | 14 +-- .../system/mapper/xml/SysDictMapper.xml | 22 ++++ .../system/mapper/xml/SysPermissionMapper.xml | 118 +++++++++++++----- 8 files changed, 132 insertions(+), 88 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java index 516cc60d..1c68bc15 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java @@ -22,10 +22,10 @@ public interface CommonAPI { /** * 2查询用户权限信息 - * @param username + * @param userId * @return */ - Set queryUserAuths(String username); + Set queryUserAuths(String userId); /** * 3根据 id 查询数据库中存储的 DynamicDataSourceModel diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java index cde97b8d..5aa048de 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroRealm.java @@ -62,9 +62,11 @@ public class ShiroRealm extends AuthorizingRealm { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { log.debug("===============Shiro权限认证开始============ [ roles、permissions]=========="); String username = null; + String userId = null; if (principals != null) { LoginUser sysUser = (LoginUser) principals.getPrimaryPrincipal(); username = sysUser.getUsername(); + userId = sysUser.getId(); } SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); @@ -74,7 +76,7 @@ public class ShiroRealm extends AuthorizingRealm { info.setRoles(roleSet); // 设置用户拥有的权限集合,比如“sys:role:add,sys:user:add” - Set permissionSet = commonApi.queryUserAuths(username); + Set permissionSet = commonApi.queryUserAuths(userId); info.addStringPermissions(permissionSet); //System.out.println(permissionSet); log.info("===============Shiro权限认证成功=============="); diff --git a/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java b/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java index a4e669f1..b11095ef 100644 --- a/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java +++ b/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java @@ -307,11 +307,11 @@ public interface ISysBaseAPI extends CommonAPI { /** * 31获取用户的权限集合 - * @param username + * @param userId * @return */ @GetMapping("/sys/api/getUserPermissionSet") - Set getUserPermissionSet(@RequestParam("username") String username); + Set getUserPermissionSet(@RequestParam("userId") String userId); /** * 32判断是否有online访问的权限 @@ -351,12 +351,12 @@ public interface ISysBaseAPI extends CommonAPI { /** * 36查询用户权限信息 - * @param username + * @param userId * @return */ @Override @GetMapping("/sys/api/queryUserAuths") - Set queryUserAuths(@RequestParam("username")String username); + Set queryUserAuths(@RequestParam("userId")String userId); /** * 37根据 id 查询数据库中存储的 DynamicDataSourceModel @@ -611,20 +611,6 @@ public interface ISysBaseAPI extends CommonAPI { @PostMapping("/sys/api/saveDataLog") void saveDataLog(DataLogDTO dataLogDto); - /** - * 添加文件到知识库 - * @param sysFilesModel - */ - @PostMapping("/sys/api/addSysFiles") - void addSysFiles(SysFilesModel sysFilesModel); - - /** - * 通过文件路径获取文件id - * @param fileId - */ - @GetMapping("/sys/api/getFileUrl") - String getFileUrl(@RequestParam(name="fileId") String fileId); - /** * 更新头像 * @param loginUser diff --git a/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java b/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java index 90b61689..ec04e226 100644 --- a/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java +++ b/jeecg-module-system/jeecg-system-api/jeecg-system-cloud-api/src/main/java/org/jeecg/common/system/api/fallback/SysBaseAPIFallback.java @@ -71,7 +71,7 @@ public class SysBaseAPIFallback implements ISysBaseAPI { } @Override - public Set getDepartParentIdsByDepIds(Set depIds) { + public Set getDepartParentIdsByDepIds(Set depIds) { return null; } @@ -194,7 +194,7 @@ public class SysBaseAPIFallback implements ISysBaseAPI { } @Override - public Set getUserPermissionSet(String username) { + public Set getUserPermissionSet(String userId) { return null; } @@ -219,7 +219,7 @@ public class SysBaseAPIFallback implements ISysBaseAPI { } @Override - public Set queryUserAuths(String username) { + public Set queryUserAuths(String userId) { return null; } @@ -361,17 +361,6 @@ public class SysBaseAPIFallback implements ISysBaseAPI { return null; } - - @Override - public void addSysFiles(SysFilesModel sysFilesModel) { - - } - - @Override - public String getFileUrl(String fileId) { - return null; - } - @Override public void updateAvatar(LoginUser loginUser) { } diff --git a/jeecg-module-system/jeecg-system-api/jeecg-system-local-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java b/jeecg-module-system/jeecg-system-api/jeecg-system-local-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java index 63b72406..b5a27223 100644 --- a/jeecg-module-system/jeecg-system-api/jeecg-system-local-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java +++ b/jeecg-module-system/jeecg-system-api/jeecg-system-local-api/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java @@ -101,7 +101,7 @@ public interface ISysBaseAPI extends CommonAPI { * @param depIds * @return 部门 parentIds */ - Set getDepartParentIdsByDepIds(Set depIds); + Set getDepartParentIdsByDepIds(Set depIds); /** * 9通过用户账号查询部门 name @@ -302,10 +302,10 @@ public interface ISysBaseAPI extends CommonAPI { /** * 32获取用户的权限集合 - * @param username + * @param userId * @return */ - Set getUserPermissionSet(String username); + Set getUserPermissionSet(String userId); /** * 33判断是否有online访问的权限 @@ -445,19 +445,6 @@ public interface ISysBaseAPI extends CommonAPI { * @param dataLogDto */ void saveDataLog(DataLogDTO dataLogDto); - - /** - * 添加文件到知识库 - * @param sysFilesModel - */ - void addSysFiles(SysFilesModel sysFilesModel); - - /** - * 通过文件路径获取文件id - * @param fileId - */ - String getFileUrl(String fileId); - /** * 更新头像 * @param loginUser diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java index b155b04e..d3cd007d 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java @@ -156,7 +156,7 @@ public class SystemApiController { * @return 部门 id */ @GetMapping("/getDepartParentIdsByDepIds") - Set getDepartParentIdsByDepIds(@RequestParam("depIds") Set depIds){ + Set getDepartParentIdsByDepIds(@RequestParam("depIds") Set depIds){ return sysBaseApi.getDepartParentIdsByDepIds(depIds); } @@ -386,12 +386,12 @@ public class SystemApiController { /** * 获取用户的权限集合 - * @param username + * @param userId 用户表ID * @return */ @GetMapping("/getUserPermissionSet") - public Set getUserPermissionSet(@RequestParam("username") String username){ - return sysBaseApi.getUserPermissionSet(username); + public Set getUserPermissionSet(@RequestParam("userId") String userId){ + return sysBaseApi.getUserPermissionSet(userId); } //----- @@ -419,12 +419,12 @@ public class SystemApiController { /** * 查询用户权限信息 - * @param username + * @param userId * @return */ @GetMapping("/queryUserAuths") - public Set queryUserAuths(@RequestParam("username") String username){ - return sysUserService.getUserPermissionsSet(username); + public Set queryUserAuths(@RequestParam("userId") String userId){ + return sysUserService.getUserPermissionsSet(userId); } /** diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml index f26397a1..ae0c60ae 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/SysDictMapper.xml @@ -63,6 +63,28 @@ ) + + + SELECT * FROM ( - SELECT p.* + SELECT p.id, + p.parent_id, + p.name, + p.url, + p.component, + p.is_route, + p.component_name, + p.redirect, + p.menu_type, + p.perms, + p.perms_type, + p.sort_no, + p.always_show, + p.icon, + p.is_leaf, + p.keep_alive, + p.hidden, + p.hide_tab, + p.rule_flag, + p.status, + p.internal_or_external FROM sys_permission p - WHERE (exists( - select a.id from sys_role_permission a - join sys_role b on a.role_id = b.id - join sys_user_role c on c.role_id = b.id - join sys_user d on d.id = c.user_id - where p.id = a.permission_id AND d.username = #{username,jdbcType=VARCHAR} + WHERE p.del_flag = 0 + AND ( p.id in ( + SELECT DISTINCT a.permission_id + FROM sys_role_permission a + JOIN sys_role b ON a.role_id = b.id + JOIN sys_user_role c ON c.role_id = b.id AND c.user_id = #{userId,jdbcType=VARCHAR} ) or (p.url like '%:code' and p.url like '/online%' and p.hidden = 1) or (p.url like '%:id' and p.url like '/online%' and p.hidden = 1) - or p.url = '/online') - and p.del_flag = 0 + or p.url = '/online' + ) UNION - SELECT p.* - FROM sys_permission p - WHERE exists( - select a.id from sys_depart_role_permission a - join sys_depart_role b on a.role_id = b.id - join sys_depart_role_user c on c.drole_id = b.id - join sys_user d on d.id = c.user_id - where p.id = a.permission_id AND d.username = #{username,jdbcType=VARCHAR} - ) + SELECT p.id, + p.parent_id, + p.name, + p.url, + p.component, + p.is_route, + p.component_name, + p.redirect, + p.menu_type, + p.perms, + p.perms_type, + p.sort_no, + p.always_show, + p.icon, + p.is_leaf, + p.keep_alive, + p.hidden, + p.hide_tab, + p.rule_flag, + p.status, + p.internal_or_external + FROM sys_permission p + WHERE p.id in( + SELECT DISTINCT a.permission_id + FROM sys_depart_role_permission a + INNER JOIN sys_depart_role b ON a.role_id = b.id + INNER JOIN sys_depart_role_user c ON c.drole_id = b.id AND c.user_id = #{userId,jdbcType=VARCHAR} + ) and p.del_flag = 0 - UNION - SELECT p.* - FROM sys_permission p - WHERE exists( - select a.id from sys_tenant_pack_perms a - join sys_tenant_pack b on a.pack_id = b.id - join sys_tenant_pack_user c on c.pack_id = b.id - join sys_user d on d.id = c.user_id - where p.id = a.permission_id AND d.username = #{username,jdbcType=VARCHAR} - ) - and p.del_flag = 0 - + UNION + SELECT p.id, + p.parent_id, + p.name, + p.url, + p.component, + p.is_route, + p.component_name, + p.redirect, + p.menu_type, + p.perms, + p.perms_type, + p.sort_no, + p.always_show, + p.icon, + p.is_leaf, + p.keep_alive, + p.hidden, + p.hide_tab, + p.rule_flag, + p.status, + p.internal_or_external + FROM sys_permission p + WHERE p.id in ( + SELECT distinct a.permission_id + FROM sys_tenant_pack_perms a + INNER JOIN sys_tenant_pack b ON a.pack_id = b.id AND b.STATUS = '1' + INNER JOIN sys_tenant_pack_user c ON c.pack_id = b.id AND c.STATUS = '1' AND c.user_id = #{userId,jdbcType=VARCHAR} + ) + and p.del_flag = 0 + ) h order by h.sort_no ASC