parent
6b68aa95fe
commit
3e869a07fd
|
@ -22,7 +22,7 @@ public class CodegenColumnBaseVO {
|
|||
|
||||
@ApiModelProperty(value = "字段类型", required = true, example = "int(11)")
|
||||
@NotNull(message = "字段类型不能为空")
|
||||
private String columnType;
|
||||
private String dataType;
|
||||
|
||||
@ApiModelProperty(value = "字段描述", required = true, example = "年龄")
|
||||
@NotNull(message = "字段描述不能为空")
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CodegenColumnDO extends BaseDO {
|
|||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
private String columnType;
|
||||
private String dataType;
|
||||
/**
|
||||
* 字段描述
|
||||
*/
|
||||
|
|
|
@ -26,11 +26,6 @@ public class DatabaseColumnDO {
|
|||
* 字段类型
|
||||
*/
|
||||
private String dataType;
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
@Deprecated
|
||||
private String columnType;
|
||||
/**
|
||||
* 字段描述
|
||||
*/
|
||||
|
|
|
@ -41,10 +41,10 @@ public class DatabaseTableMySQLDAOImpl implements DatabaseTableDAO {
|
|||
@Override
|
||||
public List<DatabaseColumnDO> selectColumnList(Connection connection, String tableName) {
|
||||
// 拼接 SQL
|
||||
String sql = "SELECT table_name, column_name, column_type, column_comment, ordinal_position" +
|
||||
String sql = "SELECT table_name, column_name, data_type, column_comment, ordinal_position," +
|
||||
" (CASE WHEN is_nullable = 'yes' THEN '1' ELSE '0' END) AS nullable," +
|
||||
" (CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END) AS primary_key," +
|
||||
" (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment," +
|
||||
" (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment" +
|
||||
" FROM information_schema.COLUMNS" +
|
||||
" WHERE table_schema = (SELECT DATABASE())" +
|
||||
String.format(" AND table_name = '%s'", tableName);
|
||||
|
@ -52,7 +52,7 @@ public class DatabaseTableMySQLDAOImpl implements DatabaseTableDAO {
|
|||
return JdbcUtils.query(connection, sql, (rs, rowNum) -> DatabaseColumnDO.builder()
|
||||
.tableName(rs.getString("table_name"))
|
||||
.columnName(rs.getString("column_name"))
|
||||
.columnType(rs.getString("column_type"))
|
||||
.dataType(rs.getString("data_type"))
|
||||
.columnComment(rs.getString("column_comment"))
|
||||
.nullable(rs.getBoolean("nullable"))
|
||||
.primaryKey(rs.getBoolean("primary_key"))
|
||||
|
|
|
@ -13,7 +13,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.db.DatabaseTableDO;
|
|||
import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenColumnMapper;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenImportTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser;
|
||||
|
|
|
@ -87,12 +87,15 @@ public class CodegenBuilder {
|
|||
*/
|
||||
private static final Map<String, Set<String>> javaTypeMappings = MapUtil.<String, Set<String>>builder()
|
||||
.put(Boolean.class.getSimpleName(), Sets.newHashSet("bit"))
|
||||
.put(Integer.class.getSimpleName(), Sets.newHashSet("tinyint", "smallint", "mediumint", "int"))
|
||||
.put(Long.class.getSimpleName(), Collections.singleton("bigint"))
|
||||
.put(Integer.class.getSimpleName(), Sets.newHashSet(
|
||||
"tinyint", "smallint", "mediumint", "int", "integer"))
|
||||
.put(Long.class.getSimpleName(), Sets.newHashSet("bigint", "number"))
|
||||
.put(Double.class.getSimpleName(), Sets.newHashSet("float", "double"))
|
||||
.put(BigDecimal.class.getSimpleName(), Sets.newHashSet("decimal", "numeric"))
|
||||
.put(String.class.getSimpleName(), Sets.newHashSet("tinytext", "text", "mediumtext", "longtext", // 长文本
|
||||
"char", "varchar", "nvarchar", "varchar2")) // 短文本
|
||||
.put(String.class.getSimpleName(), Sets.newHashSet(
|
||||
"tinytext", "text", "mediumtext", "longtext", "nclob", // 长文本
|
||||
"char", "varchar", "nvarchar", "varchar2", "nvarchar2", // 短文本
|
||||
"json")) // 特殊文本
|
||||
.put(Date.class.getSimpleName(), Sets.newHashSet("datetime", "time", "date", "timestamp"))
|
||||
.put("byte[]", Sets.newHashSet("blob"))
|
||||
.build();
|
||||
|
@ -159,16 +162,14 @@ public class CodegenBuilder {
|
|||
private void processColumnJava(CodegenColumnDO column) {
|
||||
// 处理 javaField 字段
|
||||
column.setJavaField(toCamelCase(column.getColumnName()));
|
||||
// 处理 dictType 字段,暂无
|
||||
// 处理 javaType 字段(兼容无符号类型)
|
||||
String dbType = replaceIgnoreCase(subBefore(column.getColumnType(), '(', false),
|
||||
" UNSIGNED", "");
|
||||
// 处理 dataType 字段
|
||||
String dataType = column.getDataType().toLowerCase();
|
||||
javaTypeMappings.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().contains(dbType))
|
||||
.filter(entry -> entry.getValue().contains(dataType))
|
||||
.findFirst().ifPresent(entry -> column.setJavaType(entry.getKey()));
|
||||
if (column.getJavaType() == null) {
|
||||
throw new IllegalStateException(String.format("column(%s) 的数据库类型(%s) 找不到匹配的 Java 类型",
|
||||
column.getColumnName(), column.getColumnType()));
|
||||
column.getColumnName(), column.getJavaType()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ public class CodegenSQLParser {
|
|||
String text = definition.toString().toUpperCase();
|
||||
columns.add(DatabaseColumnDO.builder()
|
||||
.columnName(normalize(definition.getColumnName()))
|
||||
.columnType(definition.getDataType().toString())
|
||||
.dataType(definition.getDataType().toString())
|
||||
.columnComment(Objects.isNull(definition.getComment()) ? ""
|
||||
: normalize(definition.getComment().toString()))
|
||||
.nullable(!text.contains(" NOT NULL"))
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
CREATE TABLE IF NOT EXISTS "${table.tableName}" (
|
||||
#foreach ($column in $columns)
|
||||
#if (${column.primaryKey})##处理主键
|
||||
"${column.javaField}"#if (${column.javaType} == 'String') ${column.columnType} NOT NULL#else ${column.columnType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
|
||||
"${column.javaField}"#if (${column.javaType} == 'String') ${column.dataType} NOT NULL#else ${column.dataType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
|
||||
#else
|
||||
#if (${column.columnName} == 'create_time')
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
#elseif (${column.columnName} == 'update_time')
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
#elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater')
|
||||
"${column.columnName}" ${column.columnType} DEFAULT '',
|
||||
"${column.columnName}" ${column.dataType} DEFAULT '',
|
||||
#elseif (${column.columnName} == 'deleted')
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
#else
|
||||
"${column.columnName}" ${column.columnType}#if (${column.nullable} == false) NOT NULL#end,
|
||||
"${column.columnName}" ${column.dataType}#if (${column.nullable} == false) NOT NULL#end,
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</el-table-column>
|
||||
<el-table-column
|
||||
label="物理类型"
|
||||
prop="columnType"
|
||||
prop="dateType"
|
||||
min-width="10%"
|
||||
:show-overflow-tooltip="true"
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue