```
/**
* @author 張躍帥
* @Description: 系統配置-redis緩存
* @date 2020/08/12
*/
public class SystemConfigRedisCache {
/**
* 系統配置-Service
*/
private static final SystemConfigService systemConfigService = SpringUtil.getBean(SystemConfigService.class);
/**
* 根據key獲取val
*/
public static String getValByKey(String key) {
// 變量
String val = null;
// 獲取參數
String appCode = SystemMe.getUserAppCode();
// 判斷
if (StrUtil.isNotBlank(key)) {
// redis緩存-獲取
String cacheValStr = RedisCacheUtil.getToStr(CacheConstant.WEB_CACHE_PREFIX + appCode + ":" + key);
// 判斷
if (StrUtil.isNotBlank(cacheValStr)) {
// 賦值
val = cacheValStr;
} else {
// 創建條件查詢包裝器
LambdaQueryWrapper<SystemConfigEntity> queryWrapper = new LambdaQueryWrapper<>();
// 設置條件
queryWrapper.eq(SystemConfigEntity::getAppCode, appCode)
.eq(SystemConfigEntity::getKey, key)
.eq(SystemConfigEntity::getDataFlag, CommonDataFlagEnum.NORMAL.getCode())
.eq(SystemConfigEntity::getDelFlag, CommonDelFlagEnum.NOT_DELETE.getCode());
// 查詢
SystemConfigEntity systemConfig = systemConfigService.getOne(queryWrapper);
// 判斷
if (ObjectUtil.isNotNull(systemConfig)) {
// 獲取參數
String cahcheAppCode = systemConfig.getAppCode();
String cahcheKey = systemConfig.getKey();
String cacheVal = systemConfig.getVal();
// 判斷
if (StrUtil.isNotBlank(cahcheAppCode) && StrUtil.isNotBlank(cahcheKey) && StrUtil.isNotBlank(cacheVal)) {
// 賦值
val = cacheVal;
// redis緩存-存入
RedisCacheUtil.put(CacheConstant.WEB_CACHE_PREFIX + cahcheAppCode + ":" + cahcheKey, cacheVal);
}
}
}
}
// 返回
return val;
}
/**
* 添加
*/
public static void put(String appCode, String key, String value) {
// 判斷
if (StrUtil.isNotBlank(appCode) && StrUtil.isNotBlank(key) && StrUtil.isNotBlank(value)) {
// redis緩存
RedisCacheUtil.put(CacheConstant.WEB_CACHE_PREFIX + appCode + ":" + key, value);
}
}
/**
* 添加所有
*/
public static void putAll(List<SystemConfigEntity> systemConfigList) {
// 判斷
if (systemConfigList != null && systemConfigList.size() > 0) {
// 遍歷
for (SystemConfigEntity systemConfig : systemConfigList) {
// 獲取參數
String cahcheAppCode = systemConfig.getAppCode();
String cacheKey = systemConfig.getKey();
String cacheVal = systemConfig.getVal();
// 判斷
if (StrUtil.isNotBlank(cahcheAppCode) && StrUtil.isNotBlank(cacheKey) && StrUtil.isNotBlank(cacheVal)) {
// redis緩存
RedisCacheUtil.put(CacheConstant.WEB_CACHE_PREFIX + cahcheAppCode + ":" + cacheKey, cacheVal);
}
}
}
}
/**
* 更新
*/
public static void upValByKey(String appCode, String key, String newVal) {
// 判斷
if (StrUtil.isNotBlank(appCode) && StrUtil.isNotBlank(key) && StrUtil.isNotBlank(newVal)) {
// 先刪除
delByKey(appCode, key);
// 在添加
put(appCode, key, newVal);
}
}
/**
* 刪除
*/
public static void delByKey(String appCode, String key) {
// 判斷
if (StrUtil.isNotBlank(appCode) && StrUtil.isNotBlank(key)) {
// redis緩存
RedisCacheUtil.remove(appCode, key);
}
}
}
- Jump簡介
- 技術架構
- 代碼規范
- 規范導讀
- JAVA規范
- 數據庫表設計規范
- 集成項目
- JDK1.8-pom.xml
- JDK21-pom.xml
- 項目結構
- 業務模塊-方法名稱規范
- 跨域配置
- License授權配置
- 公共字段自動填充
- 全局異常處理器
- PageOffice配置
- Beetl模板引擎配置
- application.properties
- application-prod.yml
- banner.txt
- logback-spring.xml
- jump-core (核心組件)
- Maven依賴
- 通用枚舉
- 公共數據狀態 - 枚舉
- 公共邏輯刪除 - 枚舉
- 公共操作編碼類型 - 枚舉
- 公共tree父節點 - 枚舉
- 公共是或否 - 枚舉
- 工具Util
- AopTargetUtil
- DownloadUtil
- GenerateNumUtil
- HttpServletUtil
- IpUtil
- JoinPointUtil
- MacUtil
- NetworkUtil
- ParamToUtil
- ResponseUtil
- TimeZoneDateUtil
- UaUtil
- 統一返回
- 結果對象
- 如何使用
- jump-cahche (緩存組件)
- Maven依賴
- Redis配置
- 緩存常量
- 工具Util
- RedisCacheUtil
- jump-idempotent (幕等組件)
- Maven依賴
- Context上下文
- 操作器
- 接口
- 如何實現
- AOP參數
- AOP使用方法
- jump-lock (分布式鎖組件)
- Maven依賴
- 枚舉
- AOP參數
- AOP使用方法
- 工具Util
- RedissonLockUtil
- Util使用方法
- jump-mybatis (mybatis組件)
- Maven依賴
- 基礎Entity
- 枚舉
- 查詢類型 - 枚舉
- 條件查詢
- search
- service
- 分頁結果集
- Mapper
- MyMapper
- 使用方法
- DDL操作
- DML操作
- 工具Util
- EntityUtil
- PageUtil
- TableUtil
- jump-dynamic-datasource (多數據源組件)
- Maven依賴
- Context上下文
- 操作器
- 接口
- 如何實現
- 工具Util
- DatasourceUtil
- 如何使用
- jump-satoken (satoken組件)
- Maven依賴
- Context上下文
- 操作器
- 接口
- 如何實現
- Satoken配置信息
- SatokenUser信息
- Redis緩存操作
- SatokenRedisCache
- SatokenUserRedisCache
- 放行白名單
- jump-oss (OSS組件)
- Maven依賴
- 工具Util
- OssFileUtil
- OssPlatformUtil
- 如何使用
- jump-xss (XSS組件)
- Maven依賴
- 白名單放行
- jump-email (郵件組件)
- Maven依賴
- Email客戶端信息
- Email發送參數
- 工具Util
- jump-websocket (WebSocket組件)
- Maven依賴
- 消息對象
- 工具Util
- 如何使用
- jump-weixin (微信組件)
- Maven依賴
- jump-system (系統管理組件)
- Maven依賴
- AOP
- 系統操作日志AOP
- 系統數據日志AOP
- 系統操作權限AOP
- 字典轉文本AOP
- Redis緩存操作
- SystemConfigRedisCache
- 工具Util
- LoginUserUtil
- SystemAreaUtil
- SystemHomeUtil
- SystemMenuUtil
- SystemOrgAdminUtil
- SystemOrgTypeUtil
- SystemRoleUtil
- SystemUserLoginAreaUtil
- SystemUserUtil
- jump-timer(定時器組件)
- Maven依賴
- 枚舉
- Api接口
- 工具Util
- ActionClassUtil
- TimerTaskUtil
- 如何使用
- jump-ueditor (富文本組件)
- Maven依賴
- 如何使用
- 配置 ueditor.config.js
- 后端 application.properties
- 前端 vue3
- vue-codemirror (代碼編譯器)
- npm依賴
- PageOffice整合
- Maven依賴
- License授權配置
- 枚舉
- 文件來源 - 枚舉
- 預覽文件類型 - 枚舉
- 文件預覽參數
- 下載文件
- 預覽文件
- 工具Util