修改代码生成器包.
This commit is contained in:
@@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
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.lang.utils.ext.yml.YmlExt;
|
||||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
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 org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -36,13 +38,15 @@ public class CodeGenerator {
|
|||||||
String author = Const.ORION_AUTHOR;
|
String author = Const.ORION_AUTHOR;
|
||||||
// 模块
|
// 模块
|
||||||
String module = "infra";
|
String module = "infra";
|
||||||
// 生成的表 表 - 业务注释 - request文件的包前缀
|
// 生成的表
|
||||||
GenTable[] tables = {
|
GenTable[] tables = {
|
||||||
new GenTable("system_user", "用户", "user"),
|
new GenTable("system_user", "用户", "user")
|
||||||
new GenTable("system_role", "角色", "role"),
|
.vue("user/user", "user", "user")
|
||||||
new GenTable("system_user_role", "用户角色关联", "role"),
|
.enums(UserStatusEnum.class),
|
||||||
|
new GenTable("system_role", "角色", "role")
|
||||||
|
.vue("user/role", "user", "role")
|
||||||
|
.enums(RoleStatusEnum.class),
|
||||||
new GenTable("system_menu", "菜单", "menu"),
|
new GenTable("system_menu", "菜单", "menu"),
|
||||||
new GenTable("system_role_menu", "角色菜单关联", "menu")
|
|
||||||
};
|
};
|
||||||
// jdbc 配置 - 使用配置文件
|
// jdbc 配置 - 使用配置文件
|
||||||
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
||||||
@@ -275,12 +279,12 @@ public class CodeGenerator {
|
|||||||
*/
|
*/
|
||||||
private static TemplateConfig getTemplateConfig() {
|
private static TemplateConfig getTemplateConfig() {
|
||||||
TemplateConfig tplConfig = new TemplateConfig.Builder()
|
TemplateConfig tplConfig = new TemplateConfig.Builder()
|
||||||
.controller("/templates/orion-controller.java.vm")
|
.controller("/templates/orion-server-controller.java.vm")
|
||||||
.entity("/templates/orion-entity-do.java.vm")
|
.entity("/templates/orion-server-entity-do.java.vm")
|
||||||
.service("/templates/orion-service.java.vm")
|
.service("/templates/orion-server-service.java.vm")
|
||||||
.serviceImpl("/templates/orion-service-impl.java.vm")
|
.serviceImpl("/templates/orion-server-service-impl.java.vm")
|
||||||
.mapper("/templates/orion-mapper.java.vm")
|
.mapper("/templates/orion-server-mapper.java.vm")
|
||||||
.xml("/templates/orion-mapper.xml.vm")
|
.xml("/templates/orion-server-mapper.xml.vm")
|
||||||
.build();
|
.build();
|
||||||
return tplConfig;
|
return tplConfig;
|
||||||
}
|
}
|
||||||
@@ -293,21 +297,35 @@ public class CodeGenerator {
|
|||||||
private static InjectionConfig getInjectionConfig() {
|
private static InjectionConfig getInjectionConfig() {
|
||||||
String[][] customFileDefineArr = new String[][]{
|
String[][] customFileDefineArr = new String[][]{
|
||||||
// http 文件
|
// http 文件
|
||||||
new String[]{"/templates/orion-controller.http.vm", "%sController.http", "controller"},
|
new String[]{"/templates/orion-server-controller.http.vm", "%sController.http", "controller"},
|
||||||
// vo 文件
|
// 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 文件
|
// 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 文件
|
// 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 文件
|
// 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 文件
|
// 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 文件
|
// convert 文件
|
||||||
new String[]{"/templates/orion-convert.java.vm", "%sConvert.java", "convert"},
|
new String[]{"/templates/orion-server-convert.java.vm", "%sConvert.java", "convert"},
|
||||||
// convert provider 文件
|
// 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"},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 构建文件
|
// 构建文件
|
||||||
@@ -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<Class<? extends Enum<?>>> 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<? extends Enum<?>>... enums) {
|
||||||
|
this.enums.addAll(Lists.of(enums));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,10 +13,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.ConstVal;
|
import com.baomidou.mybatisplus.generator.config.ConstVal;
|
||||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
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.config.po.TableInfo;
|
||||||
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||||
import com.orion.lang.utils.Strings;
|
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.lang.utils.reflect.Fields;
|
||||||
import com.orion.ops.framework.common.constant.OrionOpsProConst;
|
import com.orion.ops.framework.common.constant.OrionOpsProConst;
|
||||||
import org.apache.velocity.Template;
|
import org.apache.velocity.Template;
|
||||||
@@ -203,8 +204,30 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
// 添加注释元数据
|
// 添加注释元数据
|
||||||
this.addApiCommentMeta(tableInfo, objectMap);
|
this.addApiCommentMeta(tableInfo, objectMap);
|
||||||
|
|
||||||
// 生成文件
|
// 生成后端文件
|
||||||
|
List<CustomFile> serverFiles = customFiles.stream()
|
||||||
|
.filter(s -> !this.isVueFile(s.getTemplatePath()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
this.generatorServerFile(serverFiles, tableInfo, objectMap);
|
||||||
|
// 生成前端文件
|
||||||
|
if (tables.get(tableInfo.getName()).isGenVue()) {
|
||||||
|
List<CustomFile> 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<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||||
String parentPath = getPathInfo(OutputFile.parent);
|
String parentPath = getPathInfo(OutputFile.parent);
|
||||||
|
// 生成文件
|
||||||
customFiles.forEach(file -> {
|
customFiles.forEach(file -> {
|
||||||
// 获取 parent package
|
// 获取 parent package
|
||||||
String currentPackage = getConfigBuilder().getPackageConfig().getParent() + "." + file.getPackageName();
|
String currentPackage = getConfigBuilder().getPackageConfig().getParent() + "." + file.getPackageName();
|
||||||
@@ -212,14 +235,45 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
|||||||
objectMap.put("currentPackage", currentPackage);
|
objectMap.put("currentPackage", currentPackage);
|
||||||
|
|
||||||
// 文件路径
|
// 文件路径
|
||||||
String filePath = StringUtils.isNotBlank(file.getFilePath()) ? file.getFilePath() : parentPath;
|
String filePath = parentPath + File.separator + file.getPackageName()
|
||||||
if (StringUtils.isNotBlank(file.getPackageName())) {
|
.replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
|
||||||
filePath = filePath + File.separator + file.getPackageName();
|
|
||||||
filePath = filePath.replaceAll("\\.", StringPool.BACK_SLASH + File.separator);
|
|
||||||
}
|
|
||||||
String fileName = filePath + File.separator + String.format(file.getFileName(), objectMap.get("type"));
|
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<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> 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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
api
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
form
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
table
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
index
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
e.types.ts
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
orion-vue-views-types-form.rules.ts
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
orion-vue-views-types-table.columns.ts.vm
|
||||||
Reference in New Issue
Block a user