diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/column/CodegenColumnBaseVO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/column/CodegenColumnBaseVO.java index 5d440b6af..770255185 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/column/CodegenColumnBaseVO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/codegen/vo/column/CodegenColumnBaseVO.java @@ -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 = "字段描述不能为空") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenColumnDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenColumnDO.java index 518552255..7d58aedda 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenColumnDO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/codegen/CodegenColumnDO.java @@ -41,7 +41,7 @@ public class CodegenColumnDO extends BaseDO { /** * 字段类型 */ - private String columnType; + private String dataType; /** * 字段描述 */ diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/db/DatabaseColumnDO.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/db/DatabaseColumnDO.java index 9da763001..47a06a4f6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/db/DatabaseColumnDO.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/db/DatabaseColumnDO.java @@ -26,11 +26,6 @@ public class DatabaseColumnDO { * 字段类型 */ private String dataType; - /** - * 字段类型 - */ - @Deprecated - private String columnType; /** * 字段描述 */ diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/db/DatabaseTableMySQLDAOImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/db/DatabaseTableMySQLDAOImpl.java index bd533569b..91c8a46dc 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/db/DatabaseTableMySQLDAOImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/db/DatabaseTableMySQLDAOImpl.java @@ -41,10 +41,10 @@ public class DatabaseTableMySQLDAOImpl implements DatabaseTableDAO { @Override public List 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")) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index 1c2e44e65..a976bfa30 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -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; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java index 17ebbf9fe..f791a4b19 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenBuilder.java @@ -87,12 +87,15 @@ public class CodegenBuilder { */ private static final Map> javaTypeMappings = MapUtil.>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())); } } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenSQLParser.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenSQLParser.java index 0438cda25..a486b1750 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenSQLParser.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenSQLParser.java @@ -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")) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm index 3d30f1c34..c1461bbf6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm @@ -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 diff --git a/yudao-ui-admin/src/views/infra/codegen/editTable.vue b/yudao-ui-admin/src/views/infra/codegen/editTable.vue index f132cd731..49cd76a18 100644 --- a/yudao-ui-admin/src/views/infra/codegen/editTable.vue +++ b/yudao-ui-admin/src/views/infra/codegen/editTable.vue @@ -19,7 +19,7 @@