⚡ 优化别名逻辑.
This commit is contained in:
@@ -64,4 +64,7 @@ public class HostVO implements Serializable {
|
||||
@Schema(description = "别名")
|
||||
private String alias;
|
||||
|
||||
@Schema(description = "颜色")
|
||||
private String color;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.orion.ops.module.asset.enums;
|
||||
import com.orion.ops.framework.common.handler.data.GenericsDataDefinition;
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostSshExtraModel;
|
||||
import com.orion.ops.module.asset.handler.host.extra.strategy.HostColorExtraStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.strategy.HostSshExtraStrategy;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -24,6 +26,11 @@ public enum HostExtraItemEnum implements GenericsDataDefinition {
|
||||
*/
|
||||
SSH("ssh", HostSshExtraModel.class, HostSshExtraStrategy.class),
|
||||
|
||||
/**
|
||||
* 颜色额外配置
|
||||
*/
|
||||
COLOR("color", HostColorExtraModel.class, HostColorExtraStrategy.class),
|
||||
|
||||
;
|
||||
|
||||
private final String item;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orion.ops.module.asset.handler.host.extra.model;
|
||||
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 - color 模型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/29 23:16
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "HostExtraSshModel", description = "主机拓展信息 - color 模型")
|
||||
public class HostColorExtraModel implements GenericsDataModel {
|
||||
|
||||
@Schema(description = "颜色")
|
||||
private String color;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.orion.ops.module.asset.handler.host.extra.strategy;
|
||||
|
||||
import com.orion.ops.framework.common.handler.data.strategy.MapDataStrategy;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 - 颜色 模型处理策略
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/2/29 23:16
|
||||
*/
|
||||
@Component
|
||||
public class HostColorExtraStrategy implements MapDataStrategy<HostColorExtraModel> {
|
||||
|
||||
@Override
|
||||
public HostColorExtraModel getDefault() {
|
||||
return HostColorExtraModel.builder()
|
||||
// 默认透明
|
||||
.color("")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(HostColorExtraModel beforeModel, HostColorExtraModel afterModel) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preValid(HostColorExtraModel model) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valid(HostColorExtraModel model) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
@@ -10,8 +12,10 @@ import com.orion.ops.module.asset.convert.HostGroupConvert;
|
||||
import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.*;
|
||||
import com.orion.ops.module.asset.enums.HostConnectTypeEnum;
|
||||
import com.orion.ops.module.asset.handler.host.extra.model.HostColorExtraModel;
|
||||
import com.orion.ops.module.asset.service.*;
|
||||
import com.orion.ops.module.infra.api.*;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItems;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.tag.TagDTO;
|
||||
import com.orion.ops.module.infra.enums.*;
|
||||
@@ -67,7 +71,7 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
private TagRelApi tagRelApi;
|
||||
|
||||
@Resource
|
||||
private DataAliasApi dataAliasApi;
|
||||
private DataExtraApi dataExtraApi;
|
||||
|
||||
@Override
|
||||
public List<Long> getAuthorizedDataRelId(DataPermissionTypeEnum type, AssetAuthorizedDataQueryRequest request) {
|
||||
@@ -179,8 +183,10 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
Future<List<Long>> favoriteResult = favoriteApi.getFavoriteRelIdListAsync(FavoriteTypeEnum.HOST, userId);
|
||||
// 查询最近连接的主机
|
||||
Future<List<Long>> latestConnectHostIdList = hostConnectLogService.getLatestConnectHostIdAsync(HostConnectTypeEnum.SSH, userId);
|
||||
// 查询数据别名
|
||||
Future<Map<Long, String>> dataAliasResult = dataAliasApi.getDataAliasAsync(userId, DataExtraTypeEnum.HOST);
|
||||
// 查询别名
|
||||
Future<Map<Long, String>> dataAliasResult = dataExtraApi.getExtraItemValuesByCacheAsync(userId, DataExtraTypeEnum.HOST, DataExtraItems.ALIAS);
|
||||
// 查询颜色
|
||||
Future<Map<Long, String>> dataColorResult = dataExtraApi.getExtraItemValuesByCacheAsync(userId, DataExtraTypeEnum.HOST, DataExtraItems.COLOR);
|
||||
// 查询分组
|
||||
List<DataGroupDTO> dataGroup = dataGroupApi.getDataGroupList(DataGroupTypeEnum.HOST);
|
||||
// 查询分组引用
|
||||
@@ -207,7 +213,8 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
// 设置主机拓展信息
|
||||
this.getAuthorizedHostExtra(wrapper.getHostList(),
|
||||
favoriteResult.get(),
|
||||
dataAliasResult.get());
|
||||
dataAliasResult.get(),
|
||||
dataColorResult.get());
|
||||
// 设置最近连接的主机
|
||||
wrapper.setLatestHosts(new LinkedHashSet<>(latestConnectHostIdList.get()));
|
||||
return wrapper;
|
||||
@@ -292,10 +299,12 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
* @param hosts hosts
|
||||
* @param favorite favorite
|
||||
* @param aliasMap aliasMap
|
||||
* @param colorMap colorMap
|
||||
*/
|
||||
private void getAuthorizedHostExtra(List<HostVO> hosts,
|
||||
List<Long> favorite,
|
||||
Map<Long, String> aliasMap) {
|
||||
Map<Long, String> aliasMap,
|
||||
Map<Long, String> colorMap) {
|
||||
if (Lists.isEmpty(hosts)) {
|
||||
return;
|
||||
}
|
||||
@@ -313,7 +322,21 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic
|
||||
}
|
||||
// 设置主机别名
|
||||
if (!Maps.isEmpty(aliasMap)) {
|
||||
hosts.forEach(s -> s.setAlias(aliasMap.get(s.getId())));
|
||||
hosts.forEach(s -> {
|
||||
String alias = aliasMap.get(s.getId());
|
||||
if (alias != null) {
|
||||
s.setAlias(Refs.unrefToString(alias));
|
||||
}
|
||||
});
|
||||
}
|
||||
// 设置主机颜色
|
||||
if (!Maps.isEmpty(colorMap)) {
|
||||
hosts.forEach(s -> {
|
||||
HostColorExtraModel color = JSON.parseObject(colorMap.get(s.getId()), HostColorExtraModel.class);
|
||||
if (color != null) {
|
||||
s.setColor(Refs.unrefToString(color.getColor()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.handler.data.model.GenericsDataModel;
|
||||
@@ -12,9 +13,8 @@ import com.orion.ops.module.asset.entity.request.host.HostExtraQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostExtraUpdateRequest;
|
||||
import com.orion.ops.module.asset.enums.HostExtraItemEnum;
|
||||
import com.orion.ops.module.asset.service.HostExtraService;
|
||||
import com.orion.ops.module.infra.api.DataAliasApi;
|
||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItems;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraQueryDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraSetDTO;
|
||||
@@ -36,20 +36,18 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class HostExtraServiceImpl implements HostExtraService {
|
||||
|
||||
@Resource
|
||||
private DataAliasApi dataAliasApi;
|
||||
|
||||
@Resource
|
||||
private DataExtraApi dataExtraApi;
|
||||
|
||||
@Override
|
||||
public Integer updateHostAlias(HostAliasUpdateRequest request) {
|
||||
DataAliasUpdateDTO update = DataAliasUpdateDTO.builder()
|
||||
DataExtraSetDTO update = DataExtraSetDTO.builder()
|
||||
.userId(SecurityUtils.getLoginUserId())
|
||||
.item(DataExtraItems.ALIAS)
|
||||
.relId(request.getId())
|
||||
.alias(request.getName())
|
||||
.value(Refs.json(request.getName()))
|
||||
.build();
|
||||
return dataAliasApi.updateDataAlias(update, DataExtraTypeEnum.HOST);
|
||||
return dataExtraApi.setExtraItem(update, DataExtraTypeEnum.HOST);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 数据别名 对外服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
public interface DataAliasApi {
|
||||
|
||||
/**
|
||||
* 更新数据别名
|
||||
*
|
||||
* @param dto dto
|
||||
* @param type type
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateDataAlias(DataAliasUpdateDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return aliasName
|
||||
*/
|
||||
String getDataAlias(Long userId, DataExtraTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @return relId:aliasName
|
||||
*/
|
||||
Map<Long, String> getDataAlias(Long userId, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 异步查询数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @return relId:aliasName
|
||||
*/
|
||||
Future<Map<Long, String>> getDataAliasAsync(Long userId, DataExtraTypeEnum type);
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 对外服务类
|
||||
@@ -69,6 +70,37 @@ public interface DataExtraApi {
|
||||
*/
|
||||
Map<Long, String> getExtraItemValues(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置项 (查询缓存)
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param item item
|
||||
* @param relId relId
|
||||
* @return value
|
||||
*/
|
||||
String getExtraItemValueByCache(Long userId, DataExtraTypeEnum type, String item, Long relId);
|
||||
|
||||
/**
|
||||
* 查询额外配置项 (查询缓存)
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param item item
|
||||
* @return relId:value
|
||||
*/
|
||||
Map<Long, String> getExtraItemValuesByCache(Long userId, DataExtraTypeEnum type, String item);
|
||||
|
||||
/**
|
||||
* 异步查询额外配置项 (查询缓存)
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param item item
|
||||
* @return value
|
||||
*/
|
||||
Future<Map<Long, String>> getExtraItemValuesByCacheAsync(Long userId, DataExtraTypeEnum type, String item);
|
||||
|
||||
/**
|
||||
* 查询额外配置
|
||||
*
|
||||
|
||||
@@ -11,4 +11,6 @@ public interface DataExtraItems {
|
||||
|
||||
String ALIAS = "alias";
|
||||
|
||||
String COLOR = "color";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据别名 更新请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataAliasUpdateDTO", description = "数据别名 创建请求业务对象")
|
||||
public class DataAliasUpdateDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "数据id")
|
||||
private Long relId;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 32)
|
||||
@Schema(description = "别名")
|
||||
private String alias;
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.orion.ops.module.infra.api.impl;
|
||||
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.module.infra.api.DataAliasApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataAliasUpdateRequest;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DataAliasService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 数据别名 对外服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataAliasApiImpl implements DataAliasApi {
|
||||
|
||||
@Resource
|
||||
private DataAliasService dataAliasService;
|
||||
|
||||
@Override
|
||||
public Integer updateDataAlias(DataAliasUpdateDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
DataAliasUpdateRequest update = DataAliasUpdateRequest.builder()
|
||||
.userId(dto.getUserId())
|
||||
.type(type.name())
|
||||
.relId(dto.getRelId())
|
||||
.alias(dto.getAlias())
|
||||
.build();
|
||||
return dataAliasService.updateDataAlias(update);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataAlias(Long userId, DataExtraTypeEnum type, Long relId) {
|
||||
Valid.allNotNull(userId, relId);
|
||||
return dataAliasService.getDataAlias(userId, type.name(), relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getDataAlias(Long userId, DataExtraTypeEnum type) {
|
||||
Valid.notNull(userId);
|
||||
return dataAliasService.getDataAlias(userId, type.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<Map<Long, String>> getDataAliasAsync(Long userId, DataExtraTypeEnum type) {
|
||||
Valid.notNull(userId);
|
||||
return CompletableFuture.completedFuture(dataAliasService.getDataAlias(userId, type.name()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,8 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -83,6 +85,23 @@ public class DataExtraApiImpl implements DataExtraApi {
|
||||
return dataExtraService.getExtraItemValues(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtraItemValueByCache(Long userId, DataExtraTypeEnum type, String item, Long relId) {
|
||||
Valid.allNotNull(userId, type, item, relId);
|
||||
return dataExtraService.getExtraItemValueByCache(userId, type.name(), item, relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getExtraItemValuesByCache(Long userId, DataExtraTypeEnum type, String item) {
|
||||
Valid.allNotNull(userId, type, item);
|
||||
return dataExtraService.getExtraItemValuesByCache(userId, type.name(), item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<Long, String>> getExtraItemValuesByCacheAsync(Long userId, DataExtraTypeEnum type, String item) {
|
||||
return CompletableFuture.completedFuture(this.getExtraItemValuesByCache(userId, type, item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataExtraDTO getExtraItem(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.allNotNull(dto.getUserId(), dto.getRelId(), dto.getItem());
|
||||
|
||||
@@ -15,9 +15,9 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public interface DataExtraCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine DATA_ALIAS = new CacheKeyBuilder()
|
||||
.key("data:alias:{}:{}")
|
||||
.desc("数据别名 ${userId} ${type}")
|
||||
CacheKeyDefine DATA_EXTRA = new CacheKeyBuilder()
|
||||
.key("data:extra:{}:{}:{}")
|
||||
.desc("数据推展信息 ${userId} ${type} ${item}")
|
||||
.type(String.class)
|
||||
.struct(RedisCacheStruct.HASH)
|
||||
.timeout(1, TimeUnit.DAYS)
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.orion.ops.module.infra.entity.request.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据别名 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataAliasUpdateRequest", description = "数据别名 更新请求对象")
|
||||
public class DataAliasUpdateRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "数据id")
|
||||
private Long relId;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "别名")
|
||||
private String alias;
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.ops.module.infra.entity.request.data.DataAliasUpdateRequest;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据别名 服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
public interface DataAliasService {
|
||||
|
||||
/**
|
||||
* 更新数据别名
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateDataAlias(DataAliasUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return aliasName
|
||||
*/
|
||||
String getDataAlias(Long userId, String type, Long relId);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @return relId:aliasName
|
||||
*/
|
||||
Map<Long, String> getDataAlias(Long userId, String type);
|
||||
|
||||
}
|
||||
@@ -64,6 +64,27 @@ public interface DataExtraService {
|
||||
*/
|
||||
Map<Long, String> getExtraItemValues(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项 (查询缓存)
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param item item
|
||||
* @param relId relId
|
||||
* @return value
|
||||
*/
|
||||
String getExtraItemValueByCache(Long userId, String type, String item, Long relId);
|
||||
|
||||
/**
|
||||
* 查询额外配置项 (查询缓存)
|
||||
*
|
||||
* @param userId userId
|
||||
* @param type type
|
||||
* @param item item
|
||||
* @return relId:value
|
||||
*/
|
||||
Map<Long, String> getExtraItemValuesByCache(Long userId, String type, String item);
|
||||
|
||||
/**
|
||||
* 查询额外配置
|
||||
*
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItems;
|
||||
import com.orion.ops.module.infra.define.cache.DataExtraCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataAliasUpdateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraSetRequest;
|
||||
import com.orion.ops.module.infra.service.DataAliasService;
|
||||
import com.orion.ops.module.infra.service.DataExtraService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* 数据别名 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataAliasServiceImpl implements DataAliasService {
|
||||
|
||||
@Resource
|
||||
private DataExtraService dataExtraService;
|
||||
|
||||
@Override
|
||||
public Integer updateDataAlias(DataAliasUpdateRequest request) {
|
||||
Long userId = request.getUserId();
|
||||
String type = request.getType();
|
||||
// 更新
|
||||
DataExtraSetRequest update = new DataExtraSetRequest();
|
||||
update.setUserId(userId);
|
||||
update.setRelId(request.getRelId());
|
||||
update.setType(type);
|
||||
update.setItem(DataExtraItems.ALIAS);
|
||||
update.setValue(Refs.json(request.getAlias()));
|
||||
Integer effect = dataExtraService.setExtraItem(update);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DataExtraCacheKeyDefine.DATA_ALIAS.format(userId, type));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataAlias(Long userId, String type, Long relId) {
|
||||
return this.getDataAlias(userId, type).get(relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getDataAlias(Long userId, String type) {
|
||||
// 查询缓存
|
||||
String key = DataExtraCacheKeyDefine.DATA_ALIAS.format(userId, type);
|
||||
Map<String, String> entities = RedisMaps.entities(key);
|
||||
if (Maps.isEmpty(entities)) {
|
||||
// 查询数据库
|
||||
DataExtraQueryRequest request = DataExtraQueryRequest.builder()
|
||||
.userId(userId)
|
||||
.type(type)
|
||||
.item(DataExtraItems.ALIAS)
|
||||
.build();
|
||||
Map<Long, String> extras = dataExtraService.getExtraItemValues(request);
|
||||
entities = Maps.map(extras, String::valueOf, Refs::unrefToString);
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.MAP.check(entities);
|
||||
// 设置缓存
|
||||
RedisMaps.putAll(key, DataExtraCacheKeyDefine.DATA_ALIAS, entities);
|
||||
}
|
||||
// 删除屏障
|
||||
CacheBarriers.MAP.remove(entities);
|
||||
// 转换
|
||||
return Maps.map(entities, Long::valueOf, Function.identity());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,14 @@ package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.mybatis.core.query.ThenLambdaWrapper;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.infra.dao.DataExtraDAO;
|
||||
import com.orion.ops.module.infra.define.cache.DataExtraCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.DataExtraDO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraSetRequest;
|
||||
@@ -15,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -62,15 +68,29 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
insert.setItem(request.getItem());
|
||||
insert.setValue(request.getValue());
|
||||
dataExtraDAO.insert(insert);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DataExtraCacheKeyDefine.DATA_EXTRA.format(request.getUserId(), request.getType(), request.getItem()));
|
||||
return insert.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateExtraValue(Long id, String value) {
|
||||
// 查询数据
|
||||
DataExtraDO data = this.getCacheSelectWrapper()
|
||||
.eq(DataExtraDO::getId, id)
|
||||
.then()
|
||||
.get();
|
||||
if (data == null) {
|
||||
return Const.N_0;
|
||||
}
|
||||
DataExtraDO update = new DataExtraDO();
|
||||
update.setId(id);
|
||||
update.setValue(value);
|
||||
return dataExtraDAO.updateById(update);
|
||||
// 更新
|
||||
int effect = dataExtraDAO.updateById(update);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DataExtraCacheKeyDefine.DATA_EXTRA.format(data.getUserId(), data.getType(), data.getItem()));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,8 +98,16 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
if (Maps.isEmpty(map)) {
|
||||
return;
|
||||
}
|
||||
// 查询数据
|
||||
List<DataExtraDO> list = this.getCacheSelectWrapper()
|
||||
.in(DataExtraDO::getId, map.keySet())
|
||||
.then()
|
||||
.list();
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 批量更新
|
||||
List<DataExtraDO> list = map.entrySet()
|
||||
List<DataExtraDO> update = map.entrySet()
|
||||
.stream()
|
||||
.map(s -> {
|
||||
DataExtraDO extra = new DataExtraDO();
|
||||
@@ -87,7 +115,9 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
extra.setValue(s.getValue());
|
||||
return extra;
|
||||
}).collect(Collectors.toList());
|
||||
dataExtraDAO.updateBatch(list);
|
||||
dataExtraDAO.updateBatch(update);
|
||||
// 删除缓存
|
||||
this.deleteCache(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,6 +140,37 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtraItemValueByCache(Long userId, String type, String item, Long relId) {
|
||||
return this.getExtraItemValuesByCache(userId, type, item).get(relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getExtraItemValuesByCache(Long userId, String type, String item) {
|
||||
// todo TEST
|
||||
// 查询缓存
|
||||
String key = DataExtraCacheKeyDefine.DATA_EXTRA.format(userId, type, item);
|
||||
Map<String, String> entities = RedisMaps.entities(key);
|
||||
if (Maps.isEmpty(entities)) {
|
||||
// 查询数据库
|
||||
DataExtraQueryRequest request = DataExtraQueryRequest.builder()
|
||||
.userId(userId)
|
||||
.type(type)
|
||||
.item(item)
|
||||
.build();
|
||||
Map<Long, String> extras = this.getExtraItemValues(request);
|
||||
entities = Maps.map(extras, String::valueOf, String::valueOf);
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.MAP.check(entities);
|
||||
// 设置缓存
|
||||
RedisMaps.putAll(key, DataExtraCacheKeyDefine.DATA_EXTRA, entities);
|
||||
}
|
||||
// 删除屏障
|
||||
CacheBarriers.MAP.remove(entities);
|
||||
// 转换
|
||||
return Maps.map(entities, Long::valueOf, Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataExtraDO getExtraItem(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
@@ -126,12 +187,64 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
|
||||
@Override
|
||||
public Integer deleteByUserId(Long userId) {
|
||||
return dataExtraDAO.deleteByUserId(userId);
|
||||
// 查询数据 TODO TEST
|
||||
List<DataExtraDO> list = this.getCacheSelectWrapper()
|
||||
.eq(DataExtraDO::getUserId, userId)
|
||||
.then()
|
||||
.list();
|
||||
if (list.isEmpty()) {
|
||||
return Const.N_0;
|
||||
}
|
||||
// 删除数据
|
||||
int effect = dataExtraDAO.deleteByUserId(userId);
|
||||
// 删除缓存
|
||||
this.deleteCache(list);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(String type, Long relId) {
|
||||
return dataExtraDAO.deleteByRelId(type, relId);
|
||||
// 查询数据 TODO TEST
|
||||
List<DataExtraDO> list = this.getCacheSelectWrapper()
|
||||
.eq(DataExtraDO::getType, type)
|
||||
.eq(DataExtraDO::getRelId, relId)
|
||||
.then()
|
||||
.list();
|
||||
if (list.isEmpty()) {
|
||||
return Const.N_0;
|
||||
}
|
||||
// 删除数据
|
||||
int effect = dataExtraDAO.deleteByRelId(type, relId);
|
||||
// 删除缓存
|
||||
this.deleteCache(list);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询缓存参数 wrapper 不查询 longtext 加速查询
|
||||
*
|
||||
* @return wrapper
|
||||
*/
|
||||
private ThenLambdaWrapper<DataExtraDO> getCacheSelectWrapper() {
|
||||
return dataExtraDAO.of()
|
||||
.createWrapper()
|
||||
.select(DataExtraDO::getId, DataExtraDO::getUserId, DataExtraDO::getType, DataExtraDO::getItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param list list
|
||||
*/
|
||||
private void deleteCache(List<DataExtraDO> list) {
|
||||
if (Lists.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
List<String> keys = list.stream()
|
||||
.map(s -> DataExtraCacheKeyDefine.DATA_EXTRA.format(s.getUserId(), s.getType(), s.getItem()))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
RedisMaps.delete(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user