feat: 数据拓展服务.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.orion.ops.framework.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
|
||||
/**
|
||||
* ref 工具类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/19 18:07
|
||||
*/
|
||||
public class Refs {
|
||||
|
||||
private Refs() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为 ref json
|
||||
*
|
||||
* @param o o
|
||||
* @return json
|
||||
*/
|
||||
public static String toJson(Object o) {
|
||||
return JSON.toJSONString(Ref.of(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* ref json 转为 ref value
|
||||
*
|
||||
* @param json json
|
||||
* @return value
|
||||
*/
|
||||
public static Object parseObject(String json) {
|
||||
Ref<?> ref = JSON.parseObject(json, Ref.class);
|
||||
if (ref == null) {
|
||||
return null;
|
||||
}
|
||||
return ref.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializeFilter;
|
||||
import com.orion.lang.define.thread.ExecutorBuilder;
|
||||
import com.orion.lang.utils.Arrays1;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.json.matcher.ReplacementFormatters;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.IgnoreParameter;
|
||||
@@ -19,7 +20,6 @@ import com.orion.ops.framework.common.enums.BooleanBit;
|
||||
import com.orion.ops.framework.common.meta.TraceIdHolder;
|
||||
import com.orion.ops.framework.common.security.LoginUser;
|
||||
import com.orion.ops.framework.common.security.SecurityHolder;
|
||||
import com.orion.ops.framework.common.utils.Refs;
|
||||
import com.orion.ops.framework.common.utils.Requests;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -270,7 +270,7 @@ public class OperatorLogAspect {
|
||||
// 脱敏
|
||||
model.setReturnValue(JSON.toJSONString(ret, serializeFilters));
|
||||
} else if (ReturnType.TO_STRING.equals(retType)) {
|
||||
model.setReturnValue(Refs.toJson(Objects.toString(ret)));
|
||||
model.setReturnValue(Refs.json(Objects.toString(ret)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostVO;
|
||||
import com.orion.ops.module.asset.service.HostConfigService;
|
||||
import com.orion.ops.module.asset.service.HostService;
|
||||
import com.orion.ops.module.infra.api.DataAliasApi;
|
||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.api.FavoriteApi;
|
||||
import com.orion.ops.module.infra.api.TagRelApi;
|
||||
@@ -74,7 +74,7 @@ public class HostServiceImpl implements HostService {
|
||||
private DataGroupRelApi dataGroupRelApi;
|
||||
|
||||
@Resource
|
||||
private DataAliasApi dataAliasApi;
|
||||
private DataExtraApi dataExtraApi;
|
||||
|
||||
@Override
|
||||
public Long createHost(HostCreateRequest request) {
|
||||
@@ -218,8 +218,8 @@ public class HostServiceImpl implements HostService {
|
||||
tagRelApi.deleteRelId(TagTypeEnum.HOST, id);
|
||||
// 删除收藏引用
|
||||
favoriteApi.deleteByRelId(FavoriteTypeEnum.HOST, id);
|
||||
// 删除主机别名
|
||||
dataAliasApi.deleteByRelId(DataExtraTypeEnum.HOST, id);
|
||||
// 删除额外配置
|
||||
dataExtraApi.deleteByRelId(DataExtraTypeEnum.HOST, id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,13 +52,4 @@ public interface DataAliasApi {
|
||||
*/
|
||||
Future<Map<Long, String>> getDataAliasAsync(Long userId, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 删除数据别名
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByRelId(DataExtraTypeEnum type, Long relId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
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.DataExtraUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -26,22 +27,11 @@ public interface DataExtraApi {
|
||||
Integer updateExtraItem(DataExtraUpdateDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
* 批量更新数据拓展信息
|
||||
*
|
||||
* @param type type
|
||||
* @param dto dto
|
||||
* @return items
|
||||
* @param map map
|
||||
*/
|
||||
Map<String, String> getExtraItems(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param dto dto
|
||||
* @param type type
|
||||
* @return items
|
||||
*/
|
||||
MultiHashMap<Long, String, String> getExtraItemsList(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
void batchUpdate(Map<Long, Object> map);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
@@ -61,6 +51,15 @@ public interface DataExtraApi {
|
||||
*/
|
||||
Map<Long, String> getExtraItemList(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置
|
||||
*
|
||||
* @param dto dto
|
||||
* @param type type
|
||||
* @return effect
|
||||
*/
|
||||
List<DataExtraDTO> getExtraList(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 通过 relId 删除
|
||||
*
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.orion.ops.module.infra.constant;
|
||||
|
||||
/**
|
||||
* 数据额外字段常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/19 22:26
|
||||
*/
|
||||
public interface DataExtraItemConst {
|
||||
|
||||
String ALIAS = "alias";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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 java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 22:00
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataExtraDTO", description = "数据拓展信息 业务对象")
|
||||
public class DataExtraDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
private Long relId;
|
||||
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "拓展项")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "拓展值")
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package com.orion.ops.module.infra.handler.preference.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.utils.Refs;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -24,7 +24,7 @@ public interface PreferenceModel {
|
||||
*/
|
||||
default Map<String, String> toMap() {
|
||||
JSONObject map = JSON.parseObject(JSON.toJSONString(this));
|
||||
return Maps.map(map, Function.identity(), Refs::toJson);
|
||||
return Maps.map(map, Function.identity(), Refs::json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,10 +58,4 @@ public class DataAliasApiImpl implements DataAliasApi {
|
||||
return CompletableFuture.completedFuture(dataAliasService.getDataAlias(userId, type.name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(DataExtraTypeEnum type, Long relId) {
|
||||
Valid.notNull(relId);
|
||||
return dataAliasService.deleteByRelId(type.name(), relId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.orion.ops.module.infra.api.impl;
|
||||
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.module.infra.api.DataExtraApi;
|
||||
import com.orion.ops.module.infra.convert.DataExtraProviderConvert;
|
||||
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.DataExtraUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
@@ -14,7 +14,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 对外服务实现类
|
||||
@@ -40,23 +42,8 @@ public class DataExtraApiImpl implements DataExtraApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraItems(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
Valid.notNull(dto.getRelId());
|
||||
// 查询
|
||||
DataExtraQueryRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.getExtraItems(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiHashMap<Long, String, String> getExtraItemsList(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
Valid.notNull(dto.getRelIdList());
|
||||
// 查询
|
||||
DataExtraQueryRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.getExtraItemsList(request);
|
||||
public void batchUpdate(Map<Long, Object> map) {
|
||||
dataExtraService.batchUpdate(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,6 +66,16 @@ public class DataExtraApiImpl implements DataExtraApi {
|
||||
return dataExtraService.getExtraItemList(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataExtraDTO> getExtraList(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
DataExtraQueryRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.getExtraList(request)
|
||||
.stream()
|
||||
.map(DataExtraProviderConvert.MAPPER::to)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(DataExtraTypeEnum type, Long relId) {
|
||||
return dataExtraService.deleteByRelId(type.name(), relId);
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.module.infra.entity.domain.DataAliasDO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataAliasUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 数据别名 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataAliasConvert {
|
||||
|
||||
DataAliasConvert MAPPER = Mappers.getMapper(DataAliasConvert.class);
|
||||
|
||||
DataAliasDO to(DataAliasUpdateRequest request);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.module.infra.entity.domain.DataExtraDO;
|
||||
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.DataExtraUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
@@ -23,4 +25,6 @@ public interface DataExtraProviderConvert {
|
||||
|
||||
DataExtraUpdateRequest to(DataExtraUpdateDTO update);
|
||||
|
||||
DataExtraDTO to(DataExtraDO domain);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.orion.ops.module.infra.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.infra.entity.domain.DataAliasDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据别名 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataAliasDAO extends IMapper<DataAliasDO> {
|
||||
|
||||
/**
|
||||
* 通过 userId 删除
|
||||
*
|
||||
* @param userId userId
|
||||
* @return effect
|
||||
*/
|
||||
default int deleteByUserId(Long userId) {
|
||||
LambdaQueryWrapper<DataAliasDO> wrapper = this.lambda()
|
||||
.eq(DataAliasDO::getUserId, userId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 数据别名缓存 key
|
||||
* 数据拓展缓存 key
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
public interface DataAliasCacheKeyDefine {
|
||||
public interface DataExtraCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine DATA_ALIAS = new CacheKeyBuilder()
|
||||
.key("data:alias:{}:{}")
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.orion.ops.module.infra.entity.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.math.*;
|
||||
|
||||
/**
|
||||
* 数据别名 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-18 17:37
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "data_alias", autoResultMap = true)
|
||||
@Schema(name = "DataAliasDO", description = "数据别名 实体对象")
|
||||
public class DataAliasDO extends BaseDO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
@TableField("rel_id")
|
||||
private Long relId;
|
||||
|
||||
@Schema(description = "数据类型")
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "别名")
|
||||
@TableField("alias")
|
||||
private String alias;
|
||||
|
||||
}
|
||||
@@ -40,21 +40,4 @@ public interface DataAliasService {
|
||||
*/
|
||||
Map<Long, String> getDataAlias(Long userId, String type);
|
||||
|
||||
/**
|
||||
* 删除数据别名
|
||||
*
|
||||
* @param userId userId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 删除数据别名
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByRelId(String type, Long relId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
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.DataExtraUpdateRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -24,20 +25,11 @@ public interface DataExtraService {
|
||||
Integer updateExtraItem(DataExtraUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
* 批量更新数据拓展信息
|
||||
*
|
||||
* @param request request
|
||||
* @return items
|
||||
* @param map map
|
||||
*/
|
||||
Map<String, String> getExtraItems(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param request request
|
||||
* @return items
|
||||
*/
|
||||
MultiHashMap<Long, String, String> getExtraItemsList(DataExtraQueryRequest request);
|
||||
void batchUpdate(Map<Long, Object> map);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
@@ -55,6 +47,14 @@ public interface DataExtraService {
|
||||
*/
|
||||
Map<Long, String> getExtraItemList(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
List<DataExtraDO> getExtraList(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 通过 userId 删除
|
||||
*
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
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.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.convert.DataAliasConvert;
|
||||
import com.orion.ops.module.infra.dao.DataAliasDAO;
|
||||
import com.orion.ops.module.infra.define.cache.DataAliasCacheKeyDefine;
|
||||
import com.orion.ops.module.infra.entity.domain.DataAliasDO;
|
||||
import com.orion.ops.module.infra.constant.DataExtraItemConst;
|
||||
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.DataExtraUpdateRequest;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据别名 服务实现类
|
||||
@@ -33,36 +30,22 @@ import java.util.stream.Collectors;
|
||||
public class DataAliasServiceImpl implements DataAliasService {
|
||||
|
||||
@Resource
|
||||
private DataAliasDAO dataAliasDAO;
|
||||
private DataExtraService dataExtraService;
|
||||
|
||||
@Override
|
||||
public Integer updateDataAlias(DataAliasUpdateRequest request) {
|
||||
// 检查是否存在
|
||||
Long userId = request.getUserId();
|
||||
String type = request.getType();
|
||||
DataAliasDO alias = dataAliasDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DataAliasDO::getUserId, userId)
|
||||
.eq(DataAliasDO::getType, type)
|
||||
.eq(DataAliasDO::getRelId, request.getRelId())
|
||||
.then()
|
||||
.only()
|
||||
.get();
|
||||
int effect;
|
||||
if (alias == null) {
|
||||
// 插入
|
||||
DataAliasDO record = DataAliasConvert.MAPPER.to(request);
|
||||
effect = dataAliasDAO.insert(record);
|
||||
} else {
|
||||
// 更新
|
||||
DataAliasDO update = DataAliasDO.builder()
|
||||
.id(alias.getId())
|
||||
.alias(request.getAlias())
|
||||
.build();
|
||||
effect = dataAliasDAO.updateById(update);
|
||||
}
|
||||
// 更新
|
||||
DataExtraUpdateRequest update = new DataExtraUpdateRequest();
|
||||
update.setUserId(userId);
|
||||
update.setRelId(request.getRelId());
|
||||
update.setType(type);
|
||||
update.setItem(DataExtraItemConst.ALIAS);
|
||||
update.setValue(request.getAlias());
|
||||
Integer effect = dataExtraService.updateExtraItem(update);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(DataAliasCacheKeyDefine.DATA_ALIAS.format(userId, type));
|
||||
RedisMaps.delete(DataExtraCacheKeyDefine.DATA_ALIAS.format(userId, type));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -74,26 +57,21 @@ public class DataAliasServiceImpl implements DataAliasService {
|
||||
@Override
|
||||
public Map<Long, String> getDataAlias(Long userId, String type) {
|
||||
// 查询缓存
|
||||
String key = DataAliasCacheKeyDefine.DATA_ALIAS.format(userId, type);
|
||||
String key = DataExtraCacheKeyDefine.DATA_ALIAS.format(userId, type);
|
||||
Map<String, String> entities = RedisMaps.entities(key);
|
||||
if (Maps.isEmpty(entities)) {
|
||||
// 查询数据库
|
||||
entities = dataAliasDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DataAliasDO::getUserId, userId)
|
||||
.eq(DataAliasDO::getType, type)
|
||||
.then()
|
||||
.stream()
|
||||
.filter(s -> Objects.nonNull(s.getAlias()))
|
||||
.collect(Collectors.toMap(
|
||||
s -> String.valueOf(s.getRelId()),
|
||||
DataAliasDO::getAlias,
|
||||
Functions.right())
|
||||
);
|
||||
DataExtraQueryRequest request = DataExtraQueryRequest.builder()
|
||||
.userId(userId)
|
||||
.type(type)
|
||||
.item(DataExtraItemConst.ALIAS)
|
||||
.build();
|
||||
Map<Long, String> extras = dataExtraService.getExtraItemList(request);
|
||||
entities = Maps.map(extras, String::valueOf, Refs::unrefToString);
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.MAP.check(entities);
|
||||
// 设置缓存
|
||||
RedisMaps.putAll(key, DataAliasCacheKeyDefine.DATA_ALIAS, entities);
|
||||
RedisMaps.putAll(key, DataExtraCacheKeyDefine.DATA_ALIAS, entities);
|
||||
}
|
||||
// 删除屏障
|
||||
CacheBarriers.MAP.remove(entities);
|
||||
@@ -101,37 +79,4 @@ public class DataAliasServiceImpl implements DataAliasService {
|
||||
return Maps.map(entities, Long::valueOf, Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByUserId(Long userId) {
|
||||
// 删除
|
||||
int effect = dataAliasDAO.deleteByUserId(userId);
|
||||
// 删除缓存
|
||||
RedisMaps.scanKeysDelete(DataAliasCacheKeyDefine.DATA_ALIAS.format(userId, "*"));
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(String type, Long relId) {
|
||||
LambdaQueryWrapper<DataAliasDO> wrapper = dataAliasDAO.lambda()
|
||||
.eq(DataAliasDO::getType, type)
|
||||
.eq(DataAliasDO::getRelId, relId);
|
||||
// 查询
|
||||
List<Long> userIdList = dataAliasDAO.selectList(wrapper)
|
||||
.stream()
|
||||
.map(DataAliasDO::getUserId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (userIdList.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
// 删除
|
||||
int effect = dataAliasDAO.delete(wrapper);
|
||||
// 删除缓存
|
||||
List<String> keys = userIdList.stream()
|
||||
.map(s -> DataAliasCacheKeyDefine.DATA_ALIAS.format(s, type))
|
||||
.collect(Collectors.toList());
|
||||
RedisMaps.delete(keys);
|
||||
return effect;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.ops.framework.common.utils.Refs;
|
||||
import com.orion.lang.utils.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.module.infra.dao.DataExtraDAO;
|
||||
import com.orion.ops.module.infra.entity.domain.DataExtraDO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -53,38 +54,32 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
insert.setRelId(relId);
|
||||
insert.setType(type);
|
||||
insert.setItem(item);
|
||||
insert.setValue(Refs.toJson(value));
|
||||
insert.setValue(Refs.json(value));
|
||||
return dataExtraDAO.insert(insert);
|
||||
} else {
|
||||
// 修改
|
||||
DataExtraDO update = new DataExtraDO();
|
||||
update.setId(extraItem.getId());
|
||||
update.setValue(Refs.toJson(value));
|
||||
update.setValue(Refs.json(value));
|
||||
return dataExtraDAO.updateById(update);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME updateBatch
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraItems(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
public void batchUpdate(Map<Long, Object> map) {
|
||||
if (Maps.isEmpty(map)) {
|
||||
return;
|
||||
}
|
||||
// 批量更新
|
||||
List<DataExtraDO> list = map.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DataExtraDO::getItem,
|
||||
DataExtraDO::getValue,
|
||||
Functions.right())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiHashMap<Long, String, String> getExtraItemsList(DataExtraQueryRequest request) {
|
||||
MultiHashMap<Long, String, String> result = MultiHashMap.create();
|
||||
dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
.list()
|
||||
.forEach(s -> result.put(s.getRelId(), s.getItem(), s.getValue()));
|
||||
return result;
|
||||
.map(s -> {
|
||||
DataExtraDO extra = new DataExtraDO();
|
||||
extra.setId(s.getKey());
|
||||
extra.setValue(Refs.json(s.getValue()));
|
||||
return extra;
|
||||
}).collect(Collectors.toList());
|
||||
dataExtraDAO.updateBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,6 +102,13 @@ public class DataExtraServiceImpl implements DataExtraService {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataExtraDO> getExtraList(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByUserId(Long userId) {
|
||||
return dataExtraDAO.deleteByUserId(userId);
|
||||
|
||||
@@ -2,8 +2,8 @@ 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.Refs;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.utils.Refs;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
@@ -17,6 +17,7 @@ import com.orion.ops.module.infra.service.PreferenceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
@@ -62,13 +63,13 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
insertRecord.setUserId(userId);
|
||||
insertRecord.setType(type);
|
||||
insertRecord.setItem(item);
|
||||
insertRecord.setValue(Refs.toJson(request.getValue()));
|
||||
insertRecord.setValue(Refs.json(request.getValue()));
|
||||
effect = preferenceDAO.insert(insertRecord);
|
||||
} else {
|
||||
// 更新
|
||||
PreferenceDO updateRecord = new PreferenceDO();
|
||||
updateRecord.setId(preference.getId());
|
||||
updateRecord.setValue(Refs.toJson(request.getValue()));
|
||||
updateRecord.setValue(Refs.json(request.getValue()));
|
||||
effect = preferenceDAO.updateById(updateRecord);
|
||||
}
|
||||
// 删除缓存
|
||||
@@ -76,31 +77,49 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
return effect;
|
||||
}
|
||||
|
||||
// FIXME updateBatch
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePreferencePartial(PreferenceUpdatePartialRequest request) {
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
String type = request.getType();
|
||||
Map<String, Object> config = request.getConfig();
|
||||
Valid.valid(PreferenceTypeEnum::of, type);
|
||||
// 删除配置
|
||||
// 查询配置
|
||||
LambdaQueryWrapper<PreferenceDO> wrapper = preferenceDAO.lambda()
|
||||
.eq(PreferenceDO::getUserId, userId)
|
||||
.eq(PreferenceDO::getType, type)
|
||||
.in(PreferenceDO::getItem, config.keySet());
|
||||
preferenceDAO.delete(wrapper);
|
||||
// 插入配置
|
||||
List<PreferenceDO> records = config.entrySet()
|
||||
Map<String, PreferenceDO> items = preferenceDAO.selectList(wrapper)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
PreferenceDO::getItem,
|
||||
Function.identity(),
|
||||
Functions.right())
|
||||
);
|
||||
// 修改配置
|
||||
List<PreferenceDO> updateRecords = config.keySet()
|
||||
.stream()
|
||||
.filter(items::containsKey)
|
||||
.map(s -> {
|
||||
PreferenceDO insertRecord = new PreferenceDO();
|
||||
insertRecord.setUserId(userId);
|
||||
insertRecord.setType(type);
|
||||
insertRecord.setItem(s.getKey());
|
||||
insertRecord.setValue(Refs.toJson(s.getValue()));
|
||||
return insertRecord;
|
||||
PreferenceDO update = new PreferenceDO();
|
||||
update.setId(items.get(s).getId());
|
||||
update.setValue(Refs.json(config.get(s)));
|
||||
return update;
|
||||
}).collect(Collectors.toList());
|
||||
preferenceDAO.insertBatch(records);
|
||||
preferenceDAO.updateBatch(updateRecords);
|
||||
// 插入配置
|
||||
List<PreferenceDO> insertRecords = config.keySet()
|
||||
.stream()
|
||||
.filter(s -> !items.containsKey(s))
|
||||
.map(s -> {
|
||||
PreferenceDO insert = new PreferenceDO();
|
||||
insert.setUserId(userId);
|
||||
insert.setType(type);
|
||||
insert.setItem(s);
|
||||
insert.setValue(Refs.json(config.get(s)));
|
||||
return insert;
|
||||
}).collect(Collectors.toList());
|
||||
preferenceDAO.insertBatch(insertRecords);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(PreferenceCacheKeyDefine.PREFERENCE.format(userId, type));
|
||||
}
|
||||
@@ -183,7 +202,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
RedisMaps.putAll(key, PreferenceCacheKeyDefine.PREFERENCE, config);
|
||||
}
|
||||
// unref
|
||||
return Maps.map(config, Function.identity(), Refs::parseObject);
|
||||
return Maps.map(config, Function.identity(), Refs::unref);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.orion.ops.module.infra.dao.DataAliasDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DataAliasDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="rel_id" property="relId"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="alias" property="alias"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="creator" property="creator"/>
|
||||
<result column="updater" property="updater"/>
|
||||
<result column="deleted" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, rel_id, type, alias, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user