梳理代码生成器的配置

This commit is contained in:
YunaiV 2021-02-10 23:39:00 +08:00
parent 54c98c3a44
commit 63962d557a
22 changed files with 237 additions and 97 deletions

View File

@ -0,0 +1,9 @@
package cn.iocoder.dashboard.framework.codegen.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(CodegenProperties.class)
public class CodegenConfiguration {
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.dashboard.framework.codegen.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Collection;
@ConfigurationProperties(prefix = "yudao.codegen")
@Validated
@Data
public class CodegenProperties {
/**
* 生成的 Java 代码的基础包
*/
@NotNull(message = "Java 代码的基础包不能为空")
private String basePackage;
/**
* 数据库名数组
*/
@NotEmpty(message = "数据库不能为空")
private Collection<String> dbSchemas;
}

View File

@ -0,0 +1,4 @@
/**
* 代码生成器
*/
package cn.iocoder.dashboard.framework.codegen;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.framework.datasource;
package cn.iocoder.dashboard.framework.datasource.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

View File

@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration;
* @author 芋道源码
*/
@Configuration
@MapperScan(value = "cn.iocoder.dashboard", annotationClass = Mapper.class)
@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class)
public class MybatisConfiguration {
@Bean

View File

@ -104,4 +104,10 @@ public class QueryWrapperX<T> extends QueryWrapper<T> {
return this;
}
@Override
public QueryWrapperX<T> in(String column, Collection<?> coll) {
super.in(column, coll);
return this;
}
}

View File

