From ada22636b311163832d4f1de4c30e3d7b9b2401e Mon Sep 17 00:00:00 2001 From: lijiahang Date: Mon, 30 Oct 2023 18:35:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AD=97=E5=85=B8=E9=85=8D=E7=BD=AE=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E6=9E=9A=E4=B8=BE=E5=80=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++- .../ops/framework/common/constant/Const.java | 2 +- .../{ConstField.java => FieldConst.java} | 2 +- .../log/core/constant/OperatorLogKeys.java | 4 +- .../core/generator/CodeGenerators.java | 37 +--- .../core/generator/core/CodeGenerator.java | 2 - .../generator/core/CodeGeneratorEngine.java | 142 ++++---------- .../core/generator/core/CustomFileFilter.java | 44 +++++ .../core/generator/core/DictParser.java | 87 +++++++++ .../mybatis/core/generator/core/EnumMeta.java | 35 ---- .../core/generator/template/DictMeta.java | 91 +++++++++ .../core/generator/template/DictTemplate.java | 175 ++++++++++++++++++ .../generator/template/EnumsTemplate.java | 151 --------------- .../core/generator/template/Table.java | 6 +- .../core/generator/template/Template.java | 23 +++ .../core/generator/template/VueEnum.java | 69 ------- .../core/generator/template/VueTemplate.java | 32 ---- .../resources/templates/orion-sql-dict.sql.vm | 65 ++++--- .../resources/templates/orion-sql-menu.sql.vm | 2 +- ...rion-vue-views-components-card-list.vue.vm | 104 ++++++----- ...on-vue-views-components-form-drawer.vue.vm | 22 ++- ...ion-vue-views-components-form-modal.vue.vm | 20 +- .../orion-vue-views-components-table.vue.vm | 24 ++- .../templates/orion-vue-views-index.vue.vm | 16 +- .../orion-vue-views-types-const.ts.vm | 23 +++ .../orion-vue-views-types-enum.types.ts.vm | 15 -- .../components/host-identity-card-list.vue | 64 +++---- .../asset/host/components/host-card-list.vue | 82 ++++---- 28 files changed, 737 insertions(+), 624 deletions(-) rename orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/{ConstField.java => FieldConst.java} (93%) create mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/DictParser.java delete mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/EnumMeta.java create mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictMeta.java create mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java delete mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/EnumsTemplate.java delete mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueEnum.java delete mode 100644 orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm diff --git a/README.md b/README.md index c95f779e..e5c45a49 100644 --- a/README.md +++ b/README.md @@ -69,18 +69,20 @@ Template.create("system_role", "角色", "role") .vue("user", "role") // 前端使用抽屉表单 (多字段使用) .enableDrawerForm() + // 前端支持卡片或 (多字段使用) + .enableCardView() // 前端支持多选 .enableRowSelection() - // 枚举下拉框 替换的字段为 'type' - .enums("type") - // 枚举值为 APP HOST - .names("APP", "HOST") - // 设置参数为 label APP.label = '应用' HOST.label = '主机' - .values("label", "应用", "主机") - // 设置参数为 value APP.value = '1' HOST.value = '2' - .values("value", 1, 2) - // 设置参数为 color APP.color = 'blue' HOST.color = 'green' - .color("blue", "green") + // 生成字典配置 配置项为 'dictValueType', 替换的字段为 'value_type' + .dict("dictValueType", "value_type") + // 设置字段名称 + .fields("STRING", "INTEGER", "DECIMAL", "BOOLEAN", "COLOR") + // 设置字典值 + .value(1, 2, 3, 4, 5) + // 设置字典值描述 + .labels("字符串", "整数", "小数", "布尔值", "颜色") + // 设置额外值 color + .color("blue", "gray", "red", "green", "white") .build(); ``` diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java index b8ce8fd9..1f3ca46b 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java @@ -7,7 +7,7 @@ package com.orion.ops.framework.common.constant; * @version 1.0.0 * @since 2023/6/23 18:49 */ -public interface Const extends com.orion.lang.constant.Const, ConstField { +public interface Const extends com.orion.lang.constant.Const, FieldConst { Integer NOT_DELETE = 0; diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ConstField.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/FieldConst.java similarity index 93% rename from orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ConstField.java rename to orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/FieldConst.java index 4a940af3..a85f558a 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/ConstField.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/FieldConst.java @@ -7,7 +7,7 @@ package com.orion.ops.framework.common.constant; * @version 1.0.0 * @since 2023/10/17 12:44 */ -public interface ConstField { +public interface FieldConst { String ID = "id"; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java b/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java index 4f8e7977..0202e38e 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java @@ -1,6 +1,6 @@ package com.orion.ops.framework.biz.operator.log.core.constant; -import com.orion.ops.framework.common.constant.ConstField; +import com.orion.ops.framework.common.constant.FieldConst; /** * 操作日志常量 @@ -9,7 +9,7 @@ import com.orion.ops.framework.common.constant.ConstField; * @version 1.0.0 * @since 2023/10/10 19:00 */ -public interface OperatorLogKeys extends ConstField { +public interface OperatorLogKeys extends FieldConst { String ID_LIST = "idList"; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java index b432e436..0dc38eb5 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java @@ -30,38 +30,21 @@ public class CodeGenerators { String module = "infra"; // 生成的表 Table[] tables = { - // Template.create("preference", "用户偏好", "preference") - // .enableProviderApi() - // .cache("user:preference:{}:{}", "用户偏好 ${type} ${userId}") - // .expire(1, TimeUnit.HOURS) - // .vue("user", "preference") - // .enums("type") - // .names("APP", "HOST") - // // 同 .value(1, 2) - // .values("value", 1, 2) - // // 同 .label("应用", "主机") - // .values("label", "应用", "主机") - // .color("blue", "green") - // .build(), - // Template.create("history_value", "历史归档", "history") - // .enableProviderApi() - // .vue("meta", "history-value") - // .build(), Template.create("dict_key", "字典配置项", "dict") - .disableOperatorLog() + .enableProviderApi() + .disableUnitTest() .cache("dict:keys", "字典配置项") .expire(1, TimeUnit.DAYS) .vue("system", "dict-key") - .enums("value_type") - .names("STRING", "INTEGER", "DECIMAL", "BOOLEAN", "COLOR") - .label("字符串", "整数", "小数", "布尔值", "颜色") + .enableRowSelection() + .enableCardView() + .enableDrawerForm() + .dict("dictValueType", "value_type") + .fields("STRING", "INTEGER", "DECIMAL", "BOOLEAN", "COLOR") + .labels("字符串", "整数", "小数", "布尔值", "颜色") + .color("blue", "gray", "red", "green", "white") + .valueUseFields() .build(), - // Template.create("dict_value", "字典配置值", "dict") - // .cache("dict:value:{}", "字典配置值 ${key}") - // .expire(1, TimeUnit.DAYS) - // .vue("system", "dict-value") - // .enableRowSelection() - // .build(), }; // jdbc 配置 - 使用配置文件 File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml"); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGenerator.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGenerator.java index 4d117b05..eabfd817 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGenerator.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGenerator.java @@ -357,8 +357,6 @@ public class CodeGenerator implements Executable { new String[]{"/templates/orion-vue-views-components-table.vue.vm", "${feature}-table.vue", "vue/views/${module}/${feature}/components"}, // card-list.vue 文件 new String[]{"/templates/orion-vue-views-components-card-list.vue.vm", "${feature}-card-list.vue", "vue/views/${module}/${feature}/components"}, - // enum.types.ts 文件 - new String[]{"/templates/orion-vue-views-types-enum.types.ts.vm", "enum.types.ts", "vue/views/${module}/${feature}/types"}, // const.ts 文件 new String[]{"/templates/orion-vue-views-types-const.ts.vm", "const.ts", "vue/views/${module}/${feature}/types"}, // form.rules.ts 文件 diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGeneratorEngine.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGeneratorEngine.java index 08344870..f81f2ea7 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGeneratorEngine.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CodeGeneratorEngine.java @@ -3,9 +3,7 @@ package com.orion.ops.framework.mybatis.core.generator.core; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.generator.config.OutputFile; import com.baomidou.mybatisplus.generator.config.builder.CustomFile; -import com.baomidou.mybatisplus.generator.config.po.TableField; import com.baomidou.mybatisplus.generator.config.po.TableInfo; -import com.orion.lang.define.collect.MultiLinkedHashMap; import com.orion.lang.utils.Strings; import com.orion.lang.utils.VariableStyles; import com.orion.lang.utils.io.Files1; @@ -14,11 +12,13 @@ import com.orion.lang.utils.reflect.Fields; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.OrionOpsProConst; import com.orion.ops.framework.mybatis.core.generator.template.Table; -import com.orion.ops.framework.mybatis.core.generator.template.VueEnum; import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Predicate; @@ -46,10 +46,10 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { customFiles = new CustomFileFilter(tables.get(tableInfo.getName()), customFiles).doFilter(); // 添加表元数据 this.addTableMeta(tableInfo, objectMap); - // 替换自定义包名 - this.replacePackageName(customFiles, tableInfo, objectMap); // 添加注释元数据 this.addApiCommentMeta(tableInfo, objectMap); + // 替换自定义包名 + this.replacePackageName(customFiles, tableInfo, objectMap); // 生成后端文件 this.generatorServerFile(customFiles, tableInfo, objectMap); // 生成前端文件 @@ -65,10 +65,6 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { * @param objectMap objectMap */ private void addTableMeta(@NotNull TableInfo tableInfo, @NotNull Map objectMap) { - // http 注释标识 - objectMap.put("httpComment", "###"); - // 版本 - objectMap.put("since", OrionOpsProConst.VERSION); // 替换业务注释 tableInfo.setComment(tables.get(tableInfo.getName()).getComment()); Table table = tables.get(tableInfo.getName()); @@ -87,6 +83,38 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { objectMap.put("typeHyphen", mappingHyphen.substring(0, mappingHyphen.length() - 3)); // 类型常量 objectMap.put("typeConst", VariableStyles.BIG_HUMP.toSerpentine(entityName).toUpperCase()); + // 字典配置 + objectMap.put("dictMap", new DictParser(tableInfo, table).parse()); + } + + /** + * 插入 api 注释 + * + * @param tableInfo tableInfo + * @param objectMap objectMap + */ + private void addApiCommentMeta(@NotNull TableInfo tableInfo, @NotNull Map objectMap) { + // http 注释标识 + objectMap.put("httpComment", "###"); + // 版本 + objectMap.put("since", OrionOpsProConst.VERSION); + // api 注释 + Map apiComment = new HashMap<>(12); + String comment = tableInfo.getComment(); + apiComment.put("create", "创建" + comment); + apiComment.put("updateAll", "根据条件更新" + comment); + apiComment.put("updateById", "更新" + comment); + apiComment.put("getById", "查询" + comment); + apiComment.put("getByIdList", "批量查询" + comment); + apiComment.put("queryList", "查询全部" + comment); + apiComment.put("queryListByCache", "通过缓存查询" + comment); + apiComment.put("queryPage", "分页查询" + comment); + apiComment.put("queryCount", "查询" + comment + "数量"); + apiComment.put("deleteById", "删除" + comment); + apiComment.put("deleteAll", "根据条件删除" + comment); + apiComment.put("batchDelete", "批量删除" + comment); + apiComment.put("export", "导出" + comment); + objectMap.put("apiComment", apiComment); } /** @@ -133,31 +161,6 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { objectMap.put("customProviderFilePackages", customProviderFilePackages); } - /** - * 插入 api 注释 - * - * @param tableInfo tableInfo - * @param objectMap objectMap - */ - private void addApiCommentMeta(@NotNull TableInfo tableInfo, @NotNull Map objectMap) { - Map map = new HashMap<>(12); - objectMap.put("apiComment", map); - String comment = tableInfo.getComment(); - map.put("create", "创建" + comment); - map.put("updateAll", "根据条件更新" + comment); - map.put("updateById", "更新" + comment); - map.put("getById", "查询" + comment); - map.put("getByIdList", "批量查询" + comment); - map.put("queryList", "查询全部" + comment); - map.put("queryListByCache", "通过缓存查询" + comment); - map.put("queryPage", "分页查询" + comment); - map.put("queryCount", "查询" + comment + "数量"); - map.put("deleteById", "删除" + comment); - map.put("deleteAll", "根据条件删除" + comment); - map.put("batchDelete", "批量删除" + comment); - map.put("export", "导出" + comment); - } - /** * 生成后端文件 * @@ -222,8 +225,6 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { vueMeta.put("featureEntityFirstLower", Strings.firstLower(vueMeta.get("featureEntity"))); // 功能名称常量 vueMeta.put("featureConst", VariableStyles.SPINE.toSerpentine(table.getFeature()).toUpperCase()); - // 枚举 - vueMeta.put("enums", this.getEnumMap(tableInfo, table)); objectMap.put("vue", vueMeta); // 生成文件 @@ -263,71 +264,4 @@ public class CodeGeneratorEngine extends VelocityTemplateEngine { }); } - /** - * 获取枚举 - * - * @param tableInfo tableInfo - * @param table table - * @return enumMap - */ - private Map getEnumMap(TableInfo tableInfo, Table table) { - // 枚举值 - Map enumMap = new LinkedHashMap<>(); - for (VueEnum meta : table.getEnums()) { - // 检查字段是否存在 - String variable = meta.getVariable(); - TableField tableField = tableInfo.getFields() - .stream() - .filter(s -> variable.equals(s.getName()) || variable.equals(s.getPropertyName())) - .findFirst() - .orElseThrow(() -> new RuntimeException("未查询到枚举映射字段 " + variable)); - // 设置枚举名称 - if (meta.getClassName() == null) { - meta.setClassName(Strings.firstUpper(tableField.getPropertyName()) + "Enum"); - } - // 设置枚举注释 - if (meta.getComment() == null) { - meta.setComment(Strings.def(tableField.getComment(), meta.getClassName())); - } - // 设置枚举 - MultiLinkedHashMap enumInfo = new MultiLinkedHashMap<>(); - for (int i = 0; i < meta.getNames().size(); i++) { - // 枚举名称 - String name = meta.getNames().get(i); - // 设置枚举值 - for (int j = 0; j < meta.getFields().size(); j++) { - String field = meta.getFields().get(j); - Object value = safeGet(safeGet(meta.getValues(), j), i); - enumInfo.put(name, field, value); - } - // 检查是否有 value - if (!meta.getFields().contains(Const.VALUE)) { - // 没有 value 用 name - enumInfo.put(name, Const.VALUE, name); - } - } - enumMap.put(tableField.getPropertyName(), new EnumMeta(meta.getClassName(), meta.getComment(), enumInfo)); - } - return enumMap; - } - - /** - * 获取值 - * - * @param list list - * @param index index - * @param T - * @return value - */ - private T safeGet(List list, int index) { - if (list == null) { - return null; - } - if (list.size() > index) { - return list.get(index); - } else { - return null; - } - } - } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CustomFileFilter.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CustomFileFilter.java index 4796bfe6..cc1f60f3 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CustomFileFilter.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/CustomFileFilter.java @@ -75,6 +75,19 @@ public class CustomFileFilter { files.removeIf(file -> isVueFile(file.getTemplatePath())); // 不生成菜单 sql 文件 files.removeIf(file -> isMenuDataFile(file.getTemplatePath())); + } else { + // form + if (!table.isEnableDrawerForm()) { + // 不生成抽屉表单 + files.removeIf(file -> isVueFormDrawerFile(file.getTemplatePath())); + } else { + // 不生成模态框表单 + files.removeIf(file -> isVueFormModalFile(file.getTemplatePath())); + } + // 不生成卡片文件 + if (!table.isEnableCardView()) { + files.removeIf(file -> isVueCardViewFile(file.getTemplatePath())); + } } return files; } @@ -180,4 +193,35 @@ public class CustomFileFilter { return templatePath.contains("orion-vue-"); } + /** + * 是否为抽屉表单文件 + * + * @param templatePath templatePath + * @return 是否为抽屉表单文件 + */ + public static boolean isVueFormDrawerFile(String templatePath) { + return templatePath.contains("orion-vue-views-components-form-drawer"); + } + + /** + * 是否为模态框表单文件 + * + * @param templatePath templatePath + * @return 是否为模态框表单文件 + */ + public static boolean isVueFormModalFile(String templatePath) { + return templatePath.contains("orion-vue-views-components-form-modal"); + } + + /** + * 是否为卡片视图文件 + * + * @param templatePath templatePath + * @return 是否为卡片视图文件 + */ + public static boolean isVueCardViewFile(String templatePath) { + return templatePath.contains("orion-vue-views-components-card-list") || + templatePath.contains("orion-vue-views-types-card.fields"); + } + } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/DictParser.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/DictParser.java new file mode 100644 index 00000000..25594cb5 --- /dev/null +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/DictParser.java @@ -0,0 +1,87 @@ +package com.orion.ops.framework.mybatis.core.generator.core; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.generator.config.po.TableField; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.orion.lang.utils.Strings; +import com.orion.ops.framework.common.constant.Const; +import com.orion.ops.framework.common.constant.FieldConst; +import com.orion.ops.framework.mybatis.core.generator.template.DictMeta; +import com.orion.ops.framework.mybatis.core.generator.template.Table; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 字典解析器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/10/30 16:02 + */ +public class DictParser { + + private final TableInfo tableInfo; + + private final Table table; + + public DictParser(TableInfo tableInfo, Table table) { + this.tableInfo = tableInfo; + this.table = table; + } + + /** + * 解析字典 + * + * @return dictMap + */ + public Map parse() { + // 字典值 + Map dictMap = new LinkedHashMap<>(); + for (DictMeta meta : table.getDictList()) { + // 检查字段是否存在 + String variable = meta.getVariable(); + TableField tableField = tableInfo.getFields() + .stream() + .filter(s -> variable.equals(s.getName()) || variable.equals(s.getPropertyName())) + .findFirst() + .orElseThrow(() -> new RuntimeException("未查询到字典映射字段 " + variable)); + // 设置字段名称 + if (meta.getField() == null) { + meta.setField(Strings.firstUpper(tableField.getPropertyName())); + } + meta.setKeyField(meta.getField() + "Key"); + // 设置注释 + if (meta.getComment() == null) { + meta.setComment(Strings.def(tableField.getComment(), meta.getField())); + } + // 设置额外参数 schema + if (meta.getExtraValues().size() > 0) { + List> extraSchema = meta.getExtraValues().get(0) + .keySet() + .stream() + .map(s -> { + Map res = new LinkedHashMap<>(); + res.put(FieldConst.NAME, s); + res.put(FieldConst.TYPE, "STRING"); + return res; + }).collect(Collectors.toList()); + meta.setExtraSchema(JSON.toJSONString(extraSchema)); + } else { + meta.setExtraSchema(Const.EMPTY_ARRAY); + } + // 设置额外参数 json + List extraJson = meta.getExtraValues() + .stream() + .map(JSON::toJSONString) + .collect(Collectors.toList()); + meta.setExtraJson(extraJson); + + dictMap.put(tableField.getPropertyName(), meta); + } + return dictMap; + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/EnumMeta.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/EnumMeta.java deleted file mode 100644 index 62247007..00000000 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/core/EnumMeta.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.orion.ops.framework.mybatis.core.generator.core; - -import com.orion.lang.define.collect.MultiLinkedHashMap; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * vue 枚举 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/9/26 16:50 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class EnumMeta { - - /** - * 类名称 - */ - private String className; - - /** - * 备注 - */ - private String comment; - - /** - * 配置 - */ - private MultiLinkedHashMap info; - -} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictMeta.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictMeta.java new file mode 100644 index 00000000..f47a0a0f --- /dev/null +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictMeta.java @@ -0,0 +1,91 @@ +package com.orion.ops.framework.mybatis.core.generator.template; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 字典元数据 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/26 13:53 + */ +@Data +public class DictMeta { + + /** + * 字典配置名称 + */ + protected String keyName; + + /** + * 替换的字段 数据库/小驼峰 + */ + protected String variable; + + /** + * 字段名称 如果为空使用 Strings.firstUpper(field.propertyName) + */ + protected String field; + + /** + * key 字段名称 + */ + private String keyField; + + /** + * 注释 如果为空使用 field.comment || field + */ + protected String comment; + + /** + * 字段 + */ + protected List fields; + + /** + * label + */ + protected List labels; + + /** + * value + */ + protected List values; + + /** + * 额外参数 + */ + protected List> extraValues; + + /** + * 额外参数 schema + */ + private String extraSchema; + + /** + * 额外参数 json + */ + private List extraJson; + + public DictMeta() { + } + + public DictMeta(String keyName, String variable) { + this(keyName, variable, null); + } + + public DictMeta(String keyName, String variable, String field) { + this.keyName = keyName; + this.variable = variable; + this.field = field; + this.fields = new ArrayList<>(); + this.labels = new ArrayList<>(); + this.values = new ArrayList<>(); + this.extraValues = new ArrayList<>(); + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java new file mode 100644 index 00000000..8ccd03b9 --- /dev/null +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java @@ -0,0 +1,175 @@ +package com.orion.ops.framework.mybatis.core.generator.template; + +import com.orion.lang.utils.collect.Lists; +import com.orion.ops.framework.common.constant.Const; + +import java.util.LinkedHashMap; + +/** + * 字典配置模板 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/26 1:14 + */ +public class DictTemplate extends Template { + + private final DictMeta dictMeta; + + public DictTemplate(Table table, String keyName, String variable) { + this(table, keyName, variable, null); + } + + public DictTemplate(Table table, String keyName, String variable, String field) { + super(table); + this.dictMeta = new DictMeta(keyName, variable, field); + table.dictList.add(dictMeta); + } + + /** + * 设置字典配置名称 + * + * @param keyName keyName + * @return this + */ + public DictTemplate keyName(String keyName) { + dictMeta.keyName = keyName; + return this; + } + + /** + * 设置字段名称 + * + * @param field field + * @return this + */ + public DictTemplate field(String field) { + dictMeta.field = field; + return this; + } + + /** + * 设置注释 + * + * @param comment comment + * @return this + */ + public DictTemplate comment(String comment) { + dictMeta.comment = comment; + return this; + } + + /** + * 设置字段 + * + * @param fields fields + * @return this + */ + public DictTemplate fields(String... fields) { + dictMeta.fields.addAll(Lists.of(fields)); + return this; + } + + /** + * 设置 label + * + * @param labels labels + * @return this + */ + public DictTemplate labels(String... labels) { + dictMeta.labels.addAll(Lists.of(labels)); + return this; + } + + /** + * 设置 value + * + * @param values values + * @return this + */ + public DictTemplate values(Object... values) { + dictMeta.values.addAll(Lists.of(values)); + return this; + } + + /** + * 设置 value 使用 fields + * + * @return this + */ + public DictTemplate valueUseFields() { + dictMeta.values.addAll(dictMeta.fields); + return this; + } + + /** + * 添加 status + * + * @param status status + * @return this + */ + public DictTemplate status(Object... status) { + return this.extra(Const.STATUS, status); + } + + /** + * 添加 type + * + * @param type type + * @return this + */ + public DictTemplate type(Object... type) { + return this.extra(Const.TYPE, type); + } + + /** + * 添加 color + * + * @param colors colors + * @return this + */ + public DictTemplate color(Object... colors) { + return this.extra(Const.COLOR, colors); + } + + /** + * 添加额外值 + * + * @param key key + * @param values values + * @return this + */ + public DictTemplate extra(String key, Object... values) { + // 初始化额外值 + if (dictMeta.extraValues.size() == 0) { + for (int i = 0; i < dictMeta.fields.size(); i++) { + dictMeta.extraValues.add(new LinkedHashMap<>()); + } + } + // 设置额外值 + for (int i = 0; i < dictMeta.extraValues.size(); i++) { + Object value = this.safeGet(i, values); + dictMeta.extraValues.get(i).put(key, value); + } + return this; + } + + /** + * 获取值 + * + * @param index index + * @param list list + * @return value + */ + private Object safeGet(int index, Object... list) { + if (list == null) { + return null; + } + if (list.length > index) { + return list[index]; + } else { + return null; + } + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/EnumsTemplate.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/EnumsTemplate.java deleted file mode 100644 index fffe32de..00000000 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/EnumsTemplate.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.orion.ops.framework.mybatis.core.generator.template; - -import com.orion.lang.utils.Enums; -import com.orion.lang.utils.collect.Lists; -import com.orion.lang.utils.reflect.Fields; -import com.orion.ops.framework.common.constant.Const; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * 前端代码枚举模板 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/9/26 1:14 - */ -public class EnumsTemplate extends VueTemplate { - - private final VueEnum vueEnum; - - public EnumsTemplate(Table table, String variable) { - this(table, variable, (String) null); - } - - public EnumsTemplate(Table table, String variable, String className) { - super(table); - this.vueEnum = new VueEnum(variable, className); - table.enums.add(vueEnum); - } - - public EnumsTemplate(Table table, String variable, Class> enumClass) { - super(table); - this.vueEnum = new VueEnum(variable); - table.enums.add(vueEnum); - this.parseEnumMeta(enumClass); - } - - /** - * 解析枚举 - * - * @param enumClass enumClass - */ - private void parseEnumMeta(Class> enumClass) { - // 获取枚举 - List> enumList = Lists.of(enumClass.getEnumConstants()); - // 枚举名称 - List names = enumList.stream() - .map(Enum::name) - .collect(Collectors.toList()); - // 枚举字段 - List fields = Enums.getFields(enumClass); - // 枚举值 - List> values = fields.stream() - .map(field -> enumList.stream() - .map(enumItem -> Fields.getFieldValue(enumItem, field)) - .collect(Collectors.toList())) - .collect(Collectors.toList()); - vueEnum.className = enumClass.getSimpleName(); - vueEnum.names.addAll(names); - vueEnum.fields.addAll(fields); - vueEnum.values.addAll(values); - } - - /** - * 设置类名 - * - * @param className className - * @return this - */ - public EnumsTemplate className(String className) { - vueEnum.className = className; - return this; - } - - /** - * 设置注释 - * - * @param comment comment - * @return this - */ - public EnumsTemplate comment(String comment) { - vueEnum.comment = comment; - return this; - } - - /** - * 设置枚举名称 - * - * @param names names - * @return this - */ - public EnumsTemplate names(String... names) { - vueEnum.names.addAll(Lists.of(names)); - return this; - } - - /** - * 设置字段值 - * - * @param values values - * @return this - */ - public EnumsTemplate values(String field, Object... values) { - vueEnum.fields.add(field); - vueEnum.values.add(Lists.of(values)); - return this; - } - - /** - * 添加 label - * - * @param labels labels - * @return this - */ - public EnumsTemplate label(Object... labels) { - return this.values(Const.LABEL, labels); - } - - /** - * 添加 value - * 如果 value 和 name 相同可以省略 (无 value 自动使用 name) - * - * @param values values - * @return this - */ - public EnumsTemplate value(Object... values) { - return this.values(Const.VALUE, values); - } - - /** - * 添加 color - * - * @param colors colors - * @return this - */ - public EnumsTemplate color(Object... colors) { - return this.values(Const.COLOR, colors); - } - - /** - * 添加 status - * - * @param status status - * @return this - */ - public EnumsTemplate status(Object... status) { - return this.values(Const.STATUS, status); - } - -} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Table.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Table.java index 35d66f90..9b790e05 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Table.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Table.java @@ -116,12 +116,12 @@ public class Table { protected boolean enableCardView; /** - * 生成的枚举文件 + * 生成的字典数据 */ - protected List enums; + protected List dictList; protected Table() { - this.enums = new ArrayList<>(); + this.dictList = new ArrayList<>(); } } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Template.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Template.java index f633b99a..da62ccfe 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Template.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/Template.java @@ -69,6 +69,29 @@ public class Template { return new VueTemplate(table, module, feature); } + /** + * 设置字典 + * + * @param keyName 字典配置名称 + * @param variable 替换字段 数据库/小驼峰 + * @return dict + */ + public DictTemplate dict(String keyName, String variable) { + return new DictTemplate(table, keyName, variable); + } + + /** + * 设置字典 + * + * @param keyName 字典配置名称 + * @param variable 替换字段 数据库/小驼峰 + * @param className 字段名称 + * @return dict + */ + public DictTemplate dict(String keyName, String variable, String className) { + return new DictTemplate(table, keyName, variable, className); + } + /** * 构建 * diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueEnum.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueEnum.java deleted file mode 100644 index 06204460..00000000 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueEnum.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.orion.ops.framework.mybatis.core.generator.template; - -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * 枚举元数据 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/9/26 13:53 - */ -@Data -public class VueEnum { - - /** - * 替换的枚举字段 数据库/小驼峰 - */ - protected String variable; - - /** - * 枚举类名 如果为空使用 field.propertyName + Enum - */ - protected String className; - - /** - * 枚举注释 如果为空使用 field.comment || className - */ - protected String comment; - - /** - * 枚举名称 - */ - protected List names; - - /** - * 枚举字段 - */ - protected List fields; - - /** - * 枚举值 - */ - protected List> values; - - public VueEnum(String variable) { - this(variable, null); - } - - public VueEnum(String variable, String className) { - this.className = className; - this.variable = variable; - this.names = new ArrayList<>(); - this.fields = new ArrayList<>(); - this.values = new ArrayList<>(); - } - - public VueEnum(String variable, String className, String comment, List names, List fields, List> values) { - this.variable = variable; - this.className = className; - this.comment = comment; - this.names = names; - this.fields = fields; - this.values = values; - } - -} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueTemplate.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueTemplate.java index cc40481a..981322c5 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueTemplate.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/VueTemplate.java @@ -73,36 +73,4 @@ public class VueTemplate extends Template { return this; } - /** - * 设置枚举 - * - * @param variable 枚举字段 数据库/小驼峰 - * @return enums - */ - public EnumsTemplate enums(String variable) { - return new EnumsTemplate(table, variable); - } - - /** - * 设置枚举 - * - * @param variable 枚举字段 数据库/小驼峰 - * @param className className - * @return enums - */ - public EnumsTemplate enums(String variable, String className) { - return new EnumsTemplate(table, variable, className); - } - - /** - * 设置枚举 - * - * @param variable 枚举字段 数据库/小驼峰 - * @param enumClass 枚举类 - * @return enums - */ - public EnumsTemplate enums(String variable, Class> enumClass) { - return new EnumsTemplate(table, variable, enumClass); - } - } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm index cc2c6305..39f87bee 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-dict.sql.vm @@ -1,30 +1,49 @@ --- 执行完成后 需要在菜单页面刷新缓存 +-- 执行完成后 需要在字典配置项页面刷新缓存 +#if($meta.enableOperatorLog) --- 父菜单 -INSERT INTO system_menu - (parent_id, name, type, sort, visible, status, cache, component) +-- 模块 key id +SELECT @MODULE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogModule' AND deleted = 0; +-- 模块 key 排序 +SELECT @MODULE_KEY_MAX_SORT:= IFNULL(MAX(sort), 0) FROM dict_value where key_id = @MODULE_KEY_ID AND deleted = 0; +-- 类型 key id +SELECT @TYPE_KEY_ID:= id FROM dict_key WHERE key_name = 'operatorLogType' AND deleted = 0; +-- 类型 key 排序 +SELECT @TYPE_KEY_MAX_SORT:= IFNULL(MAX(sort), 0) FROM dict_value WHERE key_id = @TYPE_KEY_ID AND deleted = 0; +-- 插入类型 +INSERT INTO dict_value + (`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES - (0, '${table.comment}管理', 1, 10, 1, 1, 1, '$vue.moduleEntityFirstLower'); + (@MODULE_KEY_ID, 'operatorLogModule', '${package.ModuleName}:${typeHyphen}', '$!{table.comment}', '{}', @MODULE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0), + (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:create', '创建$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 10, now(), now(), '1', '1', 0), + (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:update', '更新$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 20, now(), now(), '1', '1', 0), + #if($meta.enableExport) + (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 30, now(), now(), '1', '1', 0), + (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:export', '导出$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 40, now(), now(), '1', '1', 0); + #else + (@TYPE_KEY_ID, 'operatorLogType', '${typeHyphen}:delete', '删除$!{table.comment}', '{}', @TYPE_KEY_MAX_SORT + 30, now(), now(), '1', '1', 0); + #end +#end --- 设置临时父菜单id -SELECT @TMP_PARENT_ID:=LAST_INSERT_ID(); - --- 子菜单 -INSERT INTO system_menu - (parent_id, name, type, sort, visible, status, cache, component) +#if($dictMap.entrySet().size() > 0) +#foreach($enumEntity in $dictMap.entrySet()) +-- 插入字典配置项 FIXME 检查这里的类型 +INSERT INTO dict_key + (`key_name`, `value_type`, `extra_schema`, `description`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES - (@TMP_PARENT_ID, '$table.comment', 2, 10, 1, 1, 1, '$vue.moduleEntityFirstLower$vue.featureEntity'); + ('$enumEntity.value.keyName', 'STRING', '$enumEntity.value.extraSchema', '$enumEntity.value.comment', now(), now(), '1', '1', 0); --- 设置临时子菜单id -SELECT @TMP_SUB_ID:=LAST_INSERT_ID(); +-- 设置临时配置项id +SELECT @TMP_KEY_ID:=LAST_INSERT_ID(); --- 功能 -INSERT INTO system_menu - (parent_id, name, permission, type, sort) +-- 插入字典配置值 FIXME 检查这里的类型 +INSERT INTO dict_value + (`key_id`, `key_name`, `value`, `label`, `extra`, `sort`, `create_time`, `update_time`, `creator`, `updater`, `deleted`) VALUES - (@TMP_SUB_ID, '查询$table.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10), - (@TMP_SUB_ID, '创建$table.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20), - (@TMP_SUB_ID, '修改$table.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30), - (@TMP_SUB_ID, '删除$table.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40), - (@TMP_SUB_ID, '导出$table.comment', '${package.ModuleName}:${typeHyphen}:export', 3, 50), - (@TMP_SUB_ID, '导入$table.comment', '${package.ModuleName}:${typeHyphen}:import', 3, 60); +#set($count = $enumEntity.value.fields.size() - 1) +#foreach($index in [0..$count]) +#set($sort = $index * 10 + 10) + (@TMP_KEY_ID, '$enumEntity.value.keyName', '$enumEntity.value.values.get($index)', '$enumEntity.value.labels.get($index)', '$enumEntity.value.extraJson.get($index)', $sort, now(), now(), '1', '1', 0)#if($foreach.hasNext),#else;#end +#end + +#end +#end \ No newline at end of file diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm index cc2c6305..91bd15d3 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-sql-menu.sql.vm @@ -1,4 +1,4 @@ --- 执行完成后 需要在菜单页面刷新缓存 +-- 执行完成后 需要在系统菜单页面刷新缓存 -- 父菜单 INSERT INTO system_menu diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-card-list.vue.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-card-list.vue.vm index be261522..5609852d 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-card-list.vue.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-card-list.vue.vm @@ -1,6 +1,6 @@ @@ -112,15 +120,16 @@ import useLoading from '@/hooks/loading'; import { objectTruthKeyCount, resetObject } from '@/utils'; import fieldConfig from '../types/card.fields'; + #if($dictMap.entrySet().size() > 0) + import { #foreach($entry in ${dictMap.entrySet()})${entry.value.keyField}#if($foreach.hasNext), #end#end } from '../types/const'; + #else + import {} from '../types/const'; + #end import { delete${vue.featureEntity}, get${vue.featureEntity}Page } from '@/api/${vue.module}/${vue.feature}'; import { Message, Modal } from '@arco-design/web-vue'; - import {} from '../types/const'; - #if($vue.enums.isEmpty()) - import {} from '../types/enum.types'; - #else - import { #foreach($entry in ${vue.enums.entrySet()})${entry.value.className}#if($foreach.hasNext), #end#end } from '../types/enum.types'; + #if($dictMap.entrySet().size() > 0) + import { useDictStore } from '@/store'; #end - import { toOptions, getEnumValue } from '@/utils/enum'; const emits = defineEmits(['openAdd', 'openUpdate']); @@ -129,6 +138,9 @@ const cardColLayout = useColLayout(); const pagination = usePagination(); const { loading, setLoading } = useLoading(); + #if($dictMap.entrySet().size() > 0) + const { toOptions, getDictValue } = useDictStore(); + #end const formRef = ref(); const formModel = reactive<${vue.featureEntity}QueryRequest>({ diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm index e085280f..af036585 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-drawer.vue.vm @@ -20,10 +20,10 @@ #if("$field.propertyName" != "id") - #if(${vue.enums.containsKey(${field.propertyName})}) + #if(${dictMap.containsKey(${field.propertyName})}) + :options="toOptions($dictMap.get(${field.propertyName}).keyField)" + placeholder="请选择${field.comment}" /> #else #if("$field.propertyType" == "Integer" || "$field.propertyType" == "Long") 0) + import { #foreach($entry in ${dictMap.entrySet()})${entry.value.keyField}#if($foreach.hasNext), #end#end } from '../types/const'; + #else + import {} from '../types/const'; + #end import { create${vue.featureEntity}, update${vue.featureEntity} } from '@/api/${vue.module}/${vue.feature}'; import { Message } from '@arco-design/web-vue'; - import {} from '../types/const'; - #if($vue.enums.isEmpty()) - import {} from '../types/enum.types'; - #else - import { #foreach($entry in ${vue.enums.entrySet()})${entry.value.className}#if($foreach.hasNext), #end#end } from '../types/enum.types'; + #if($dictMap.entrySet().size() > 0) + import { useDictStore } from '@/store'; #end - import { toOptions } from '@/utils/enum'; const { visible, setVisible } = useVisible(); const { loading, setLoading } = useLoading(); + #if($dictMap.entrySet().size() > 0) + const { toOptions } = useDictStore(); + #end const title = ref(); const isAddHandle = ref(true); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm index bdfdd33c..60f2e3ce 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm @@ -24,9 +24,9 @@ #if("$field.propertyName" != "id") - #if(${vue.enums.containsKey(${field.propertyName})}) + #if(${dictMap.containsKey(${field.propertyName})}) #else #if("$field.propertyType" == "Integer" || "$field.propertyType" == "Long") @@ -62,18 +62,22 @@ import useLoading from '@/hooks/loading'; import useVisible from '@/hooks/visible'; import formRules from '../types/form.rules'; + #if($dictMap.entrySet().size() > 0) + import { #foreach($entry in ${dictMap.entrySet()})${entry.value.keyField}#if($foreach.hasNext), #end#end } from '../types/const'; + #else + import {} from '../types/const'; + #end import { create${vue.featureEntity}, update${vue.featureEntity} } from '@/api/${vue.module}/${vue.feature}'; import { Message } from '@arco-design/web-vue'; - import {} from '../types/const'; - #if($vue.enums.isEmpty()) - import {} from '../types/enum.types'; - #else - import { #foreach($entry in ${vue.enums.entrySet()})${entry.value.className}#if($foreach.hasNext), #end#end } from '../types/enum.types'; + #if($dictMap.entrySet().size() > 0) + import { useDictStore } from '@/store'; #end - import { toOptions } from '@/utils/enum'; const { visible, setVisible } = useVisible(); const { loading, setLoading } = useLoading(); + #if($dictMap.entrySet().size() > 0) + const { toOptions } = useDictStore(); + #end const title = ref(); const isAddHandle = ref(true); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-table.vue.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-table.vue.vm index fdd33a90..1103c6dc 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-table.vue.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-components-table.vue.vm @@ -9,9 +9,9 @@ #foreach($field in ${table.fields}) - #if(${vue.enums.containsKey(${field.propertyName})}) + #if(${dictMap.containsKey(${field.propertyName})}) #else @@ -93,10 +93,10 @@ @page-size-change="(size) => fetchTableData(1, size)" :bordered="false"> #foreach($field in ${table.fields}) - #if(${vue.enums.containsKey(${field.propertyName})}) + #if(${dictMap.containsKey(${field.propertyName})}) #end #end @@ -141,18 +141,19 @@ import { Message } from '@arco-design/web-vue'; import useLoading from '@/hooks/loading'; import columns from '../types/table.columns'; + #if($dictMap.entrySet().size() > 0) + import { #foreach($entry in ${dictMap.entrySet()})${entry.value.keyField}#if($foreach.hasNext), #end#end } from '../types/const'; + #else + import {} from '../types/const'; + #end #if($vue.enableRowSelection) import { usePagination, useRowSelection } from '@/types/table'; #else import { usePagination } from '@/types/table'; #end - import {} from '../types/const'; - #if($vue.enums.isEmpty()) - import {} from '../types/enum.types'; - #else - import { #foreach($entry in ${vue.enums.entrySet()})${entry.value.className}#if($foreach.hasNext), #end#end } from '../types/enum.types'; + #if($dictMap.entrySet().size() > 0) + import { useDictStore } from '@/store'; #end - import { toOptions, getEnumValue } from '@/utils/enum'; const emits = defineEmits(['openAdd', 'openUpdate']); @@ -166,6 +167,9 @@ const rowSelection = useRowSelection(); #end const { loading, setLoading } = useLoading(); + #if($dictMap.entrySet().size() > 0) + const { toOptions, getDictValue } = useDictStore(); + #end const formModel = reactive<${vue.featureEntity}QueryRequest>({ #foreach($field in ${table.fields}) diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-index.vue.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-index.vue.vm index 4698c8af..6db22603 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-index.vue.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-index.vue.vm @@ -47,12 +47,20 @@ #else import ${vue.featureEntity}FormModal from './components/${vue.feature}-form-modal.vue'; #end - #if($vue.enableCardView) import { computed, ref, onBeforeMount } from 'vue'; + #if($dictMap.entrySet().size() > 0) + import { useAppStore, useDictStore } from '@/store'; + import { dictKeys } from './types/const'; + #else import { useAppStore } from '@/store'; + #end #else import { ref } from 'vue'; + #if($dictMap.entrySet().size() > 0) + import { useDictStore } from '@/store'; + import { dictKeys } from './types/const'; + #end #end const render = ref(false); @@ -68,7 +76,7 @@ #if($vue.enableCardView) const appStore = useAppStore(); - // FIXME 这里需要修改一下字段名称 + // FIXME 这里需要修改一下字段名称 同时 appStore 的类型和 AppPreferenceModel 都需要定义该字段类型 const renderTable = computed(() => appStore.${vue.featureEntityFirstLower}View === 'table'); #end @@ -99,6 +107,10 @@ }; onBeforeMount(async () => { + #if($dictMap.entrySet().size() > 0) + const dictStore = useDictStore(); + await dictStore.loadKeys(dictKeys); + #end render.value = true; }); diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-const.ts.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-const.ts.vm index e69de29b..ab8d847b 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-const.ts.vm +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-const.ts.vm @@ -0,0 +1,23 @@ +#if($dictMap.entrySet().size() > 0) +#foreach($enumEntity in $dictMap.entrySet()) +/** + * $enumEntity.value.comment + */ +// FIXME 检查这里的类型 +export const $enumEntity.value.field = { +#set($count = $enumEntity.value.fields.size() - 1) +#foreach($index in [0..$count]) + // $enumEntity.value.labels.get($index) + $enumEntity.value.fields.get($index): '$enumEntity.value.values.get($index)', +#end +} + +#end +#foreach($enumEntity in $dictMap.entrySet()) +// $enumEntity.value.comment 字典项 +export const $enumEntity.value.keyField = '$enumEntity.value.keyName'; + +#end +// 加载的字典值 +export const dictKeys = [#foreach($enumEntity in $dictMap.entrySet())${enumEntity.value.field}Key#if($foreach.hasNext), #end#end]; +#end diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm deleted file mode 100644 index 9385e630..00000000 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm +++ /dev/null @@ -1,15 +0,0 @@ -#foreach($enumEntity in ${vue.enums.entrySet()}) -/** - * $!{enumEntity.value.comment} - */ -export const $enumEntity.value.className = { -#foreach($enumEntityItem in $enumEntity.value.info.entrySet()) - $enumEntityItem.key: { - #foreach($enumEntityItemFields in $enumEntityItem.value.entrySet()) - $enumEntityItemFields.key: '$!enumEntityItemFields.value', - #end - }, -#end -} - -#end \ No newline at end of file diff --git a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-card-list.vue b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-card-list.vue index 3014743a..4803ab27 100644 --- a/orion-ops-ui/src/views/asset/host-identity/components/host-identity-card-list.vue +++ b/orion-ops-ui/src/views/asset/host-identity/components/host-identity-card-list.vue @@ -13,6 +13,38 @@ @reset="reset" @search="fetchCardData" @page-change="fetchCardData"> + + - - diff --git a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue index 2c325d22..b5f6e1e7 100644 --- a/orion-ops-ui/src/views/asset/host/components/host-card-list.vue +++ b/orion-ops-ui/src/views/asset/host/components/host-card-list.vue @@ -13,6 +13,47 @@ @reset="reset" @search="fetchCardData" @page-change="fetchCardData"> + + - -