NorthLan 7 years ago
parent
commit
bd486492d2

+ 1 - 1
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/ISysPermissionService.kt

@@ -16,5 +16,5 @@ interface ISysPermissionService {
     /**
      * 初始化所有用户的权限缓存
      */
-    fun initPermissionCacheAllUser()
+    fun initAllUserPermissionCache()
 }

+ 1 - 1
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/ISysUserRoleService.kt

@@ -21,5 +21,5 @@ interface ISysUserRoleService : BaseService<SysUserRole> {
     /**
      * 获取所有用户的角色列表
      */
-    fun getUserRoleList(): Map<Int, MutableList<SysRole>>
+    fun getUserRoleList(): Map<Long, MutableList<SysRole>>
 }

+ 11 - 2
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysPermissionServiceImpl.kt

@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.cache.CacheManager
 import org.springframework.cache.annotation.Cacheable
 import org.springframework.stereotype.Service
+import javax.annotation.PostConstruct
 
 /**
  * <p>
@@ -35,9 +36,17 @@ class SysPermissionServiceImpl : ISysPermissionService {
         return permIds
     }
 
-    override fun initPermissionCacheAllUser() {
+    @PostConstruct
+    override fun initAllUserPermissionCache() {
         val cache = cacheManager.getCache(CACHEKEYS.USER_PERM)
-
+        val userRoleMap = sysUserRoleService.getUserRoleList()
+        for (item in userRoleMap) {
+            val permIds = linkedSetOf<String>()
+            for (role in item.value) {
+                role.perms?.split(',')?.toCollection(permIds)
+            }
+            cache.put("uid_${item.key}", permIds)
+        }
     }
 
 }

+ 15 - 3
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysUserRoleServiceImpl.kt

@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl
 import com.gxzc.zen.api.sys.mapper.SysUserRoleMapper
 import com.gxzc.zen.api.sys.model.SysRole
 import com.gxzc.zen.api.sys.model.SysUserRole
+import com.gxzc.zen.api.sys.service.ISysRoleService
 import com.gxzc.zen.api.sys.service.ISysUserRoleService
+import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
 
 /**
@@ -18,13 +20,23 @@ import org.springframework.stereotype.Service
  */
 @Service
 class SysUserRoleServiceImpl : ServiceImpl<SysUserRoleMapper, SysUserRole>(), ISysUserRoleService {
+    @Autowired
+    private lateinit var sysRoleService: ISysRoleService
+
     override fun getUserRoleListByUserId(id: Long): MutableList<SysRole> {
         return baseMapper.selectUserRoleListByUserId(id)
     }
 
-    override fun getUserRoleList(): Map<Int, MutableList<SysRole>> {
+    override fun getUserRoleList(): Map<Long, MutableList<SysRole>> {
         val allSysUserRole = baseMapper.selectList(EntityWrapper<SysUserRole>())
-        allSysUserRole.
-                return baseMapper.selectUserRoleList()
+        val groupUserRole = allSysUserRole.groupBy({ it.userId }, { it.roleId })
+        val result = mutableMapOf<Long, MutableList<SysRole>>()
+        for (item in groupUserRole) {
+            if (item.key == null) {
+                continue
+            }
+            result[item.key!!] = sysRoleService.selectBatchIds(item.value)
+        }
+        return result
     }
 }

+ 0 - 27
zen-core/src/main/kotlin/com/gxzc/zen/common/dto/RD.java

@@ -1,27 +0,0 @@
-package com.gxzc.zen.common.dto;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import lombok.Data;
-import org.springframework.format.annotation.DateTimeFormat;
-
-import java.util.Date;
-
-/**
- * @author NorthLan
- * @date 2018/2/1
- * @url https://noahlan.com
- */
-
-public class RD {
-
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date time;
-
-//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    public Date getTime() {
-        return time;
-    }
-    public void setTime(Date time) {
-        this.time = time;
-    }
-}

+ 3 - 3
zen-orm/src/main/resources/application-orm.yml

@@ -12,9 +12,9 @@ spring:
         login-password: root
         reset-enable: false
       ############ 以下是关闭多数据源时使用的默认数据源 ############
-      username: root
-      password: root
-      url: jdbc:mysql://127.0.0.1:3306/archives_sys?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
+      username: archives
+      password: archives
+      url: jdbc:mysql://192.168.1.124:3307/archives_sys?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
       driver-class-name: com.mysql.jdbc.Driver
       test-on-borrow: false
       test-on-return: false

+ 1 - 1
zen-umps/src/main/kotlin/com/gxzc/zen/umps/common/Permission.kt

@@ -21,7 +21,7 @@ class Permission(private val permission: String) {
         }
         val splitList = permission.split(':')
         if (splitList.size < 3) {
-            throw RuntimeException("permission字符串错误,必须为:分割且长度等于4")
+            throw RuntimeException("permission字符串错误,必须为:分割且长度等于3")
         }
         platformId = splitList[0].toInt()
         perm = splitList[1]

+ 7 - 0
zen-umps/src/main/kotlin/com/gxzc/zen/umps/util/PermissionUtil.kt

@@ -1,5 +1,7 @@
 package com.gxzc.zen.umps.util
 
+import com.gxzc.zen.umps.common.Permission
+
 /**
  *
  * @author NorthLan
@@ -8,6 +10,11 @@ package com.gxzc.zen.umps.util
  */
 object PermissionUtil {
 
+    fun convertPermission(perms: HashSet<String>): HashSet<Permission> {
+        val result = hashSetOf<Permission>()
+        perms.forEach()
+    }
+
 
     /**
      * 权限判定

+ 2 - 1
zen-web/src/main/kotlin/com/gxzc/zen/controller/ExampleController.kt

@@ -41,8 +41,9 @@ class ExampleController {
     fun testCache() {
         println(cacheManager.cacheNames)
 
-        val a = sysPermissionService.getPermissionByUserId(1)
+        val a = sysPermissionService.getPermissionSetByUserId(1)
 
+        println(a)
         val test = cacheManager.getCache("user")["test1"]
     }
 }

+ 1 - 1
zen-web/src/main/resources/application.yml

@@ -6,7 +6,7 @@ server:
 spring:
   profiles:
     active: dev
-    include: orm-local,mq,cache,umps,platform
+    include: orm,mq,cache,umps,platform
 #  redis:
 #    host: localhost
 #    port: 6379