Files
hotime/.cursor/plans/修复dm类型映射大小写_b8477014.plan.md
T
hoteas 3681564ca4 feat(config): 扩展数据类型映射与数据库字段备注提取功能
- 在 ColumnDataType 中新增对 PostgreSQL 和 Oracle 数据类型的支持
- 更新 Db2JSON 方法,优化对达梦数据库表和列信息的查询逻辑
- 增强字段备注解析,支持从备注中提取提示信息并清理标签
- 更新文档,详细说明字段备注格式及前端提示的展示效果
2026-03-23 16:48:56 +08:00

82 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: 修复DM类型映射大小写
overview: DM 返回的列类型为大写(BIGINT、VARCHAR、INT、TIMESTAMP),但 ColumnDataType 的匹配键是小写且 strings.Contains 区分大小写,导致类型映射全部失败。
todos:
- id: fix-type-case
content: 修改 makecode.go 类型比较加 strings.ToLower 忽略大小写
status: completed
- id: add-dm-types
content: 在 config.go 的 ColumnDataType 中追加 DM 特有数据类型映射
status: completed
isProject: false
---
# 修复达梦数据库列类型映射失败
## 问题分析
通过 MCP 查询 `adminDB.json` 确认:大量字段 type 仍为 DM 原始类型(`BIGINT``VARCHAR``INT``TIMESTAMP``DECIMAL`),未映射到框架类型(`number``text``time`),导致前端编辑页无法识别控件类型。
### 根因
[config.go](d:\work\hotimev1.5\code\config.go) 第 43-59 行定义的 `ColumnDataType` 映射表键全部为小写:
```go
var ColumnDataType = map[string]string{
"int": "number",
"char": "text",
"text": "text",
"time": "time",
// ...
}
```
[makecode.go](d:\work\hotimev1.5\code\makecode.go) 第 191-194 行的匹配逻辑使用 `strings.Contains`**区分大小写**
```go
for k, v1 := range ColumnDataType {
if strings.Contains(info.GetString("type"), k) { // "BIGINT" 不包含 "int"
info["type"] = v1
break
}
}
```
DM 返回的类型全部为大写(`INT``VARCHAR``BIGINT`),而键为小写(`int``char`),`strings.Contains("BIGINT", "int")` 返回 `false`,映射全部跳过。
## 修复方案
### 修改 1:类型比较忽略大小写 - [makecode.go](d:\work\hotimev1.5\code\makecode.go)
第 192 行,将 `info.GetString("type")` 转为小写再匹配:
```go
if strings.Contains(strings.ToLower(info.GetString("type")), k) {
```
效果验证:
- `"BIGINT"` -> `"bigint"` -> contains `"int"` -> `"number"`
- `"VARCHAR"` -> `"varchar"` -> contains `"char"` -> `"text"`
- `"INT"` -> `"int"` -> contains `"int"` -> `"number"`
- `"TIMESTAMP"` -> `"timestamp"` -> contains `"time"` -> `"time"`
- `"DECIMAL"` -> `"decimal"` -> contains `"decimal"` -> `"number"`
### 修改 2:补充 DM 特有类型 - [config.go](d:\work\hotimev1.5\code\config.go)
`ColumnDataType` 中追加 DM 特有的数据类型,确保 CLOB、NUMBER 等也能被识别:
```go
var ColumnDataType = map[string]string{
// 现有 MySQL/SQLite 类型...
// DM 特有类型
"clob": "text",
"number": "number",
"numeric": "number",
"binary": "text",
"boolean": "number",
"bit": "number",
}
```