feat: 数据拓展信息服务.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataAliasTypeEnum;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -22,7 +22,7 @@ public interface DataAliasApi {
|
||||
* @param type type
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateDataAlias(DataAliasUpdateDTO dto, DataAliasTypeEnum type);
|
||||
Integer updateDataAlias(DataAliasUpdateDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
@@ -32,7 +32,7 @@ public interface DataAliasApi {
|
||||
* @param relId relId
|
||||
* @return aliasName
|
||||
*/
|
||||
String getDataAlias(Long userId, DataAliasTypeEnum type, Long relId);
|
||||
String getDataAlias(Long userId, DataExtraTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 查询数据别名
|
||||
@@ -41,7 +41,7 @@ public interface DataAliasApi {
|
||||
* @param type type
|
||||
* @return relId:aliasName
|
||||
*/
|
||||
Map<Long, String> getDataAlias(Long userId, DataAliasTypeEnum type);
|
||||
Map<Long, String> getDataAlias(Long userId, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 异步查询数据别名
|
||||
@@ -50,7 +50,7 @@ public interface DataAliasApi {
|
||||
* @param type type
|
||||
* @return relId:aliasName
|
||||
*/
|
||||
Future<Map<Long, String>> getDataAliasAsync(Long userId, DataAliasTypeEnum type);
|
||||
Future<Map<Long, String>> getDataAliasAsync(Long userId, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 删除数据别名
|
||||
@@ -59,6 +59,6 @@ public interface DataAliasApi {
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByRelId(DataAliasTypeEnum type, Long relId);
|
||||
Integer deleteByRelId(DataExtraTypeEnum type, Long relId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 对外服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
public interface DataExtraApi {
|
||||
|
||||
/**
|
||||
* 更新数据拓展信息
|
||||
*
|
||||
* @param type type
|
||||
* @param dto dto
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateExtraItem(DataExtraUpdateDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param type type
|
||||
* @param dto dto
|
||||
* @return items
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param type type
|
||||
* @param dto dto
|
||||
* @return item
|
||||
*/
|
||||
String getExtraItem(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param dto dto
|
||||
* @param type type
|
||||
* @return item
|
||||
*/
|
||||
Map<Long, String> getExtraItemList(DataExtraQueryDTO dto, DataExtraTypeEnum type);
|
||||
|
||||
/**
|
||||
* 通过 relId 删除
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByRelId(DataExtraTypeEnum type, Long relId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 查询请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataExtraQueryDTO", description = "数据拓展信息 查询请求业务对象")
|
||||
public class DataExtraQueryDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NonNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
private Long relId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
private List<Long> relIdList;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "拓展项")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "拓展项")
|
||||
private List<String> items;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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.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-19 18:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataExtraUpdateDTO", description = "数据拓展信息 更新请求业务对象")
|
||||
public class DataExtraUpdateDTO 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 item;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "拓展值")
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.orion.ops.module.infra.enums;
|
||||
|
||||
/**
|
||||
* 数据别名类型
|
||||
* 数据拓展类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/18 21:51
|
||||
*/
|
||||
public enum DataAliasTypeEnum {
|
||||
public enum DataExtraTypeEnum {
|
||||
|
||||
/**
|
||||
* 主机
|
||||
@@ -16,11 +16,11 @@ public enum DataAliasTypeEnum {
|
||||
|
||||
;
|
||||
|
||||
public static DataAliasTypeEnum of(String type) {
|
||||
public static DataExtraTypeEnum of(String type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
for (DataAliasTypeEnum value : values()) {
|
||||
for (DataExtraTypeEnum value : values()) {
|
||||
if (value.name().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
@@ -2,10 +2,9 @@ package com.orion.ops.module.infra.handler.preference.model;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
import com.orion.lang.utils.collect.Maps;
|
||||
import com.orion.ops.framework.common.utils.Refs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -25,7 +24,7 @@ public interface PreferenceModel {
|
||||
*/
|
||||
default Map<String, String> toMap() {
|
||||
JSONObject map = JSON.parseObject(JSON.toJSONString(this));
|
||||
return Maps.map(map, Function.identity(), v -> JSON.toJSONString(Ref.of(v)));
|
||||
return Maps.map(map, Function.identity(), Refs::toJson);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ 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.DataAliasTypeEnum;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DataAliasService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -29,7 +29,7 @@ public class DataAliasApiImpl implements DataAliasApi {
|
||||
private DataAliasService dataAliasService;
|
||||
|
||||
@Override
|
||||
public Integer updateDataAlias(DataAliasUpdateDTO dto, DataAliasTypeEnum type) {
|
||||
public Integer updateDataAlias(DataAliasUpdateDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
DataAliasUpdateRequest update = DataAliasUpdateRequest.builder()
|
||||
.userId(dto.getUserId())
|
||||
@@ -41,25 +41,25 @@ public class DataAliasApiImpl implements DataAliasApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataAlias(Long userId, DataAliasTypeEnum type, Long relId) {
|
||||
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, DataAliasTypeEnum type) {
|
||||
public Map<Long, String> getDataAlias(Long userId, DataExtraTypeEnum type) {
|
||||
Valid.notNull(userId);
|
||||
return dataAliasService.getDataAlias(userId, type.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Map<Long, String>> getDataAliasAsync(Long userId, DataAliasTypeEnum type) {
|
||||
public Future<Map<Long, String>> getDataAliasAsync(Long userId, DataExtraTypeEnum type) {
|
||||
Valid.notNull(userId);
|
||||
return CompletableFuture.completedFuture(dataAliasService.getDataAlias(userId, type.name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(DataAliasTypeEnum type, Long relId) {
|
||||
public Integer deleteByRelId(DataExtraTypeEnum type, Long relId) {
|
||||
Valid.notNull(relId);
|
||||
return dataAliasService.deleteByRelId(type.name(), relId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
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.DataExtraQueryDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataExtraUpdateDTO;
|
||||
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.enums.DataExtraTypeEnum;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 对外服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataExtraApiImpl implements DataExtraApi {
|
||||
|
||||
@Resource
|
||||
private DataExtraService dataExtraService;
|
||||
|
||||
@Override
|
||||
public Integer updateExtraItem(DataExtraUpdateDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
// 更新
|
||||
DataExtraUpdateRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.updateExtraItem(request);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtraItem(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
Valid.allNotNull(dto.getRelId(), dto.getItem());
|
||||
// 查询
|
||||
DataExtraQueryRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.getExtraItem(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getExtraItemList(DataExtraQueryDTO dto, DataExtraTypeEnum type) {
|
||||
Valid.valid(dto);
|
||||
Valid.allNotNull(dto.getRelIdList(), dto.getItem());
|
||||
// 查询
|
||||
DataExtraQueryRequest request = DataExtraProviderConvert.MAPPER.to(dto);
|
||||
request.setType(type.name());
|
||||
return dataExtraService.getExtraItemList(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(DataExtraTypeEnum type, Long relId) {
|
||||
return dataExtraService.deleteByRelId(type.name(), relId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
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;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 对外服务对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataExtraProviderConvert {
|
||||
|
||||
DataExtraProviderConvert MAPPER = Mappers.getMapper(DataExtraProviderConvert.class);
|
||||
|
||||
DataExtraQueryRequest to(DataExtraQueryDTO query);
|
||||
|
||||
DataExtraUpdateRequest to(DataExtraUpdateDTO update);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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.DataExtraDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataExtraDAO extends IMapper<DataExtraDO> {
|
||||
|
||||
/**
|
||||
* 通过 userId 删除
|
||||
*
|
||||
* @param userId userId
|
||||
* @return effect
|
||||
*/
|
||||
default int deleteByUserId(Long userId) {
|
||||
LambdaQueryWrapper<DataExtraDO> wrapper = this.lambda()
|
||||
.eq(DataExtraDO::getUserId, userId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 relId 删除
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
default int deleteByRelId(String type, Long relId) {
|
||||
LambdaQueryWrapper<DataExtraDO> wrapper = this.lambda()
|
||||
.eq(DataExtraDO::getType, type)
|
||||
.eq(DataExtraDO::getRelId, relId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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-19 18:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "data_extra", autoResultMap = true)
|
||||
@Schema(name = "DataExtraDO", description = "数据拓展信息 实体对象")
|
||||
public class DataExtraDO 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("item")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "拓展值")
|
||||
@TableField("value")
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.orion.ops.module.infra.entity.request.data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataExtraQueryRequest", description = "数据拓展信息 查询请求对象")
|
||||
public class DataExtraQueryRequest {
|
||||
|
||||
@NonNull
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
private Long relId;
|
||||
|
||||
@Schema(description = "数据id")
|
||||
private List<Long> relIdList;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "数据类型")
|
||||
private String type;
|
||||
|
||||
@Size(max = 32)
|
||||
@Schema(description = "拓展项")
|
||||
private String item;
|
||||
|
||||
@Schema(description = "拓展项")
|
||||
private List<String> items;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
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-19 18:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataExtraUpdateRequest", description = "数据拓展信息 更新请求对象")
|
||||
public class DataExtraUpdateRequest 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;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "拓展项")
|
||||
private String item;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "拓展值")
|
||||
private Object value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.lang.define.collect.MultiHashMap;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraQueryRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataExtraUpdateRequest;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
public interface DataExtraService {
|
||||
|
||||
/**
|
||||
* 更新数据拓展信息
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateExtraItem(DataExtraUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param request request
|
||||
* @return items
|
||||
*/
|
||||
Map<String, String> getExtraItems(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param request request
|
||||
* @return items
|
||||
*/
|
||||
MultiHashMap<Long, String, String> getExtraItemsList(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param request request
|
||||
* @return item
|
||||
*/
|
||||
String getExtraItem(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 查询额外配置项
|
||||
*
|
||||
* @param request request
|
||||
* @return item
|
||||
*/
|
||||
Map<Long, String> getExtraItemList(DataExtraQueryRequest request);
|
||||
|
||||
/**
|
||||
* 通过 userId 删除
|
||||
*
|
||||
* @param userId userId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 通过 relId 删除
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteByRelId(String type, Long relId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
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.ops.module.infra.dao.DataExtraDAO;
|
||||
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 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.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据拓展信息 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-19 18:05
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataExtraServiceImpl implements DataExtraService {
|
||||
|
||||
@Resource
|
||||
private DataExtraDAO dataExtraDAO;
|
||||
|
||||
@Override
|
||||
public Integer updateExtraItem(DataExtraUpdateRequest request) {
|
||||
Long userId = request.getUserId();
|
||||
Long relId = request.getRelId();
|
||||
String type = request.getType();
|
||||
String item = request.getItem();
|
||||
Object value = request.getValue();
|
||||
// 查询配置是否存在
|
||||
DataExtraDO extraItem = dataExtraDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DataExtraDO::getUserId, userId)
|
||||
.eq(DataExtraDO::getRelId, relId)
|
||||
.eq(DataExtraDO::getType, type)
|
||||
.eq(DataExtraDO::getItem, item)
|
||||
.then()
|
||||
.getOne();
|
||||
if (extraItem == null) {
|
||||
// 插入
|
||||
DataExtraDO insert = new DataExtraDO();
|
||||
insert.setUserId(userId);
|
||||
insert.setRelId(relId);
|
||||
insert.setType(type);
|
||||
insert.setItem(item);
|
||||
insert.setValue(Refs.toJson(value));
|
||||
return dataExtraDAO.insert(insert);
|
||||
} else {
|
||||
// 修改
|
||||
DataExtraDO update = new DataExtraDO();
|
||||
update.setId(extraItem.getId());
|
||||
update.setValue(Refs.toJson(value));
|
||||
return dataExtraDAO.updateById(update);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME updateBatch
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraItems(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtraItem(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
.optionalOne()
|
||||
.map(DataExtraDO::getValue)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getExtraItemList(DataExtraQueryRequest request) {
|
||||
return dataExtraDAO.of()
|
||||
.wrapper(this.buildWrapper(request))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DataExtraDO::getRelId,
|
||||
DataExtraDO::getValue,
|
||||
Functions.right())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByUserId(Long userId) {
|
||||
return dataExtraDAO.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(String type, Long relId) {
|
||||
return dataExtraDAO.deleteByRelId(type, relId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 查询条件
|
||||
*/
|
||||
private LambdaQueryWrapper<DataExtraDO> buildWrapper(DataExtraQueryRequest entity) {
|
||||
return dataExtraDAO.wrapper()
|
||||
.eq(DataExtraDO::getUserId, entity.getUserId())
|
||||
.eq(DataExtraDO::getRelId, entity.getRelId())
|
||||
.in(DataExtraDO::getRelId, entity.getRelIdList())
|
||||
.eq(DataExtraDO::getType, entity.getType())
|
||||
.eq(DataExtraDO::getItem, entity.getItem())
|
||||
.in(DataExtraDO::getItem, entity.getItems());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.define.wrapper.Ref;
|
||||
import com.orion.lang.function.Functions;
|
||||
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;
|
||||
@@ -63,13 +62,13 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
insertRecord.setUserId(userId);
|
||||
insertRecord.setType(type);
|
||||
insertRecord.setItem(item);
|
||||
insertRecord.setValue(this.toJsonValue(request.getValue()));
|
||||
insertRecord.setValue(Refs.toJson(request.getValue()));
|
||||
effect = preferenceDAO.insert(insertRecord);
|
||||
} else {
|
||||
// 更新
|
||||
PreferenceDO updateRecord = new PreferenceDO();
|
||||
updateRecord.setId(preference.getId());
|
||||
updateRecord.setValue(this.toJsonValue(request.getValue()));
|
||||
updateRecord.setValue(Refs.toJson(request.getValue()));
|
||||
effect = preferenceDAO.updateById(updateRecord);
|
||||
}
|
||||
// 删除缓存
|
||||
@@ -77,6 +76,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
return effect;
|
||||
}
|
||||
|
||||
// FIXME updateBatch
|
||||
@Override
|
||||
public void updatePreferencePartial(PreferenceUpdatePartialRequest request) {
|
||||
Long userId = SecurityUtils.getLoginUserId();
|
||||
@@ -97,7 +97,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
insertRecord.setUserId(userId);
|
||||
insertRecord.setType(type);
|
||||
insertRecord.setItem(s.getKey());
|
||||
insertRecord.setValue(this.toJsonValue(s.getValue()));
|
||||
insertRecord.setValue(Refs.toJson(s.getValue()));
|
||||
return insertRecord;
|
||||
}).collect(Collectors.toList());
|
||||
preferenceDAO.insertBatch(records);
|
||||
@@ -183,17 +183,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
RedisMaps.putAll(key, PreferenceCacheKeyDefine.PREFERENCE, config);
|
||||
}
|
||||
// unref
|
||||
return Maps.map(config, Function.identity(), v -> JSON.parseObject(v, Ref.class).getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为 json 对象
|
||||
*
|
||||
* @param o o
|
||||
* @return value
|
||||
*/
|
||||
private String toJsonValue(Object o) {
|
||||
return JSON.toJSONString(Ref.of(o));
|
||||
return Maps.map(config, Function.identity(), Refs::parseObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
private DataPermissionService dataPermissionService;
|
||||
|
||||
@Resource
|
||||
private DataAliasService dataAliasService;
|
||||
private DataExtraService dataExtraService;
|
||||
|
||||
@Override
|
||||
public Long createSystemUser(SystemUserCreateRequest request) {
|
||||
@@ -249,8 +249,8 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
preferenceService.deletePreferenceByUserId(id);
|
||||
// 删除用户数据权限
|
||||
dataPermissionService.deleteByUserId(id);
|
||||
// 删除用户数据别名
|
||||
dataAliasService.deleteByUserId(id);
|
||||
// 删除用户拓展数据
|
||||
dataExtraService.deleteByUserId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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.DataExtraDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DataExtraDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="rel_id" property="relId"/>
|
||||
<result column="type" property="type"/>
|
||||
<result column="item" property="item"/>
|
||||
<result column="value" property="value"/>
|
||||
<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, item, value, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user