Commit 3e869a07fdf2751a77285ddf640ceb1e96df755c

Authored by YunaiV
1 parent 6b68aa95

1. 将 column_type 调整成 data_type 字段

2. 完善 Oracle 的字段映射
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 {
22 22  
23 23 @ApiModelProperty(value = "字段类型", required = true, example = "int(11)")
24 24 @NotNull(message = "字段类型不能为空")
25   - private String columnType;
  25 + private String dataType;
26 26  
27 27 @ApiModelProperty(value = "字段描述", required = true, example = "年龄")
28 28 @NotNull(message = "字段描述不能为空")
... ...
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 {
41 41 /**
42 42 * 字段类型
43 43 */
44   - private String columnType;
  44 + private String dataType;
45 45 /**
46 46 * 字段描述
47 47 */
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/db/DatabaseColumnDO.java
... ... @@ -27,11 +27,6 @@ public class DatabaseColumnDO {
27 27 */
28 28 private String dataType;
29 29 /**
30   - * 字段类型
31   - */
32   - @Deprecated
33   - private String columnType;
34   - /**
35 30 * 字段描述
36 31 */
37 32 private String columnComment;
... ...
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 {
41 41 @Override
42 42 public List<DatabaseColumnDO> selectColumnList(Connection connection, String tableName) {
43 43 // 拼接 SQL
44   - String sql = "SELECT table_name, column_name, column_type, column_comment, ordinal_position" +
  44 + String sql = "SELECT table_name, column_name, data_type, column_comment, ordinal_position," +
45 45 " (CASE WHEN is_nullable = 'yes' THEN '1' ELSE '0' END) AS nullable," +
46 46 " (CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END) AS primary_key," +
47   - " (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment," +
  47 + " (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment" +
48 48 " FROM information_schema.COLUMNS" +
49 49 " WHERE table_schema = (SELECT DATABASE())" +
50 50 String.format(" AND table_name = '%s'", tableName);
... ... @@ -52,7 +52,7 @@ public class DatabaseTableMySQLDAOImpl implements DatabaseTableDAO {
52 52 return JdbcUtils.query(connection, sql, (rs, rowNum) -> DatabaseColumnDO.builder()
53 53 .tableName(rs.getString("table_name"))
54 54 .columnName(rs.getString("column_name"))
55   - .columnType(rs.getString("column_type"))
  55 + .dataType(rs.getString("data_type"))
56 56 .columnComment(rs.getString("column_comment"))
57 57 .nullable(rs.getBoolean("nullable"))
58 58 .primaryKey(rs.getBoolean("primary_key"))
... ...
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;
13 13 import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenColumnMapper;
14 14 import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper;
15 15 import cn.iocoder.yudao.module.infra.enums.codegen.CodegenImportTypeEnum;
16   -import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
17 16 import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
18 17 import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine;
19 18 import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenSQLParser;
... ...
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 {
87 87 */
88 88 private static final Map<String, Set<String>> javaTypeMappings = MapUtil.<String, Set<String>>builder()
89 89 .put(Boolean.class.getSimpleName(), Sets.newHashSet("bit"))
90   - .put(Integer.class.getSimpleName(), Sets.newHashSet("tinyint", "smallint", "mediumint", "int"))
91   - .put(Long.class.getSimpleName(), Collections.singleton("bigint"))
  90 + .put(Integer.class.getSimpleName(), Sets.newHashSet(
  91 + "tinyint", "smallint", "mediumint", "int", "integer"))
  92 + .put(Long.class.getSimpleName(), Sets.newHashSet("bigint", "number"))
92 93 .put(Double.class.getSimpleName(), Sets.newHashSet("float", "double"))
93 94 .put(BigDecimal.class.getSimpleName(), Sets.newHashSet("decimal", "numeric"))
94   - .put(String.class.getSimpleName(), Sets.newHashSet("tinytext", "text", "mediumtext", "longtext", // 长文本
95   - "char", "varchar", "nvarchar", "varchar2")) // 短文本
  95 + .put(String.class.getSimpleName(), Sets.newHashSet(
  96 + "tinytext", "text", "mediumtext", "longtext", "nclob", // 长文本
  97 + "char", "varchar", "nvarchar", "varchar2", "nvarchar2", // 短文本
  98 + "json")) // 特殊文本
96 99 .put(Date.class.getSimpleName(), Sets.newHashSet("datetime", "time", "date", "timestamp"))
97 100 .put("byte[]", Sets.newHashSet("blob"))
98 101 .build();
... ... @@ -159,16 +162,14 @@ public class CodegenBuilder {
159 162 private void processColumnJava(CodegenColumnDO column) {
160 163 // 处理 javaField 字段
161 164 column.setJavaField(toCamelCase(column.getColumnName()));
162   - // 处理 dictType 字段,暂无
163   - // 处理 javaType 字段(兼容无符号类型)
164   - String dbType = replaceIgnoreCase(subBefore(column.getColumnType(), '(', false),
165   - " UNSIGNED", "");
  165 + // 处理 dataType 字段
  166 + String dataType = column.getDataType().toLowerCase();
166 167 javaTypeMappings.entrySet().stream()
167   - .filter(entry -> entry.getValue().contains(dbType))
  168 + .filter(entry -> entry.getValue().contains(dataType))
168 169 .findFirst().ifPresent(entry -> column.setJavaType(entry.getKey()));
169 170 if (column.getJavaType() == null) {
170 171 throw new IllegalStateException(String.format("column(%s) 的数据库类型(%s) 找不到匹配的 Java 类型",
171   - column.getColumnName(), column.getColumnType()));
  172 + column.getColumnName(), column.getJavaType()));
172 173 }
173 174 }
174 175  
... ...
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 {
104 104 String text = definition.toString().toUpperCase();
105 105 columns.add(DatabaseColumnDO.builder()
106 106 .columnName(normalize(definition.getColumnName()))
107   - .columnType(definition.getDataType().toString())
  107 + .dataType(definition.getDataType().toString())
108 108 .columnComment(Objects.isNull(definition.getComment()) ? ""
109 109 : normalize(definition.getComment().toString()))
110 110 .nullable(!text.contains(" NOT NULL"))
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/sql/h2.vm
... ... @@ -2,18 +2,18 @@
2 2 CREATE TABLE IF NOT EXISTS "${table.tableName}" (
3 3 #foreach ($column in $columns)
4 4 #if (${column.primaryKey})##处理主键
5   - "${column.javaField}"#if (${column.javaType} == 'String') ${column.columnType} NOT NULL#else ${column.columnType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
  5 + "${column.javaField}"#if (${column.javaType} == 'String') ${column.dataType} NOT NULL#else ${column.dataType} NOT NULL GENERATED BY DEFAULT AS IDENTITY#end,
6 6 #else
7 7 #if (${column.columnName} == 'create_time')
8 8 "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
9 9 #elseif (${column.columnName} == 'update_time')
10 10 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
11 11 #elseif (${column.columnName} == 'creator' || ${column.columnName} == 'updater')
12   - "${column.columnName}" ${column.columnType} DEFAULT '',
  12 + "${column.columnName}" ${column.dataType} DEFAULT '',
13 13 #elseif (${column.columnName} == 'deleted')
14 14 "deleted" bit NOT NULL DEFAULT FALSE,
15 15 #else
16   - "${column.columnName}" ${column.columnType}#if (${column.nullable} == false) NOT NULL#end,
  16 + "${column.columnName}" ${column.dataType}#if (${column.nullable} == false) NOT NULL#end,
17 17 #end
18 18 #end
19 19 #end
... ...
yudao-ui-admin/src/views/infra/codegen/editTable.vue
... ... @@ -19,7 +19,7 @@
19 19 </el-table-column>
20 20 <el-table-column
21 21 label="物理类型"
22   - prop="columnType"
  22 + prop="dateType"
23 23 min-width="10%"
24 24 :show-overflow-tooltip="true"
25 25 />
... ...