refactor: 重构缓存逻辑.

This commit is contained in:
lijiahangmax
2023-11-15 02:04:55 +08:00
parent 34ea140004
commit 30f0496328
38 changed files with 235 additions and 169 deletions

View File

@@ -1,5 +1,6 @@
package ${currentPackage}; package ${currentPackage};
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serializable; import java.io.Serializable;
import lombok.*; import lombok.*;
@@ -19,7 +20,7 @@ import java.math.*;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "${type}CacheDTO", description = "$!{table.comment} 缓存对象") @Schema(name = "${type}CacheDTO", description = "$!{table.comment} 缓存对象")
public class ${type}CacheDTO implements Serializable { public class ${type}CacheDTO implements LongCacheIdModel, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
#foreach($field in ${table.fields}) #foreach($field in ${table.fields})

View File

@@ -1,7 +1,8 @@
package ${currentPackage}; package ${currentPackage};
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
#foreach($pkg in ${customModuleFilePackages}) #foreach($pkg in ${customModuleFilePackages})
import ${pkg}.*; import ${pkg}.*;
#end #end
@@ -21,6 +22,7 @@ public interface ${type}CacheKeyDefine {
.key("$meta.cacheKey") .key("$meta.cacheKey")
.desc("$meta.cacheDesc") .desc("$meta.cacheDesc")
.type(${type}CacheDTO.class) .type(${type}CacheDTO.class)
.struct(RedisCacheStruct.HASH)
#if($meta.cacheExpired) #if($meta.cacheExpired)
.timeout($meta.cacheExpireTime, TimeUnit.$meta.cacheExpireUnit.name()) .timeout($meta.cacheExpireTime, TimeUnit.$meta.cacheExpireUnit.name())
#end #end

View File

@@ -8,9 +8,6 @@ import com.orion.lang.utils.collect.Lists;
#if($meta.enableExport) #if($meta.enableExport)
import com.orion.office.excel.writer.exporting.ExcelExport; import com.orion.office.excel.writer.exporting.ExcelExport;
#end #end
#if($meta.enableCache)
import com.orion.ops.framework.common.constant.Const;
#end
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.FileNames; import com.orion.ops.framework.common.utils.FileNames;
import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.common.utils.Valid;
@@ -32,7 +29,6 @@ import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* $!{table.comment} 服务实现类 * $!{table.comment} 服务实现类
@@ -140,21 +136,16 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = ${typeLower}DAO.of().list(${type}Convert.MAPPER::toCache); list = ${typeLower}DAO.of().list(${type}Convert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, ${type}CacheDTO::new);
list.add(${type}CacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(${type}CacheKeyDefine.${typeConst}.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(${type}CacheKeyDefine.${typeConst}.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(${type}CacheKeyDefine.${typeConst}); RedisMaps.setExpire(${type}CacheKeyDefine.${typeConst});
} }
// 删除默认值 // 删除屏障
return list.stream() RedisMaps.removeBarrier(list);
.filter(s -> !s.getId().equals(Const.NONE_ID)) // 转换
.map(${type}Convert.MAPPER::to) return Lists.map(list, ${type}Convert.MAPPER::to);
.collect(Collectors.toList());
} }
#end #end

View File

@@ -0,0 +1,64 @@
package com.orion.ops.framework.redis.core.utils;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.Const;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;
/**
* 缓存工具类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/11/15 1:22
*/
public class CacheUtils {
protected CacheUtils() {
}
/**
* 创建屏障对象 防止穿透
*
* @param supplier supplier
* @param <T> T
* @return barrier
*/
public static <T extends LongCacheIdModel> T createBarrier(Supplier<T> supplier) {
T val = supplier.get();
val.setId(Const.NONE_ID);
return val;
}
/**
* 检测是否需要 创建屏障对象 防止穿透
*
* @param list list
* @param supplier supplier
* @param <T> T
*/
public static <T extends LongCacheIdModel> void checkBarrier(List<T> list, Supplier<T> supplier) {
if (list != null && list.isEmpty()) {
// 添加屏障对象
list.add(createBarrier(supplier));
}
}
/**
* 移除屏障对象
*
* @param list list
* @param <T> T
*/
public static <T extends LongCacheIdModel> void removeBarrier(Collection<T> list) {
if (!Lists.isEmpty(list)) {
list.removeIf(s -> Const.NONE_ID.equals(s.getId()));
}
}
}

View File

@@ -1,7 +1,7 @@
package com.orion.ops.framework.redis.core.utils; package com.orion.ops.framework.redis.core.utils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.Const;

View File

@@ -1,7 +1,7 @@
package com.orion.ops.framework.redis.core.utils; package com.orion.ops.framework.redis.core.utils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.function.Functions; import com.orion.lang.function.Functions;
import com.orion.lang.utils.Objects1; import com.orion.lang.utils.Objects1;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;

View File

@@ -3,7 +3,7 @@ package com.orion.ops.framework.redis.core.utils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import java.util.ArrayList; import java.util.ArrayList;

View File

@@ -1,6 +1,6 @@
package com.orion.ops.framework.redis.core.utils; package com.orion.ops.framework.redis.core.utils;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.utils.Arrays1; import com.orion.lang.utils.Arrays1;
import com.orion.lang.utils.io.Streams; import com.orion.lang.utils.io.Streams;
import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.Cursor;
@@ -20,7 +20,7 @@ import java.util.Set;
* @version 1.0.0 * @version 1.0.0
* @since 2021/11/6 11:09 * @since 2021/11/6 11:09
*/ */
public class RedisUtils { public class RedisUtils extends CacheUtils {
protected static RedisTemplate<String, String> redisTemplate; protected static RedisTemplate<String, String> redisTemplate;

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.asset.define.cache; package com.orion.ops.module.asset.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import com.orion.ops.module.asset.entity.dto.HostCacheDTO; import com.orion.ops.module.asset.entity.dto.HostCacheDTO;
import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO; import com.orion.ops.module.asset.entity.dto.HostIdentityCacheDTO;
import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO; import com.orion.ops.module.asset.entity.dto.HostKeyCacheDTO;
@@ -21,6 +22,7 @@ public interface HostCacheKeyDefine {
.key("host:info:list") .key("host:info:list")
.desc("主机列表") .desc("主机列表")
.type(HostCacheDTO.class) .type(HostCacheDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -28,6 +30,7 @@ public interface HostCacheKeyDefine {
.key("host:key:list") .key("host:key:list")
.desc("主机秘钥列表") .desc("主机秘钥列表")
.type(HostKeyCacheDTO.class) .type(HostKeyCacheDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -35,6 +38,7 @@ public interface HostCacheKeyDefine {
.key("host:identity:list") .key("host:identity:list")
.desc("主机身份列表") .desc("主机身份列表")
.type(HostIdentityCacheDTO.class) .type(HostIdentityCacheDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.asset.entity.dto; package com.orion.ops.module.asset.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -20,7 +21,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "HostCacheDTO", description = "主机 缓存对象") @Schema(name = "HostCacheDTO", description = "主机 缓存对象")
public class HostCacheDTO implements Serializable { public class HostCacheDTO implements LongCacheIdModel, Serializable {
@Schema(description = "id") @Schema(description = "id")
private Long id; private Long id;

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.asset.entity.dto; package com.orion.ops.module.asset.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -20,7 +21,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "HostIdentityCacheDTO", description = "主机身份缓存") @Schema(name = "HostIdentityCacheDTO", description = "主机身份缓存")
public class HostIdentityCacheDTO implements Serializable { public class HostIdentityCacheDTO implements LongCacheIdModel, Serializable {
@Schema(description = "id") @Schema(description = "id")
private Long id; private Long id;

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.asset.entity.dto; package com.orion.ops.module.asset.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -20,7 +21,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "HostKeyCacheDTO", description = "主机秘钥缓存") @Schema(name = "HostKeyCacheDTO", description = "主机秘钥缓存")
public class HostKeyCacheDTO implements Serializable { public class HostKeyCacheDTO implements LongCacheIdModel, Serializable {
@Schema(description = "id") @Schema(description = "id")
private Long id; private Long id;

View File

@@ -64,4 +64,11 @@ public interface HostService {
*/ */
Integer deleteHostById(Long id); Integer deleteHostById(Long id);
/**
* 通过 id 删除主机引用
*
* @param id id
*/
void deleteHostRelByIdAsync(Long id);
} }

View File

@@ -6,8 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.orion.lang.define.wrapper.DataGrid; import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.security.PasswordModifier; import com.orion.ops.framework.common.security.PasswordModifier;
import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.common.utils.Valid;
@@ -117,21 +117,16 @@ public class HostIdentityServiceImpl implements HostIdentityService {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = hostIdentityDAO.of().list(HostIdentityConvert.MAPPER::toCache); list = hostIdentityDAO.of().list(HostIdentityConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, HostIdentityCacheDTO::new);
list.add(HostIdentityCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(HostCacheKeyDefine.HOST_IDENTITY.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(HostCacheKeyDefine.HOST_IDENTITY); RedisMaps.setExpire(HostCacheKeyDefine.HOST_IDENTITY);
} }
// 删除默认值 // 删除屏障
return list.stream() RedisMaps.removeBarrier(list);
.filter(s -> !s.getId().equals(Const.NONE_ID)) // 转换
.map(HostIdentityConvert.MAPPER::to) return Lists.map(list, HostIdentityConvert.MAPPER::to);
.collect(Collectors.toList());
} }
@Override @Override

View File

@@ -4,8 +4,8 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid; import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.security.PasswordModifier; import com.orion.ops.framework.common.security.PasswordModifier;
import com.orion.ops.framework.common.utils.CryptoUtils; import com.orion.ops.framework.common.utils.CryptoUtils;
@@ -29,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 主机秘钥 服务实现类 * 主机秘钥 服务实现类
@@ -131,21 +130,16 @@ public class HostKeyServiceImpl implements HostKeyService {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = hostKeyDAO.of().list(HostKeyConvert.MAPPER::toCache); list = hostKeyDAO.of().list(HostKeyConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, HostKeyCacheDTO::new);
list.add(HostKeyCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(HostCacheKeyDefine.HOST_KEY.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(HostCacheKeyDefine.HOST_KEY); RedisMaps.setExpire(HostCacheKeyDefine.HOST_KEY);
} }
// 删除默认值 // 删除屏障
return list.stream() RedisMaps.removeBarrier(list);
.filter(s -> !s.getId().equals(Const.NONE_ID)) // 转换
.map(HostKeyConvert.MAPPER::to) return Lists.map(list, HostKeyConvert.MAPPER::to);
.collect(Collectors.toList());
} }
@Override @Override

View File

@@ -7,7 +7,6 @@ import com.orion.lang.utils.Booleans;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.redis.core.utils.RedisMaps; import com.orion.ops.framework.redis.core.utils.RedisMaps;
@@ -31,6 +30,7 @@ import com.orion.ops.module.infra.entity.dto.tag.TagDTO;
import com.orion.ops.module.infra.enums.DataGroupTypeEnum; import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
import com.orion.ops.module.infra.enums.FavoriteTypeEnum; import com.orion.ops.module.infra.enums.FavoriteTypeEnum;
import com.orion.ops.module.infra.enums.TagTypeEnum; import com.orion.ops.module.infra.enums.TagTypeEnum;
import com.orion.spring.SpringHolder;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -83,7 +83,7 @@ public class HostServiceImpl implements HostService {
log.info("HostService-createHost effect: {}", effect); log.info("HostService-createHost effect: {}", effect);
Long id = record.getId(); Long id = record.getId();
// 插入 tag // 插入 tag
tagRelApi.addTagRelAsync(TagTypeEnum.HOST, id, request.getTags()); tagRelApi.addTagRel(TagTypeEnum.HOST, id, request.getTags());
// 引用分组 // 引用分组
List<Long> groupIdList = request.getGroupIdList(); List<Long> groupIdList = request.getGroupIdList();
if (!Lists.isEmpty(groupIdList)) { if (!Lists.isEmpty(groupIdList)) {
@@ -119,10 +119,10 @@ public class HostServiceImpl implements HostService {
log.info("HostService-updateHostById effect: {}", effect); log.info("HostService-updateHostById effect: {}", effect);
// 引用分组 // 引用分组
dataGroupRelApi.updateGroupRel(DataGroupTypeEnum.HOST, request.getGroupIdList(), id); dataGroupRelApi.updateGroupRel(DataGroupTypeEnum.HOST, request.getGroupIdList(), id);
// 更新 tag
tagRelApi.setTagRel(TagTypeEnum.HOST, id, request.getTags());
// 删除缓存 // 删除缓存
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO); RedisMaps.delete(HostCacheKeyDefine.HOST_INFO);
// 更新 tag
tagRelApi.setTagRelAsync(TagTypeEnum.HOST, id, request.getTags());
return effect; return effect;
} }
@@ -154,21 +154,16 @@ public class HostServiceImpl implements HostService {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = hostDAO.of().list(HostConvert.MAPPER::toCache); list = hostDAO.of().list(HostConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, HostCacheDTO::new);
list.add(HostCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(HostCacheKeyDefine.HOST_INFO.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(HostCacheKeyDefine.HOST_INFO.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(HostCacheKeyDefine.HOST_INFO); RedisMaps.setExpire(HostCacheKeyDefine.HOST_INFO);
} }
// 删除默认值 // 删除屏障
return list.stream() RedisMaps.removeBarrier(list);
.filter(s -> !s.getId().equals(Const.NONE_ID)) // 转换
.map(HostConvert.MAPPER::to) return Lists.map(list, HostConvert.MAPPER::to);
.collect(Collectors.toList());
} }
@Override @Override
@@ -198,17 +193,24 @@ public class HostServiceImpl implements HostService {
// 删除 // 删除
int effect = hostDAO.deleteById(id); int effect = hostDAO.deleteById(id);
log.info("HostService-deleteHostById effect: {}", effect); log.info("HostService-deleteHostById effect: {}", effect);
// 删除缓存
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id);
// 删除主机引用
SpringHolder.getBean(HostService.class)
.deleteHostRelByIdAsync(id);
return effect;
}
@Override
public void deleteHostRelByIdAsync(Long id) {
// 删除配置 // 删除配置
hostConfigDAO.deleteByHostId(id); hostConfigDAO.deleteByHostId(id);
// 删除分组 // 删除分组
dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id); dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id);
// 删除缓存
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id);
// 删除 tag 引用 // 删除 tag 引用
tagRelApi.deleteRelIdAsync(TagTypeEnum.HOST, id); tagRelApi.deleteRelId(TagTypeEnum.HOST, id);
// 删除收藏引用 // 删除收藏引用
favoriteApi.deleteByRelIdAsync(FavoriteTypeEnum.HOST, id); favoriteApi.deleteByRelId(FavoriteTypeEnum.HOST, id);
return effect;
} }
/** /**

View File

@@ -28,7 +28,7 @@ public interface FavoriteApi {
* @param type type * @param type type
* @param relId relId * @param relId relId
*/ */
void deleteByRelIdAsync(FavoriteTypeEnum type, Long relId); void deleteByRelId(FavoriteTypeEnum type, Long relId);
/** /**
* 通过 relId 删除收藏 * 通过 relId 删除收藏
@@ -36,6 +36,6 @@ public interface FavoriteApi {
* @param type type * @param type type
* @param relIdList relIdList * @param relIdList relIdList
*/ */
void deleteByRelIdListAsync(FavoriteTypeEnum type, List<Long> relIdList); void deleteByRelIdList(FavoriteTypeEnum type, List<Long> relIdList);
} }

View File

@@ -22,7 +22,7 @@ public interface TagRelApi {
* @param relId relId * @param relId relId
* @param tagIdList tagIdList * @param tagIdList tagIdList
*/ */
void addTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList); void addTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList);
/** /**
* 设置标签引用 先删除后新增 * 设置标签引用 先删除后新增
@@ -31,7 +31,7 @@ public interface TagRelApi {
* @param relId relId * @param relId relId
* @param tagIdList tagIdList * @param tagIdList tagIdList
*/ */
void setTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList); void setTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList);
/** /**
* 获取引用 tag * 获取引用 tag
@@ -73,7 +73,7 @@ public interface TagRelApi {
* @param type type * @param type type
* @param relId relId * @param relId relId
*/ */
void deleteRelIdAsync(TagTypeEnum type, Long relId); void deleteRelId(TagTypeEnum type, Long relId);
/** /**
* 通过 relIdList 删除 * 通过 relIdList 删除
@@ -81,6 +81,6 @@ public interface TagRelApi {
* @param type type * @param type type
* @param relIdList relIdList * @param relIdList relIdList
*/ */
void deleteRelIdListAsync(TagTypeEnum type, List<Long> relIdList); void deleteRelIdList(TagTypeEnum type, List<Long> relIdList);
} }

