|
@@ -16,31 +16,24 @@
|
|
|
*/
|
|
|
package org.springblade.develop.support;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import com.baomidou.mybatisplus.generator.AutoGenerator;
|
|
|
-import com.baomidou.mybatisplus.generator.InjectionConfig;
|
|
|
-import com.baomidou.mybatisplus.generator.config.*;
|
|
|
-import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
|
|
|
-import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert;
|
|
|
-import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert;
|
|
|
-import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert;
|
|
|
-import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|
|
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
|
|
+import com.baomidou.mybatisplus.generator.config.TemplateType;
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
|
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.ibatis.annotations.Mapper;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
|
-import org.springblade.develop.constant.DevelopConstant;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static org.springblade.develop.constant.DevelopConstant.*;
|
|
|
|
|
|
/**
|
|
|
* 代码生成器配置类
|
|
@@ -51,14 +44,22 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
public class BladeCodeGenerator {
|
|
|
/**
|
|
|
- * 代码所在系统
|
|
|
+ * 代码风格
|
|
|
*/
|
|
|
- private String systemName = DevelopConstant.SWORD_NAME;
|
|
|
+ private String codeStyle = SABER_NAME;
|
|
|
/**
|
|
|
* 代码模块名称
|
|
|
*/
|
|
|
private String codeName;
|
|
|
/**
|
|
|
+ * 模型编号
|
|
|
+ */
|
|
|
+ private String modelCode;
|
|
|
+ /**
|
|
|
+ * 模型实体类
|
|
|
+ */
|
|
|
+ private String modelClass;
|
|
|
+ /**
|
|
|
* 代码所在服务名
|
|
|
*/
|
|
|
private String serviceName = "blade-service";
|
|
@@ -67,6 +68,34 @@ public class BladeCodeGenerator {
|
|
|
*/
|
|
|
private String packageName = "org.springblade.test";
|
|
|
/**
|
|
|
+ * 模版类型
|
|
|
+ */
|
|
|
+ private String templateType;
|
|
|
+ /**
|
|
|
+ * 作者信息
|
|
|
+ */
|
|
|
+ private String author;
|
|
|
+ /**
|
|
|
+ * 子表模型主键
|
|
|
+ */
|
|
|
+ private String subModelId;
|
|
|
+ /**
|
|
|
+ * 子表绑定外键
|
|
|
+ */
|
|
|
+ private String subFkId;
|
|
|
+ /**
|
|
|
+ * 树主键字段
|
|
|
+ */
|
|
|
+ private String treeId;
|
|
|
+ /**
|
|
|
+ * 树父主键字段
|
|
|
+ */
|
|
|
+ private String treePid;
|
|
|
+ /**
|
|
|
+ * 树名称字段
|
|
|
+ */
|
|
|
+ private String treeName;
|
|
|
+ /**
|
|
|
* 代码后端生成的地址
|
|
|
*/
|
|
|
private String packageDir;
|
|
@@ -89,24 +118,28 @@ public class BladeCodeGenerator {
|
|
|
/**
|
|
|
* 是否包含基础业务字段
|
|
|
*/
|
|
|
- private Boolean hasSuperEntity = Boolean.FALSE;
|
|
|
+ private Boolean hasSuperEntity = Boolean.TRUE;
|
|
|
/**
|
|
|
* 是否包含包装器
|
|
|
*/
|
|
|
- private Boolean hasWrapper = Boolean.FALSE;
|
|
|
+ private Boolean hasWrapper = Boolean.TRUE;
|
|
|
+ /**
|
|
|
+ * 是否包含远程调用
|
|
|
+ */
|
|
|
+ private Boolean hasFeign = Boolean.FALSE;
|
|
|
+ /**
|
|
|
+ * 是否包含服务名
|
|
|
+ */
|
|
|
+ private Boolean hasServiceName = Boolean.FALSE;
|
|
|
/**
|
|
|
* 基础业务字段
|
|
|
*/
|
|
|
- private String[] superEntityColumns = {"id", "create_time", "create_user", "create_dept", "update_time", "update_user", "status", "is_deleted"};
|
|
|
+ private String[] superEntityColumns = {"create_time", "create_user", "create_dept", "update_time", "update_user", "status", "is_deleted"};
|
|
|
/**
|
|
|
* 租户字段
|
|
|
*/
|
|
|
private String tenantColumn = "tenant_id";
|
|
|
/**
|
|
|
- * 是否启用swagger
|
|
|
- */
|
|
|
- private Boolean isSwagger2 = Boolean.TRUE;
|
|
|
- /**
|
|
|
* 数据库驱动名
|
|
|
*/
|
|
|
private String driverName;
|
|
@@ -122,199 +155,156 @@ public class BladeCodeGenerator {
|
|
|
* 数据库密码
|
|
|
*/
|
|
|
private String password;
|
|
|
+ /**
|
|
|
+ * 数据模型
|
|
|
+ */
|
|
|
+ private Map<String, Object> model;
|
|
|
+ /**
|
|
|
+ * 数据原型
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> prototypes;
|
|
|
+ /**
|
|
|
+ * 子数据模型
|
|
|
+ */
|
|
|
+ private Map<String, Object> subModel;
|
|
|
+ /**
|
|
|
+ * 子数据原型
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> subPrototypes;
|
|
|
|
|
|
+ /**
|
|
|
+ * 代码生成执行
|
|
|
+ */
|
|
|
public void run() {
|
|
|
- Properties props = getProperties();
|
|
|
- AutoGenerator mpg = new AutoGenerator();
|
|
|
- GlobalConfig gc = new GlobalConfig();
|
|
|
- String outputDir = getOutputDir();
|
|
|
- String author = props.getProperty("author");
|
|
|
- gc.setOutputDir(outputDir);
|
|
|
- gc.setAuthor(author);
|
|
|
- gc.setFileOverride(true);
|
|
|
- gc.setOpen(false);
|
|
|
- gc.setActiveRecord(false);
|
|
|
- gc.setEnableCache(false);
|
|
|
- gc.setBaseResultMap(true);
|
|
|
- gc.setBaseColumnList(true);
|
|
|
- gc.setMapperName("%sMapper");
|
|
|
- gc.setXmlName("%sMapper");
|
|
|
- gc.setServiceName("I%sService");
|
|
|
- gc.setServiceImplName("%sServiceImpl");
|
|
|
- gc.setControllerName("%sController");
|
|
|
- gc.setSwagger2(isSwagger2);
|
|
|
- mpg.setGlobalConfig(gc);
|
|
|
- DataSourceConfig dsc = new DataSourceConfig();
|
|
|
- String driverName = Func.toStr(this.driverName, props.getProperty("spring.datasource.driver-class-name"));
|
|
|
- if (StringUtil.containsAny(driverName, DbType.MYSQL.getDb())) {
|
|
|
- dsc.setDbType(DbType.MYSQL);
|
|
|
- dsc.setTypeConvert(new MySqlTypeConvert());
|
|
|
- } else if (StringUtil.containsAny(driverName, DbType.POSTGRE_SQL.getDb())) {
|
|
|
- dsc.setDbType(DbType.POSTGRE_SQL);
|
|
|
- dsc.setTypeConvert(new PostgreSqlTypeConvert());
|
|
|
- } else if (StringUtil.containsAny(driverName, DbType.SQL_SERVER.getDb())) {
|
|
|
- dsc.setDbType(DbType.SQL_SERVER);
|
|
|
- dsc.setTypeConvert(new SqlServerTypeConvert());
|
|
|
- } else {
|
|
|
- dsc.setDbType(DbType.ORACLE);
|
|
|
- dsc.setTypeConvert(new OracleTypeConvert());
|
|
|
- }
|
|
|
- dsc.setDriverName(driverName);
|
|
|
- dsc.setUrl(Func.toStr(this.url, props.getProperty("spring.datasource.url")));
|
|
|
- dsc.setUsername(Func.toStr(this.username, props.getProperty("spring.datasource.username")));
|
|
|
- dsc.setPassword(Func.toStr(this.password, props.getProperty("spring.datasource.password")));
|
|
|
- mpg.setDataSource(dsc);
|
|
|
- // 策略配置
|
|
|
- StrategyConfig strategy = new StrategyConfig();
|
|
|
- // strategy.setCapitalMode(true);// 全局大写命名
|
|
|
- // strategy.setDbColumnUnderline(true);//全局下划线命名
|
|
|
- strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
|
- strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
|
- strategy.setTablePrefix(tablePrefix);
|
|
|
- if (includeTables.length > 0) {
|
|
|
- strategy.setInclude(includeTables);
|
|
|
+ // 主模块代码生成
|
|
|
+ getAutoGenerator(getCustomMap(TEMPLATE_MAIN), getCustomFile(TEMPLATE_MAIN)).templateEngine(new BladeTemplateEngine(getOutputDir(), getOutputWebDir())).execute();
|
|
|
+ // 子模块代码生成
|
|
|
+ if (Func.equals(templateType, TEMPLATE_SUB) && StringUtil.isNotBlank(subModelId)) {
|
|
|
+ getAutoGenerator(getCustomMap(TEMPLATE_SUB), getCustomFile(TEMPLATE_SUB)).templateEngine(new BladeTemplateEngine(getOutputDir(), getOutputWebDir())).execute();
|
|
|
}
|
|
|
- if (excludeTables.length > 0) {
|
|
|
- strategy.setExclude(excludeTables);
|
|
|
- }
|
|
|
- if (hasSuperEntity) {
|
|
|
- strategy.setSuperEntityClass("org.springblade.core.mp.base.BaseEntity");
|
|
|
- strategy.setSuperEntityColumns(superEntityColumns);
|
|
|
- strategy.setSuperServiceClass("org.springblade.core.mp.base.BaseService");
|
|
|
- strategy.setSuperServiceImplClass("org.springblade.core.mp.base.BaseServiceImpl");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置 customMap
|
|
|
+ */
|
|
|
+ private Map<String, Object> getCustomMap(String generateType) {
|
|
|
+ List<Map<String, Object>> prototypeList;
|
|
|
+ String[] split = packageName.split("\\.");
|
|
|
+ String serviceCode = split[split.length - 1];
|
|
|
+ Map<String, Object> customMap = new HashMap<>(11);
|
|
|
+ customMap.put("generateType", generateType);
|
|
|
+ customMap.put("codeName", codeName);
|
|
|
+ customMap.put("serviceName", serviceName);
|
|
|
+ customMap.put("serviceCode", serviceCode);
|
|
|
+ customMap.put("packageName", packageName);
|
|
|
+ customMap.put("tenantColumn", tenantColumn);
|
|
|
+ customMap.put("hasWrapper", hasWrapper);
|
|
|
+ customMap.put("hasServiceName", hasServiceName);
|
|
|
+ customMap.put("templateType", templateType);
|
|
|
+ customMap.put("author", author);
|
|
|
+ customMap.put("subModelId", subModelId);
|
|
|
+ customMap.put("subFkId", subFkId);
|
|
|
+ customMap.put("treeId", treeId);
|
|
|
+ customMap.put("treePid", treePid);
|
|
|
+ customMap.put("treeName", treeName);
|
|
|
+ customMap.put("subFkIdHump", StringUtil.underlineToHump(subFkId));
|
|
|
+ customMap.put("treeIdHump", StringUtil.underlineToHump(treeId));
|
|
|
+ customMap.put("treePidHump", StringUtil.underlineToHump(treePid));
|
|
|
+ if (Func.equals(generateType, TEMPLATE_SUB)) {
|
|
|
+ prototypeList = subPrototypes;
|
|
|
+ customMap.put("model", subModel);
|
|
|
+ customMap.put("prototypes", subPrototypes);
|
|
|
+ customMap.put("modelCode", subModel.get("modelCode"));
|
|
|
+ customMap.put("modelClass", subModel.get("modelClass"));
|
|
|
+ customMap.put("modelTable", subModel.get("modelTable"));
|
|
|
} else {
|
|
|
- strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService");
|
|
|
- strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl");
|
|
|
+ prototypeList = prototypes;
|
|
|
+ customMap.put("model", model);
|
|
|
+ customMap.put("prototypes", prototypes);
|
|
|
+ customMap.put("subModel", subModel);
|
|
|
+ customMap.put("subPrototypes", subPrototypes);
|
|
|
+ customMap.put("modelCode", model.get("modelCode"));
|
|
|
+ customMap.put("modelClass", model.get("modelClass"));
|
|
|
+ customMap.put("modelTable", model.get("modelTable"));
|
|
|
}
|
|
|
- // 自定义 controller 父类
|
|
|
- strategy.setSuperControllerClass("org.springblade.core.boot.ctrl.BladeController");
|
|
|
- strategy.setEntityBuilderModel(false);
|
|
|
- strategy.setEntityLombokModel(true);
|
|
|
- strategy.setControllerMappingHyphenStyle(true);
|
|
|
- mpg.setStrategy(strategy);
|
|
|
- // 包配置
|
|
|
- PackageConfig pc = new PackageConfig();
|
|
|
- // 控制台扫描
|
|
|
- pc.setModuleName(null);
|
|
|
- pc.setParent(packageName);
|
|
|
- pc.setController("controller");
|
|
|
- pc.setEntity("entity");
|
|
|
- pc.setXml("mapper");
|
|
|
- mpg.setPackageInfo(pc);
|
|
|
- mpg.setCfg(getInjectionConfig());
|
|
|
- mpg.execute();
|
|
|
+ List<String> propertyImport = prototypeList.stream().filter(prototype -> {
|
|
|
+ String propertyType = String.valueOf(prototype.get("propertyType"));
|
|
|
+ return !"String".equals(propertyType) && !"Integer".equals(propertyType) && !"Long".equals(propertyType);
|
|
|
+ }).map(prototype -> String.valueOf(prototype.get("propertyEntity"))).distinct().collect(Collectors.toList());
|
|
|
+ customMap.put("propertyImport", propertyImport);
|
|
|
+ return customMap;
|
|
|
}
|
|
|
|
|
|
- private InjectionConfig getInjectionConfig() {
|
|
|
- String servicePackage = serviceName.split("-").length > 1 ? serviceName.split("-")[1] : serviceName;
|
|
|
- // 自定义配置
|
|
|
- Map<String, Object> map = new HashMap<>(16);
|
|
|
- InjectionConfig cfg = new InjectionConfig() {
|
|
|
- @Override
|
|
|
- public void initMap() {
|
|
|
- map.put("codeName", codeName);
|
|
|
- map.put("serviceName", serviceName);
|
|
|
- map.put("servicePackage", servicePackage);
|
|
|
- map.put("servicePackageLowerCase", servicePackage.toLowerCase());
|
|
|
- map.put("tenantColumn", tenantColumn);
|
|
|
- map.put("hasWrapper", hasWrapper);
|
|
|
- this.setMap(map);
|
|
|
- }
|
|
|
- };
|
|
|
- List<FileOutConfig> focList = new ArrayList<>();
|
|
|
- focList.add(new FileOutConfig("/templates/sql/menu.sql.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- map.put("entityKey", (tableInfo.getEntityName().toLowerCase()));
|
|
|
- map.put("menuId", IdWorker.getId());
|
|
|
- map.put("addMenuId", IdWorker.getId());
|
|
|
- map.put("editMenuId", IdWorker.getId());
|
|
|
- map.put("removeMenuId", IdWorker.getId());
|
|
|
- map.put("viewMenuId", IdWorker.getId());
|
|
|
- return getOutputDir() + "/" + "/sql/" + tableInfo.getEntityName().toLowerCase() + ".menu.mysql";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/entityVO.java.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "vo" + "/" + tableInfo.getEntityName() + "VO" + StringPool.DOT_JAVA;
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/entityDTO.java.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "dto" + "/" + tableInfo.getEntityName() + "DTO" + StringPool.DOT_JAVA;
|
|
|
- }
|
|
|
- });
|
|
|
+ /**
|
|
|
+ * 设置 customFile
|
|
|
+ */
|
|
|
+ private Map<String, String> getCustomFile(String type) {
|
|
|
+ Map<String, String> customFile = new HashMap<>(15);
|
|
|
+ if (!Func.equals(type, TEMPLATE_SUB)) {
|
|
|
+ customFile.put("menu.sql", "/templates/sql/menu.sql.btl");
|
|
|
+ }
|
|
|
+ customFile.put("entityVO.java", "/templates/api/entityVO.java.btl");
|
|
|
+ customFile.put("entityDTO.java", "/templates/api/entityDTO.java.btl");
|
|
|
if (hasWrapper) {
|
|
|
- focList.add(new FileOutConfig("/templates/wrapper.java.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "wrapper" + "/" + tableInfo.getEntityName() + "Wrapper" + StringPool.DOT_JAVA;
|
|
|
- }
|
|
|
- });
|
|
|
+ customFile.put("wrapper.java", "/templates/api/wrapper.java.btl");
|
|
|
+ }
|
|
|
+ if (hasFeign) {
|
|
|
+ customFile.put("feign.java", "/templates/api/feign.java.btl");
|
|
|
+ customFile.put("feignclient.java", "/templates/api/feignclient.java.btl");
|
|
|
}
|
|
|
if (Func.isNotBlank(packageWebDir)) {
|
|
|
- if (Func.equals(systemName, DevelopConstant.SWORD_NAME)) {
|
|
|
- focList.add(new FileOutConfig("/templates/sword/action.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/actions" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/model.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/models" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/service.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/list.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + ".js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/add.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Add.js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/edit.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Edit.js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/sword/view.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/pages" + "/" + StringUtil.firstCharToUpper(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "View.js";
|
|
|
- }
|
|
|
- });
|
|
|
- } else if (Func.equals(systemName, DevelopConstant.SABER_NAME)) {
|
|
|
- focList.add(new FileOutConfig("/templates/saber/api.js.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/api" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
|
- }
|
|
|
- });
|
|
|
- focList.add(new FileOutConfig("/templates/saber/crud.vue.vm") {
|
|
|
- @Override
|
|
|
- public String outputFile(TableInfo tableInfo) {
|
|
|
- return getOutputWebDir() + "/views" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".vue";
|
|
|
- }
|
|
|
- });
|
|
|
+ if (Func.equals(codeStyle, SWORD_NAME)) {
|
|
|
+ customFile.put("action.js", "/templates/sword/action.js.btl");
|
|
|
+ customFile.put("model.js", "/templates/sword/model.js.btl");
|
|
|
+ customFile.put("service.js", "/templates/sword/service.js.btl");
|
|
|
+ customFile.put("list.js", "/templates/sword/list.js.btl");
|
|
|
+ customFile.put("add.js", "/templates/sword/add.js.btl");
|
|
|
+ customFile.put("edit.js", "/templates/sword/edit.js.btl");
|
|
|
+ customFile.put("view.js", "/templates/sword/view.js.btl");
|
|
|
+ } else if (Func.equals(codeStyle, SABER_NAME)) {
|
|
|
+ customFile.put("api.js", "/templates/saber/" + templateType + "/api.js.btl");
|
|
|
+ customFile.put("const.js", "/templates/saber/" + templateType + "/const.js.btl");
|
|
|
+ if (!Func.equals(type, TEMPLATE_SUB)) {
|
|
|
+ customFile.put("crud.vue", "/templates/saber/" + templateType + "/crud.vue.btl");
|
|
|
+ }
|
|
|
+ } else if (Func.equals(codeStyle, ELEMENT_NAME)) {
|
|
|
+ customFile.put("api.js", "/templates/element/" + templateType + "/api.js.btl");
|
|
|
+ customFile.put("const.js", "/templates/element/" + templateType + "/const.js.btl");
|
|
|
+ if (!Func.equals(type, TEMPLATE_SUB)) {
|
|
|
+ customFile.put("crud.vue", "/templates/element/" + templateType + "/crud.vue.btl");
|
|
|
+ } else {
|
|
|
+ customFile.put("sub.vue", "/templates/element/" + templateType + "/sub.vue.btl");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- cfg.setFileOutConfigList(focList);
|
|
|
- return cfg;
|
|
|
+ return customFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ private FastAutoGenerator getAutoGenerator(Map<String, Object> customMap, Map<String, String> customFile) {
|
|
|
+ Properties props = getProperties();
|
|
|
+ String url = Func.toStr(this.url, props.getProperty("spring.datasource.url"));
|
|
|
+ String username = Func.toStr(this.username, props.getProperty("spring.datasource.username"));
|
|
|
+ String password = Func.toStr(this.password, props.getProperty("spring.datasource.password"));
|
|
|
+ return FastAutoGenerator.create(url, username, password)
|
|
|
+ .globalConfig(builder -> builder.author(StringUtil.isBlank(author) ? props.getProperty("author") : author).dateType(DateType.TIME_PACK).enableSwagger().outputDir(getOutputDir()).disableOpenDir())
|
|
|
+ .packageConfig(builder -> builder.parent(packageName).controller("controller").entity("entity").service("service").serviceImpl("service.impl").mapper("mapper").xml("mapper"))
|
|
|
+ .strategyConfig(builder -> builder.addTablePrefix(tablePrefix).addInclude(Func.toStrArray(String.valueOf(customMap.get("modelTable")))).addExclude(excludeTables)
|
|
|
+ .entityBuilder().naming(NamingStrategy.underline_to_camel).columnNaming(NamingStrategy.underline_to_camel).enableLombok().superClass("org.springblade.core.mp.base.BaseEntity").formatFileName("%sEntity").addSuperEntityColumns(superEntityColumns).enableFileOverride()
|
|
|
+ .serviceBuilder().superServiceClass("org.springblade.core.mp.base.BaseService").superServiceImplClass("org.springblade.core.mp.base.BaseServiceImpl").formatServiceFileName("I%sService").formatServiceImplFileName("%sServiceImpl").enableFileOverride()
|
|
|
+ .mapperBuilder().mapperAnnotation(Mapper.class).enableBaseResultMap().enableBaseColumnList().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper").enableFileOverride()
|
|
|
+ .controllerBuilder().superClass("org.springblade.core.boot.ctrl.BladeController").formatFileName("%sController").enableRestStyle().enableHyphenStyle().enableFileOverride()
|
|
|
+ )
|
|
|
+ .templateConfig(builder -> builder.disable(TemplateType.ENTITY)
|
|
|
+ .entity("/templates/api/entity.java")
|
|
|
+ .service("/templates/api/service.java")
|
|
|
+ .serviceImpl("/templates/api/serviceImpl.java")
|
|
|
+ .mapper("/templates/api/mapper.java")
|
|
|
+ .xml("/templates/api/mapper.xml")
|
|
|
+ .controller("/templates/api/controller.java"))
|
|
|
+ .injectionConfig(builder -> builder.beforeOutputFile(
|
|
|
+ (tableInfo, objectMap) -> System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size())
|
|
|
+ ).customMap(customMap).customFile(customFile)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -343,6 +333,7 @@ public class BladeCodeGenerator {
|
|
|
return (Func.isBlank(packageDir) ? System.getProperty("user.dir") + "/blade-ops/blade-develop" : packageDir) + "/src/main/java";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 生成到Web项目中
|
|
|
*
|
|
@@ -352,17 +343,4 @@ public class BladeCodeGenerator {
|
|
|
return (Func.isBlank(packageWebDir) ? System.getProperty("user.dir") : packageWebDir) + "/src";
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 页面生成的文件名
|
|
|
- */
|
|
|
- private String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
|
|
|
- String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
|
|
|
- String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
|
|
|
- File viewDir = new File(path).getParentFile();
|
|
|
- if (!viewDir.exists()) {
|
|
|
- viewDir.mkdirs();
|
|
|
- }
|
|
|
- return path;
|
|
|
- }
|
|
|
-
|
|
|
}
|