检索升级
This commit is contained in:
parent
6d9af149ad
commit
78420a692f
277
code/makecode.go
277
code/makecode.go
@ -43,20 +43,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.Config = DeepCopyMap(Config).(Map)
|
||||
|
||||
that.Config["name"] = config.GetString("table")
|
||||
//if err == nil {
|
||||
// cmap := Map{}
|
||||
// //文件是否损坏
|
||||
// cmap.JsonToMap(string(btes), &that.Error)
|
||||
// for k, v := range cmap {
|
||||
// that.Config[k] = v //程序配置
|
||||
// //Config[k] = v //系统配置
|
||||
// }
|
||||
// hasConfigFile = true
|
||||
//} else {
|
||||
//
|
||||
// that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
//
|
||||
//}
|
||||
//加载规则文件
|
||||
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||
that.RuleConfig = []Map{}
|
||||
@ -147,7 +133,8 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
"auth": []string{"show", "add", "delete", "edit", "info", "download"},
|
||||
"columns": []Map{},
|
||||
"search": []Map{
|
||||
|
||||
{"type": "search", "name": "keywordtable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
|
||||
{"type": "search", "name": "daterangetable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
|
||||
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
||||
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||
@ -332,21 +319,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
//数据生成完后进一步解析
|
||||
for fk, fv := range that.TableColumns {
|
||||
|
||||
//判断是否将表写入menu中
|
||||
//isMenusGet := false //判断是否被目录收录
|
||||
//for indexKey, _ := range that.IndexMenus {
|
||||
// indexCode := strings.Index(indexKey, fk)
|
||||
// if indexCode == 0 || indexCode == 4 {
|
||||
// isMenusGet = false
|
||||
// continue
|
||||
// }
|
||||
// //如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||
// if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||
// isMenusGet = true
|
||||
// break
|
||||
// }
|
||||
//}
|
||||
|
||||
//目录没有收录
|
||||
//if !isMenusGet {
|
||||
//if !hasConfigFile {
|
||||
@ -373,12 +345,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk, "auth": that.TableConfig.GetMap(fk).GetSlice("auth")}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
mMenu := Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "Setting"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
mMenu = Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": "系统管理", "name": prefixName, "icon": "Setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
@ -399,103 +371,129 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
}
|
||||
//}
|
||||
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
for k, v := range fv {
|
||||
|
||||
//虚招后缀是_id结尾的表字段 假设org_id
|
||||
if !(len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3) {
|
||||
//普通表匹配 org_id匹配为org
|
||||
oldTableName := k[:len(k)-3]
|
||||
//上级ID匹配
|
||||
if oldTableName == "parent" {
|
||||
oldTableName = fk
|
||||
}
|
||||
//如果本身匹配则不再继续精简匹配
|
||||
if that.TableConfig[oldTableName] == nil {
|
||||
|
||||
//如果依然找不到则查询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:]
|
||||
}
|
||||
if prefixColumn >= len(oldTableName) {
|
||||
prefixColumn = -1
|
||||
}
|
||||
//如果依然找不到则查询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 || that.TableConfig[oldTableName] != nil {
|
||||
//不存在则改为org
|
||||
tableName = oldTableName
|
||||
}
|
||||
//表前缀+去除字段前缀
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
if prefixColumn > -1 {
|
||||
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
|
||||
if that.TableConfig[tableName] == nil {
|
||||
tableName = oldTableName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果数据匹配则写入到配置中
|
||||
if that.TableConfig[tableName] != nil {
|
||||
v["link"] = tableName
|
||||
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
|
||||
if that.TableColumns[tableName]["name"] != nil {
|
||||
v["value"] = "name"
|
||||
continue
|
||||
}
|
||||
if that.TableColumns[tableName]["label"] != nil {
|
||||
v["value"] = "label"
|
||||
continue
|
||||
}
|
||||
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
|
||||
isGet := true
|
||||
for k2, _ := range tempC {
|
||||
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
|
||||
v["value"] = tempC.GetMap(k2).GetString("name")
|
||||
isGet = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//搜索服务
|
||||
if that.SearchColumns[fk][v.GetString("name")] == nil &&
|
||||
v.GetString("type") == "select" {
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
//search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
sv := DeepCopyMap(v).(Map)
|
||||
sv["value"] = nil
|
||||
sv["options"] = append(sv.GetSlice("options"), Map{"name": "全部", "value": nil})
|
||||
that.TableConfig.GetMap(fk)["search"] = append(search, sv)
|
||||
search = append(search, sv)
|
||||
that.TableConfig.GetMap(fk)["search"] = search
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
//虚招后缀是_id结尾的表字段 假设org_id
|
||||
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
||||
continue
|
||||
//搜索关键字
|
||||
if strings.Contains(v.GetString("type"), "text") || v.GetString("name") == "id" {
|
||||
keyWordSearchData := search.GetMap(0)
|
||||
|
||||
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
|
||||
search[0] = keyWordSearchData
|
||||
}
|
||||
//普通表匹配 org_id匹配为org
|
||||
oldTableName := k[:len(k)-3]
|
||||
//上级ID匹配
|
||||
if oldTableName == "parent" {
|
||||
oldTableName = fk
|
||||
}
|
||||
//如果本身匹配则不再继续精简匹配
|
||||
if that.TableConfig[oldTableName] == nil {
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
|
||||
//如果依然找不到则查询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:]
|
||||
}
|
||||
if prefixColumn >= len(oldTableName) {
|
||||
prefixColumn = -1
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||
}
|
||||
keyWordSearchData := search.GetMap(0)
|
||||
name := strings.Replace(that.TableConfig.GetMap(v.GetString("link")).GetString("label"), "管理", "", -1)
|
||||
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": name, "value": v.GetString("name")})
|
||||
search[0] = keyWordSearchData
|
||||
}
|
||||
|
||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||
//比如表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 || that.TableConfig[oldTableName] != nil {
|
||||
//不存在则改为org
|
||||
tableName = oldTableName
|
||||
}
|
||||
//表前缀+去除字段前缀
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
if prefixColumn > -1 {
|
||||
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
|
||||
if that.TableConfig[tableName] == nil {
|
||||
tableName = oldTableName
|
||||
}
|
||||
}
|
||||
}
|
||||
//搜索时间
|
||||
if strings.Contains(v.GetString("type"), "time") {
|
||||
daterangeData := search.GetMap(1)
|
||||
|
||||
//如果数据匹配则写入到配置中
|
||||
if that.TableConfig[tableName] != nil {
|
||||
v["link"] = tableName
|
||||
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
|
||||
if that.TableColumns[tableName]["name"] != nil {
|
||||
v["value"] = "name"
|
||||
continue
|
||||
}
|
||||
if that.TableColumns[tableName]["label"] != nil {
|
||||
v["value"] = "label"
|
||||
continue
|
||||
}
|
||||
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
|
||||
isGet := true
|
||||
for k2, _ := range tempC {
|
||||
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
|
||||
v["value"] = tempC.GetMap(k2).GetString("name")
|
||||
isGet = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||
continue
|
||||
}
|
||||
daterangeData["options"] = append(daterangeData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
|
||||
search[1] = daterangeData
|
||||
|
||||
}
|
||||
|
||||
@ -787,6 +785,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
hasUser := false
|
||||
|
||||
keywordStr := req.FormValue("keyword")
|
||||
keywordTableStr := req.FormValue("keywordtable")
|
||||
daterangeTableStr := req.FormValue("daterangetable")
|
||||
|
||||
testQu := []string{}
|
||||
testQuData := that.TableColumns[table]
|
||||
@ -899,30 +899,57 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
if v.GetString("type") == "unixtime" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
|
||||
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
}
|
||||
}
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue(v.GetString("name"))), 0).Format("2006-01-02 15:04:05")
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue(v.GetString("name"))), 0).Format("2006-01-02 15:04:05")
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = t
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = t
|
||||
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
t1 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][0]), 0).Format("2006-01-02 15:04:05")
|
||||
t2 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][1]), 0).Format("2006-01-02 15:04:05")
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
|
||||
}
|
||||
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
t1 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][0]), 0).Format("2006-01-02 15:04:05")
|
||||
t2 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][1]), 0).Format("2006-01-02 15:04:05")
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
|
||||
}
|
||||
}
|
||||
|
||||
if keywordStr != "" {
|
||||
if keywordTableStr == v.GetString("name") {
|
||||
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr
|
||||
}
|
||||
|
||||
if keywordTableStr == v.GetString("value") {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
}
|
||||
|
||||
if keywordTableStr != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.GetString("type") == "text" {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user