@ -9,13 +9,16 @@ import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenPrevie
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolSchemaTableRespVO;
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.service.codegen.ToolCodegenService;
import cn.iocoder.dashboard.util.servlet.ServletUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -40,6 +43,23 @@ public class ToolCodegenController {
@Resource
private ToolCodegenService codegenService;
@ApiOperation(value = "获得数据库自带的表定义列表", notes = "会过滤掉已经导入 Codegen 的表")
@GetMapping("/db/table/list")
@ApiImplicitParams({
@ApiImplicitParam(name = "tableName", required = true, example = "yudao", dataTypeClass = String.class),
@ApiImplicitParam(name = "tableComment", required = true, example = "芋道", dataTypeClass = Long.class)
})
// @PreAuthorize("@ss.hasPermi('tool:gen:list')") TODO 权限
public CommonResult<List<ToolSchemaTableRespVO>> getSchemaTableList(
@RequestParam(value = "tableName", required = false) String tableName,
@RequestParam(value = "tableComment", required = false) String tableComment) {
// 获得数据库自带的表定义列表
List<ToolSchemaTableDO> schemaTables = codegenService.getSchemaTableList(tableName, tableComment);
// 移除在 Codegen 已经存在的
return null;
}
@ApiOperation("获得表定义分页")
@GetMapping("/table/page")
// TODO 权限 @PreAuthorize("@ss.hasPermi('tool:gen:list')")

View File

@ -0,0 +1,25 @@
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ApiModel("数据字典的表定义 Response VO")
@Data
public class ToolSchemaTableRespVO {
@ApiModelProperty(value = "数据库", required = true, example = "yudao")
private String tableSchema;
@ApiModelProperty(value = "表名称", required = true, example = "yuanma")
private String tableName;
@ApiModelProperty(value = "表描述", required = true, example = "芋道源码")
private String tableComment;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -8,8 +8,8 @@ import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.column.ToolCodege
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -24,11 +24,11 @@ public interface ToolCodegenConvert {
// ========== ToolInformationSchemaTableDO ToolInformationSchemaColumnDO 相关 ==========
ToolCodegenTableDO convert(ToolInformationSchemaTableDO bean);
ToolCodegenTableDO convert(ToolSchemaTableDO bean);
List<ToolCodegenColumnDO> convertList(List<ToolInformationSchemaColumnDO> list);
List<ToolCodegenColumnDO> convertList(List<ToolSchemaColumnDO> list);
ToolCodegenTableRespVO convert(ToolInformationSchemaColumnDO bean);
ToolCodegenTableRespVO convert(ToolSchemaColumnDO bean);
// ========== ToolCodegenTableDO 相关 ==========

View File

@ -13,7 +13,7 @@ import lombok.Data;
@TableName(value = "information_schema.columns", autoResultMap = true)
@Data
@Builder
public class ToolInformationSchemaColumnDO {
public class ToolSchemaColumnDO {
/**
* 表名称

View File

@ -14,7 +14,7 @@ import java.util.Date;
@TableName(value = "information_schema.tables", autoResultMap = true)
@Data
@Builder
public class ToolInformationSchemaTableDO {
public class ToolSchemaTableDO {
/**
* 数据库

View File

@ -1,21 +0,0 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ToolInformationSchemaTableMapper extends BaseMapperX<ToolInformationSchemaTableDO> {
default List<ToolInformationSchemaTableDO> selectListByTableSchema(String tableSchema) {
return selectList(new QueryWrapper<ToolInformationSchemaTableDO>().eq("table_schema", tableSchema));
}
default ToolInformationSchemaTableDO selectByTableName(String tableName) {
return selectOne(new QueryWrapper<ToolInformationSchemaTableDO>().eq("table_name", tableName));
}
}

View File

@ -1,17 +1,17 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ToolInformationSchemaColumnMapper extends BaseMapperX<ToolInformationSchemaColumnDO> {
public interface ToolSchemaColumnMapper extends BaseMapperX<ToolSchemaColumnDO> {
default List<ToolInformationSchemaColumnDO> selectListByTableName(String tableName) {
return selectList(new QueryWrapper<ToolInformationSchemaColumnDO>().eq("table_name", tableName)
default List<ToolSchemaColumnDO> selectListByTableName(String tableName) {
return selectList(new QueryWrapper<ToolSchemaColumnDO>().eq("table_name", tableName)
.orderByAsc("ordinal_position"));
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> {
default List<ToolSchemaTableDO> selectList(Collection<String> tableSchemas, String tableName, String tableComment) {
return selectList(new QueryWrapperX<ToolSchemaTableDO>().in("table_schema", tableSchemas)
.eqIfPresent("table_name", tableName)
.eqIfPresent("table_comment", tableComment));
}
default List<ToolSchemaTableDO> selectListByTableSchema(String tableSchema) {
return selectList(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema", tableSchema));
}
default ToolSchemaTableDO selectByTableName(String tableName) {
return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_name", tableName));
}
}

View File

@ -5,6 +5,7 @@ import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdate
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import java.util.List;
import java.util.Map;
@ -63,4 +64,13 @@ public interface ToolCodegenService {
*/
Map<String, String> generationCodes(Long tableId);
/**
* 获得数据库自带的表定义列表
*
* @param tableName 表名称
* @param tableComment 表描述
* @return 表定义列表
*/
List<ToolSchemaTableDO> getSchemaTableList(String tableName, String tableComment);
}

View File

@ -6,8 +6,8 @@ import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnHtmlTypeEnum;
import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenColumnListConditionEnum;
import cn.iocoder.dashboard.modules.tool.enums.codegen.ToolCodegenTemplateTypeEnum;
@ -21,8 +21,8 @@ import static cn.hutool.core.text.CharSequenceUtil.*;
/**
* 代码生成器的 Builder负责
* 1. 将数据库的表 {@link ToolInformationSchemaTableDO} 定义构建成 {@link ToolCodegenTableDO}
* 2. 将数据库的列 {@link ToolInformationSchemaColumnDO} 构定义建成 {@link ToolCodegenColumnDO}
* 1. 将数据库的表 {@link ToolSchemaTableDO} 定义构建成 {@link ToolCodegenTableDO}
* 2. 将数据库的列 {@link ToolSchemaColumnDO} 构定义建成 {@link ToolCodegenColumnDO}
*/
@Component
public class ToolCodegenBuilder {
@ -112,7 +112,7 @@ public class ToolCodegenBuilder {
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间还是需要返回的
}
public ToolCodegenTableDO buildTable(ToolInformationSchemaTableDO schemaTable) {
public ToolCodegenTableDO buildTable(ToolSchemaTableDO schemaTable) {
ToolCodegenTableDO table = ToolCodegenConvert.INSTANCE.convert(schemaTable);
initTableDefault(table);
return table;
@ -135,7 +135,7 @@ public class ToolCodegenBuilder {
table.setTemplateType(ToolCodegenTemplateTypeEnum.CRUD.getType());
}
public List<ToolCodegenColumnDO> buildColumns(List<ToolInformationSchemaColumnDO> schemaColumns) {
public List<ToolCodegenColumnDO> buildColumns(List<ToolSchemaColumnDO> schemaColumns) {
List<ToolCodegenColumnDO> columns = ToolCodegenConvert.INSTANCE.convertList(schemaColumns);
columns.forEach(this::initColumnDefault);
return columns;

View File

@ -9,6 +9,7 @@ import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageParam;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.codegen.config.CodegenProperties;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
@ -19,6 +20,7 @@ import cn.iocoder.dashboard.util.date.DateUtils;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -45,18 +47,30 @@ public class ToolCodegenEngine {
*/
private static final Map<String, String> TEMPLATES = MapUtil.<String, String>builder(new LinkedHashMap<>()) // 有序
// Java
.put("codegen/java/controller/controller.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/${table.className}Controller.java")
.put("codegen/java/controller/vo/baseVO.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/vo/${table.className}BaseVO.java")
.put("codegen/java/controller/vo/createReqVO.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/vo/${table.className}CreateReqVO.java")
.put("codegen/java/controller/vo/pageReqVO.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/vo/${table.className}PageReqVO.java")
.put("codegen/java/controller/vo/respVO.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/vo/${table.className}RespVO.java")
.put("codegen/java/controller/vo/updateReqVO.vm", "java/${basePackage}/${table.moduleName}/controller/${table.businessName}/vo/${table.className}UpdateReqVO.java")
.put("codegen/java/convert/convert.vm", "java/${basePackage}/${table.moduleName}/convert/${table.businessName}/${table.className}Convert.java")
.put("codegen/java/dal/do.vm", "java/${basePackage}/${table.moduleName}/dal/dataobject/${table.businessName}/${table.className}DO.java")
.put("codegen/java/dal/mapper.vm", "java/${basePackage}/${table.moduleName}/dal/mysql/${table.businessName}/${table.className}Mapper.java")
.put("codegen/java/enums/errorcode.vm", "java/${basePackage}/${table.moduleName}/enums/${simpleModuleName_upperFirst}ErrorCodeConstants.java")
.put("codegen/java/service/service.vm", "java/${basePackage}/${table.moduleName}/service/${table.businessName}/${table.className}Service.java")
.put("codegen/java/service/serviceImpl.vm", "java/${basePackage}/${table.moduleName}/service/${table.businessName}/impl/${table.className}ServiceImpl.java")
.put(javaTemplatePath("controller/controller"),
javaFilePath("controller/${table.businessName}/${table.className}Controller"))
.put(javaTemplatePath("controller/vo/baseVO"),
javaFilePath("controller/${table.businessName}/vo/${table.className}BaseVO"))
.put(javaTemplatePath("controller/vo/createReqVO"),
javaFilePath("controller/${table.businessName}/vo/${table.className}CreateReqVO"))
.put(javaTemplatePath("controller/vo/pageReqVO"),
javaFilePath("controller/${table.businessName}/vo/${table.className}PageReqVO"))
.put(javaTemplatePath("controller/vo/respVO"),
javaFilePath("controller/${table.businessName}/vo/${table.className}RespVO"))
.put(javaTemplatePath("controller/vo/updateReqVO"),
javaFilePath("controller/${table.businessName}/vo/${table.className}UpdateReqVO"))
.put(javaTemplatePath("convert/convert"),
javaFilePath("convert/${table.businessName}/${table.className}Convert"))
.put(javaTemplatePath("dal/do"),
javaFilePath("dal/dataobject/${table.businessName}/${table.className}DO"))
.put(javaTemplatePath("dal/mapper"),
javaFilePath("dal/mysql/${table.businessName}/${table.className}Mapper"))
.put(javaTemplatePath("enums/errorcode"),
javaFilePath("enums/${simpleModuleName_upperFirst}ErrorCodeConstants"))
.put(javaTemplatePath("service/service"),
javaFilePath("service/${table.businessName}/${table.className}Service"))
.put(javaTemplatePath("service/serviceImpl"),
javaFilePath("service/${table.businessName}/impl/${table.className}ServiceImpl"))
// Vue
// SQL
.build();
@ -64,6 +78,9 @@ public class ToolCodegenEngine {
@Resource
private ToolCodegenBuilder codegenBuilder;
@Resource
private CodegenProperties codegenProperties;
/**
* 模板引擎 hutool 实现
*/
@ -78,13 +95,12 @@ public class ToolCodegenEngine {
TemplateConfig config = new TemplateConfig();
config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH);
this.templateEngine = TemplateUtil.createEngine(config);
// 初始化基础 bindingMap
initGlobalBindingMap();
}
@PostConstruct
private void initGlobalBindingMap() {
// 全局配置
globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包, 抽成参数
globalBindingMap.put("basePackage", codegenProperties.getBasePackage());
// 全局 Java Bean
globalBindingMap.put("CommonResultClassName", CommonResult.class.getName());
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
@ -137,4 +153,12 @@ public class ToolCodegenEngine {
return filePath;
}
private static String javaTemplatePath(String path) {
return "codegen/java/" + path + ".vm";
}
private static String javaFilePath(String path) {
return "java/${basePackage}/${table.moduleName}/" + path + ".java";
}
}

View File

@ -2,17 +2,18 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.codegen.config.CodegenProperties;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolInformationSchemaColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolInformationSchemaTableMapper;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolCodegenTableMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolSchemaColumnMapper;
import cn.iocoder.dashboard.modules.tool.dal.mysql.coegen.ToolSchemaTableMapper;
import cn.iocoder.dashboard.modules.tool.service.codegen.ToolCodegenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -30,9 +31,9 @@ import java.util.Map;
public class ToolCodegenServiceImpl implements ToolCodegenService {
@Resource
private ToolInformationSchemaTableMapper informationSchemaTableMapper;
private ToolSchemaTableMapper schemaTableMapper;
@Resource
private ToolInformationSchemaColumnMapper informationSchemaColumnMapper;
private ToolSchemaColumnMapper schemaColumnMapper;
@Resource
private ToolCodegenTableMapper codegenTableMapper;
@Resource
@ -43,15 +44,18 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Resource
private ToolCodegenEngine codegenEngine;
@Resource
private CodegenProperties codegenProperties;
@Override
@Transactional
public Long createCodegen(String tableName) {
// 从数据库中获得数据库表结构
ToolInformationSchemaTableDO schemaTable = informationSchemaTableMapper.selectByTableName(tableName);
ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName(tableName);
if (schemaTable == null) {
throw new RuntimeException(""); // TODO
}
List<ToolInformationSchemaColumnDO> schemaColumns = informationSchemaColumnMapper.selectListByTableName(tableName);
List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableName);
if (CollUtil.isEmpty(schemaColumns)) {
throw new RuntimeException(""); // TODO
}
@ -119,4 +123,9 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
return codegenEngine.execute(table, columns);
}
@Override
public List<ToolSchemaTableDO> getSchemaTableList(String tableName, String tableComment) {
return schemaTableMapper.selectList(codegenProperties.getDbSchemas(), tableName, tableComment);
}
}

View File

@ -44,10 +44,12 @@ spring:
# 芋道配置项,设置当前项目所有自定义的配置
yudao:
version: 1.0.0
info:
version: 1.0.0
base-package: cn.iocoder.dashboard
web:
api-prefix: /api
controller-package: cn.iocoder.dashboard
controller-package: ${yudao.info.base-package}
security:
token-header: Authorization
token-secret: abcdefghijklmnopqrstuvwxyz
@ -66,6 +68,9 @@ yudao:
height: 60
file:
base-path: http://127.0.0.1:1024/api/file/get/
codegen:
base-package: ${yudao.info.base-package}.modules
db-schemas: ruoyi-vue-pro
# Apollo 配置中心
apollo:
@ -89,7 +94,7 @@ mybatis-plus:
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
mapper-locations: classpath*:mapper/*.xml
type-aliases-package: cn.iocoder.dashboard.modules.*.dal.mysql.dataobject
type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject
# Actuator 监控端点的配置项
management:

View File

@ -1,25 +1,17 @@
芋道源码 http://www.iocoder.cn
Application Version: ${yudao.version}
Application Version: ${yudao.info.version}
Spring Boot Version: ${spring-boot.version}
////////////////////////////////////////////////////////////////////
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
////////////////////////////////////////////////////////////////////
.__ __. ______ .______ __ __ _______
| \ | | / __ \ | _ \ | | | | / _____|
| \| | | | | | | |_) | | | | | | | __
| . ` | | | | | | _ < | | | | | | |_ |
| |\ | | `--' | | |_) | | `--' | | |__| |
|__| \__| \______/ |______/ \______/ \______|
███╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗
████╗ ██║██╔═══██╗ ██╔══██╗██║ ██║██╔════╝
██╔██╗ ██║██║ ██║ ██████╔╝██║ ██║██║ ███╗
██║╚██╗██║██║ ██║ ██╔══██╗██║ ██║██║ ██║
██║ ╚████║╚██████╔╝ ██████╔╝╚██████╔╝╚██████╔╝
╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.TestApplication;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaColumnDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -15,11 +15,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class ToolInformationSchemaColumnMapperTest {
@Resource
private ToolInformationSchemaColumnMapper toolInformationSchemaColumnMapper;
private ToolSchemaColumnMapper toolInformationSchemaColumnMapper;
@Test
public void testSelectListByTableName() {
List<ToolInformationSchemaColumnDO> columns = toolInformationSchemaColumnMapper
List<ToolSchemaColumnDO> columns = toolInformationSchemaColumnMapper
.selectListByTableName("inf_config");
assertTrue(columns.size() > 0);
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.modules.tool.dal.mysql.coegen;
import cn.iocoder.dashboard.TestApplication;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolInformationSchemaTableDO;
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@ -14,11 +14,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class ToolInformationSchemaTableMapperTest {
@Resource
private ToolInformationSchemaTableMapper toolInformationSchemaTableMapper;
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
@Test
public void tstSelectListByTableSchema() {
List<ToolInformationSchemaTableDO> tables = toolInformationSchemaTableMapper
List<ToolSchemaTableDO> tables = toolInformationSchemaTableMapper
.selectListByTableSchema("ruoyi-vue-pro");
assertTrue(tables.size() > 0);
}