|
@@ -3,15 +3,20 @@ package com.aizuda.boot.modules.gen.service.impl;
|
|
|
import com.aizuda.boot.modules.gen.service.IGenTableService;
|
|
|
import com.aizuda.core.bean.BaseEntity;
|
|
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.generator.config.*;
|
|
|
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
|
|
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|
|
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
|
|
+import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
|
|
import com.baomidou.mybatisplus.generator.fill.Column;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 代码生成业务表 服务实现类
|
|
@@ -36,7 +41,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|
|
PackageConfig.Builder packageInfo = new PackageConfig.Builder().parent("com.aizuda.boot.modules.gen");
|
|
|
// 策略配置
|
|
|
StrategyConfig.Builder strategy = new StrategyConfig.Builder();
|
|
|
- strategy.addInclude(List.of("gen_table"))
|
|
|
+ strategy.addInclude(List.of("sys_user", "sys_role"))
|
|
|
.controllerBuilder().enableRestStyle().enableHyphenStyle()
|
|
|
.serviceBuilder().superServiceClass("com.aizuda.service.service.IBaseService")
|
|
|
.mapperBuilder().superClass("com.aizuda.service.mapper.CrudMapper")
|
|
@@ -57,7 +62,51 @@ public class GenTableServiceImpl implements IGenTableService {
|
|
|
// 模板渲染引擎 new CodeTemplateEngine()
|
|
|
ConfigBuilder config = new ConfigBuilder(packageInfo.build(), dataSource.build(), strategy.build(), template.build(),
|
|
|
globalConfig.build(), injection.build());
|
|
|
- config.getTableInfoList();
|
|
|
+ List<TableInfo> tableInfos = config.getTableInfoList();
|
|
|
+ VelocityTemplateEngine templateEngine = new VelocityTemplateEngine();
|
|
|
+ templateEngine.init(config);
|
|
|
+ tableInfos.forEach((tableInfo) -> {
|
|
|
+ Map<String, Object> objectMap = this.getObjectMap(config, tableInfo);
|
|
|
+ try {
|
|
|
+ String tmp = templateEngine.writer(objectMap, tableInfo.getEntityName(), "hi ${author}");
|
|
|
+ System.err.println("----dsa----" + tmp);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ public Map<String, Object> getObjectMap(ConfigBuilder config, TableInfo tableInfo) {
|
|
|
+ StrategyConfig strategyConfig = config.getStrategyConfig();
|
|
|
+ Map<String, Object> controllerData = strategyConfig.controller().renderData(tableInfo);
|
|
|
+ Map<String, Object> objectMap = new HashMap(controllerData);
|
|
|
+ Map<String, Object> mapperData = strategyConfig.mapper().renderData(tableInfo);
|
|
|
+ objectMap.putAll(mapperData);
|
|
|
+ Map<String, Object> serviceData = strategyConfig.service().renderData(tableInfo);
|
|
|
+ objectMap.putAll(serviceData);
|
|
|
+ Map<String, Object> entityData = strategyConfig.entity().renderData(tableInfo);
|
|
|
+ objectMap.putAll(entityData);
|
|
|
+ objectMap.put("config", config);
|
|
|
+ objectMap.put("package", config.getPackageConfig().getPackageInfo());
|
|
|
+ GlobalConfig globalConfig = config.getGlobalConfig();
|
|
|
+ objectMap.put("author", globalConfig.getAuthor());
|
|
|
+ objectMap.put("kotlin", globalConfig.isKotlin());
|
|
|
+ objectMap.put("swagger", globalConfig.isSwagger());
|
|
|
+ objectMap.put("springdoc", globalConfig.isSpringdoc());
|
|
|
+ objectMap.put("date", globalConfig.getCommentDate());
|
|
|
+ String schemaName = "";
|
|
|
+ if (strategyConfig.isEnableSchema()) {
|
|
|
+ schemaName = config.getDataSourceConfig().getSchemaName();
|
|
|
+ if (StringUtils.isNotBlank(schemaName)) {
|
|
|
+ schemaName = schemaName + ".";
|
|
|
+ tableInfo.setConvert(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ objectMap.put("schemaName", schemaName);
|
|
|
+ objectMap.put("table", tableInfo);
|
|
|
+ objectMap.put("entity", tableInfo.getEntityName());
|
|
|
+ return objectMap;
|
|
|
+ }
|
|
|
}
|