feat(config): 扩展数据类型映射与数据库字段备注提取功能
- 在 ColumnDataType 中新增对 PostgreSQL 和 Oracle 数据类型的支持 - 更新 Db2JSON 方法,优化对达梦数据库表和列信息的查询逻辑 - 增强字段备注解析,支持从备注中提取提示信息并清理标签 - 更新文档,详细说明字段备注格式及前端提示的展示效果
This commit is contained in:
+18
-4
@@ -42,20 +42,34 @@ var DefaultMenuParentName = "sys"
|
||||
|
||||
var ColumnDataType = map[string]string{
|
||||
//sqlite专有类型
|
||||
"real": "number",
|
||||
//mysql数据类型宽泛类型
|
||||
"real": "number",
|
||||
"integer": "number",
|
||||
//mysql数据类型
|
||||
"int": "number",
|
||||
"float": "number",
|
||||
"double": "number",
|
||||
"decimal": "number",
|
||||
"integer": "number", //sqlite3
|
||||
"char": "text",
|
||||
"text": "text",
|
||||
"blob": "text",
|
||||
"date": "time",
|
||||
"time": "time",
|
||||
"year": "time",
|
||||
"geometry": "gis", //不建议使用gis类型,建议使用其他代替
|
||||
"bit": "number",
|
||||
"binary": "text",
|
||||
"geometry": "gis",
|
||||
//postgresql数据类型
|
||||
"numeric": "number",
|
||||
"boolean": "number",
|
||||
"serial": "number",
|
||||
"json": "text",
|
||||
"uuid": "text",
|
||||
"bytea": "text",
|
||||
"interval": "text",
|
||||
"money": "number",
|
||||
//达梦(DM)/Oracle数据类型
|
||||
"clob": "text",
|
||||
"number": "number",
|
||||
}
|
||||
|
||||
type ColumnShow struct {
|
||||
|
||||
+58
-20
@@ -119,7 +119,7 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
nowTables = db.Select("sqlite_master", "name", Map{"type": "table"})
|
||||
}
|
||||
if db.Type == "dm" || db.Type == "dameng" {
|
||||
nowTables = db.Query(`SELECT TABLE_NAME AS "name", COMMENTS AS "label" FROM USER_TAB_COMMENTS WHERE TABLE_TYPE='TABLE'`)
|
||||
nowTables = db.Query(`SELECT TABLE_NAME AS "name", COMMENTS AS "label" FROM ALL_TAB_COMMENTS WHERE TABLE_TYPE='TABLE' AND OWNER='` + db.DBName + `'`)
|
||||
}
|
||||
//idSlice=append(idSlice,nowTables)
|
||||
for _, v := range nowTables {
|
||||
@@ -130,6 +130,14 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
if v.GetString("label") == "" {
|
||||
v["label"] = v.GetString("name")
|
||||
}
|
||||
if strings.HasSuffix(v.GetString("label"), "表") {
|
||||
withoutTable := strings.TrimSuffix(v.GetString("label"), "表")
|
||||
if len([]rune(withoutTable)) <= 3 {
|
||||
v["label"] = withoutTable + "管理"
|
||||
} else {
|
||||
v["label"] = withoutTable
|
||||
}
|
||||
}
|
||||
that.TableConfig[v.GetString("name")] = Map{
|
||||
"label": v.GetString("label"),
|
||||
"table": v.GetString("name"),
|
||||
@@ -167,7 +175,7 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
tableInfo = db.Query("pragma table_info([" + v.GetString("name") + "]);")
|
||||
}
|
||||
if db.Type == "dm" || db.Type == "dameng" {
|
||||
tableInfo = db.Query(`SELECT c.COLUMN_NAME AS "name", c.DATA_TYPE AS "type", m.COMMENTS AS "label", c.NULLABLE AS "must", c.DATA_DEFAULT AS "dflt_value" FROM USER_TAB_COLUMNS c LEFT JOIN USER_COL_COMMENTS m ON c.TABLE_NAME=m.TABLE_NAME AND c.COLUMN_NAME=m.COLUMN_NAME WHERE c.TABLE_NAME='` + v.GetString("name") + `' ORDER BY c.COLUMN_ID`)
|
||||
tableInfo = db.Query(`SELECT c.COLUMN_NAME AS "name", c.DATA_TYPE AS "type", m.COMMENTS AS "label", c.NULLABLE AS "must", c.DATA_DEFAULT AS "dflt_value" FROM ALL_TAB_COLUMNS c LEFT JOIN USER_COL_COMMENTS m ON c.TABLE_NAME=m.TABLE_NAME AND c.COLUMN_NAME=m.COLUMN_NAME WHERE c.TABLE_NAME='` + v.GetString("name") + `' AND c.OWNER='` + db.DBName + `' ORDER BY c.COLUMN_ID`)
|
||||
}
|
||||
|
||||
idSlice = append(idSlice, tableInfo)
|
||||
@@ -181,7 +189,7 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
if coloum == nil {
|
||||
//根据类型判断真实类型
|
||||
for k, v1 := range ColumnDataType {
|
||||
if strings.Contains(info.GetString("type"), k) {
|
||||
if strings.Contains(strings.ToLower(info.GetString("type")), k) {
|
||||
info["type"] = v1
|
||||
break
|
||||
}
|
||||
@@ -207,22 +215,26 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
coloum["must"] = true
|
||||
}
|
||||
|
||||
//备注以空格隔开,空格后的是其他备注
|
||||
indexNum := strings.Index(info.GetString("label"), " ")
|
||||
if indexNum > -1 {
|
||||
coloum["label"] = info.GetString("label")[:indexNum]
|
||||
//提取括号内的提示信息:支持 ()、()、{}
|
||||
rawLabel := info.GetString("label")
|
||||
for _, pair := range [][2]string{{"(", ")"}, {"(", ")"}, {"{", "}"}} {
|
||||
start := strings.Index(rawLabel, pair[0])
|
||||
end := strings.Index(rawLabel, pair[1])
|
||||
if start != -1 && end > start {
|
||||
coloum["ps"] = rawLabel[start+len(pair[0]) : end]
|
||||
rawLabel = rawLabel[:start] + rawLabel[end+len(pair[1]):]
|
||||
break
|
||||
}
|
||||
}
|
||||
psStart := strings.Index(info.GetString("label"), "{")
|
||||
psEnd := strings.Index(info.GetString("label"), "}")
|
||||
if psStart != -1 && psEnd > psStart {
|
||||
coloum["ps"] = info.GetString("label")[psStart+1 : psEnd]
|
||||
//空格截断,空格后的内容丢弃
|
||||
if idx := strings.Index(rawLabel, " "); idx > -1 {
|
||||
rawLabel = rawLabel[:idx]
|
||||
}
|
||||
|
||||
//去除数据信息,是用:号分割的
|
||||
indexNum = strings.Index(coloum.GetString("label"), ":")
|
||||
if indexNum > -1 {
|
||||
coloum["label"] = coloum.GetString("label")[:indexNum]
|
||||
//冒号截断,去除选项数据部分
|
||||
if idx := strings.Index(rawLabel, ":"); idx > -1 {
|
||||
rawLabel = rawLabel[:idx]
|
||||
}
|
||||
coloum["label"] = rawLabel
|
||||
|
||||
for _, ColumnName := range that.RuleConfig {
|
||||
if (ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name")) ||
|
||||
@@ -311,6 +323,25 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
//}
|
||||
|
||||
} else {
|
||||
//对已有配置列也提取 ps 并清理 label
|
||||
rawLabel := coloum.GetString("label")
|
||||
for _, pair := range [][2]string{{"(", ")"}, {"(", ")"}, {"{", "}"}} {
|
||||
start := strings.Index(rawLabel, pair[0])
|
||||
end := strings.Index(rawLabel, pair[1])
|
||||
if start != -1 && end > start {
|
||||
coloum["ps"] = rawLabel[start+len(pair[0]) : end]
|
||||
rawLabel = rawLabel[:start] + rawLabel[end+len(pair[1]):]
|
||||
break
|
||||
}
|
||||
}
|
||||
if idx := strings.Index(rawLabel, " "); idx > -1 {
|
||||
rawLabel = rawLabel[:idx]
|
||||
}
|
||||
if idx := strings.Index(rawLabel, ":"); idx > -1 {
|
||||
rawLabel = rawLabel[:idx]
|
||||
}
|
||||
coloum["label"] = rawLabel
|
||||
}
|
||||
|
||||
//暂时不关闭参数,保证表数据完全读取到
|
||||
@@ -803,7 +834,7 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
if v.GetString("type") == "time" {
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -813,7 +844,7 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
if v.GetString("type") == "time" {
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,7 +893,7 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
if v.GetString("type") == "time" {
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1178,7 +1209,14 @@ func (that *MakeCode) Search(table string, userData Map, data Map, req *http.Req
|
||||
}
|
||||
|
||||
if len(reqValue) != 0 && searchItem.GetString("name") == "sort" && reqValue[0] != "" {
|
||||
sortMap["ORDER"] = reqValue[0]
|
||||
parts := strings.Fields(reqValue[0])
|
||||
if len(parts) == 2 {
|
||||
col := parts[0]
|
||||
dir := strings.ToUpper(parts[1])
|
||||
if (dir == "ASC" || dir == "DESC") && that.TableColumns[table][col] != nil {
|
||||
sortMap["ORDER"] = col + " " + dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user