View File

@@ -39,15 +39,13 @@ public class FavoriteApiImpl implements FavoriteApi {
} }
@Override @Override
@Async("asyncExecutor") public void deleteByRelId(FavoriteTypeEnum type, Long relId) {
public void deleteByRelIdAsync(FavoriteTypeEnum type, Long relId) {
Valid.allNotNull(type, relId); Valid.allNotNull(type, relId);
favoriteDAO.deleteFavoriteByRelId(type.name(), relId); favoriteDAO.deleteFavoriteByRelId(type.name(), relId);
} }
@Override @Override
@Async("asyncExecutor") public void deleteByRelIdList(FavoriteTypeEnum type, List<Long> relIdList) {
public void deleteByRelIdListAsync(FavoriteTypeEnum type, List<Long> relIdList) {
Valid.notNull(type); Valid.notNull(type);
Valid.notEmpty(relIdList); Valid.notEmpty(relIdList);
favoriteDAO.deleteFavoriteByRelIdList(type.name(), relIdList); favoriteDAO.deleteFavoriteByRelIdList(type.name(), relIdList);

View File

@@ -31,8 +31,7 @@ public class TagRelApiImpl implements TagRelApi {
private TagRelService tagRelService; private TagRelService tagRelService;
@Override @Override
@Async("asyncExecutor") public void addTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList) {
public void addTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList) {
Valid.notNull(relId); Valid.notNull(relId);
if (Lists.isEmpty(tagIdList)) { if (Lists.isEmpty(tagIdList)) {
return; return;
@@ -41,8 +40,7 @@ public class TagRelApiImpl implements TagRelApi {
} }
@Override @Override
@Async("asyncExecutor") public void setTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList) {
public void setTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList) {
Valid.notNull(relId); Valid.notNull(relId);
tagRelService.setTagRel(type.name(), relId, tagIdList); tagRelService.setTagRel(type.name(), relId, tagIdList);
} }
@@ -73,14 +71,12 @@ public class TagRelApiImpl implements TagRelApi {
} }
@Override @Override
@Async("asyncExecutor") public void deleteRelId(TagTypeEnum type, Long relId) {
public void deleteRelIdAsync(TagTypeEnum type, Long relId) {
tagRelService.deleteRelId(type.name(), relId); tagRelService.deleteRelId(type.name(), relId);
} }
@Override @Override
@Async("asyncExecutor") public void deleteRelIdList(TagTypeEnum type, List<Long> relIdList) {
public void deleteRelIdListAsync(TagTypeEnum type, List<Long> relIdList) {
tagRelService.deleteRelIdList(type.name(), relIdList); tagRelService.deleteRelIdList(type.name(), relIdList);
} }

View File

@@ -28,10 +28,10 @@ public interface TagConvert {
TagVO to(TagDO domain); TagVO to(TagDO domain);
TagVO to(TagCacheDTO cache);
TagCacheDTO toCache(TagDO domain); TagCacheDTO toCache(TagDO domain);
List<TagVO> to(List<TagDO> list); List<TagVO> to(List<TagDO> list);
List<TagVO> toList(List<TagCacheDTO> cache);
} }

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO; import com.orion.ops.module.infra.entity.dto.DataGroupCacheDTO;
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO; import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
@@ -20,6 +21,7 @@ public interface DataGroupCacheKeyDefine {
.key("data:group-list:{}") .key("data:group-list:{}")
.desc("数据分组列表结构 ${type}") .desc("数据分组列表结构 ${type}")
.type(DataGroupCacheDTO.class) .type(DataGroupCacheDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -27,6 +29,7 @@ public interface DataGroupCacheKeyDefine {
.key("data:group-tree:{}") .key("data:group-tree:{}")
.desc("数据分组树结构 ${type}") .desc("数据分组树结构 ${type}")
.type(DataGroupCacheDTO.class) .type(DataGroupCacheDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -34,6 +37,7 @@ public interface DataGroupCacheKeyDefine {
.key("data:group-rel:group:{}") .key("data:group-rel:group:{}")
.desc("数据分组数据关联-分组 ${groupId}") .desc("数据分组数据关联-分组 ${groupId}")
.type(DataGroupRelCacheDTO.class) .type(DataGroupRelCacheDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -41,6 +45,7 @@ public interface DataGroupCacheKeyDefine {
.key("data:group-rel:type:{}") .key("data:group-rel:type:{}")
.desc("数据分组数据关联-类型 ${type}") .desc("数据分组数据关联-类型 ${type}")
.type(DataGroupRelCacheDTO.class) .type(DataGroupRelCacheDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,8 +1,9 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import com.orion.ops.module.infra.entity.dto.DictKeyCacheDTO; import com.orion.ops.module.infra.entity.dto.DictKeyCacheDTO;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -20,6 +21,7 @@ public interface DictCacheKeyDefine {
.key("dict:keys") .key("dict:keys")
.desc("字典配置项") .desc("字典配置项")
.type(DictKeyCacheDTO.class) .type(DictKeyCacheDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -27,6 +29,7 @@ public interface DictCacheKeyDefine {
.key("dict:schema:{}") .key("dict:schema:{}")
.desc("字典配置项 schema ${key}") .desc("字典配置项 schema ${key}")
.type(JSONObject.class) .type(JSONObject.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -34,6 +37,7 @@ public interface DictCacheKeyDefine {
.key("dict:values:{}") .key("dict:values:{}")
.desc("字典配置值 ${key}") .desc("字典配置值 ${key}")
.type(JSONObject.class) .type(JSONObject.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -18,6 +19,7 @@ public interface FavoriteCacheKeyDefine {
.key("favorite:{}:{}") .key("favorite:{}:{}")
.desc("收藏信息 ${type} ${userId}") .desc("收藏信息 ${type} ${userId}")
.type(Long.class) .type(Long.class)
.struct(RedisCacheStruct.LIST)
.timeout(3, TimeUnit.DAYS) .timeout(3, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,8 +1,9 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -19,6 +20,7 @@ public interface PreferenceCacheKeyDefine {
.key("user:preference:{}:{}") .key("user:preference:{}:{}")
.desc("用户偏好 ${userId} ${type}") .desc("用户偏好 ${userId} ${type}")
.type(JSONObject.class) .type(JSONObject.class)
.struct(RedisCacheStruct.STRING)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import com.orion.ops.module.infra.entity.dto.TagCacheDTO; import com.orion.ops.module.infra.entity.dto.TagCacheDTO;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -19,6 +20,7 @@ public interface TagCacheKeyDefine {
.key("tag:name:{}") .key("tag:name:{}")
.desc("tag 名称 ${type}") .desc("tag 名称 ${type}")
.type(TagCacheDTO.class) .type(TagCacheDTO.class)
.struct(RedisCacheStruct.LIST)
.timeout(8, TimeUnit.HOURS) .timeout(8, TimeUnit.HOURS)
.build(); .build();
@@ -26,6 +28,7 @@ public interface TagCacheKeyDefine {
.key("tag:rel:{}:{}") .key("tag:rel:{}:{}")
.desc("tag 引用 ${type} ${relId}") .desc("tag 引用 ${type} ${relId}")
.type(TagCacheDTO.class) .type(TagCacheDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(8, TimeUnit.HOURS) .timeout(8, TimeUnit.HOURS)
.build(); .build();

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -18,6 +19,7 @@ public interface TipsCacheKeyDefine {
.key("user:tips:{}") .key("user:tips:{}")
.desc("user:tips ${userId} 90天不会重复提示") .desc("user:tips ${userId} 90天不会重复提示")
.type(String.class) .type(String.class)
.struct(RedisCacheStruct.LIST)
.timeout(90, TimeUnit.DAYS) .timeout(90, TimeUnit.DAYS)
.build(); .build();

View File

@@ -1,7 +1,8 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.key.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
import com.orion.ops.framework.common.security.LoginUser; import com.orion.ops.framework.common.security.LoginUser;
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO; import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
import com.orion.ops.module.infra.entity.dto.UserInfoDTO; import com.orion.ops.module.infra.entity.dto.UserInfoDTO;
@@ -21,12 +22,14 @@ public interface UserCacheKeyDefine {
.key("user:info:{}") .key("user:info:{}")
.desc("用户信息 ${id}") .desc("用户信息 ${id}")
.type(LoginUser.class) .type(LoginUser.class)
.struct(RedisCacheStruct.STRING)
.build(); .build();
CacheKeyDefine USER_LIST = new CacheKeyBuilder() CacheKeyDefine USER_LIST = new CacheKeyBuilder()
.key("user:base:list") .key("user:base:list")
.desc("用户列表") .desc("用户列表")
.type(UserInfoDTO.class) .type(UserInfoDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
@@ -34,6 +37,7 @@ public interface UserCacheKeyDefine {
.key("user:login-failed:{}") .key("user:login-failed:{}")
.desc("用户登录失败次数 ${username}") .desc("用户登录失败次数 ${username}")
.type(Integer.class) .type(Integer.class)
.struct(RedisCacheStruct.STRING)
.timeout(3, TimeUnit.DAYS) .timeout(3, TimeUnit.DAYS)
.build(); .build();
@@ -41,6 +45,7 @@ public interface UserCacheKeyDefine {
.key("user:token:{}:{}") .key("user:token:{}:{}")
.desc("用户登录 token ${id} ${time}") .desc("用户登录 token ${id} ${time}")
.type(LoginTokenDTO.class) .type(LoginTokenDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(24, TimeUnit.HOURS) .timeout(24, TimeUnit.HOURS)
.build(); .build();
@@ -48,6 +53,7 @@ public interface UserCacheKeyDefine {
.key("user:refresh:{}:{}") .key("user:refresh:{}:{}")
.desc("用户刷新 token ${id} ${time}") .desc("用户刷新 token ${id} ${time}")
.type(LoginTokenDTO.class) .type(LoginTokenDTO.class)
.struct(RedisCacheStruct.STRING)
.timeout(28, TimeUnit.HOURS) .timeout(28, TimeUnit.HOURS)
.build(); .build();

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.infra.entity.dto; package com.orion.ops.module.infra.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -21,7 +22,7 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "DataGroupCacheDTO", description = "数据分组 缓存对象") @Schema(name = "DataGroupCacheDTO", description = "数据分组 缓存对象")
public class DataGroupCacheDTO implements Serializable { public class DataGroupCacheDTO implements LongCacheIdModel, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.infra.entity.dto; package com.orion.ops.module.infra.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -20,7 +21,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "DataGroupRelCacheDTO", description = "数据分组关联 缓存对象") @Schema(name = "DataGroupRelCacheDTO", description = "数据分组关联 缓存对象")
public class DataGroupRelCacheDTO implements Serializable { public class DataGroupRelCacheDTO implements LongCacheIdModel, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.infra.entity.dto; package com.orion.ops.module.infra.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -21,7 +22,7 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "DictKeyCacheDTO", description = "字典配置项 缓存对象") @Schema(name = "DictKeyCacheDTO", description = "字典配置项 缓存对象")
public class DictKeyCacheDTO implements Serializable { public class DictKeyCacheDTO implements LongCacheIdModel, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -1,8 +1,11 @@
package com.orion.ops.module.infra.entity.dto; package com.orion.ops.module.infra.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import java.io.Serializable;
/** /**
* @author Jiahang Li * @author Jiahang Li
* @version 1.0.0 * @version 1.0.0
@@ -14,7 +17,7 @@ import lombok.*;
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Schema(name = "TagCacheDTO", description = "菜单 缓存业务对象") @Schema(name = "TagCacheDTO", description = "菜单 缓存业务对象")
public class TagCacheDTO { public class TagCacheDTO implements LongCacheIdModel, Serializable {
@EqualsAndHashCode.Include @EqualsAndHashCode.Include
@Schema(description = "id") @Schema(description = "id")

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.infra.entity.dto; package com.orion.ops.module.infra.entity.dto;
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
@@ -20,7 +21,7 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Schema(name = "UserInfoDTO", description = "用户信息 缓存对象") @Schema(name = "UserInfoDTO", description = "用户信息 缓存对象")
public class UserInfoDTO implements Serializable { public class UserInfoDTO implements LongCacheIdModel, Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -1,10 +1,9 @@
package com.orion.ops.module.infra.service.impl; package com.orion.ops.module.infra.service.impl;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.key.CacheKeyDefine;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.framework.redis.core.utils.RedisStrings;
@@ -229,17 +228,13 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
if (Lists.isEmpty(list)) { if (Lists.isEmpty(list)) {
// 查询数据库 // 查询数据库
list = valueSupplier.get(); list = valueSupplier.get();
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (Lists.isEmpty(list)) { RedisStrings.checkBarrier(list, DataGroupRelCacheDTO::new);
list.add(DataGroupRelCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisStrings.setJson(key, define, list); RedisStrings.setJson(key, define, list);
} }
// 删除默认值 // 删除屏障
list.removeIf(s -> s.getId().equals(Const.NONE_ID)); RedisStrings.removeBarrier(list);
return list; return list;
} }

View File

@@ -161,17 +161,13 @@ public class DataGroupServiceImpl implements DataGroupService {
.eq(DataGroupDO::getType, type) .eq(DataGroupDO::getType, type)
.then() .then()
.list(DataGroupConvert.MAPPER::toCache); .list(DataGroupConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisStrings.checkBarrier(list, DataGroupCacheDTO::new);
list.add(DataGroupCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, list); RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, list);
} }
// 删除默认值 // 删除屏障
list.removeIf(s -> s.getId().equals(Const.NONE_ID)); RedisStrings.removeBarrier(list);
return list; return list;
} }
@@ -183,12 +179,9 @@ public class DataGroupServiceImpl implements DataGroupService {
if (Lists.isEmpty(treeData)) { if (Lists.isEmpty(treeData)) {
// 查询列表缓存 // 查询列表缓存
List<DataGroupCacheDTO> rows = this.getDataGroupListByCache(type); List<DataGroupCacheDTO> rows = this.getDataGroupListByCache(type);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (Lists.isEmpty(rows)) { RedisStrings.checkBarrier(rows, DataGroupCacheDTO::new);
treeData = Lists.of(DataGroupCacheDTO.builder() if (!Lists.isEmpty(rows)) {
.id(Const.NONE_ID)
.build());
} else {
// 构建树 // 构建树
DataGroupCacheDTO rootNode = DataGroupCacheDTO.builder() DataGroupCacheDTO rootNode = DataGroupCacheDTO.builder()
.id(Const.ROOT_PARENT_ID) .id(Const.ROOT_PARENT_ID)
@@ -200,8 +193,8 @@ public class DataGroupServiceImpl implements DataGroupService {
// 设置缓存 // 设置缓存
RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, treeData); RedisStrings.setJson(key, DataGroupCacheKeyDefine.DATA_GROUP_LIST, treeData);
} }
// 删除默认值 // 删除屏障
treeData.removeIf(s -> s.getId().equals(Const.NONE_ID)); RedisStrings.removeBarrier(treeData);
return treeData; return treeData;
} }

View File

@@ -106,19 +106,16 @@ public class DictKeyServiceImpl implements DictKeyService {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = dictKeyDAO.of().list(DictKeyConvert.MAPPER::toCache); list = dictKeyDAO.of().list(DictKeyConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, DictKeyCacheDTO::new);
list.add(DictKeyCacheDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(DictCacheKeyDefine.DICT_KEY.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(DictCacheKeyDefine.DICT_KEY.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(DictCacheKeyDefine.DICT_KEY); RedisMaps.setExpire(DictCacheKeyDefine.DICT_KEY);
} }
// 删除默认值 // 删除屏障
RedisMaps.removeBarrier(list);
// 转换
return list.stream() return list.stream()
.filter(s -> !s.getId().equals(Const.NONE_ID))
.map(DictKeyConvert.MAPPER::to) .map(DictKeyConvert.MAPPER::to)
.sorted(Comparator.comparing(DictKeyVO::getId).reversed()) .sorted(Comparator.comparing(DictKeyVO::getId).reversed())
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@@ -6,7 +6,6 @@ import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.collect.Lists; import com.orion.lang.utils.collect.Lists;
import com.orion.lang.utils.crypto.Signatures; import com.orion.lang.utils.crypto.Signatures;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorCode; import com.orion.ops.framework.common.constant.ErrorCode;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.security.LoginUser; import com.orion.ops.framework.common.security.LoginUser;
@@ -164,21 +163,16 @@ public class SystemUserServiceImpl implements SystemUserService {
if (list.isEmpty()) { if (list.isEmpty()) {
// 查询数据库 // 查询数据库
list = systemUserDAO.of().list(SystemUserConvert.MAPPER::toUserInfo); list = systemUserDAO.of().list(SystemUserConvert.MAPPER::toUserInfo);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (list.isEmpty()) { RedisMaps.checkBarrier(list, UserInfoDTO::new);
list.add(UserInfoDTO.builder()
.id(Const.NONE_ID)
.build());
}
// 设置缓存 // 设置缓存
RedisMaps.putAllJson(UserCacheKeyDefine.USER_LIST.getKey(), s -> s.getId().toString(), list); RedisMaps.putAllJson(UserCacheKeyDefine.USER_LIST.getKey(), s -> s.getId().toString(), list);
RedisMaps.setExpire(UserCacheKeyDefine.USER_LIST); RedisMaps.setExpire(UserCacheKeyDefine.USER_LIST);
} }
// 删除默认值 // 删除屏障
return list.stream() RedisMaps.removeBarrier(list);
.filter(s -> !s.getId().equals(Const.NONE_ID)) // 转换
.map(SystemUserConvert.MAPPER::to) return Lists.map(list, SystemUserConvert.MAPPER::to);
.collect(Collectors.toList());
} }
@Override @Override

View File

@@ -2,6 +2,7 @@ package com.orion.ops.module.infra.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.mybatis.core.query.Conditions; import com.orion.ops.framework.mybatis.core.query.Conditions;
import com.orion.ops.framework.redis.core.utils.RedisLists; import com.orion.ops.framework.redis.core.utils.RedisLists;
@@ -61,23 +62,21 @@ public class TagServiceImpl implements TagService {
public List<TagVO> getTagList(String type) { public List<TagVO> getTagList(String type) {
// 查询缓存 // 查询缓存
String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type); String cacheKey = TagCacheKeyDefine.TAG_NAME.format(type);
List<TagCacheDTO> cacheValues = RedisLists.rangeJson(cacheKey, TagCacheKeyDefine.TAG_NAME); List<TagCacheDTO> list = RedisLists.rangeJson(cacheKey, TagCacheKeyDefine.TAG_NAME);
if (cacheValues.isEmpty()) { if (list.isEmpty()) {
// 为空则需要查询缓存 // 为空则需要查询缓存
LambdaQueryWrapper<TagDO> wrapper = Conditions.eq(TagDO::getType, type); LambdaQueryWrapper<TagDO> wrapper = Conditions.eq(TagDO::getType, type);
cacheValues = tagDAO.of(wrapper).list(TagConvert.MAPPER::toCache); list = tagDAO.of(wrapper).list(TagConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 设置屏障 防止穿透
if (cacheValues.isEmpty()) { RedisLists.checkBarrier(list, TagCacheDTO::new);
cacheValues.add(TagCacheDTO.builder().id(Const.NONE_ID).build());
}
// 设置到缓存 // 设置到缓存
RedisLists.pushAllJson(cacheKey, cacheValues); RedisLists.pushAllJson(cacheKey, list);
RedisLists.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME); RedisLists.setExpire(cacheKey, TagCacheKeyDefine.TAG_NAME);
} }
// 删除防止穿透的 key // 删除屏障
cacheValues.removeIf(s -> Const.NONE_ID.equals(s.getId())); RedisLists.removeBarrier(list);
// 转换 // 转换
return TagConvert.MAPPER.toList(cacheValues); return Lists.map(list, TagConvert.MAPPER::to);
} }
@Override @Override