diff --git a/code/config.go b/code/config.go index c5c02f8..4af2e2e 100644 --- a/code/config.go +++ b/code/config.go @@ -23,7 +23,7 @@ var Config = Map{ //}, }, } -var DefaultMenuParentName = "system" +var DefaultMenuParentName = "sys" var ColumnDataType = map[string]string{ //sqlite专有类型 diff --git a/code/makecode.go b/code/makecode.go index dbd6275..0599191 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -311,30 +311,44 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { } for k, v := range fv { - //虚招后缀是_id结尾的表字段 + //虚招后缀是_id结尾的表字段 假设org_id if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 { continue } - //普通表匹配 + //普通表匹配 org_id匹配为org oldTableName := k[:len(k)-3] //上级ID匹配 if oldTableName == "parent" { oldTableName = fk } + + //如果依然找不到则查询system_org是否存在 + if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil { + oldTableName = DefaultMenuParentName + "_" + oldTableName + } + //字段有动词前缀,自动进行解析 prefixColumn := strings.Index(oldTableName, "_") + //sys_org_id oldTableName即为sys此处判断为org表存在 if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil { 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, "_") tableName := oldTableName if prefix > 0 { - //表模块前缀 + //表模块前缀sys_user sys即为前缀 sys_org tableName = fk[:prefix+1] + oldTableName if that.TableConfig[tableName] == nil { + //不存在则改为org tableName = oldTableName } //表前缀+去除字段前缀 @@ -350,11 +364,15 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { //如果数据匹配则写入到配置中 if that.TableConfig[tableName] != nil { v["link"] = tableName - //一般查询name字段,如果没有name字段则默认第二个地段 + //一般查询name字段或者label字段,如果没有name字段则默认第二个地段 if that.TableColumns[tableName]["name"] != nil { v["value"] = tableName + "." + "name" break } + if that.TableColumns[tableName]["label"] != nil { + v["value"] = tableName + "." + "label" + break + } if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 { v["value"] = tableName + "." + that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name") diff --git a/db/hotimedb.go b/db/hotimedb.go index a3d6c28..e77cc96 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -106,12 +106,12 @@ func (that *HoTimeDB) PageSelect(table string, qu ...interface{}) []Map { qu = append(qu, Map{"LIMIT": that.limit}) } if len(qu) == 2 { - temp := qu[1].(Map) + temp := DeepCopyMap(qu[1]).(Map) temp["LIMIT"] = that.limit qu[1] = temp } if len(qu) == 3 { - temp := qu[2].(Map) + temp := DeepCopyMap(qu[2]).(Map) temp["LIMIT"] = that.limit qu[2] = temp }