生成数据字典代码.

This commit is contained in:
lijiahang
2023-10-18 15:06:45 +08:00
parent b83b212a4f
commit 284501b3fb
36 changed files with 1113 additions and 95 deletions

View File

@@ -17,4 +17,6 @@ public interface OperatorLogKeys extends ConstField {
String STATUS_NAME = "statusName"; String STATUS_NAME = "statusName";
String KEY_NAME = "keyName";
} }

View File

@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 字典配置值 api * 字典配置值 api
@@ -74,6 +75,13 @@ public class DictValueController {
return dictValueService.getDictValueList(key); return dictValueService.getDictValueList(key);
} }
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/enum")
@Operation(summary = "查询字典配置值枚举")
public Map<String, Map<String, Object>> getDictValueEnum(@RequestParam("key") String key) {
return dictValueService.getDictValueEnum(key);
}
@IgnoreLog(IgnoreLogMode.RET) @IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query") @PostMapping("/query")
@Operation(summary = "分页查询字典配置值") @Operation(summary = "分页查询字典配置值")

View File

@@ -1,5 +1,7 @@
package com.orion.ops.module.infra.dao; package com.orion.ops.module.infra.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.mybatis.core.mapper.IMapper; import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.infra.entity.domain.DictKeyDO; import com.orion.ops.module.infra.entity.domain.DictKeyDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@@ -14,4 +16,17 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface DictKeyDAO extends IMapper<DictKeyDO> { public interface DictKeyDAO extends IMapper<DictKeyDO> {
/**
* 通过 key 查询
*
* @param key key
* @return dictKey
*/
default DictKeyDO selectByKey(String key) {
LambdaQueryWrapper<DictKeyDO> wrapper = this.lambda()
.eq(DictKeyDO::getKeyName, key)
.last(Const.LIMIT_1);
return this.selectOne(wrapper);
}
} }

View File

@@ -1,5 +1,6 @@
package com.orion.ops.module.infra.define.cache; package com.orion.ops.module.infra.define.cache;
import com.alibaba.fastjson.JSONObject;
import com.orion.lang.define.cache.CacheKeyBuilder; import com.orion.lang.define.cache.CacheKeyBuilder;
import com.orion.lang.define.cache.CacheKeyDefine; import com.orion.lang.define.cache.CacheKeyDefine;
import com.orion.ops.module.infra.entity.dto.DictKeyCacheDTO; import com.orion.ops.module.infra.entity.dto.DictKeyCacheDTO;
@@ -23,8 +24,15 @@ public interface DictCacheKeyDefine {
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)
.build(); .build();
CacheKeyDefine DICT_SCHEMA = new CacheKeyBuilder()
.key("dict:schema:{}")
.desc("字典配置项 schema ${key}")
.type(JSONObject.class)
.timeout(1, TimeUnit.DAYS)
.build();
CacheKeyDefine DICT_VALUE = new CacheKeyBuilder() CacheKeyDefine DICT_VALUE = new CacheKeyBuilder()
.key("dict:value:{}") .key("dict:values:{}")
.desc("字典配置值 ${key}") .desc("字典配置值 ${key}")
.type(DictValueCacheDTO.class) .type(DictValueCacheDTO.class)
.timeout(1, TimeUnit.DAYS) .timeout(1, TimeUnit.DAYS)

View File

