Эх сурвалжийг харах

update 优化根据字典类型查询信息增加一级缓存

AprilWind 4 сар өмнө
parent
commit
71180584da

+ 5 - 0
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java

@@ -30,6 +30,11 @@ public interface CacheNames {
      */
      */
     String SYS_DICT = "sys_dict";
     String SYS_DICT = "sys_dict";
 
 
+    /**
+     * 数据字典类型
+     */
+    String SYS_DICT_TYPE = "sys_dict_type";
+
     /**
     /**
      * 租户
      * 租户
      */
      */

+ 4 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDictTypeServiceImpl.java

@@ -124,6 +124,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
      * @param dictType 字典类型
      * @param dictType 字典类型
      * @return 字典类型
      * @return 字典类型
      */
      */
+    @Cacheable(cacheNames = CacheNames.SYS_DICT_TYPE, key = "#dictType")
     @Override
     @Override
     public SysDictTypeVo selectDictTypeByType(String dictType) {
     public SysDictTypeVo selectDictTypeByType(String dictType) {
         return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
         return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
@@ -143,6 +144,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
                 throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
                 throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
             }
             }
             CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
             CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
+            CacheUtils.evict(CacheNames.SYS_DICT_TYPE, dictType.getDictType());
         }
         }
         baseMapper.deleteByIds(Arrays.asList(dictIds));
         baseMapper.deleteByIds(Arrays.asList(dictIds));
     }
     }
@@ -153,6 +155,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
     @Override
     @Override
     public void resetDictCache() {
     public void resetDictCache() {
         CacheUtils.clear(CacheNames.SYS_DICT);
         CacheUtils.clear(CacheNames.SYS_DICT);
+        CacheUtils.clear(CacheNames.SYS_DICT_TYPE);
     }
     }
 
 
     /**
     /**
@@ -191,6 +194,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
         int row = baseMapper.updateById(dict);
         int row = baseMapper.updateById(dict);
         if (row > 0) {
         if (row > 0) {
             CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
             CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType());
+            CacheUtils.evict(CacheNames.SYS_DICT_TYPE, oldDict.getDictType());
             return dictDataMapper.selectDictDataByType(dict.getDictType());
             return dictDataMapper.selectDictDataByType(dict.getDictType());
         }
         }
         throw new ServiceException("操作失败");
         throw new ServiceException("操作失败");