forked from golang/hotime
检索升级
This commit is contained in:
parent
6d9af149ad
commit
78420a692f
123
code/makecode.go
123
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,24 +371,11 @@ 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 {
|
||||
|
||||
//搜索服务
|
||||
if that.SearchColumns[fk][v.GetString("name")] == nil &&
|
||||
v.GetString("type") == "select" {
|
||||
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)
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
//虚招后缀是_id结尾的表字段 假设org_id
|
||||
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
||||
continue
|
||||
}
|
||||
if !(len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3) {
|
||||
//普通表匹配 org_id匹配为org
|
||||
oldTableName := k[:len(k)-3]
|
||||
//上级ID匹配
|
||||
@ -500,6 +459,45 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//搜索服务
|
||||
if that.SearchColumns[fk][v.GetString("name")] == nil &&
|
||||
v.GetString("type") == "select" {
|
||||
//search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
sv := DeepCopyMap(v).(Map)
|
||||
sv["value"] = nil
|
||||
sv["options"] = append(sv.GetSlice("options"), Map{"name": "全部", "value": nil})
|
||||
search = append(search, sv)
|
||||
that.TableConfig.GetMap(fk)["search"] = search
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
//搜索关键字
|
||||
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
|
||||
}
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
//搜索时间
|
||||
if strings.Contains(v.GetString("type"), "time") {
|
||||
daterangeData := search.GetMap(1)
|
||||
|
||||
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,16 +899,22 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
if v.GetString("type") == "unixtime" {
|
||||
//fmt.Println(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")
|
||||
@ -920,9 +926,30 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
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