feat: 删除字典值 name 字段.

This commit is contained in:
lijiahang
2023-10-26 19:20:40 +08:00
parent 18de1a2a3a
commit 29e3bde5b6
20 changed files with 214 additions and 198 deletions

View File

@@ -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 位的数字,字母或下滑线";
}

View File

@@ -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<JSONObject> getJsonList(List<String> keys) {
List<String> 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> T
* @return cache
*/
public static <T> List<T> getJsonList(List<String> keys, CacheKeyDefine define) {
return getJsonList(keys, (Class<T>) define.getType());
}
/**
* 获取 json 列表
*
* @param keys keys
* @param type type
* @param <T> T
* @return cache
*/
public static <T> List<T> getJsonList(List<String> keys, Class<T> type) {
List<String> 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<JSONArray> getJsonArrayList(List<String> keys) {
List<String> 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> T
* @return cache
*/
public static <T> List<List<T>> getJsonArrayList(List<String> keys, CacheKeyDefine define) {
return getJsonArrayList(keys, (Class<T>) define.getType());
}
/**
* 获取 jsonArray 列表
*
* @param keys keys
* @param type type
* @param <T> T
* @return cache
*/
public static <T> List<List<T>> getJsonArrayList(List<String> keys, Class<T> type) {
List<String> values = redisTemplate.opsForValue().multiGet(keys);
if (values == null) {
return new ArrayList<>();
}
return values.stream()
.map(s -> JSON.parseArray(s, type))
.collect(Collectors.toList());
}
/**
* 设置 json
*

View File

@@ -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")

View File

@@ -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<DictValueVO> getDictValueList(@RequestParam("keyName") String keyName) {
return dictValueService.getDictValueList(keyName);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/enum")
@Operation(summary = "查询字典配置值枚举")
public Map<String, Map<String, Object>> getDictValueEnum(@RequestParam("keyName") String keyName) {
return dictValueService.getDictValueEnum(keyName);
@Operation(summary = "查询字典配置值选项")
public Map<String, List<JSONObject>> getDictValueList(@RequestParam("keys") List<String> keys) {
return dictValueService.getDictValueList(keys);
}
@IgnoreLog(IgnoreLogMode.RET)

View File

@@ -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<DictValueVO> to(List<DictValueDO> list);
DictValueVO to(DictValueCacheDTO cache);
DictValueCacheDTO toCache(DictValueDO domain);
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 = "配置值")

View File

@@ -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;

View File

@@ -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 = "配置值")

View File

@@ -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;

View File

@@ -34,9 +34,6 @@ public class DictValueEnumVO implements Serializable {
@Schema(description = "配置项")
private String keyName;
@Schema(description = "配置名称")
private String name;
@Schema(description = "配置值")
private String value;

View File

@@ -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;

View File

@@ -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<DictValueVO> getDictValueList(String keyName);
/**
* 查询全部字典配置值枚举
*
* @param keyName keyName
* @return enum
*/
Map<String, Map<String, Object>> getDictValueEnum(String keyName);
Map<String, List<JSONObject>> getDictValueList(List<String> keys);
/**
* 分页查询字典配置值

View File

@@ -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);
}
}

View File

@@ -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<DictValueVO> getDictValueList(String keyName) {
public Map<String, List<JSONObject>> getDictValueList(List<String> keys) {
Map<String, List<JSONObject>> result = new HashMap<>();
// 查询缓存
String cacheKey = DictCacheKeyDefine.DICT_VALUE.format(keyName);
List<DictValueCacheDTO> list = RedisMaps.valuesJson(cacheKey, (Class<DictValueCacheDTO>) 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<String> cacheKeyList = keys.stream()
.map(DictCacheKeyDefine.DICT_VALUE::format)
.collect(Collectors.toList());
List<List<JSONObject>> jsonArrayList = RedisStrings.getJsonArrayList(cacheKeyList, JSONObject.class);
// 检查数据
List<String> emptyKeyList = new ArrayList<>();
IntStream.range(0, jsonArrayList.size()).forEach(i -> {
String key = keys.get(i);
List<JSONObject> value = jsonArrayList.get(i);
result.put(key, value);
// 需要查询的数据
if (value == null) {
emptyKeyList.add(key);
}
});
if (!emptyKeyList.isEmpty()) {
// 查询数据库
Map<String, List<DictValueDO>> 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<JSONObject> 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<String, Map<String, Object>> getDictValueEnum(String keyName) {
// 查询配置值
List<DictValueVO> values = this.getDictValueList(keyName);
if (values.isEmpty()) {
return Maps.empty();
}
// 查询配置项
Map<String, String> schema = dictKeyService.getDictSchema(keyName);
// 返回
Map<String, Map<String, Object>> result = Maps.newLinkedMap();
for (DictValueVO value : values) {
Map<String, Object> 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<JSONObject> options : result.values()) {
if (options.size() == 1 && options.get(0).remove(Const.DOLLAR) != null) {
Iterator<JSONObject> iterator = options.iterator();
iterator.next();
iterator.remove();
}
result.put(value.getName(), item);
}
return result;
}
@@ -203,9 +191,24 @@ public class DictValueServiceImpl implements DictValueService {
// 条件
LambdaQueryWrapper<DictValueDO> wrapper = this.buildQueryWrapper(request);
// 查询
return dictValueDAO.of(wrapper)
DataGrid<DictValueVO> dataGrid = dictValueDAO.of(wrapper)
.page(request)
.dataGrid(DictValueConvert.MAPPER::to);
if (!dataGrid.isEmpty()) {
List<Long> keyIdList = dataGrid.stream()
.map(DictValueVO::getKeyId)
.distinct()
.collect(Collectors.toList());
// 查询 key 信息
List<DictKeyDO> keys = dictKeyDAO.selectBatchIds(keyIdList);
Map<Long, String> 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<DictValueDO> 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<JSONObject> toCacheOptions(String key, List<DictValueDO> values) {
// 添加默认值
if (Lists.isEmpty(values)) {
JSONObject item = new JSONObject();
item.put(Const.DOLLAR, Const.DOLLAR);
return Lists.of(item);
}
// 查询 schema
Map<String, String> 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());
}
}

View File

@@ -7,7 +7,6 @@
<id column="id" property="id"/>
<result column="key_id" property="keyId"/>
<result column="key_name" property="keyName"/>
<result column="name" property="name"/>
<result column="value" property="value"/>
<result column="label" property="label"/>
<result column="extra" property="extra"/>
@@ -21,7 +20,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
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
</sql>
</mapper>