瀏覽代碼

再次修复缓存

NorthLan 7 年之前
父節點
當前提交
fee99141af

+ 2 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/ISysResourceRoleService.kt

@@ -13,4 +13,6 @@ import com.gxzc.zen.common.base.BaseService
  */
 interface ISysResourceRoleService : BaseService<SysResourceRole> {
     fun saveResourceRoleByRoleId(roleId: Long, menuId: Long, resList: List<Long>)
+
+    fun physicalDeleteByResourceId(resId: Long)
 }

+ 4 - 4
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysResourceRoleServiceImpl.kt

@@ -38,10 +38,6 @@ class SysResourceRoleServiceImpl : ServiceImpl<SysResourceRoleMapper, SysResourc
         val deleteIds = ret.subtract(resList)
         val insertIds = resList.subtract(ret)
 
-        if (deleteIds.isEmpty() && insertIds.isEmpty() && resList.isNotEmpty()) {
-            throw ZenException(ZenExceptionEnum.BIZ_UPDATE_ERROR)
-        }
-
         var eff = false
         if (deleteIds.isNotEmpty()) {
             // 删除啊 批量啊
@@ -67,4 +63,8 @@ class SysResourceRoleServiceImpl : ServiceImpl<SysResourceRoleMapper, SysResourc
         }
     }
 
+    override fun physicalDeleteByResourceId(resId: Long) {
+        baseMapper.physicalDelete(EntityWrapper<SysResourceRole>().eq("resource_id", resId))
+    }
+
 }

+ 8 - 0
zen-api/src/main/kotlin/com/gxzc/zen/api/sys/service/impl/SysResourceServiceImpl.kt

@@ -5,9 +5,11 @@ import com.baomidou.mybatisplus.service.impl.ServiceImpl
 import com.gxzc.zen.api.sys.mapper.SysResourceMapper
 import com.gxzc.zen.api.sys.model.SysResource
 import com.gxzc.zen.api.sys.service.ISysPermissionService
+import com.gxzc.zen.api.sys.service.ISysResourceRoleService
 import com.gxzc.zen.api.sys.service.ISysResourceService
 import com.gxzc.zen.common.exception.ZenException
 import com.gxzc.zen.common.exception.ZenExceptionEnum
+import com.gxzc.zen.orm.annotation.ZenTransactional
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
 
@@ -24,6 +26,9 @@ class SysResourceServiceImpl : ServiceImpl<SysResourceMapper, SysResource>(), IS
     @Autowired
     private lateinit var permissionService: ISysPermissionService
 
+    @Autowired
+    private lateinit var resourceRoleService: ISysResourceRoleService
+
     override fun getResourcesByRoleIds(roleIds: List<Long>): MutableList<SysResource> {
         return baseMapper.selectByRoleIds(roleIds)
     }
@@ -62,8 +67,11 @@ class SysResourceServiceImpl : ServiceImpl<SysResourceMapper, SysResource>(), IS
         return sysResource
     }
 
+    @ZenTransactional
     override fun deleteResourceById(id: Long) {
         baseMapper.physicalDeleteById(id)
+        // 还要同时删掉 sys_resource_role 对应id的记录
+        resourceRoleService.physicalDeleteByResourceId(id)
         ////
         permissionService.updateAllSysPermission()
         permissionService.updateAllSessionPermission()

+ 1 - 1
zen-core/src/main/kotlin/com/gxzc/zen/common/util/RedisCacheUtil.kt

@@ -54,7 +54,7 @@ object RedisCacheUtil {
      * 移除缓存
      */
     fun evict(cacheKey: String, key: String) {
-        getCahce(cacheKey)?.evict(key)
+        getCahce(cacheKey)?.evict(RedisKeyGenerator.joinToString(cacheKey, key))
     }
 
     /**