@@ -25,9 +25,9 @@ public class DictKeyOperatorType extends InitializingOperatorTypes {
@Override @Override
public OperatorType[] types() { public OperatorType[] types() {
return new OperatorType[]{ return new OperatorType[]{
new OperatorType(L, CREATE, "创建字典配置项 <sb>${key}</sb>"), new OperatorType(L, CREATE, "创建字典配置项 <sb>${keyName}</sb>"),
new OperatorType(M, UPDATE, "更新字典配置项 <sb>${key}</sb>"), new OperatorType(M, UPDATE, "更新字典配置项 <sb>${keyName}</sb>"),
new OperatorType(H, DELETE, "删除字典配置项 <sb>${key}</sb>"), new OperatorType(H, DELETE, "删除字典配置项 <sb>${keyName}</sb>"),
}; };
} }

View File

@@ -25,8 +25,8 @@ public class DictValueOperatorType extends InitializingOperatorTypes {
@Override @Override
public OperatorType[] types() { public OperatorType[] types() {
return new OperatorType[]{ return new OperatorType[]{
new OperatorType(L, CREATE, "创建字典配置值 <sb>${key}</sb> <sb>${label}=${value}</sb>"), new OperatorType(L, CREATE, "创建字典配置值 <sb>${keyName}</sb> <sb>${label}=${value}</sb>"),
new OperatorType(M, UPDATE, "更新字典配置值 <sb>${key}</sb> <sb>${label}=${value}</sb>"), new OperatorType(M, UPDATE, "更新字典配置值 <sb>${keyName}</sb> <sb>${label}=${value}</sb>"),
new OperatorType(H, DELETE, "删除字典配置值 <sb>${value}</sb>"), new OperatorType(H, DELETE, "删除字典配置值 <sb>${value}</sb>"),
}; };
} }

View File

@@ -31,8 +31,8 @@ public class DictKeyDO extends BaseDO {
private Long id; private Long id;
@Schema(description = "配置项") @Schema(description = "配置项")
@TableField("key") @TableField("key_name")
private String key; private String keyName;
@Schema(description = "配置值定义") @Schema(description = "配置值定义")
@TableField("value_type") @TableField("value_type")
@@ -43,7 +43,7 @@ public class DictKeyDO extends BaseDO {
private String extraSchema; private String extraSchema;
@Schema(description = "配置描述") @Schema(description = "配置描述")
@TableField("desc") @TableField("description")
private String desc; private String description;
} }

View File

@@ -35,20 +35,20 @@ public class DictValueDO extends BaseDO {
private Long keyId; private Long keyId;
@Schema(description = "配置项") @Schema(description = "配置项")
@TableField("key") @TableField("key_name")
private String key; private String keyName;
@Schema(description = "配置名称") @Schema(description = "配置名称")
@TableField("label") @TableField("name")
private String label; private String name;
@Schema(description = "配置值") @Schema(description = "配置值")
@TableField("value") @TableField("value")
private String value; private String value;
@Schema(description = "配置描述") @Schema(description = "配置描述")
@TableField("desc") @TableField("label")
private String desc; private String label;
@Schema(description = "额外参数") @Schema(description = "额外参数")
@TableField("extra") @TableField("extra")

View File

@@ -29,7 +29,7 @@ public class DictKeyCacheDTO implements Serializable {
private Long id; private Long id;
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@Schema(description = "配置值定义") @Schema(description = "配置值定义")
private String valueType; private String valueType;
@@ -38,18 +38,6 @@ public class DictKeyCacheDTO implements Serializable {
private String extraSchema; private String extraSchema;
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String description;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
} }

View File

@@ -32,16 +32,16 @@ public class DictValueCacheDTO implements Serializable {
private Long keyId; private Long keyId;
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@Schema(description = "配置名称") @Schema(description = "配置名称")
private String label; private String name;
@Schema(description = "配置值") @Schema(description = "配置值")
private String value; private String value;
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String label;
@Schema(description = "额外参数") @Schema(description = "额外参数")
private String extra; private String extra;

View File

@@ -29,7 +29,7 @@ public class DictKeyCreateRequest implements Serializable {
@Size(max = 32) @Size(max = 32)
@Pattern(regexp = "^[a-zA-Z0-9]{4,32}$") @Pattern(regexp = "^[a-zA-Z0-9]{4,32}$")
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@NotBlank @NotBlank
@Size(max = 12) @Size(max = 12)
@@ -43,6 +43,6 @@ public class DictKeyCreateRequest implements Serializable {
@NotBlank @NotBlank
@Size(max = 64) @Size(max = 64)
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String description;
} }

View File

@@ -34,7 +34,7 @@ public class DictKeyUpdateRequest implements Serializable {
@Size(max = 32) @Size(max = 32)
@Pattern(regexp = "^[a-zA-Z0-9]{4,32}$") @Pattern(regexp = "^[a-zA-Z0-9]{4,32}$")
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@NotBlank @NotBlank
@Size(max = 12) @Size(max = 12)
@@ -48,6 +48,6 @@ public class DictKeyUpdateRequest implements Serializable {
@NotBlank @NotBlank
@Size(max = 64) @Size(max = 64)
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String description;
} }

View File

@@ -34,7 +34,7 @@ public class DictValueCreateRequest implements Serializable {
@Size(max = 32) @Size(max = 32)
@Pattern(regexp = "^[a-zA-Z0-9]{4,32}$") @Pattern(regexp = "^[a-zA-Z0-9]{4,32}$")
@Schema(description = "配置名称") @Schema(description = "配置名称")
private String label; private String name;
@NotBlank @NotBlank
@Size(max = 512) @Size(max = 512)
@@ -44,7 +44,7 @@ public class DictValueCreateRequest implements Serializable {
@NotBlank @NotBlank
@Size(max = 64) @Size(max = 64)
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String label;
@NotBlank @NotBlank
@Schema(description = "额外参数") @Schema(description = "额外参数")

View File

@@ -26,7 +26,7 @@ public class DictValueQueryRequest extends PageRequest {
@Size(max = 32) @Size(max = 32)
@Schema(description = "配置名称") @Schema(description = "配置名称")
private String label; private String name;
@Size(max = 512) @Size(max = 512)
@Schema(description = "配置值") @Schema(description = "配置值")
@@ -34,6 +34,6 @@ public class DictValueQueryRequest extends PageRequest {
@Size(max = 64) @Size(max = 64)
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String label;
} }

View File

@@ -38,7 +38,7 @@ public class DictValueUpdateRequest implements Serializable {
@Size(max = 32) @Size(max = 32)
@Pattern(regexp = "^[a-zA-Z0-9]{4,32}$") @Pattern(regexp = "^[a-zA-Z0-9]{4,32}$")
@Schema(description = "配置名称") @Schema(description = "配置名称")
private String label; private String name;
@NotBlank @NotBlank
@Size(max = 512) @Size(max = 512)
@@ -48,7 +48,7 @@ public class DictValueUpdateRequest implements Serializable {
@NotBlank @NotBlank
@Size(max = 64) @Size(max = 64)
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String label;
@NotBlank @NotBlank
@Schema(description = "额外参数") @Schema(description = "额外参数")

View File

@@ -29,7 +29,7 @@ public class DictKeyVO implements Serializable {
private Long id; private Long id;
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@Schema(description = "配置值定义") @Schema(description = "配置值定义")
private String valueType; private String valueType;
@@ -38,18 +38,6 @@ public class DictKeyVO implements Serializable {
private String extraSchema; private String extraSchema;
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String description;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
} }

View File

@@ -0,0 +1,64 @@
package com.orion.ops.module.infra.entity.vo;
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 = "DictValueEnumVO", description = "字典配置值 枚举视图响应对象")
public class DictValueEnumVO 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

@@ -32,16 +32,16 @@ public class DictValueVO implements Serializable {
private Long keyId; private Long keyId;
@Schema(description = "配置项") @Schema(description = "配置项")
private String key; private String keyName;
@Schema(description = "配置名称") @Schema(description = "配置名称")
private String label; private String name;
@Schema(description = "配置值") @Schema(description = "配置值")
private String value; private String value;
@Schema(description = "配置描述") @Schema(description = "配置描述")
private String desc; private String label;
@Schema(description = "额外参数") @Schema(description = "额外参数")
private String extra; private String extra;

View File

@@ -1,7 +1,10 @@
package com.orion.ops.module.infra.enums; package com.orion.ops.module.infra.enums;
import com.orion.lang.utils.convert.Converts;
import lombok.Getter; import lombok.Getter;
import java.math.BigDecimal;
/** /**
* 字典值类型 * 字典值类型
* *
@@ -18,14 +21,46 @@ public enum DictValueTypeEnum {
STRING, STRING,
/** /**
* 数 *
*/ */
NUMBER, INTEGER {
@Override
public Object parse(String s) {
try {
return Integer.valueOf(s);
} catch (Exception e) {
return super.parse(s);
}
}
},
/**
* 小数
*/
DECIMAL {
@Override
public Object parse(String s) {
try {
return BigDecimal.valueOf(Double.valueOf(s));
} catch (Exception e) {
return super.parse(s);
}
}
},
/** /**
* 布尔值 * 布尔值
*/ */
BOOLEAN, BOOLEAN {
@Override
public Object parse(String s) {
try {
return Converts.toBoolean(s);
} catch (Exception e) {
return super.parse(s);
}
}
},
/** /**
* 颜色 * 颜色
@@ -34,6 +69,16 @@ public enum DictValueTypeEnum {
; ;
/**
* 转换
*
* @param s s
* @return value
*/
public Object parse(String s) {
return s;
}
public static DictValueTypeEnum of(String type) { public static DictValueTypeEnum of(String type) {
if (type == null) { if (type == null) {
return STRING; return STRING;

View File

@@ -5,6 +5,7 @@ import com.orion.ops.module.infra.entity.request.dict.DictKeyUpdateRequest;
import com.orion.ops.module.infra.entity.vo.DictKeyVO; import com.orion.ops.module.infra.entity.vo.DictKeyVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 字典配置项 服务类 * 字典配置项 服务类
@@ -38,6 +39,14 @@ public interface DictKeyService {
*/ */
List<DictKeyVO> getDictKeyList(); List<DictKeyVO> getDictKeyList();
/**
* 查询字典配置项 schema
*
* @param key key
* @return schema
*/
Map<String, String> getDictSchema(String key);
/** /**
* 删除字典配置项 * 删除字典配置项
* *

View File

@@ -8,6 +8,7 @@ import com.orion.ops.module.infra.entity.request.dict.DictValueUpdateRequest;
import com.orion.ops.module.infra.entity.vo.DictValueVO; import com.orion.ops.module.infra.entity.vo.DictValueVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 字典配置值 服务类 * 字典配置值 服务类
@@ -50,6 +51,14 @@ public interface DictValueService {
*/ */
List<DictValueVO> getDictValueList(String key); List<DictValueVO> getDictValueList(String key);
/**
* 查询全部字典配置值枚举
*
* @param key key
* @return enum
*/
Map<String, Map<String, Object>> getDictValueEnum(String key);
/** /**
* 分页查询字典配置值 * 分页查询字典配置值
* *

View File

@@ -1,13 +1,16 @@
package com.orion.ops.module.infra.service.impl; package com.orion.ops.module.infra.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.utils.Objects1; import com.orion.lang.utils.Objects1;
import com.orion.lang.utils.collect.Maps;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; 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.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.framework.redis.core.utils.RedisMaps; 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.DictKeyConvert; import com.orion.ops.module.infra.convert.DictKeyConvert;
import com.orion.ops.module.infra.dao.DictKeyDAO; import com.orion.ops.module.infra.dao.DictKeyDAO;
import com.orion.ops.module.infra.define.cache.DictCacheKeyDefine; import com.orion.ops.module.infra.define.cache.DictCacheKeyDefine;
@@ -26,6 +29,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -78,11 +83,12 @@ public class DictKeyServiceImpl implements DictKeyService {
// 更新 // 更新
int effect = dictKeyDAO.updateById(updateRecord); int effect = dictKeyDAO.updateById(updateRecord);
// 如果修改了 key 则需要修改 dictValue.key // 如果修改了 key 则需要修改 dictValue.key
if (!Objects1.eq(record.getKey(), request.getKey())) { if (!Objects1.eq(record.getKeyName(), request.getKeyName())) {
dictValueService.updateKeyNameByKeyId(id, record.getKey(), request.getKey()); dictValueService.updateKeyNameByKeyId(id, record.getKeyName(), request.getKeyName());
} }
// 删除缓存 // 删除缓存
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY); RedisMaps.delete(DictCacheKeyDefine.DICT_KEY,
DictCacheKeyDefine.DICT_SCHEMA.format(record.getKeyName()));
log.info("DictKeyService-updateDictKeyById effect: {}", effect); log.info("DictKeyService-updateDictKeyById effect: {}", effect);
return effect; return effect;
} }
@@ -108,23 +114,54 @@ public class DictKeyServiceImpl implements DictKeyService {
return list.stream() return list.stream()
.filter(s -> !s.getId().equals(Const.NONE_ID)) .filter(s -> !s.getId().equals(Const.NONE_ID))
.map(DictKeyConvert.MAPPER::to) .map(DictKeyConvert.MAPPER::to)
.sorted(Comparator.comparing(DictKeyVO::getKey)) .sorted(Comparator.comparing(DictKeyVO::getKeyName))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public Map<String, String> getDictSchema(String key) {
// 查询缓存
String cacheKey = DictCacheKeyDefine.DICT_SCHEMA.format(key);
JSONObject cacheResult = RedisStrings.getJson(cacheKey);
if (cacheResult == null) {
cacheResult = new JSONObject();
// 查询数据库
DictKeyDO dictKey = dictKeyDAO.selectByKey(key);
if (dictKey == null) {
return Maps.newMap();
}
// 构建缓存数据
cacheResult.put(Const.VALUE, dictKey.getValueType());
String extraSchema = dictKey.getExtraSchema();
if (extraSchema != null) {
cacheResult.putAll(JSON.parseObject(extraSchema));
}
// 设置缓存
RedisStrings.setJson(cacheKey, DictCacheKeyDefine.DICT_SCHEMA, cacheResult);
}
// 返回
Map<String, String> result = Maps.newMap();
Set<String> schemaKeys = cacheResult.keySet();
for (String schemaKey : schemaKeys) {
result.put(schemaKey, cacheResult.getString(schemaKey));
}
return result;
}
@Override @Override
public Integer deleteDictKeyById(Long id) { public Integer deleteDictKeyById(Long id) {
log.info("DictKeyService-deleteDictKeyById id: {}", id); log.info("DictKeyService-deleteDictKeyById id: {}", id);
// 检查数据是否存在 // 检查数据是否存在
DictKeyDO record = dictKeyDAO.selectById(id); DictKeyDO record = dictKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.CONFIG_ABSENT); Valid.notNull(record, ErrorMessage.CONFIG_ABSENT);
OperatorLogs.add(OperatorLogs.KEY, record.getKey()); OperatorLogs.add(OperatorLogs.KEY_NAME, record.getKeyName());
// 删除配置项 // 删除配置项
int effect = dictKeyDAO.deleteById(id); int effect = dictKeyDAO.deleteById(id);
// 删除配置值 // 删除配置值
dictValueService.deleteDictValueByKeyId(id); dictValueService.deleteDictValueByKeyId(id);
// 删除缓存 // 删除缓存
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, id); RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, id);
RedisMaps.delete(DictCacheKeyDefine.DICT_SCHEMA.format(record.getKeyName()));
log.info("DictKeyService-deleteDictKeyById id: {}, effect: {}", id, effect); log.info("DictKeyService-deleteDictKeyById id: {}, effect: {}", id, effect);
return effect; return effect;
} }
@@ -138,9 +175,9 @@ public class DictKeyServiceImpl implements DictKeyService {
return 0; return 0;
} }
String keys = dictKeys.stream() String keys = dictKeys.stream()
.map(DictKeyDO::getKey) .map(DictKeyDO::getKeyName)
.collect(Collectors.joining(Const.COMMA)); .collect(Collectors.joining(Const.COMMA));
OperatorLogs.add(OperatorLogs.KEY, keys); OperatorLogs.add(OperatorLogs.KEY_NAME, keys);
// 删除配置项 // 删除配置项
int effect = dictKeyDAO.deleteBatchIds(idList); int effect = dictKeyDAO.deleteBatchIds(idList);
// 删除配置值 // 删除配置值
@@ -148,6 +185,11 @@ public class DictKeyServiceImpl implements DictKeyService {
log.info("DictKeyService-deleteDictKeyByIdList effect: {}", effect); log.info("DictKeyService-deleteDictKeyByIdList effect: {}", effect);
// 删除缓存 // 删除缓存
RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, idList); RedisMaps.delete(DictCacheKeyDefine.DICT_KEY, idList);
List<String> schemaKeys = dictKeys.stream()
.map(DictKeyDO::getKeyName)
.map(DictCacheKeyDefine.DICT_SCHEMA::format)
.collect(Collectors.toList());
RedisMaps.delete(schemaKeys);
return effect; return effect;
} }
@@ -162,7 +204,7 @@ public class DictKeyServiceImpl implements DictKeyService {
// 更新时忽略当前记录 // 更新时忽略当前记录
.ne(DictKeyDO::getId, domain.getId()) .ne(DictKeyDO::getId, domain.getId())
// 用其他字段做重复校验 // 用其他字段做重复校验
.eq(DictKeyDO::getKey, domain.getKey()); .eq(DictKeyDO::getKeyName, domain.getKeyName());
// 检查是否存在 // 检查是否存在
boolean present = dictKeyDAO.of(wrapper).present(); boolean present = dictKeyDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.DATA_PRESENT); Valid.isFalse(present, ErrorMessage.DATA_PRESENT);

View File

@@ -1,9 +1,12 @@
package com.orion.ops.module.infra.service.impl; package com.orion.ops.module.infra.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid; 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.Lists;
import com.orion.lang.utils.collect.Maps;
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; 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.Const;
import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.constant.ErrorMessage;
@@ -24,7 +27,9 @@ import com.orion.ops.module.infra.entity.request.dict.DictValueRollbackRequest;
import com.orion.ops.module.infra.entity.request.dict.DictValueUpdateRequest; import com.orion.ops.module.infra.entity.request.dict.DictValueUpdateRequest;
import com.orion.ops.module.infra.entity.request.history.HistoryValueCreateRequest; import com.orion.ops.module.infra.entity.request.history.HistoryValueCreateRequest;
import com.orion.ops.module.infra.entity.vo.DictValueVO; import com.orion.ops.module.infra.entity.vo.DictValueVO;
import com.orion.ops.module.infra.enums.DictValueTypeEnum;
import com.orion.ops.module.infra.enums.HistoryValueTypeEnum; import com.orion.ops.module.infra.enums.HistoryValueTypeEnum;
import com.orion.ops.module.infra.service.DictKeyService;
import com.orion.ops.module.infra.service.DictValueService; import com.orion.ops.module.infra.service.DictValueService;
import com.orion.ops.module.infra.service.HistoryValueService; import com.orion.ops.module.infra.service.HistoryValueService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -33,6 +38,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -52,6 +58,9 @@ public class DictValueServiceImpl implements DictValueService {
@Resource @Resource
private DictValueDAO dictValueDAO; private DictValueDAO dictValueDAO;
@Resource
private DictKeyService dictKeyService;
@Resource @Resource
private HistoryValueService historyValueService; private HistoryValueService historyValueService;
@@ -62,12 +71,12 @@ public class DictValueServiceImpl implements DictValueService {
DictValueDO record = DictValueConvert.MAPPER.to(request); DictValueDO record = DictValueConvert.MAPPER.to(request);
// 查询 dictKey 是否存在 // 查询 dictKey 是否存在
DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId()); DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId());
String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKey(); String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKeyName();
// 查询数据是否冲突 // 查询数据是否冲突
this.checkDictValuePresent(record); this.checkDictValuePresent(record);
// 插入 // 插入
OperatorLogs.add(OperatorLogs.KEY, dictKey); OperatorLogs.add(OperatorLogs.KEY_NAME, dictKey);
record.setKey(key); record.setKeyName(key);
int effect = dictValueDAO.insert(record); int effect = dictValueDAO.insert(record);
Long id = record.getId(); Long id = record.getId();
log.info("DictValueService-createDictValue id: {}, effect: {}", id, effect); log.info("DictValueService-createDictValue id: {}, effect: {}", id, effect);
@@ -85,14 +94,14 @@ public class DictValueServiceImpl implements DictValueService {
Valid.notNull(record, ErrorMessage.CONFIG_ABSENT); Valid.notNull(record, ErrorMessage.CONFIG_ABSENT);
// 查询 dictKey 是否存在 // 查询 dictKey 是否存在
DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId()); DictKeyDO dictKey = dictKeyDAO.selectById(request.getKeyId());
String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKey(); String key = Valid.notNull(dictKey, ErrorMessage.CONFIG_ABSENT).getKeyName();
// 转换 // 转换
DictValueDO updateRecord = DictValueConvert.MAPPER.to(request); DictValueDO updateRecord = DictValueConvert.MAPPER.to(request);
// 查询数据是否冲突 // 查询数据是否冲突
this.checkDictValuePresent(updateRecord); this.checkDictValuePresent(updateRecord);
// 更新 // 更新
OperatorLogs.add(OperatorLogs.KEY, dictKey); OperatorLogs.add(OperatorLogs.KEY_NAME, dictKey);
updateRecord.setKey(key); updateRecord.setKeyName(key);
int effect = dictValueDAO.updateById(updateRecord); int effect = dictValueDAO.updateById(updateRecord);
log.info("DictValueService-updateDictValueById effect: {}", effect); log.info("DictValueService-updateDictValueById effect: {}", effect);
// 删除缓存 // 删除缓存
@@ -113,8 +122,8 @@ public class DictValueServiceImpl implements DictValueService {
HistoryValueDO history = historyValueService.getHistoryByRelId(request.getValueId(), id, HistoryValueTypeEnum.DICT.name()); HistoryValueDO history = historyValueService.getHistoryByRelId(request.getValueId(), id, HistoryValueTypeEnum.DICT.name());
Valid.notNull(history, ErrorMessage.HISTORY_ABSENT); Valid.notNull(history, ErrorMessage.HISTORY_ABSENT);
// 记录日志参数 // 记录日志参数
OperatorLogs.add(OperatorLogs.KEY, record.getKey()); OperatorLogs.add(OperatorLogs.KEY_NAME, record.getKeyName());
OperatorLogs.add(OperatorLogs.LABEL, record.getLabel()); OperatorLogs.add(OperatorLogs.LABEL, record.getName());
OperatorLogs.add(OperatorLogs.VALUE, history.getBeforeValue()); OperatorLogs.add(OperatorLogs.VALUE, history.getBeforeValue());
// 更新 // 更新
DictValueDO updateRecord = new DictValueDO(); DictValueDO updateRecord = new DictValueDO();
@@ -123,7 +132,7 @@ public class DictValueServiceImpl implements DictValueService {
int effect = dictValueDAO.updateById(updateRecord); int effect = dictValueDAO.updateById(updateRecord);
log.info("DictValueService-rollbackDictValueById effect: {}", effect); log.info("DictValueService-rollbackDictValueById effect: {}", effect);
// 删除缓存 // 删除缓存
RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(record.getKey())); RedisMaps.delete(DictCacheKeyDefine.DICT_VALUE.format(record.getKeyName()));
// 记录历史归档 // 记录历史归档
this.checkRecordHistory(updateRecord, record); this.checkRecordHistory(updateRecord, record);
return effect; return effect;
@@ -139,7 +148,7 @@ public class DictValueServiceImpl implements DictValueService {
// 查询数据库 // 查询数据库
list = dictValueDAO.of() list = dictValueDAO.of()
.createWrapper() .createWrapper()
.eq(DictValueDO::getKey, key) .eq(DictValueDO::getKeyName, key)
.then() .then()
.list(DictValueConvert.MAPPER::toCache); .list(DictValueConvert.MAPPER::toCache);
// 添加默认值 防止穿透 // 添加默认值 防止穿透
@@ -160,6 +169,34 @@ public class DictValueServiceImpl implements DictValueService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public Map<String, Map<String, Object>> getDictValueEnum(String key) {
// 查询配置值
List<DictValueVO> values = this.getDictValueList(key);
if (values.isEmpty()) {
return Maps.empty();
}
// 查询配置项
Map<String, String> schema = dictKeyService.getDictSchema(key);
// 返回
Map<String, Map<String, Object>> result = Maps.newLinkedMap();
for (DictValueVO value : values) {
Map<String, Object> item = Maps.newMap();
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)));
}
}
result.put(value.getName(), item);
}
return result;
}
@Override @Override
public DataGrid<DictValueVO> getDictValuePage(DictValueQueryRequest request) { public DataGrid<DictValueVO> getDictValuePage(DictValueQueryRequest request) {
// 条件 // 条件
@@ -174,7 +211,7 @@ public class DictValueServiceImpl implements DictValueService {
public Integer updateKeyNameByKeyId(Long keyId, String beforeKey, String newKey) { public Integer updateKeyNameByKeyId(Long keyId, String beforeKey, String newKey) {
// 修改数据库 // 修改数据库
DictValueDO updateRecord = new DictValueDO(); DictValueDO updateRecord = new DictValueDO();
updateRecord.setKey(newKey); updateRecord.setKeyName(newKey);
LambdaQueryWrapper<DictValueDO> wrapper = dictValueDAO.lambda() LambdaQueryWrapper<DictValueDO> wrapper = dictValueDAO.lambda()
.eq(DictValueDO::getKeyId, beforeKey); .eq(DictValueDO::getKeyId, beforeKey);
int effect = dictValueDAO.update(updateRecord, wrapper); int effect = dictValueDAO.update(updateRecord, wrapper);
@@ -192,7 +229,7 @@ public class DictValueServiceImpl implements DictValueService {
DictValueDO record = dictValueDAO.selectById(id); DictValueDO record = dictValueDAO.selectById(id);
Valid.notNull(record, ErrorMessage.CONFIG_ABSENT); Valid.notNull(record, ErrorMessage.CONFIG_ABSENT);
// 添加日志参数 // 添加日志参数
OperatorLogs.add(OperatorLogs.VALUE, record.getKey() + "-" + record.getLabel()); OperatorLogs.add(OperatorLogs.VALUE, record.getKeyName() + "-" + record.getName());
// 删除 // 删除
return this.deleteDictValue(Lists.singleton(id), Lists.singleton(record)); return this.deleteDictValue(Lists.singleton(id), Lists.singleton(record));
} }
@@ -204,7 +241,7 @@ public class DictValueServiceImpl implements DictValueService {
List<DictValueDO> records = dictValueDAO.selectBatchIds(idList); List<DictValueDO> records = dictValueDAO.selectBatchIds(idList);
// 添加日志参数 // 添加日志参数
String value = records.stream() String value = records.stream()
.map(s -> s.getKey() + "-" + s.getLabel()) .map(s -> s.getKeyName() + "-" + s.getName())
.collect(Collectors.joining(Const.COMMA)); .collect(Collectors.joining(Const.COMMA));
OperatorLogs.add(OperatorLogs.VALUE, value); OperatorLogs.add(OperatorLogs.VALUE, value);
// 删除 // 删除
@@ -251,7 +288,7 @@ public class DictValueServiceImpl implements DictValueService {
log.info("DictValueService-deleteDictValue effect: {}", effect); log.info("DictValueService-deleteDictValue effect: {}", effect);
// 删除缓存 // 删除缓存
List<String> keyList = records.stream() List<String> keyList = records.stream()
.map(DictValueDO::getKey) .map(DictValueDO::getKeyName)
.distinct() .distinct()
.map(DictCacheKeyDefine.DICT_VALUE::format) .map(DictCacheKeyDefine.DICT_VALUE::format)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -292,7 +329,7 @@ public class DictValueServiceImpl implements DictValueService {
.ne(DictValueDO::getId, domain.getId()) .ne(DictValueDO::getId, domain.getId())
// 用其他字段做重复校验 // 用其他字段做重复校验
.eq(DictValueDO::getKeyId, domain.getKeyId()) .eq(DictValueDO::getKeyId, domain.getKeyId())
.eq(DictValueDO::getLabel, domain.getLabel()); .eq(DictValueDO::getName, domain.getName());
// 检查是否存在 // 检查是否存在
boolean present = dictValueDAO.of(wrapper).present(); boolean present = dictValueDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.CONFIG_PRESENT); Valid.isFalse(present, ErrorMessage.CONFIG_PRESENT);
@@ -307,9 +344,9 @@ public class DictValueServiceImpl implements DictValueService {
private LambdaQueryWrapper<DictValueDO> buildQueryWrapper(DictValueQueryRequest request) { private LambdaQueryWrapper<DictValueDO> buildQueryWrapper(DictValueQueryRequest request) {
return dictValueDAO.wrapper() return dictValueDAO.wrapper()
.eq(DictValueDO::getKeyId, request.getKeyId()) .eq(DictValueDO::getKeyId, request.getKeyId())
.like(DictValueDO::getName, request.getName())
.eq(DictValueDO::getValue, request.getValue())
.like(DictValueDO::getLabel, request.getLabel()) .like(DictValueDO::getLabel, request.getLabel())
.like(DictValueDO::getValue, request.getValue())
.like(DictValueDO::getDesc, request.getDesc())
.orderByDesc(DictValueDO::getId); .orderByDesc(DictValueDO::getId);
} }

View File

@@ -5,10 +5,10 @@
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DictKeyDO"> <resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DictKeyDO">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="key" property="key"/> <result column="key_name" property="keyName"/>
<result column="value_type" property="valueType"/> <result column="value_type" property="valueType"/>
<result column="extra_schema" property="extraSchema"/> <result column="extra_schema" property="extraSchema"/>
<result column="desc" property="desc"/> <result column="description" property="description"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/> <result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/> <result column="creator" property="creator"/>
@@ -18,7 +18,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, key, value_type, extra_schema, desc, create_time, update_time, creator, updater, deleted id, key_name, value_type, extra_schema, description, create_time, update_time, creator, updater, deleted
</sql> </sql>
</mapper> </mapper>

View File

@@ -6,10 +6,10 @@
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DictValueDO"> <resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.DictValueDO">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="key_id" property="keyId"/> <result column="key_id" property="keyId"/>
<result column="key" property="key"/> <result column="key_name" property="keyName"/>
<result column="label" property="label"/> <result column="name" property="name"/>
<result column="value" property="value"/> <result column="value" property="value"/>
<result column="desc" property="desc"/> <result column="label" property="label"/>
<result column="extra" property="extra"/> <result column="extra" property="extra"/>
<result column="sort" property="sort"/> <result column="sort" property="sort"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
@@ -21,7 +21,7 @@
<!-- 通用查询结果列 --> <!-- 通用查询结果列 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, key_id, key, label, value, desc, extra, sort, create_time, update_time, creator, updater, deleted id, key_id, key_name, name, value, label, extra, sort, create_time, update_time, creator, updater, deleted
</sql> </sql>
</mapper> </mapper>

View File

@@ -0,0 +1,30 @@
import axios from 'axios';
import { DataGrid, Pagination } from '@/types/global';
import { TableData } from '@arco-design/web-vue/es/table/interface';
/**
* 历史归档查询请求
*/
export interface HistoryValueQueryRequest extends Pagination {
searchValue?: string;
relId?: number;
type?: string;
}
/**
* 历史归档查询响应
*/
export interface HistoryValueQueryResponse extends TableData {
id?: number;
beforeValue?: string;
afterValue?: string;
createTime: number;
creator: string;
}
/**
* 分页查询历史归档
*/
export function getHistoryValuePage(request: HistoryValueQueryRequest) {
return axios.post<DataGrid<HistoryValueQueryResponse>>('/infra/history-value/query', request);
}

View File

@@ -0,0 +1,71 @@
import axios from 'axios';
import qs from 'query-string';
import { TableData } from '@arco-design/web-vue/es/table/interface';
/**
* 字典配置项创建请求
*/
export interface DictKeyCreateRequest {
keyName?: string;
valueType?: string;
extraSchema?: string;
description?: string;
}
/**
* 字典配置项更新请求
*/
export interface DictKeyUpdateRequest extends DictKeyCreateRequest {
id?: number;
}
/**
* 字典配置项查询响应
*/
export interface DictKeyQueryResponse extends TableData {
id?: number;
keyName?: string;
valueType?: string;
extraSchema?: string;
description?: string;
}
/**
* 创建字典配置项
*/
export function createDictKey(request: DictKeyCreateRequest) {
return axios.post('/infra/dict-key/create', request);
}
/**
* 更新字典配置项
*/
export function updateDictKey(request: DictKeyUpdateRequest) {
return axios.put('/infra/dict-key/update', request);
}
/**
* 查询全部字典配置项
*/
export function getDictKeyList() {
return axios.post<Array<DictKeyQueryResponse>>('/infra/dict-key/list');
}
/**
* 删除字典配置项
*/
export function deleteDictKey(id: number) {
return axios.delete('/infra/dict-key/delete', { params: { id } });
}
/**
* 批量删除字典配置项
*/
export function batchDeleteDictKey(idList: Array<number>) {
return axios.delete('/infra/dict-key/batch-delete', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}

View File

@@ -0,0 +1,134 @@
import axios from 'axios';
import qs from 'query-string';
import { AnyObject, DataGrid, Options, Pagination } from '@/types/global';
import { TableData } from '@arco-design/web-vue/es/table/interface';
/**
* 字典配置值创建请求
*/
export interface DictValueCreateRequest {
keyId?: number;
keyName?: string;
name?: string;
value?: string;
label?: string;
extra?: string;
sort?: number;
}
/**
* 字典配置值更新请求
*/
export interface DictValueUpdateRequest extends DictValueCreateRequest {
id?: number;
}
/**
* 字典配置值回滚请求
*/
export interface DictValueRollbackRequest {
id?: number;
relId?: number;
}
/**
* 字典配置值查询请求
*/
export interface DictValueQueryRequest extends Pagination {
searchValue?: string;
id?: number;
keyId?: number;
keyName?: string;
name?: string;
value?: string;
label?: string;
extra?: string;
sort?: number;
}
/**
* 字典配置值查询响应
*/
export interface DictValueQueryResponse extends TableData {
id?: number;
keyId?: number;
keyName?: string;
name?: string;
value?: string;
label?: string;
extra?: string;
sort?: number;
createTime: number;
updateTime: number;
creator: string;
updater: string;
}
/**
* 字典配置值枚举查询响应
*/
export interface DictValueEnumQueryResponse extends Options {
[key: string]: unknown;
}
/**
* 创建字典配置值
*/
export function createDictValue(request: DictValueCreateRequest) {
return axios.post('/infra/dict-value/create', request);
}
/**
* 更新字典配置值
*/
export function updateDictValue(request: DictValueUpdateRequest) {
return axios.put('/infra/dict-value/update', request);
}
/**
* 回滚字典配置值
*/
export function rollbackDictValue(request: DictValueRollbackRequest) {
return axios.put('/infra/dict-value/rollback', request);
}
/**
* 查询字典配置值
*/
export function getDictValue(keyName: string) {
return axios.get<Array<DictValueQueryResponse>>('/infra/dict-value/list', { params: { keyName } });
}
/**
* 查询字典配置值枚举
*/
export function getDictValueEnum(keyName: string) {
return axios.get<Record<string, DictValueEnumQueryResponse>>('/infra/dict-value/enum', { params: { keyName } });
}
/**
* 分页查询字典配置值
*/
export function getDictValuePage(request: DictValueQueryRequest) {
return axios.post<DataGrid<DictValueQueryResponse>>('/infra/dict-value/query', request);
}
/**
* 删除字典配置值
*/
export function deleteDictValue(id: number) {
return axios.delete('/infra/dict-value/delete', { params: { id } });
}
/**
* 批量删除字典配置值
*/
export function batchDeleteDictValue(idList: Array<number>) {
return axios.delete('/infra/dict-value/batch-delete', {
params: { idList },
paramsSerializer: params => {
return qs.stringify(params, { arrayFormat: 'comma' });
}
});
}

View File

@@ -11,6 +11,11 @@ const SYSTEM: AppRouteRecordRaw = {
path: '/system/menu', path: '/system/menu',
component: () => import('@/views/system/menu/index.vue'), component: () => import('@/views/system/menu/index.vue'),
}, },
{
name: 'systemDict',
path: '/system/dict',
component: () => import('@/views/system/dict/index.vue'),
},
], ],
}; };

View File

@@ -0,0 +1,168 @@
<template>
<a-modal v-model:visible="visible"
body-class="modal-form"
title-align="start"
:title="title"
:top="80"
:align-center="false"
:draggable="true"
:mask-closable="false"
:unmount-on-close="true"
:ok-button-props="{ disabled: loading }"
:cancel-button-props="{ disabled: loading }"
:on-before-ok="handlerOk"
@close="handleClose">
<a-spin :loading="loading">
<a-form :model="formModel"
ref="formRef"
label-align="right"
:style="{ width: '460px' }"
:label-col-props="{ span: 6 }"
:wrapper-col-props="{ span: 18 }"
:rules="formRules">
<!-- 配置项id -->
<a-form-item field="keyId" label="配置项id">
<a-input-number v-model="formModel.keyId"
placeholder="请输入配置项id"
hide-button />
</a-form-item>
<!-- 配置项 -->
<a-form-item field="keyName" label="配置项">
<a-input v-model="formModel.keyName" placeholder="请输入配置项" allow-clear />
</a-form-item>
<!-- 配置名称 -->
<a-form-item field="name" label="配置名称">
<a-input v-model="formModel.name" placeholder="请输入配置名称" allow-clear />
</a-form-item>
<!-- 配置值 -->
<a-form-item field="value" label="配置值">
<a-input v-model="formModel.value" placeholder="请输入配置值" allow-clear />
</a-form-item>
<!-- 配置描述 -->
<a-form-item field="label" label="配置描述">
<a-input v-model="formModel.label" placeholder="请输入配置描述" allow-clear />
</a-form-item>
<!-- 额外参数 -->
<a-form-item field="extra" label="额外参数">
<a-input v-model="formModel.extra" placeholder="请输入额外参数" allow-clear />
</a-form-item>
<!-- 排序 -->
<a-form-item field="sort" label="排序">
<a-input-number v-model="formModel.sort"
placeholder="请输入排序"
hide-button />
</a-form-item>
</a-form>
</a-spin>
</a-modal>
</template>
<script lang="ts">
export default {
name: 'system-dict-value-form-modal'
};
</script>
<script lang="ts" setup>
import { ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules';
import { createDictValue, updateDictValue, DictValueUpdateRequest } from '@/api/system/dict-value';
import { Message } from '@arco-design/web-vue';
import {} from '../types/const';
import {} from '../types/enum.types';
import { toOptions } from '@/utils/enum';
const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading();
const title = ref<string>();
const isAddHandle = ref<boolean>(true);
const defaultForm = (): DictValueUpdateRequest => {
return {
id: undefined,
keyId: undefined,
keyName: undefined,
name: undefined,
value: undefined,
label: undefined,
extra: undefined,
sort: undefined,
};
};
const formRef = ref<any>();
const formModel = ref<DictValueUpdateRequest>({});
const emits = defineEmits(['added', 'updated']);
// 打开新增
const openAdd = () => {
title.value = '添加字典值';
isAddHandle.value = true;
renderForm({ ...defaultForm() });
setVisible(true);
};
// 打开修改
const openUpdate = (record: any) => {
title.value = '修改字典值';
isAddHandle.value = false;
renderForm({ ...defaultForm(), ...record });
setVisible(true);
};
// 渲染表单
const renderForm = (record: any) => {
formModel.value = Object.assign({}, record);
};
defineExpose({ openAdd, openUpdate });
// 确定
const handlerOk = async () => {
setLoading(true);
try {
// 验证参数
const error = await formRef.value.validate();
if (error) {
return false;
}
if (isAddHandle.value) {
// 新增
await createDictValue(formModel.value);
Message.success('创建成功');
emits('added');
} else {
// 修改
await updateDictValue(formModel.value);
Message.success('修改成功');
emits('updated');
}
// 清空
handlerClear();
} catch (e) {
return false;
} finally {
setLoading(false);
}
};
// 关闭
const handleClose = () => {
handlerClear();
};
// 清空
const handlerClear = () => {
setLoading(false);
setVisible(false);
};
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,224 @@
<template>
<!-- 搜索 -->
<a-card class="general-card table-search-card">
<a-query-header :model="formModel"
label-align="left"
@submit="fetchTableData"
@reset="fetchTableData">
<!-- 配置项 fixme 修改为下拉框 -->
<a-form-item field="keyName" label="配置项" label-col-flex="50px">
<a-input v-model="formModel.keyName" placeholder="请输入配置项" allow-clear />
</a-form-item>
<!-- 配置名称 -->
<a-form-item field="name" label="配置名称" label-col-flex="50px">
<a-input v-model="formModel.name" placeholder="请输入配置名称" allow-clear />
</a-form-item>
<!-- 配置值 -->
<a-form-item field="value" label="配置值" label-col-flex="50px">
<a-input v-model="formModel.value" placeholder="请输入配置值" allow-clear />
</a-form-item>
<!-- 配置描述 -->
<a-form-item field="label" label="配置描述" label-col-flex="50px">
<a-input v-model="formModel.label" placeholder="请输入配置描述" allow-clear />
</a-form-item>
</a-query-header>
</a-card>
<!-- 表格 -->
<a-card class="general-card table-card">
<template #title>
<!-- 左侧操作 -->
<div class="table-left-bar-handle">
<!-- 标题 -->
<div class="table-title">
数据字典
</div>
</div>
<!-- 右侧操作 -->
<div class="table-right-bar-handle">
<a-space>
<!-- 新增 -->
<a-button type="primary"
v-permission="['infra:dict-value:create']"
@click="emits('openAdd')">
新增字典值
<template #icon>
<icon-plus />
</template>
</a-button>
<!-- 删除 -->
<a-popconfirm position="br"
type="warning"
:content="`确认删除选中的${selectedKeys.length}条记录吗?`"
@ok="deleteSelectRows">
<a-button v-permission="['infra:dict-value:delete']"
type="secondary"
status="danger"
:disabled="selectedKeys.length === 0">
删除
<template #icon>
<icon-delete />
</template>
</a-button>
</a-popconfirm>
</a-space>
</div>
</template>
<!-- table -->
<a-table row-key="id"
class="table-wrapper-8"
ref="tableRef"
label-align="left"
:loading="loading"
:columns="columns"
v-model:selected-keys="selectedKeys"
:row-selection="rowSelection"
:data="tableRenderData"
:pagination="pagination"
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(1, size)"
:bordered="false">
<!-- 操作 -->
<template #handle="{ record }">
<div class="table-handle-wrapper">
<!-- 修改 -->
<a-button type="text"
size="mini"
v-permission="['infra:dict-value:update']"
@click="emits('openUpdate', record)">
修改
</a-button>
<!-- 历史 -->
<a-button type="text"
size="mini"
v-permission="['infra:dict-value:update']"
@click="emits('openUpdate', record)">
历史
</a-button>
<!-- 删除 -->
<a-popconfirm content="确认删除这条记录吗?"
position="left"
type="warning"
@ok="deleteRow(record)">
<a-button v-permission="['infra:dict-value:delete']"
type="text"
size="mini"
status="danger">
删除
</a-button>
</a-popconfirm>
</div>
</template>
</a-table>
</a-card>
</template>
<script lang="ts">
export default {
name: 'system-dict-value-table'
};
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { batchDeleteDictValue, deleteDictValue, getDictValuePage, DictValueQueryRequest, DictValueQueryResponse } from '@/api/system/dict-value';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import columns from '../types/table.columns';
import { usePagination, useRowSelection } from '@/types/table';
import {} from '../types/const';
import {} from '../types/enum.types';
import { toOptions, getEnumValue } from '@/utils/enum';
const tableRenderData = ref<DictValueQueryResponse[]>([]);
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate']);
const pagination = usePagination();
const selectedKeys = ref<number[]>([]);
const rowSelection = useRowSelection();
const formModel = reactive<DictValueQueryRequest>({
id: undefined,
keyId: undefined,
keyName: undefined,
name: undefined,
value: undefined,
label: undefined,
extra: undefined,
sort: undefined,
});
// 删除选中行
const deleteSelectRows = async () => {
try {
setLoading(true);
// 调用删除接口
await batchDeleteDictValue(selectedKeys.value);
Message.success(`成功删除${selectedKeys.value.length}条数据`);
selectedKeys.value = [];
// 重新加载数据
await fetchTableData();
} catch (e) {
} finally {
setLoading(false);
}
};
// 删除当前行
const deleteRow = async ({ id }: {
id: number
}) => {
try {
setLoading(true);
// 调用删除接口
await deleteDictValue(id);
Message.success('删除成功');
// 重新加载数据
await fetchTableData();
} catch (e) {
} finally {
setLoading(false);
}
};
// 添加后回调
const addedCallback = () => {
fetchTableData();
};
// 更新后回调
const updatedCallback = () => {
fetchTableData();
};
defineExpose({
addedCallback, updatedCallback
});
// 加载数据
const doFetchTableData = async (request: DictValueQueryRequest) => {
try {
setLoading(true);
const { data } = await getDictValuePage(request);
tableRenderData.value = data.rows;
pagination.total = data.total;
pagination.current = request.page;
pagination.pageSize = request.limit;
selectedKeys.value = [];
} catch (e) {
} finally {
setLoading(false);
}
};
// 切换页码
const fetchTableData = (page = 1, limit = pagination.pageSize, form = formModel) => {
doFetchTableData({ page, limit, ...form });
};
fetchTableData();
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,43 @@
<template>
<div class="layout-container">
<!-- 列表-表格 -->
<dict-value-table ref="table"
@openAdd="() => modal.openAdd()"
@openUpdate="(e) => modal.openUpdate(e)" />
<!-- 添加修改模态框 -->
<dict-value-form-modal ref="modal"
@added="modalAddCallback"
@updated="modalUpdateCallback" />
</div>
</template>
<script lang="ts">
export default {
name: 'systemDict'
};
</script>
<script lang="ts" setup>
import DictValueTable from './components/dict-value-table.vue';
import DictValueFormModal from './components/dict-value-form-modal.vue';
import { ref } from 'vue';
const table = ref();
const modal = ref();
// 添加回调
const modalAddCallback = () => {
table.value.addedCallback();
};
// 修改回调
const modalUpdateCallback = () => {
table.value.updatedCallback();
};
</script>
<style lang="less" scoped>
</style>

View File

@@ -0,0 +1,64 @@
import { FieldRule } from '@arco-design/web-vue';
export const keyId = [{
required: true,
message: '请输入配置项id'
}] as FieldRule[];
export const keyName = [{
required: true,
message: '请输入配置项'
}, {
maxLength: 32,
message: '配置项长度不能大于32位'
}, {
match: /^[a-zA-Z0-9]{4,32}$/,
message: '配置项需要为 4-32 位的数字以及字母'
}] as FieldRule[];
export const name = [{
required: true,
message: '请输入配置名称'
}, {
maxLength: 32,
message: '配置名称长度不能大于32位'
}, {
match: /^[a-zA-Z0-9]{4,32}$/,
message: '配置名称需要为 4-32 位的数字以及字母'
}] as FieldRule[];
export const value = [{
required: true,
message: '请输入配置值'
}, {
maxLength: 512,
message: '配置值长度不能大于512位'
}] as FieldRule[];
export const label = [{
required: true,
message: '请输入配置描述'
}, {
maxLength: 64,
message: '配置描述长度不能大于64位'
}] as FieldRule[];
export const extra = [{
required: true,
message: '请输入额外参数'
}] as FieldRule[];
export const sort = [{
required: true,
message: '请输入排序'
}] as FieldRule[];
export default {
keyId,
keyName,
name,
value,
label,
extra,
sort,
} as Record<string, FieldRule | FieldRule[]>;

View File

@@ -0,0 +1,64 @@
import { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import { dateFormat } from '@/utils';
const columns = [
{
title: 'id',
dataIndex: 'id',
slotName: 'id',
width: 70,
align: 'left',
fixed: 'left',
}, {
title: '配置项',
dataIndex: 'keyName',
slotName: 'keyName',
ellipsis: true,
tooltip: true,
}, {
title: '配置名称',
dataIndex: 'name',
slotName: 'name',
ellipsis: true,
tooltip: true,
}, {
title: '配置描述',
dataIndex: 'label',
slotName: 'label',
ellipsis: true,
tooltip: true,
}, {
title: '配置值',
dataIndex: 'value',
slotName: 'value',
ellipsis: true,
tooltip: true,
}, {
title: '额外参数',
dataIndex: 'extra',
slotName: 'extra',
ellipsis: true,
tooltip: true,
}, {
title: '排序',
dataIndex: 'sort',
slotName: 'sort',
width: 70,
}, {
title: '修改时间',
dataIndex: 'updateTime',
slotName: 'updateTime',
width: 180,
render: ({ record }) => {
return dateFormat(new Date(record.updateTime));
},
}, {
title: '操作',
slotName: 'handle',
width: 160,
align: 'center',
fixed: 'right',
},
] as TableColumnData[];
export default columns;