优化表单生成规则
This commit is contained in:
parent
32167d4721
commit
cc4d91cdbb
@ -23,7 +23,7 @@ var Config = Map{
|
|||||||
//},
|
//},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var DefaultMenuParentName = "system"
|
var DefaultMenuParentName = "sys"
|
||||||
|
|
||||||
var ColumnDataType = map[string]string{
|
var ColumnDataType = map[string]string{
|
||||||
//sqlite专有类型
|
//sqlite专有类型
|
||||||
|
@ -311,30 +311,44 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range fv {
|
for k, v := range fv {
|
||||||
//虚招后缀是_id结尾的表字段
|
//虚招后缀是_id结尾的表字段 假设org_id
|
||||||
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//普通表匹配
|
//普通表匹配 org_id匹配为org
|
||||||
oldTableName := k[:len(k)-3]
|
oldTableName := k[:len(k)-3]
|
||||||
//上级ID匹配
|
//上级ID匹配
|
||||||
if oldTableName == "parent" {
|
if oldTableName == "parent" {
|
||||||
oldTableName = fk
|
oldTableName = fk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//如果依然找不到则查询system_org是否存在
|
||||||
|
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||||
|
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||||
|
}
|
||||||
|
|
||||||
//字段有动词前缀,自动进行解析
|
//字段有动词前缀,自动进行解析
|
||||||
prefixColumn := strings.Index(oldTableName, "_")
|
prefixColumn := strings.Index(oldTableName, "_")
|
||||||
|
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||||
oldTableName = oldTableName[prefixColumn+1:]
|
oldTableName = oldTableName[prefixColumn+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,比如表sys_user 字段org_id,查询不到sys_org表则查询org表,
|
//如果依然找不到则查询system_org是否存在
|
||||||
|
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||||
|
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||||
|
//比如表sys_user 字段org_id,查询不到sys_org表则查询org表,org表查询不到则查询默认前缀system_org表
|
||||||
//都查询不到则找不到,
|
//都查询不到则找不到,
|
||||||
prefix := strings.Index(fk, "_")
|
prefix := strings.Index(fk, "_")
|
||||||
tableName := oldTableName
|
tableName := oldTableName
|
||||||
if prefix > 0 {
|
if prefix > 0 {
|
||||||
//表模块前缀
|
//表模块前缀sys_user sys即为前缀 sys_org
|
||||||
tableName = fk[:prefix+1] + oldTableName
|
tableName = fk[:prefix+1] + oldTableName
|
||||||
if that.TableConfig[tableName] == nil {
|
if that.TableConfig[tableName] == nil {
|
||||||
|
//不存在则改为org
|
||||||
tableName = oldTableName
|
tableName = oldTableName
|
||||||
}
|
}
|
||||||
//表前缀+去除字段前缀
|
//表前缀+去除字段前缀
|
||||||
@ -350,11 +364,15 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
|
|||||||
//如果数据匹配则写入到配置中
|
//如果数据匹配则写入到配置中
|
||||||
if that.TableConfig[tableName] != nil {
|
if that.TableConfig[tableName] != nil {
|
||||||
v["link"] = tableName
|
v["link"] = tableName
|
||||||
//一般查询name字段,如果没有name字段则默认第二个地段
|
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
|
||||||
if that.TableColumns[tableName]["name"] != nil {
|
if that.TableColumns[tableName]["name"] != nil {
|
||||||
v["value"] = tableName + "." + "name"
|
v["value"] = tableName + "." + "name"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if that.TableColumns[tableName]["label"] != nil {
|
||||||
|
v["value"] = tableName + "." + "label"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||||
v["value"] = tableName + "." + that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
v["value"] = tableName + "." + that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||||
|
@ -106,12 +106,12 @@ func (that *HoTimeDB) PageSelect(table string, qu ...interface{}) []Map {
|
|||||||
qu = append(qu, Map{"LIMIT": that.limit})
|
qu = append(qu, Map{"LIMIT": that.limit})
|
||||||
}
|
}
|
||||||
if len(qu) == 2 {
|
if len(qu) == 2 {
|
||||||
temp := qu[1].(Map)
|
temp := DeepCopyMap(qu[1]).(Map)
|
||||||
temp["LIMIT"] = that.limit
|
temp["LIMIT"] = that.limit
|
||||||
qu[1] = temp
|
qu[1] = temp
|
||||||
}
|
}
|
||||||
if len(qu) == 3 {
|
if len(qu) == 3 {
|
||||||
temp := qu[2].(Map)
|
temp := DeepCopyMap(qu[2]).(Map)
|
||||||
temp["LIMIT"] = that.limit
|
temp["LIMIT"] = that.limit
|
||||||
qu[2] = temp
|
qu[2] = temp
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user