From 3e194c0902c307b0cfa2ec14bf303310eb1fb6e9 Mon Sep 17 00:00:00 2001
From: wl <173@qq.com>
Date: 星期三, 26 十月 2022 16:52:35 +0800
Subject: [PATCH] 解决用户权限问题

---
 ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java      |   18 ++++-----
 ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java               |    3 +
 ycl-common/src/main/java/com/ycl/service/user/UmsAdminCacheService.java          |    5 +-
 ycl-platform/src/main/java/com/ycl/config/YclSecurityConfig.java                 |   10 +++--
 ycl-common/src/main/java/com/ycl/bo/AdminUserDetails.java                        |   11 +++--
 ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminCacheServiceImpl.java |    9 ++--
 ycl-platform/src/main/resources/application.yml                                  |    2 
 ycl-platform/src/main/resources/mapper/caseHandler/DisposeRecordMapper.xml       |    4 +-
 8 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/ycl-common/src/main/java/com/ycl/bo/AdminUserDetails.java b/ycl-common/src/main/java/com/ycl/bo/AdminUserDetails.java
index b1a6671..4f8975b 100644
--- a/ycl-common/src/main/java/com/ycl/bo/AdminUserDetails.java
+++ b/ycl-common/src/main/java/com/ycl/bo/AdminUserDetails.java
@@ -1,7 +1,7 @@
 package com.ycl.bo;
 
 import com.ycl.entity.user.UmsAdmin;
