feat: 刷新字典缓存.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.orion.ops.module.infra.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
@@ -72,6 +73,14 @@ public class DictKeyController {
|
||||
return dictKeyService.getDictKeyPage(request);
|
||||
}
|
||||
|
||||
@PutMapping("/refresh-cache")
|
||||
@Operation(summary = "刷新字典缓存")
|
||||
@PreAuthorize("@ss.hasPermission('infra:dict-key:refresh-cache')")
|
||||
public HttpWrapper<?> refreshCache() {
|
||||
dictKeyService.refreshCache();
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
@OperatorLog(DictKeyOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除字典配置项")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
### 初始化角色权限缓存
|
||||
GET {{baseUrl}}/infra/permission/init-cache
|
||||
GET {{baseUrl}}/infra/permission/refresh-cache
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ public class PermissionController {
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
@PutMapping("/init-cache")
|
||||
@Operation(summary = "初始化角色权限缓存")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:init-cache')")
|
||||
public HttpWrapper<?> initCache() {
|
||||
@PutMapping("/refresh-cache")
|
||||
@Operation(summary = "刷新角色权限缓存")
|
||||
@PreAuthorize("@ss.hasPermission('infra:system-menu:refresh-cache')")
|
||||
public HttpWrapper<?> refreshCache() {
|
||||
permissionService.initPermissionCache();
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ public interface DictKeyService {
|
||||
*/
|
||||
Map<String, String> getDictSchema(String key);
|
||||
|
||||
/**
|
||||
* 刷新字典缓存
|
||||
*/
|
||||
void refreshCache();
|
||||
|
||||
/**
|
||||
* 删除字典配置项
|
||||
*
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.utils.Objects1;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
@@ -166,6 +167,18 @@ public class DictKeyServiceImpl implements DictKeyService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshCache() {
|
||||
Set<String> schemaKeys = RedisUtils.scanKeys(DictCacheKeyDefine.DICT_SCHEMA.format("*"));
|
||||
Set<String> valueKeys = RedisUtils.scanKeys(DictCacheKeyDefine.DICT_VALUE.format("*"));
|
||||
// 需要删除的缓存 key
|
||||
List<String> list = Lists.of(DictCacheKeyDefine.DICT_KEY.getKey());
|
||||
list.addAll(schemaKeys);
|
||||
list.addAll(valueKeys);
|
||||
// 删除缓存
|
||||
RedisUtils.delete(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDictKeyById(Long id) {
|
||||
log.info("DictKeyService-deleteDictKeyById id: {}", id);
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.mybatis.core.query.Conditions;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
||||
import com.orion.ops.module.infra.convert.DictValueConvert;
|
||||
import com.orion.ops.module.infra.dao.DictKeyDAO;
|
||||
@@ -79,7 +78,7 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
Long id = record.getId();
|
||||
log.info("DictValueService-createDictValue id: {}, effect: {}", id, effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
RedisStrings.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
int effect = dictValueDAO.updateById(updateRecord);
|
||||
log.info("DictValueService-updateDictValueById effect: {}", effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
RedisStrings.delete(DictCacheKeyDefine.DICT_VALUE.format(key));
|
||||
// 记录历史归档
|
||||
this.checkRecordHistory(updateRecord, record);
|
||||
return effect;
|
||||
@@ -130,7 +129,7 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
int effect = dictValueDAO.updateById(updateRecord);
|
||||
log.info("DictValueService-rollbackDictValueById effect: {}", effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(record.getKeyName()));
|
||||
RedisStrings.delete(DictCacheKeyDefine.DICT_VALUE.format(record.getKeyName()));
|
||||
// 记录历史归档
|
||||
this.checkRecordHistory(updateRecord, record);
|
||||
return effect;
|
||||
@@ -222,7 +221,7 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
// 删除缓存
|
||||
String beforeCacheKey = DictCacheKeyDefine.DICT_VALUE.format(beforeKey);
|
||||
String newCacheKey = DictCacheKeyDefine.DICT_VALUE.format(newKey);
|
||||
RedisMaps.delete(beforeCacheKey, newCacheKey);
|
||||
RedisStrings.delete(beforeCacheKey, newCacheKey);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -296,7 +295,7 @@ public class DictValueServiceImpl implements DictValueService {
|
||||
.distinct()
|
||||
.map(DictCacheKeyDefine.DICT_VALUE::format)
|
||||
.collect(Collectors.toList());
|
||||
RedisMaps.delete(keyList);
|
||||
RedisStrings.delete(keyList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user