From 29e3bde5b696034af9c69b372288bc2b50d8c71e Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 26 Oct 2023 19:20:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E5=80=BC=20name=20=E5=AD=97=E6=AE=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/constant/ValidConst.java | 12 +- .../redis/core/utils/RedisStrings.java | 94 +++++++++++ .../ops/launch/generator/CodeGenerator.java | 2 +- .../infra/controller/DictValueController.java | 14 +- .../infra/convert/DictValueConvert.java | 5 - .../define/cache/DictCacheKeyDefine.java | 3 +- .../infra/entity/domain/DictValueDO.java | 4 - .../infra/entity/dto/DictValueCacheDTO.java | 64 ------- .../request/dict/DictKeyCreateRequest.java | 2 +- .../request/dict/DictKeyUpdateRequest.java | 2 +- .../request/dict/DictValueCreateRequest.java | 8 - .../request/dict/DictValueQueryRequest.java | 4 - .../request/dict/DictValueUpdateRequest.java | 8 - .../request/user/SystemUserCreateRequest.java | 2 +- .../infra/entity/vo/DictValueEnumVO.java | 3 - .../module/infra/entity/vo/DictValueVO.java | 4 +- .../infra/service/DictValueService.java | 15 +- .../service/impl/DictKeyServiceImpl.java | 6 +- .../service/impl/DictValueServiceImpl.java | 157 +++++++++++------- .../main/resources/mapper/DictValueMapper.xml | 3 +- 20 files changed, 214 insertions(+), 198 deletions(-) delete mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/DictValueCacheDTO.java diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ValidConst.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ValidConst.java index 072d6156..679558d0 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ValidConst.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ValidConst.java @@ -9,16 +9,12 @@ package com.orion.ops.framework.common.constant; */ public interface ValidConst { - String CHAR_NUMBER_1_32_PATTERN = "^[a-zA-Z0-9]{1,32}$"; + String USERNAME_4_32_PATTERN = "^[a-zA-Z0-9_]{4,32}$"; - String CHAR_NUMBER_1_32_MESSAGE = "只能为 1-32 位的数字或字母"; + String USERNAME_4_32_MESSAGE = "只能为 4-32 位的数字,字母或下滑线"; - String CHAR_NUMBER_2_32_PATTERN = "^[a-zA-Z0-9]{2,32}$"; + String DICT_1_32_PATTERN = "^[a-zA-Z0-9_]{1,32}$"; - String CHAR_NUMBER_2_32_MESSAGE = "只能为 2-32 位的数字或字母"; - - String CHAR_NUMBER_4_32_PATTERN = "^[a-zA-Z0-9]{4,32}$"; - - String CHAR_NUMBER_4_32_MESSAGE = "只能为 4-32 位的数字或字母"; + String DICT_1_32_MESSAGE = "只能为 1-32 位的数字,字母或下滑线"; } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java index ae22de39..b5409032 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-redis/src/main/java/com/orion/ops/framework/redis/core/utils/RedisStrings.java @@ -6,8 +6,10 @@ import com.alibaba.fastjson.JSONObject; import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.utils.Strings; +import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +import java.util.stream.Collectors; /** * redis string 工具类 @@ -75,6 +77,52 @@ public class RedisStrings extends RedisUtils { return (T) JSON.parseObject(value, type); } + /** + * 获取 json 列表 + * + * @param keys keys + * @return cache + */ + public static List getJsonList(List keys) { + List values = redisTemplate.opsForValue().multiGet(keys); + if (values == null) { + return new ArrayList<>(); + } + return values.stream() + .map(JSON::parseObject) + .collect(Collectors.toList()); + } + + /** + * 获取 json 列表 + * + * @param keys keys + * @param define define + * @param T + * @return cache + */ + public static List getJsonList(List keys, CacheKeyDefine define) { + return getJsonList(keys, (Class) define.getType()); + } + + /** + * 获取 json 列表 + * + * @param keys keys + * @param type type + * @param T + * @return cache + */ + public static List getJsonList(List keys, Class type) { + List values = redisTemplate.opsForValue().multiGet(keys); + if (values == null) { + return new ArrayList<>(); + } + return values.stream() + .map(s -> JSON.parseObject(s, type)) + .collect(Collectors.toList()); + } + /** * 获取 json * @@ -128,6 +176,52 @@ public class RedisStrings extends RedisUtils { return JSON.parseArray(value, type); } + /** + * 获取 jsonArray 列表 + * + * @param keys keys + * @return cache + */ + public static List getJsonArrayList(List keys) { + List values = redisTemplate.opsForValue().multiGet(keys); + if (values == null) { + return new ArrayList<>(); + } + return values.stream() + .map(JSON::parseArray) + .collect(Collectors.toList()); + } + + /** + * 获取 jsonArray 列表 + * + * @param keys keys + * @param define define + * @param T + * @return cache + */ + public static List> getJsonArrayList(List keys, CacheKeyDefine define) { + return getJsonArrayList(keys, (Class) define.getType()); + } + + /** + * 获取 jsonArray 列表 + * + * @param keys keys + * @param type type + * @param T + * @return cache + */ + public static List> getJsonArrayList(List keys, Class type) { + List values = redisTemplate.opsForValue().multiGet(keys); + if (values == null) { + return new ArrayList<>(); + } + return values.stream() + .map(s -> JSON.parseArray(s, type)) + .collect(Collectors.toList()); + } + /** * 设置 json * diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java index 0fcc8a02..ab0b59b6 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java @@ -426,7 +426,7 @@ public class CodeGenerator { private static void printTips() { String line = AnsiAppender.create() .append(AnsiForeground.BRIGHT_GREEN.and(AnsiFont.BOLD), "\n:: 代码生成完毕 ^_^ ::\n") - .append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码复制后请先 clean 模块父工程\n") + .append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码复制后请先 clean 父工程\n") .append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码需要自行修改缓存逻辑\n") .append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码修改完成后请先执行单元测试检测是否正常\n") .append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- vue 代码需要注意同一模块的 router 需要自行合并\n") diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/DictValueController.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/DictValueController.java index bfa5af15..58dad1de 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/DictValueController.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/DictValueController.java @@ -1,5 +1,6 @@ package com.orion.ops.module.infra.controller; +import com.alibaba.fastjson.JSONObject; import com.orion.lang.define.wrapper.DataGrid; import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog; import com.orion.ops.framework.common.validator.group.Page; @@ -70,16 +71,9 @@ public class DictValueController { @IgnoreLog(IgnoreLogMode.RET) @GetMapping("/list") - @Operation(summary = "查询字典配置值") - public List getDictValueList(@RequestParam("keyName") String keyName) { - return dictValueService.getDictValueList(keyName); - } - - @IgnoreLog(IgnoreLogMode.RET) - @GetMapping("/enum") - @Operation(summary = "查询字典配置值枚举") - public Map> getDictValueEnum(@RequestParam("keyName") String keyName) { - return dictValueService.getDictValueEnum(keyName); + @Operation(summary = "查询字典配置值选项") + public Map> getDictValueList(@RequestParam("keys") List keys) { + return dictValueService.getDictValueList(keys); } @IgnoreLog(IgnoreLogMode.RET) diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/DictValueConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/DictValueConvert.java index 97e7b690..f4cf69e4 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/DictValueConvert.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/DictValueConvert.java @@ -1,7 +1,6 @@ package com.orion.ops.module.infra.convert; import com.orion.ops.module.infra.entity.domain.DictValueDO; -import com.orion.ops.module.infra.entity.dto.DictValueCacheDTO; import com.orion.ops.module.infra.entity.request.dict.DictValueCreateRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueQueryRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueUpdateRequest; @@ -33,8 +32,4 @@ public interface DictValueConvert { List to(List list); - DictValueVO to(DictValueCacheDTO cache); - - DictValueCacheDTO toCache(DictValueDO domain); - } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/cache/DictCacheKeyDefine.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/cache/DictCacheKeyDefine.java index 93bbc1d6..f1cedaeb 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/cache/DictCacheKeyDefine.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/cache/DictCacheKeyDefine.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.ops.module.infra.entity.dto.DictKeyCacheDTO; -import com.orion.ops.module.infra.entity.dto.DictValueCacheDTO; import java.util.concurrent.TimeUnit; @@ -34,7 +33,7 @@ public interface DictCacheKeyDefine { CacheKeyDefine DICT_VALUE = new CacheKeyBuilder() .key("dict:values:{}") .desc("字典配置值 ${key}") - .type(DictValueCacheDTO.class) + .type(JSONObject.class) .timeout(1, TimeUnit.DAYS) .build(); diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DictValueDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DictValueDO.java index 862e85fa..6e99d546 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DictValueDO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DictValueDO.java @@ -38,10 +38,6 @@ public class DictValueDO extends BaseDO { @TableField("key_name") private String keyName; - @Schema(description = "配置名称") - @TableField("name") - private String name; - @Schema(description = "配置值") @TableField("value") private String value; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/DictValueCacheDTO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/DictValueCacheDTO.java deleted file mode 100644 index a879d9c9..00000000 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/DictValueCacheDTO.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.orion.ops.module.infra.entity.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.Date; - -/** - * 字典配置值 缓存对象 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023-10-16 16:33 - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Schema(name = "DictValueCacheDTO", description = "字典配置值 缓存对象") -public class DictValueCacheDTO implements Serializable { - - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "配置项id") - private Long keyId; - - @Schema(description = "配置项") - private String keyName; - - @Schema(description = "配置名称") - private String name; - - @Schema(description = "配置值") - private String value; - - @Schema(description = "配置描述") - private String label; - - @Schema(description = "额外参数") - private String extra; - - @Schema(description = "排序") - private Integer sort; - - @Schema(description = "创建时间") - private Date createTime; - - @Schema(description = "修改时间") - private Date updateTime; - - @Schema(description = "创建人") - private String creator; - - @Schema(description = "修改人") - private String updater; - -} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyCreateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyCreateRequest.java index 23cace55..ecf8986f 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyCreateRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyCreateRequest.java @@ -28,7 +28,7 @@ public class DictKeyCreateRequest implements Serializable { @NotBlank @Size(max = 32) - @Pattern(regexp = ValidConst.CHAR_NUMBER_2_32_PATTERN, message = ValidConst.CHAR_NUMBER_2_32_MESSAGE) + @Pattern(regexp = ValidConst.DICT_1_32_PATTERN, message = ValidConst.DICT_1_32_MESSAGE) @Schema(description = "配置项") private String keyName; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyUpdateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyUpdateRequest.java index 4072e054..c28cb681 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyUpdateRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictKeyUpdateRequest.java @@ -33,7 +33,7 @@ public class DictKeyUpdateRequest implements Serializable { @NotBlank @Size(max = 32) - @Pattern(regexp = ValidConst.CHAR_NUMBER_2_32_PATTERN, message = ValidConst.CHAR_NUMBER_2_32_MESSAGE) + @Pattern(regexp = ValidConst.DICT_1_32_PATTERN, message = ValidConst.DICT_1_32_MESSAGE) @Schema(description = "配置项") private String keyName; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueCreateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueCreateRequest.java index b556a27e..e6c53344 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueCreateRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueCreateRequest.java @@ -1,6 +1,5 @@ package com.orion.ops.module.infra.entity.request.dict; -import com.orion.ops.framework.common.constant.ValidConst; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,7 +8,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.io.Serializable; @@ -31,12 +29,6 @@ public class DictValueCreateRequest implements Serializable { @Schema(description = "配置项id") private Long keyId; - @NotBlank - @Size(max = 32) - @Pattern(regexp = ValidConst.CHAR_NUMBER_1_32_PATTERN, message = ValidConst.CHAR_NUMBER_1_32_MESSAGE) - @Schema(description = "配置名称") - private String name; - @NotBlank @Size(max = 512) @Schema(description = "配置值") diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueQueryRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueQueryRequest.java index 4b49c64d..ab7b6365 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueQueryRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueQueryRequest.java @@ -28,10 +28,6 @@ public class DictValueQueryRequest extends PageRequest { @Schema(description = "配置项名称") private String keyName; - @Size(max = 32) - @Schema(description = "配置名称") - private String name; - @Size(max = 512) @Schema(description = "配置值") private String value; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueUpdateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueUpdateRequest.java index 9c9e52a1..82621afd 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueUpdateRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/dict/DictValueUpdateRequest.java @@ -1,6 +1,5 @@ package com.orion.ops.module.infra.entity.request.dict; -import com.orion.ops.framework.common.constant.ValidConst; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,7 +8,6 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.io.Serializable; @@ -35,12 +33,6 @@ public class DictValueUpdateRequest implements Serializable { @Schema(description = "配置项id") private Long keyId; - @NotBlank - @Size(max = 32) - @Pattern(regexp = ValidConst.CHAR_NUMBER_1_32_PATTERN, message = ValidConst.CHAR_NUMBER_1_32_MESSAGE) - @Schema(description = "配置名称") - private String name; - @NotBlank @Size(max = 512) @Schema(description = "配置值") diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/user/SystemUserCreateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/user/SystemUserCreateRequest.java index 8b8d8b6c..020af766 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/user/SystemUserCreateRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/user/SystemUserCreateRequest.java @@ -28,7 +28,7 @@ public class SystemUserCreateRequest implements Serializable { @NotBlank @Size(max = 32) - @Pattern(regexp = ValidConst.CHAR_NUMBER_4_32_PATTERN, message = ValidConst.CHAR_NUMBER_4_32_MESSAGE) + @Pattern(regexp = ValidConst.USERNAME_4_32_PATTERN, message = ValidConst.USERNAME_4_32_MESSAGE) @Schema(description = "用户名") private String username; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueEnumVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueEnumVO.java index 16bb7ae8..184af8e8 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueEnumVO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueEnumVO.java @@ -34,9 +34,6 @@ public class DictValueEnumVO implements Serializable { @Schema(description = "配置项") private String keyName; - @Schema(description = "配置名称") - private String name; - @Schema(description = "配置值") private String value; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueVO.java index edbcbf23..183dc5a1 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueVO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/DictValueVO.java @@ -34,8 +34,8 @@ public class DictValueVO implements Serializable { @Schema(description = "配置项") private String keyName; - @Schema(description = "配置名称") - private String name; + @Schema(description = "配置描述") + private String keyDescription; @Schema(description = "配置值") private String value; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/DictValueService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/DictValueService.java index 830a9dba..e563fadc 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/DictValueService.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/DictValueService.java @@ -1,5 +1,6 @@ package com.orion.ops.module.infra.service; +import com.alibaba.fastjson.JSONObject; import com.orion.lang.define.wrapper.DataGrid; import com.orion.ops.module.infra.entity.request.dict.DictValueCreateRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueQueryRequest; @@ -44,20 +45,12 @@ public interface DictValueService { Integer rollbackDictValueById(DictValueRollbackRequest request); /** - * 查询全部字典配置值 + * 查询字典配置值 * - * @param keyName keyName + * @param keys keys * @return rows */ - List getDictValueList(String keyName); - - /** - * 查询全部字典配置值枚举 - * - * @param keyName keyName - * @return enum - */ - Map> getDictValueEnum(String keyName); + Map> getDictValueList(List keys); /** * 分页查询字典配置值 diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java index 7971fab1..e027b4fe 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictKeyServiceImpl.java @@ -119,7 +119,7 @@ public class DictKeyServiceImpl implements DictKeyService { return list.stream() .filter(s -> !s.getId().equals(Const.NONE_ID)) .map(DictKeyConvert.MAPPER::to) - .sorted(Comparator.comparing(DictKeyVO::getKeyName)) + .sorted(Comparator.comparing(DictKeyVO::getId).reversed()) .collect(Collectors.toList()); } @@ -207,7 +207,7 @@ public class DictKeyServiceImpl implements DictKeyService { .map(DictKeyDO::getKeyName) .map(DictCacheKeyDefine.DICT_SCHEMA::format) .collect(Collectors.toList()); - RedisMaps.delete(schemaKeys); + RedisUtils.delete(schemaKeys); return effect; } @@ -243,7 +243,7 @@ public class DictKeyServiceImpl implements DictKeyService { .and(Strings.isNotEmpty(searchValue), c -> c .like(DictKeyDO::getKeyName, searchValue).or() .like(DictKeyDO::getDescription, searchValue) - ); + ).orderByDesc(DictKeyDO::getId); } } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java index 675607c1..da205425 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java @@ -6,13 +6,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.define.wrapper.DataGrid; import com.orion.lang.utils.Strings; import com.orion.lang.utils.collect.Lists; -import com.orion.lang.utils.collect.Maps; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.mybatis.core.query.Conditions; import com.orion.ops.framework.redis.core.utils.RedisMaps; +import com.orion.ops.framework.redis.core.utils.RedisStrings; import com.orion.ops.module.infra.convert.DictValueConvert; import com.orion.ops.module.infra.dao.DictKeyDAO; import com.orion.ops.module.infra.dao.DictValueDAO; @@ -20,7 +20,6 @@ import com.orion.ops.module.infra.define.cache.DictCacheKeyDefine; import com.orion.ops.module.infra.entity.domain.DictKeyDO; import com.orion.ops.module.infra.entity.domain.DictValueDO; import com.orion.ops.module.infra.entity.domain.HistoryValueDO; -import com.orion.ops.module.infra.entity.dto.DictValueCacheDTO; import com.orion.ops.module.infra.entity.request.dict.DictValueCreateRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueQueryRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueRollbackRequest; @@ -36,10 +35,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * 字典配置值 服务实现类 @@ -123,7 +121,7 @@ public class DictValueServiceImpl implements DictValueService { Valid.notNull(history, ErrorMessage.HISTORY_ABSENT); // 记录日志参数 OperatorLogs.add(OperatorLogs.KEY_NAME, record.getKeyName()); - OperatorLogs.add(OperatorLogs.LABEL, record.getName()); + OperatorLogs.add(OperatorLogs.LABEL, record.getLabel()); OperatorLogs.add(OperatorLogs.VALUE, history.getBeforeValue()); // 更新 DictValueDO updateRecord = new DictValueDO(); @@ -139,61 +137,51 @@ public class DictValueServiceImpl implements DictValueService { } @Override - @SuppressWarnings("unchecked") - public List getDictValueList(String keyName) { + public Map> getDictValueList(List keys) { + Map> result = new HashMap<>(); // 查询缓存 - String cacheKey = DictCacheKeyDefine.DICT_VALUE.format(keyName); - List list = RedisMaps.valuesJson(cacheKey, (Class) DictCacheKeyDefine.DICT_VALUE.getType()); - if (list.isEmpty()) { - // 查询数据库 - list = dictValueDAO.of() - .createWrapper() - .eq(DictValueDO::getKeyName, keyName) - .then() - .list(DictValueConvert.MAPPER::toCache); - // 添加默认值 防止穿透 - if (list.isEmpty()) { - list.add(DictValueCacheDTO.builder() - .id(Const.NONE_ID) - .build()); + List cacheKeyList = keys.stream() + .map(DictCacheKeyDefine.DICT_VALUE::format) + .collect(Collectors.toList()); + List> jsonArrayList = RedisStrings.getJsonArrayList(cacheKeyList, JSONObject.class); + // 检查数据 + List emptyKeyList = new ArrayList<>(); + IntStream.range(0, jsonArrayList.size()).forEach(i -> { + String key = keys.get(i); + List value = jsonArrayList.get(i); + result.put(key, value); + // 需要查询的数据 + if (value == null) { + emptyKeyList.add(key); } + }); + if (!emptyKeyList.isEmpty()) { + // 查询数据库 + Map> valueGrouping = dictValueDAO.of() + .createWrapper() + .in(DictValueDO::getKeyName, emptyKeyList) + .then() + .stream() + .collect(Collectors.groupingBy(DictValueDO::getKeyName)); // 设置缓存 - RedisMaps.putAllJson(cacheKey, s -> s.getId().toString(), list); - RedisMaps.setExpire(cacheKey, DictCacheKeyDefine.DICT_VALUE); + emptyKeyList.parallelStream().forEach(s -> { + // 转为配置 + List options = this.toCacheOptions(s, valueGrouping.get(s)); + // 设置缓存 + RedisStrings.setJson(DictCacheKeyDefine.DICT_VALUE.format(s), + DictCacheKeyDefine.DICT_VALUE, + options); + // 设置值 + result.put(s, options); + }); } // 删除默认值 - return list.stream() - .filter(s -> !s.getId().equals(Const.NONE_ID)) - .map(DictValueConvert.MAPPER::to) - .sorted(Comparator.comparing(DictValueVO::getSort)) - .collect(Collectors.toList()); - } - - @Override - public Map> getDictValueEnum(String keyName) { - // 查询配置值 - List values = this.getDictValueList(keyName); - if (values.isEmpty()) { - return Maps.empty(); - } - // 查询配置项 - Map schema = dictKeyService.getDictSchema(keyName); - // 返回 - Map> result = Maps.newLinkedMap(); - for (DictValueVO value : values) { - Map item = Maps.newMap(); - item.put(Const.NAME, value.getName()); - item.put(Const.LABEL, value.getLabel()); - item.put(Const.VALUE, DictValueTypeEnum.of(schema.get(Const.VALUE)).parse(value.getValue())); - // 额外值 - String extra = value.getExtra(); - if (!Strings.isBlank(extra)) { - JSONObject extraObject = JSON.parseObject(extra); - for (String extraKey : extraObject.keySet()) { - item.put(extraKey, DictValueTypeEnum.of(schema.get(extraKey)).parse(extraObject.getString(extraKey))); - } + for (List options : result.values()) { + if (options.size() == 1 && options.get(0).remove(Const.DOLLAR) != null) { + Iterator iterator = options.iterator(); + iterator.next(); + iterator.remove(); } - result.put(value.getName(), item); } return result; } @@ -203,9 +191,24 @@ public class DictValueServiceImpl implements DictValueService { // 条件 LambdaQueryWrapper wrapper = this.buildQueryWrapper(request); // 查询 - return dictValueDAO.of(wrapper) + DataGrid dataGrid = dictValueDAO.of(wrapper) .page(request) .dataGrid(DictValueConvert.MAPPER::to); + if (!dataGrid.isEmpty()) { + List keyIdList = dataGrid.stream() + .map(DictValueVO::getKeyId) + .distinct() + .collect(Collectors.toList()); + // 查询 key 信息 + List keys = dictKeyDAO.selectBatchIds(keyIdList); + Map keyDescMapping = keys.stream() + .collect(Collectors.toMap(DictKeyDO::getId, DictKeyDO::getDescription)); + // 设置 key 描述 + dataGrid.forEach(s -> { + s.setKeyDescription(keyDescMapping.get(s.getKeyId())); + }); + } + return dataGrid; } @Override @@ -230,7 +233,7 @@ public class DictValueServiceImpl implements DictValueService { DictValueDO record = dictValueDAO.selectById(id); Valid.notNull(record, ErrorMessage.CONFIG_ABSENT); // 添加日志参数 - OperatorLogs.add(OperatorLogs.VALUE, record.getKeyName() + "-" + record.getName()); + OperatorLogs.add(OperatorLogs.VALUE, record.getKeyName() + "-" + record.getLabel()); // 删除 return this.deleteDictValue(Lists.singleton(id), Lists.singleton(record)); } @@ -242,7 +245,7 @@ public class DictValueServiceImpl implements DictValueService { List records = dictValueDAO.selectBatchIds(idList); // 添加日志参数 String value = records.stream() - .map(s -> s.getKeyName() + "-" + s.getName()) + .map(s -> s.getKeyName() + "-" + s.getLabel()) .collect(Collectors.joining(Const.COMMA)); OperatorLogs.add(OperatorLogs.VALUE, value); // 删除 @@ -330,7 +333,7 @@ public class DictValueServiceImpl implements DictValueService { .ne(DictValueDO::getId, domain.getId()) // 用其他字段做重复校验 .eq(DictValueDO::getKeyId, domain.getKeyId()) - .eq(DictValueDO::getName, domain.getName()); + .eq(DictValueDO::getValue, domain.getValue()); // 检查是否存在 boolean present = dictValueDAO.of(wrapper).present(); Valid.isFalse(present, ErrorMessage.CONFIG_PRESENT); @@ -346,10 +349,44 @@ public class DictValueServiceImpl implements DictValueService { return dictValueDAO.wrapper() .eq(DictValueDO::getKeyId, request.getKeyId()) .like(DictValueDO::getKeyName, request.getKeyName()) - .like(DictValueDO::getName, request.getName()) .eq(DictValueDO::getValue, request.getValue()) .like(DictValueDO::getLabel, request.getLabel()) .orderByDesc(DictValueDO::getId); } + /** + * 转为配置 + * + * @param key key + * @param values values + * @return options + */ + private List toCacheOptions(String key, List values) { + // 添加默认值 + if (Lists.isEmpty(values)) { + JSONObject item = new JSONObject(); + item.put(Const.DOLLAR, Const.DOLLAR); + return Lists.of(item); + } + // 查询 schema + Map schema = dictKeyService.getDictSchema(key); + // 转换 + return values.stream() + .map(s -> { + // 设置值 + JSONObject item = new JSONObject(); + item.put(Const.LABEL, s.getLabel()); + item.put(Const.VALUE, DictValueTypeEnum.of(schema.get(Const.VALUE)).parse(s.getValue())); + // 额外值 + String extra = s.getExtra(); + if (!Strings.isBlank(extra)) { + JSONObject extraObject = JSON.parseObject(extra); + for (String extraKey : extraObject.keySet()) { + item.put(extraKey, DictValueTypeEnum.of(schema.get(extraKey)).parse(extraObject.getString(extraKey))); + } + } + return item; + }).collect(Collectors.toList()); + } + } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/DictValueMapper.xml b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/DictValueMapper.xml index 6203cb9d..d1216ac6 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/DictValueMapper.xml +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/DictValueMapper.xml @@ -7,7 +7,6 @@ - @@ -21,7 +20,7 @@ - id, key_id, key_name, name, value, label, extra, sort, create_time, update_time, creator, updater, deleted + id, key_id, key_name, value, label, extra, sort, create_time, update_time, creator, updater, deleted