-import com.ycl.entity.user.UmsResource;
+import com.ycl.entity.user.UmsMenu;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.userdetails.UserDetails;
@@ -15,8 +15,9 @@
  */
 public class AdminUserDetails implements UserDetails {
     private UmsAdmin umsAdmin;
-    private List<UmsResource> resourceList;
-    public AdminUserDetails(UmsAdmin umsAdmin, List<UmsResource> resourceList) {
+    private List<UmsMenu> resourceList;
+
+    public AdminUserDetails(UmsAdmin umsAdmin, List<UmsMenu> resourceList) {
         this.umsAdmin = umsAdmin;
         this.resourceList = resourceList;
     }
@@ -25,7 +26,7 @@
     public Collection<? extends GrantedAuthority> getAuthorities() {
         //杩斿洖褰撳墠鐢ㄦ埛鐨勮鑹�
         return resourceList.stream()
-                .map(role ->new SimpleGrantedAuthority(role.getId()+":"+role.getName()))
+                .map(role -> new SimpleGrantedAuthority(role.getId() + ":" + role.getTitle()))
                 .collect(Collectors.toList());
     }
 
@@ -59,7 +60,7 @@
         return umsAdmin.getStatus().equals(1);
     }
 
-    public Long getUserId(){
+    public Long getUserId() {
         return umsAdmin.getId();
     }
 }
diff --git a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminCacheService.java b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminCacheService.java
index fbcf0b5..73b257b 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminCacheService.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminCacheService.java
@@ -4,6 +4,7 @@
 
 
 import com.ycl.entity.user.UmsAdmin;
+import com.ycl.entity.user.UmsMenu;
 import com.ycl.entity.user.UmsResource;
 
 import java.util.List;
@@ -50,12 +51,12 @@
     /**
      * 鑾峰彇缂撳瓨鍚庡彴鐢ㄦ埛璧勬簮鍒楄〃
      */
-    List<UmsResource> getResourceList(Long adminId);
+    List<UmsMenu> getResourceList(Long adminId);
 
     /**
      * 璁剧疆鍚庡彴鍚庡彴鐢ㄦ埛璧勬簮鍒楄〃
      */
-    void setResourceList(Long adminId, List<UmsResource> resourceList);
+    void setResourceList(Long adminId, List<UmsMenu> umsMenuList);
 
     /**
      * 鎵归噺鍒犻櫎缂撳瓨鐢ㄦ埛
diff --git a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
index 3e2cc03..5f23c20 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/UmsAdminService.java
@@ -6,6 +6,7 @@
 import com.ycl.dto.UmsAdminParam;
 import com.ycl.dto.UpdateAdminPasswordParam;
 import com.ycl.entity.user.UmsAdmin;
+import com.ycl.entity.user.UmsMenu;
 import com.ycl.entity.user.UmsResource;
 import com.ycl.entity.user.UmsRole;
 import com.ycl.vo.user.UserVO;
@@ -72,7 +73,7 @@
     /**
      * 鑾峰彇鎸囧畾鐢ㄦ埛鐨勫彲璁块棶璧勬簮
      */
-    List<UmsResource> getResourceList(Long adminId);
+    List<UmsMenu> getResourceList(Long adminId);
 
     /**
      * 淇敼瀵嗙爜
diff --git a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminCacheServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminCacheServiceImpl.java
index 39a9145..9e1a4cb 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminCacheServiceImpl.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminCacheServiceImpl.java
@@ -5,6 +5,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ycl.entity.user.UmsAdmin;
 import com.ycl.entity.user.UmsAdminRoleRelation;
+import com.ycl.entity.user.UmsMenu;
 import com.ycl.entity.user.UmsResource;
 import com.ycl.mapper.user.UmsAdminMapper;
 import com.ycl.service.redis.RedisService;
@@ -106,18 +107,18 @@
     }
 
     @Override
-    public List<UmsResource> getResourceList(Long adminId) {
+    public List<UmsMenu> getResourceList(Long adminId) {
         String key = REDIS_DATABASE + ":" + REDIS_KEY_RESOURCE_LIST + ":" + adminId;
         String s = (String) redisService.get(key);
 //        return (List<UmsResource>) redisService.get(key);
-        List<UmsResource> umsResources = JSON.parseArray(s, UmsResource.class);
+        List<UmsMenu> umsResources = JSON.parseArray(s, UmsMenu.class);
         return umsResources;
     }
 
     @Override
-    public void setResourceList(Long adminId, List<UmsResource> resourceList) {
+    public void setResourceList(Long adminId, List<UmsMenu> menuList) {
         String key = REDIS_DATABASE + ":" + REDIS_KEY_RESOURCE_LIST + ":" + adminId;
-        redisService.set(key, JSON.toJSONString(resourceList), REDIS_EXPIRE);
+        redisService.set(key, JSON.toJSONString(menuList), REDIS_EXPIRE);
     }
 
     @Override
diff --git a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
index bb6d7fe..c2748d6 100644
--- a/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
+++ b/ycl-common/src/main/java/com/ycl/service/user/impl/UmsAdminServiceImpl.java
@@ -288,16 +288,14 @@
     }
 
     @Override
-    public List<UmsResource> getResourceList(Long adminId) {
-        List<UmsResource> resourceList = getCacheService().getResourceList(adminId);
-        if (CollUtil.isNotEmpty(resourceList)) {
-            return resourceList;
+    public List<UmsMenu> getResourceList(Long adminId) {
+        List<UmsMenu> umsMenuList = getCacheService().getResourceList(adminId);
+        if (CollUtil.isNotEmpty(umsMenuList)) {
+            return umsMenuList;
         }
-        resourceList = umsResourceMapper.getResourceList(adminId);
-        if (CollUtil.isNotEmpty(resourceList)) {
-            getCacheService().setResourceList(adminId, resourceList);
-        }
-        return resourceList;
+        umsMenuList = umsMenuMapper.getMenuList(adminId);
+            getCacheService().setResourceList(adminId, umsMenuList);
+        return umsMenuList;
     }
 
     @Override
@@ -328,7 +326,7 @@
         //鑾峰彇鐢ㄦ埛淇℃伅
         UmsAdmin admin = getAdminByUsername(username);
         if (admin != null) {
-            List<UmsResource> resourceList = getResourceList(admin.getId());
+            List<UmsMenu> resourceList = getResourceList(admin.getId());
             return new AdminUserDetails(admin, resourceList);
         }
         throw new UsernameNotFoundException("鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒");
diff --git a/ycl-platform/src/main/java/com/ycl/config/YclSecurityConfig.java b/ycl-platform/src/main/java/com/ycl/config/YclSecurityConfig.java
index b5d2bfb..d41c7e5 100644
--- a/ycl-platform/src/main/java/com/ycl/config/YclSecurityConfig.java
+++ b/ycl-platform/src/main/java/com/ycl/config/YclSecurityConfig.java
@@ -1,8 +1,10 @@
 package com.ycl.config;
 
 import com.ycl.component.DynamicSecurityService;
+import com.ycl.entity.user.UmsMenu;
 import com.ycl.entity.user.UmsResource;
 import com.ycl.service.user.UmsAdminService;
+import com.ycl.service.user.UmsMenuService;
 import com.ycl.service.user.UmsResourceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
@@ -24,7 +26,7 @@
     @Autowired
     private UmsAdminService adminService;
     @Autowired
-    private UmsResourceService resourceService;
+    private UmsMenuService umsMenuService;
 
     @Bean
     public UserDetailsService userDetailsService() {
@@ -38,9 +40,9 @@
             @Override
             public Map<String, ConfigAttribute> loadDataSource() {
                 Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
-                List<UmsResource> resourceList = resourceService.list();
-                for (UmsResource resource : resourceList) {
-                    map.put(resource.getUrl(), new org.springframework.security.access.SecurityConfig(resource.getId() + ":" + resource.getName()));
+                List<UmsMenu> resourceList = umsMenuService.list();
+                for (UmsMenu resource : resourceList) {
+                    map.put(resource.getTitle(), new org.springframework.security.access.SecurityConfig(resource.getId() + ":" + resource.getTitle()));
                 }
                 return map;
             }
diff --git a/ycl-platform/src/main/resources/application.yml b/ycl-platform/src/main/resources/application.yml
index 4e81bc2..e44a192 100644
--- a/ycl-platform/src/main/resources/application.yml
+++ b/ycl-platform/src/main/resources/application.yml
@@ -36,7 +36,7 @@
   database: sccg
   key:
     admin: 'ums:admin'
-    resourceList: 'ums:resourceList'
+    resourceList: 'ums:menuList'
   expire:
     common: 86400 # 24灏忔椂
 
diff --git a/ycl-platform/src/main/resources/mapper/caseHandler/DisposeRecordMapper.xml b/ycl-platform/src/main/resources/mapper/caseHandler/DisposeRecordMapper.xml
index 73fc29e..c47e565 100644
--- a/ycl-platform/src/main/resources/mapper/caseHandler/DisposeRecordMapper.xml
+++ b/ycl-platform/src/main/resources/mapper/caseHandler/DisposeRecordMapper.xml
@@ -33,8 +33,8 @@
         t2.limit_time
         FROM
         ums_admin_role_relation t1
-        JOIN ums_dispose_record t2 ON t1.role_id = t2.handler_role_id
-        JOIN ums_base_case t3 ON t2.base_case_id=t3.id
+        left JOIN ums_dispose_record t2 ON t1.role_id = t2.handler_role_id
+        left JOIN ums_base_case t3 ON t2.base_case_id=t3.id
         <where>
             t1.admin_id = #{id}
             AND ISNULL( t2.end_time )

--
Gitblit v1.8.0