use of com.baomidou.mybatisplus.generator.config.OutputFile in project blade-tool by chillzhuang.
the class BladeCodeGenerator method run.
/**
* 代码生成执行
*/
public void run() {
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"));
String servicePackage = serviceName.split("-").length > 1 ? serviceName.split("-")[1] : serviceName;
Map<String, Object> customMap = new HashMap<>(11);
customMap.put("codeName", codeName);
customMap.put("serviceName", serviceName);
customMap.put("servicePackage", servicePackage);
customMap.put("servicePackageLowerCase", servicePackage.toLowerCase());
customMap.put("tenantColumn", tenantColumn);
customMap.put("hasWrapper", hasWrapper);
Map<String, String> customFile = new HashMap<>(15);
customFile.put("menu.sql", "/templates/sql/menu.sql.vm");
customFile.put("entityVO.java", "/templates/entityVO.java.vm");
customFile.put("entityDTO.java", "/templates/entityDTO.java.vm");
if (hasWrapper) {
customFile.put("wrapper.java", "/templates/wrapper.java.vm");
}
if (Func.isNotBlank(packageWebDir)) {
if (Func.equals(systemName, DevelopConstant.SWORD_NAME)) {
customFile.put("action.js", "/templates/sword/action.js.vm");
customFile.put("model.js", "/templates/sword/model.js.vm");
customFile.put("service.js", "/templates/sword/service.js.vm");
customFile.put("list.js", "/templates/sword/list.js.vm");
customFile.put("add.js", "/templates/sword/add.js.vm");
customFile.put("edit.js", "/templates/sword/edit.js.vm");
customFile.put("view.js", "/templates/sword/view.js.vm");
} else if (Func.equals(systemName, DevelopConstant.SABER_NAME)) {
customFile.put("api.js", "/templates/saber/api.js.vm");
customFile.put("crud.vue", "/templates/saber/crud.vue.vm");
}
}
FastAutoGenerator.create(url, username, password).globalConfig(builder -> builder.author(props.getProperty("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(includeTables).addExclude(excludeTables).entityBuilder().naming(NamingStrategy.underline_to_camel).columnNaming(NamingStrategy.underline_to_camel).enableLombok().superClass("org.springblade.core.mp.base.BaseEntity").addSuperEntityColumns(superEntityColumns).serviceBuilder().superServiceClass("org.springblade.core.mp.base.BaseService").superServiceImplClass("org.springblade.core.mp.base.BaseServiceImpl").formatServiceFileName("I%sService").formatServiceImplFileName("%sServiceImpl").mapperBuilder().enableMapperAnnotation().enableBaseResultMap().enableBaseColumnList().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper").controllerBuilder().superClass("org.springblade.core.boot.ctrl.BladeController").formatFileName("%sController").enableRestStyle().enableHyphenStyle()).templateConfig(builder -> builder.disable(TemplateType.ENTITY).entity("/templates/entity.java.vm").service("/templates/service.java.vm").serviceImpl("/templates/serviceImpl.java.vm").mapper("/templates/mapper.java.vm").xml("/templates/mapper.xml.vm").controller("/templates/controller.java.vm")).injectionConfig(builder -> builder.beforeOutputFile((tableInfo, objectMap) -> System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size())).customMap(customMap).customFile(customFile)).templateEngine(new VelocityTemplateEngine() {
@Override
protected void outputCustomFile(Map<String, String> customFile, TableInfo tableInfo, Map<String, Object> objectMap) {
String entityName = tableInfo.getEntityName();
String entityNameLower = tableInfo.getEntityName().toLowerCase();
customFile.forEach((key, value) -> {
String outputPath = getPathInfo(OutputFile.other);
if (StringUtil.equals(key, "menu.sql")) {
objectMap.put("entityKey", entityNameLower);
objectMap.put("menuId", IdWorker.getId());
objectMap.put("addMenuId", IdWorker.getId());
objectMap.put("editMenuId", IdWorker.getId());
objectMap.put("removeMenuId", IdWorker.getId());
objectMap.put("viewMenuId", IdWorker.getId());
outputPath = getOutputDir() + StringPool.SLASH + "sql" + StringPool.SLASH + entityNameLower + ".menu.sql";
}
if (StringUtil.equals(key, "entityVO.java")) {
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "vo" + StringPool.SLASH + entityName + "VO" + StringPool.DOT_JAVA;
}
if (StringUtil.equals(key, "entityDTO.java")) {
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "dto" + StringPool.SLASH + entityName + "DTO" + StringPool.DOT_JAVA;
}
if (StringUtil.equals(key, "wrapper.java")) {
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "wrapper" + StringPool.SLASH + entityName + "Wrapper" + StringPool.DOT_JAVA;
}
if (StringUtil.equals(key, "action.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "actions" + StringPool.SLASH + entityNameLower + ".js";
}
if (StringUtil.equals(key, "model.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "models" + StringPool.SLASH + entityNameLower + ".js";
}
if (StringUtil.equals(key, "service.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "services" + StringPool.SLASH + entityNameLower + ".js";
}
if (StringUtil.equals(key, "list.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + ".js";
}
if (StringUtil.equals(key, "add.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "Add.js";
}
if (StringUtil.equals(key, "edit.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "Edit.js";
}
if (StringUtil.equals(key, "view.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "View.js";
}
if (StringUtil.equals(key, "api.js")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "api" + StringPool.SLASH + servicePackage.toLowerCase() + StringPool.SLASH + entityNameLower + ".js";
}
if (StringUtil.equals(key, "crud.vue")) {
outputPath = getOutputWebDir() + StringPool.SLASH + "views" + StringPool.SLASH + servicePackage.toLowerCase() + StringPool.SLASH + entityNameLower + ".vue";
}
outputFile(new File(String.valueOf(outputPath)), objectMap, value, Boolean.TRUE);
});
}
}).execute();
}
Aggregations