diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/GenTable.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/GenTable.java deleted file mode 100644 index cb0dc725..00000000 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/GenTable.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.orion.ops.framework.mybatis.core.generator; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/7/17 10:44 - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class GenTable { - - /** - * 表名称 - */ - private String tableName; - - /** - * 注释 - */ - private String comment; - - /** - * 请求实体包名 - */ - private String requestPackage; - -} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerator.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java similarity index 77% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerator.java rename to orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java index c0b864bf..ab326942 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerator.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java @@ -1,4 +1,4 @@ -package com.orion.ops.framework.mybatis.core.generator; +package com.orion.ops.launch.generator; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.generator.AutoGenerator; @@ -12,6 +12,8 @@ import com.orion.lang.constant.Const; import com.orion.lang.utils.ext.yml.YmlExt; import com.orion.ops.framework.mybatis.core.domain.BaseDO; import com.orion.ops.framework.mybatis.core.mapper.IMapper; +import com.orion.ops.module.infra.enums.RoleStatusEnum; +import com.orion.ops.module.infra.enums.UserStatusEnum; import org.apache.ibatis.annotations.Mapper; import java.io.File; @@ -36,13 +38,15 @@ public class CodeGenerator { String author = Const.ORION_AUTHOR; // 模块 String module = "infra"; - // 生成的表 表 - 业务注释 - request文件的包前缀 + // 生成的表 GenTable[] tables = { - new GenTable("system_user", "用户", "user"), - new GenTable("system_role", "角色", "role"), - new GenTable("system_user_role", "用户角色关联", "role"), + new GenTable("system_user", "用户", "user") + .vue("user/user", "user", "user") + .enums(UserStatusEnum.class), + new GenTable("system_role", "角色", "role") + .vue("user/role", "user", "role") + .enums(RoleStatusEnum.class), new GenTable("system_menu", "菜单", "menu"), - new GenTable("system_role_menu", "角色菜单关联", "menu") }; // jdbc 配置 - 使用配置文件 File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml"); @@ -275,12 +279,12 @@ public class CodeGenerator { */ private static TemplateConfig getTemplateConfig() { TemplateConfig tplConfig = new TemplateConfig.Builder() - .controller("/templates/orion-controller.java.vm") - .entity("/templates/orion-entity-do.java.vm") - .service("/templates/orion-service.java.vm") - .serviceImpl("/templates/orion-service-impl.java.vm") - .mapper("/templates/orion-mapper.java.vm") - .xml("/templates/orion-mapper.xml.vm") + .controller("/templates/orion-server-controller.java.vm") + .entity("/templates/orion-server-entity-do.java.vm") + .service("/templates/orion-server-service.java.vm") + .serviceImpl("/templates/orion-server-service-impl.java.vm") + .mapper("/templates/orion-server-mapper.java.vm") + .xml("/templates/orion-server-mapper.xml.vm") .build(); return tplConfig; } @@ -293,21 +297,35 @@ public class CodeGenerator { private static InjectionConfig getInjectionConfig() { String[][] customFileDefineArr = new String[][]{ // http 文件 - new String[]{"/templates/orion-controller.http.vm", "%sController.http", "controller"}, + new String[]{"/templates/orion-server-controller.http.vm", "%sController.http", "controller"}, // vo 文件 - new String[]{"/templates/orion-entity-vo.java.vm", "%sVO.java", "entity.vo"}, + new String[]{"/templates/orion-server-entity-vo.java.vm", "%sVO.java", "entity.vo"}, // dto 文件 - new String[]{"/templates/orion-entity-dto.java.vm", "%sDTO.java", "entity.dto"}, + new String[]{"/templates/orion-server-entity-dto.java.vm", "%sDTO.java", "entity.dto"}, // create request 文件 - new String[]{"/templates/orion-entity-request-create.java.vm", "%sCreateRequest.java", "entity.request.%s"}, + new String[]{"/templates/orion-server-entity-request-create.java.vm", "%sCreateRequest.java", "entity.request.%s"}, // update request 文件 - new String[]{"/templates/orion-entity-request-update.java.vm", "%sUpdateRequest.java", "entity.request.%s"}, + new String[]{"/templates/orion-server-entity-request-update.java.vm", "%sUpdateRequest.java", "entity.request.%s"}, // query request 文件 - new String[]{"/templates/orion-entity-request-query.java.vm", "%sQueryRequest.java", "entity.request.%s"}, + new String[]{"/templates/orion-server-entity-request-query.java.vm", "%sQueryRequest.java", "entity.request.%s"}, // convert 文件 - new String[]{"/templates/orion-convert.java.vm", "%sConvert.java", "convert"}, + new String[]{"/templates/orion-server-convert.java.vm", "%sConvert.java", "convert"}, // convert provider 文件 - new String[]{"/templates/orion-convert-provider.java.vm", "%sProviderConvert.java", "convert"}, + new String[]{"/templates/orion-server-convert-provider.java.vm", "%sProviderConvert.java", "convert"}, + // vue api 文件 + new String[]{"/templates/orion-vue-api.ts.vm", "${feature}.ts", "vue/api/${apiPath}"}, + // vue views index.ts 文件 + new String[]{"/templates/orion-vue-views-index.vue.vm", "index.vue", "vue/views/${viewsPath}"}, + // vue form-modal.vue 文件 + new String[]{"/templates/orion-vue-views-components-form-modal.vue.vm", "${feature}-form-modal.vue", "vue/views/${viewsPath}/components"}, + // vue table.vue 文件 + new String[]{"/templates/orion-vue-views-components-table.vue.vm", "${feature}-table.vue", "vue/views/${viewsPath}/components"}, + // vue enum.types.ts 文件 + new String[]{"/templates/orion-vue-views-types-enum.types.ts.vm", "enum.types.ts", "vue/views/${viewsPath}/types"}, + // vue form.rules.ts 文件 + new String[]{"/templates/orion-vue-views-types-form.rules.ts.vm", "form.rules.ts", "vue/views/${viewsPath}/types"}, + // vue table.vue 文件 + new String[]{"/templates/orion-vue-views-types-table.columns.ts.vm", "table.columns.ts", "vue/views/${viewsPath}/types"}, }; // 构建文件 diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/GenTable.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/GenTable.java new file mode 100644 index 00000000..89502d5f --- /dev/null +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/GenTable.java @@ -0,0 +1,96 @@ +package com.orion.ops.launch.generator; + +import com.orion.lang.utils.collect.Lists; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/7/17 10:44 + */ +@Data +public class GenTable { + + // -------------------- 后端 -------------------- + + /** + * 表名称 + */ + private String tableName; + + /** + * 业务注释 + */ + private String comment; + + /** + * 请求实体包名 + */ + private String requestPackage; + + // -------------------- 前端 -------------------- + + /** + * 是否生成 vue 代码 + */ + private boolean genVue; + + /** + * views 父目录 + */ + private String viewsPath; + + /** + * api 文件目录 + */ + private String apiPath; + + /** + * 功能 用于文件名称生成 + */ + private String feature; + + /** + * 生成的枚举文件 + */ + private List>> enums; + + public GenTable(String tableName, String comment, String requestPackage) { + this.tableName = tableName; + this.comment = comment; + this.requestPackage = requestPackage; + this.enums = new ArrayList<>(); + } + + /** + * 生成 vue 模板 + * + * @param viewsPath viewsPath + * @param apiPath apiPath + * @param feature feature + * @return this + */ + public GenTable vue(String viewsPath, String apiPath, String feature) { + this.genVue = true; + this.viewsPath = viewsPath; + this.apiPath = apiPath; + this.feature = feature; + return this; + } + + /** + * 生成 vue 枚举对象 + * + * @param enums enums + * @return enums + */ + @SafeVarargs + public final GenTable enums(Class>... enums) { + this.enums.addAll(Lists.of(enums)); + return this; + } + +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/VelocityTemplateEngine.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java similarity index 77% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/VelocityTemplateEngine.java rename to orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java index 7cf8e6c6..0bfbf193 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/VelocityTemplateEngine.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/VelocityTemplateEngine.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.orion.ops.framework.mybatis.core.generator; +package com.orion.ops.launch.generator; import com.baomidou.mybatisplus.core.toolkit.StringPool; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.generator.config.ConstVal; import com.baomidou.mybatisplus.generator.config.OutputFile; import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder; @@ -24,6 +23,8 @@ import com.baomidou.mybatisplus.generator.config.builder.CustomFile; import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine; import com.orion.lang.utils.Strings; +import com.orion.lang.utils.io.Files1; +import com.orion.lang.utils.reflect.BeanMap; import com.orion.lang.utils.reflect.Fields; import com.orion.ops.framework.common.constant.OrionOpsProConst; import org.apache.velocity.Template; @@ -203,8 +204,30 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine { // 添加注释元数据 this.addApiCommentMeta(tableInfo, objectMap); - // 生成文件 + // 生成后端文件 + List serverFiles = customFiles.stream() + .filter(s -> !this.isVueFile(s.getTemplatePath())) + .collect(Collectors.toList()); + this.generatorServerFile(serverFiles, tableInfo, objectMap); + // 生成前端文件 + if (tables.get(tableInfo.getName()).isGenVue()) { + List vueFiles = customFiles.stream() + .filter(s -> this.isVueFile(s.getTemplatePath())) + .collect(Collectors.toList()); + this.generatorVueFile(vueFiles, tableInfo, objectMap); + } + } + + /** + * 生成后端文件 + * + * @param customFiles customFiles + * @param tableInfo tableInfo + * @param objectMap objectMap + */ + private void generatorServerFile(@NotNull List customFiles, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { String parentPath = getPathInfo(OutputFile.parent); + // 生成文件 customFiles.forEach(file -> { // 获取 parent package String currentPackage = getConfigBuilder().getPackageConfig().getParent() + "." + file.getPackageName(); @@ -212,14 +235,45 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine { objectMap.put("currentPackage", currentPackage); // 文件路径 - String filePath = StringUtils.isNotBlank(file.getFilePath()) ? file.getFilePath() : parentPath; - if (StringUtils.isNotBlank(file.getPackageName())) { - filePath = filePath + File.separator + file.getPackageName(); - filePath = filePath.replaceAll("\\.", StringPool.BACK_SLASH + File.separator); - } + String filePath = parentPath + File.separator + file.getPackageName() + .replaceAll("\\.", StringPool.BACK_SLASH + File.separator); String fileName = filePath + File.separator + String.format(file.getFileName(), objectMap.get("type")); - outputFile(new File(fileName), objectMap, file.getTemplatePath(), file.isFileOverride()); + outputFile(Files1.newFile(fileName), objectMap, file.getTemplatePath(), file.isFileOverride()); }); } + /** + * 生成前端文件 + * + * @param customFiles customFiles + * @param tableInfo tableInfo + * @param objectMap objectMap + */ + private void generatorVueFile(@NotNull List customFiles, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { + String outPath = getConfigBuilder().getGlobalConfig().getOutputDir(); + GenTable table = tables.get(tableInfo.getName()); + BeanMap beanMap = BeanMap.create(table, "enums"); + + // 生成文件 + customFiles.forEach(file -> { + // 文件路径 + String filePath = outPath + + "/" + Strings.format(file.getPackageName(), beanMap) + + "/" + Strings.format(file.getFileName(), beanMap); + // 输出文件 + this.outputFile(Files1.newFile(filePath), objectMap, file.getTemplatePath(), file.isFileOverride()); + }); + } + + /** + * 是否为 vue 文件 + * + * @param templatePath templatePath + * @return 是否为 vue 文件 + */ + private boolean isVueFile(String templatePath) { + return templatePath.endsWith(".ts.vm") || + templatePath.endsWith(".vue.vm"); + } + } diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-controller.http.vm b/orion-ops-launch/src/main/resources/templates/orion-server-controller.http.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-controller.http.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-controller.http.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-controller.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-controller.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-controller.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-controller.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-convert-provider.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-convert-provider.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-convert-provider.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-convert-provider.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-convert.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-convert.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-convert.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-convert.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-do.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-do.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-do.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-do.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-dto.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-dto.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-dto.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-dto.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-create.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-request-create.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-create.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-request-create.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-query.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-request-query.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-query.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-request-query.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-update.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-request-update.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-request-update.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-request-update.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-vo.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-entity-vo.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-entity-vo.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-entity-vo.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-mapper.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-mapper.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-mapper.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-mapper.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-mapper.xml.vm b/orion-ops-launch/src/main/resources/templates/orion-server-mapper.xml.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-mapper.xml.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-mapper.xml.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-service-impl.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-service-impl.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-service-impl.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-service-impl.java.vm diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-service.java.vm b/orion-ops-launch/src/main/resources/templates/orion-server-service.java.vm similarity index 100% rename from orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/resources/templates/orion-service.java.vm rename to orion-ops-launch/src/main/resources/templates/orion-server-service.java.vm diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm new file mode 100644 index 00000000..9e5bfb42 --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-api.ts.vm @@ -0,0 +1 @@ +api \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm new file mode 100644 index 00000000..cc285770 --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-form-modal.vue.vm @@ -0,0 +1 @@ +form \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm new file mode 100644 index 00000000..faea15ea --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-components-table.vue.vm @@ -0,0 +1 @@ +table \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm new file mode 100644 index 00000000..b2d525b2 --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-index.vue.vm @@ -0,0 +1 @@ +index \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm new file mode 100644 index 00000000..197c2a45 --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-enum.types.ts.vm @@ -0,0 +1 @@ +e.types.ts \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-form.rules.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-form.rules.ts.vm new file mode 100644 index 00000000..0480931a --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-form.rules.ts.vm @@ -0,0 +1 @@ +orion-vue-views-types-form.rules.ts \ No newline at end of file diff --git a/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-table.columns.ts.vm b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-table.columns.ts.vm new file mode 100644 index 00000000..776118eb --- /dev/null +++ b/orion-ops-launch/src/main/resources/templates/orion-vue-views-types-table.columns.ts.vm @@ -0,0 +1 @@ +orion-vue-views-types-table.columns.ts.vm \ No newline at end of file