Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c55e26021b | |||
| 78420a692f | |||
| 6d9af149ad | |||
| 253cad35ef | |||
| 47c8736f34 | |||
| dcce8ace9e | |||
| 125ccc5c3b | |||
| 432d59d483 | |||
| 60f222b011 | |||
| 7a8b86ed12 | |||
| b940afa6b0 | |||
| 8afd00ff86 | |||
| 8992fd6d3a |
+2
-7
@@ -566,14 +566,9 @@ func Init(config string) *Application {
|
|||||||
codeMake["name"] = codeMake.GetString("table")
|
codeMake["name"] = codeMake.GetString("table")
|
||||||
}
|
}
|
||||||
|
|
||||||
if appIns.Config.GetInt("mode") > 0 {
|
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||||
|
|
||||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
|
||||||
} else {
|
|
||||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
|
||||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
|
|
||||||
}
|
|
||||||
//接入动态代码层
|
//接入动态代码层
|
||||||
if appIns.Router == nil {
|
if appIns.Router == nil {
|
||||||
appIns.Router = Router{}
|
appIns.Router = Router{}
|
||||||
|
|||||||
@@ -675,11 +675,15 @@ var TptProject = Proj{
|
|||||||
where := Map{"name": name}
|
where := Map{"name": name}
|
||||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||||
where["phone"] = name
|
where["phone"] = name
|
||||||
where = Map{"AND": Map{"OR": where, "password": Md5(password)}}
|
where = Map{"OR": where, "password": Md5(password)}
|
||||||
} else {
|
} else {
|
||||||
where["password"] = Md5(password)
|
where["password"] = Md5(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(where) > 1 {
|
||||||
|
where = Map{"AND": where}
|
||||||
|
}
|
||||||
|
|
||||||
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
@@ -776,16 +780,24 @@ var TptProject = Proj{
|
|||||||
name = v2.GetString("table")
|
name = v2.GetString("table")
|
||||||
}
|
}
|
||||||
if v2["auth"] != nil {
|
if v2["auth"] != nil {
|
||||||
newAuth := Slice{}
|
|
||||||
for k3, _ := range linkAuth.GetSlice(name) {
|
|
||||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
|
||||||
if strings.Contains(v2.GetString("auth"), v3) {
|
|
||||||
newAuth = append(newAuth, v3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
linkAuth[name] = newAuth
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if linkAuth[name] == nil {
|
||||||
|
linkAuth[name] = v2["auth"]
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
newAuth := Slice{}
|
||||||
|
for k3, _ := range linkAuth.GetSlice(name) {
|
||||||
|
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||||
|
if strings.Contains(v2.GetString("auth"), v3) {
|
||||||
|
newAuth = append(newAuth, v3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linkAuth[name] = newAuth
|
||||||
|
continue
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+152
-125
@@ -43,20 +43,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
|||||||
that.Config = DeepCopyMap(Config).(Map)
|
that.Config = DeepCopyMap(Config).(Map)
|
||||||
|
|
||||||
that.Config["name"] = config.GetString("table")
|
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"))
|
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||||
that.RuleConfig = []Map{}
|
that.RuleConfig = []Map{}
|
||||||
@@ -147,7 +133,8 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
|||||||
"auth": []string{"show", "add", "delete", "edit", "info", "download"},
|
"auth": []string{"show", "add", "delete", "edit", "info", "download"},
|
||||||
"columns": []Map{},
|
"columns": []Map{},
|
||||||
"search": []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": "keyword", "label": "请输入关键词", "value": nil},
|
||||||
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||||
{"type": "search", "name": "sort", "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 {
|
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 !isMenusGet {
|
||||||
//if !hasConfigFile {
|
//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")}
|
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 {
|
if !isNewPrefix {
|
||||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||||
prefixName = DefaultMenuParentName
|
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 {
|
if that.IndexMenus[prefixName] != nil {
|
||||||
@@ -399,103 +371,129 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
|||||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
|
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||||
for k, v := range fv {
|
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 &&
|
if that.SearchColumns[fk][v.GetString("name")] == nil &&
|
||||||
v.GetString("type") == "select" {
|
v.GetString("type") == "select" {
|
||||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
//search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||||
sv := DeepCopyMap(v).(Map)
|
sv := DeepCopyMap(v).(Map)
|
||||||
sv["value"] = nil
|
sv["value"] = nil
|
||||||
sv["options"] = append(sv.GetSlice("options"), Map{"name": "全部", "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
|
that.SearchColumns[fk][k] = sv
|
||||||
}
|
}
|
||||||
|
|
||||||
//虚招后缀是_id结尾的表字段 假设org_id
|
//搜索关键字
|
||||||
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
if strings.Contains(v.GetString("type"), "text") || v.GetString("name") == "id" {
|
||||||
continue
|
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
|
if v.GetString("link") != "" &&
|
||||||
oldTableName := k[:len(k)-3]
|
v.GetString("name") != "parent_id" {
|
||||||
//上级ID匹配
|
|
||||||
if oldTableName == "parent" {
|
|
||||||
oldTableName = fk
|
|
||||||
}
|
|
||||||
//如果本身匹配则不再继续精简匹配
|
|
||||||
if that.TableConfig[oldTableName] == nil {
|
|
||||||
|
|
||||||
//如果依然找不到则查询system_org是否存在
|
keyWordSearchData := search.GetMap(0)
|
||||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
name := strings.Replace(that.TableConfig.GetMap(v.GetString("link")).GetString("label"), "管理", "", -1)
|
||||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": name, "value": v.GetString("name")})
|
||||||
}
|
search[0] = keyWordSearchData
|
||||||
|
|
||||||
//字段有动词前缀,自动进行解析
|
|
||||||
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表
|
if strings.Contains(v.GetString("type"), "time") {
|
||||||
//都查询不到则找不到,
|
daterangeData := search.GetMap(1)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//如果数据匹配则写入到配置中
|
daterangeData["options"] = append(daterangeData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
|
||||||
if that.TableConfig[tableName] != nil {
|
search[1] = daterangeData
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,6 +785,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
|||||||
hasUser := false
|
hasUser := false
|
||||||
|
|
||||||
keywordStr := req.FormValue("keyword")
|
keywordStr := req.FormValue("keyword")
|
||||||
|
keywordTableStr := req.FormValue("keywordtable")
|
||||||
|
daterangeTableStr := req.FormValue("daterangetable")
|
||||||
|
|
||||||
testQu := []string{}
|
testQu := []string{}
|
||||||
testQuData := that.TableColumns[table]
|
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" {
|
if v.GetString("type") == "unixtime" {
|
||||||
//fmt.Println(req.Form["daterange"])
|
|
||||||
if len(req.Form[v.GetString("name")]) == 1 {
|
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
|
||||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
if len(req.Form[v.GetString("name")]) == 1 {
|
||||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
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" {
|
if v.GetString("type") == "time" {
|
||||||
//fmt.Println(req.Form["daterange"])
|
//fmt.Println(req.Form["daterange"])
|
||||||
|
if daterangeTableStr == "" || v.GetString("name") == daterangeTableStr {
|
||||||
|
|
||||||
if len(req.Form[v.GetString("name")]) == 1 {
|
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")
|
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 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" {
|
if v.GetString("type") == "text" {
|
||||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||||
|
|
||||||
|
|||||||
+113
-28
@@ -70,7 +70,21 @@ func (that *HotimeDBBuilder) Select(qu ...interface{}) []Map {
|
|||||||
return that.HoTimeDB.Select(that.table, that.join, qu, that.where)
|
return that.HoTimeDB.Select(that.table, that.join, qu, that.where)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *HotimeDBBuilder) Update(data Map) int64 {
|
func (that *HotimeDBBuilder) Update(qu ...interface{}) int64 {
|
||||||
|
lth := len(qu)
|
||||||
|
if lth == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
data := Map{}
|
||||||
|
if lth == 1 {
|
||||||
|
data = ObjToMap(qu[0])
|
||||||
|
}
|
||||||
|
if lth > 1 {
|
||||||
|
for k := 1; k < lth; k++ {
|
||||||
|
data[ObjToStr(qu[k-1])] = qu[k]
|
||||||
|
k++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return that.HoTimeDB.Update(that.table, data, that.where)
|
return that.HoTimeDB.Update(that.table, data, that.where)
|
||||||
}
|
}
|
||||||
@@ -101,19 +115,51 @@ func (that *HotimeDBBuilder) FullJoin(table, joinStr string) *HotimeDBBuilder {
|
|||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *HotimeDBBuilder) Join(join Map) *HotimeDBBuilder {
|
func (that *HotimeDBBuilder) Join(qu ...interface{}) *HotimeDBBuilder {
|
||||||
|
lth := len(qu)
|
||||||
|
if lth == 0 {
|
||||||
|
return that
|
||||||
|
}
|
||||||
|
data := Map{}
|
||||||
|
if lth == 1 {
|
||||||
|
data = ObjToMap(qu[0])
|
||||||
|
}
|
||||||
|
if lth > 1 {
|
||||||
|
for k := 1; k < lth; k++ {
|
||||||
|
data[ObjToStr(qu[k-1])] = qu[k]
|
||||||
|
k++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if that.join == nil {
|
if that.join == nil {
|
||||||
that.join = Slice{}
|
that.join = Slice{}
|
||||||
}
|
}
|
||||||
if join == nil {
|
if data == nil {
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
that.join = append(that.join, join)
|
that.join = append(that.join, data)
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder {
|
func (that *HotimeDBBuilder) And(qu ...interface{}) *HotimeDBBuilder {
|
||||||
|
|
||||||
|
lth := len(qu)
|
||||||
|
if lth == 0 {
|
||||||
|
return that
|
||||||
|
}
|
||||||
|
var where Map
|
||||||
|
if lth == 1 {
|
||||||
|
where = ObjToMap(qu[0])
|
||||||
|
}
|
||||||
|
if lth > 1 {
|
||||||
|
where = Map{}
|
||||||
|
for k := 1; k < lth; k++ {
|
||||||
|
where[ObjToStr(qu[k-1])] = qu[k]
|
||||||
|
k++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if where == nil {
|
if where == nil {
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
@@ -129,7 +175,22 @@ func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder {
|
|||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder {
|
func (that *HotimeDBBuilder) Or(qu ...interface{}) *HotimeDBBuilder {
|
||||||
|
lth := len(qu)
|
||||||
|
if lth == 0 {
|
||||||
|
return that
|
||||||
|
}
|
||||||
|
var where Map
|
||||||
|
if lth == 1 {
|
||||||
|
where = ObjToMap(qu[0])
|
||||||
|
}
|
||||||
|
if lth > 1 {
|
||||||
|
where = Map{}
|
||||||
|
for k := 1; k < lth; k++ {
|
||||||
|
where[ObjToStr(qu[k-1])] = qu[k]
|
||||||
|
k++
|
||||||
|
}
|
||||||
|
}
|
||||||
if where == nil {
|
if where == nil {
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
@@ -144,7 +205,24 @@ func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder {
|
|||||||
|
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
func (that *HotimeDBBuilder) Where(where Map) *HotimeDBBuilder {
|
func (that *HotimeDBBuilder) Where(qu ...interface{}) *HotimeDBBuilder {
|
||||||
|
|
||||||
|
lth := len(qu)
|
||||||
|
if lth == 0 {
|
||||||
|
return that
|
||||||
|
}
|
||||||
|
var where Map
|
||||||
|
if lth == 1 {
|
||||||
|
where = ObjToMap(qu[0])
|
||||||
|
}
|
||||||
|
if lth > 1 {
|
||||||
|
where = Map{}
|
||||||
|
for k := 1; k < lth; k++ {
|
||||||
|
where[ObjToStr(qu[k-1])] = qu[k]
|
||||||
|
k++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if where == nil {
|
if where == nil {
|
||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
@@ -193,7 +271,11 @@ func (that *HoTimeDB) GetType() string {
|
|||||||
|
|
||||||
// Action 事务,如果action返回true则执行成功;false则回滚
|
// Action 事务,如果action返回true则执行成功;false则回滚
|
||||||
func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
|
func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
|
||||||
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
|
db := HoTimeDB{that.DB, that.ContextBase, that.DBName,
|
||||||
|
that.HoTimeCache, that.Log, that.Type,
|
||||||
|
that.Prefix, that.LastQuery, that.LastData,
|
||||||
|
that.ConnectFunc, that.LastErr, that.limit, that.Tx,
|
||||||
|
that.SlaveDB, that.Mode}
|
||||||
tx, err := db.Begin()
|
tx, err := db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
that.LastErr.SetError(err)
|
that.LastErr.SetError(err)
|
||||||
@@ -236,7 +318,7 @@ func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
|||||||
e := that.SlaveDB.Ping()
|
e := that.SlaveDB.Ping()
|
||||||
that.LastErr.SetError(e)
|
that.LastErr.SetError(e)
|
||||||
}
|
}
|
||||||
|
//that.DB.SetConnMaxLifetime(time.Second)
|
||||||
return that.LastErr
|
return that.LastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,7 +538,7 @@ func (that *HoTimeDB) md5(query string, args ...interface{}) string {
|
|||||||
|
|
||||||
func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||||
defer func() {
|
defer func() {
|
||||||
if that.Mode == 2 {
|
if that.Mode != 0 {
|
||||||
that.Log.Info("SQL:"+that.LastQuery, " DATA:", that.LastData, " ERROR:", that.LastErr.GetError())
|
that.Log.Info("SQL:"+that.LastQuery, " DATA:", that.LastData, " ERROR:", that.LastErr.GetError())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -484,16 +566,18 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
|||||||
resl, err = db.Query(query, args...)
|
resl, err = db.Query(query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil && that.LastErr.GetError() != nil &&
|
||||||
|
that.LastErr.GetError().Error() == err.Error() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
that.LastErr.SetError(err)
|
that.LastErr.SetError(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err = db.Ping(); err != nil {
|
|
||||||
that.LastErr.SetError(err)
|
if err = db.Ping(); err == nil {
|
||||||
_ = that.InitDb()
|
|
||||||
if that.LastErr.GetError() != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return that.Query(query, args...)
|
return that.Query(query, args...)
|
||||||
}
|
}
|
||||||
|
that.LastErr.SetError(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,7 +586,7 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
|||||||
|
|
||||||
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
|
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if that.Mode == 2 {
|
if that.Mode != 0 {
|
||||||
that.Log.Info("SQL: "+that.LastQuery, " DATA: ", that.LastData, " ERROR: ", that.LastErr.GetError())
|
that.Log.Info("SQL: "+that.LastQuery, " DATA: ", that.LastData, " ERROR: ", that.LastErr.GetError())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -523,19 +607,18 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
|||||||
resl, e = that.DB.Exec(query, args...)
|
resl, e = that.DB.Exec(query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e != nil && that.LastErr.GetError() != nil &&
|
||||||
|
that.LastErr.GetError().Error() == e.Error() {
|
||||||
|
return resl, that.LastErr
|
||||||
|
}
|
||||||
that.LastErr.SetError(e)
|
that.LastErr.SetError(e)
|
||||||
|
|
||||||
//判断是否连接断开了
|
//判断是否连接断开了
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
|
||||||
if e = that.DB.Ping(); e != nil {
|
if e = that.DB.Ping(); e == nil {
|
||||||
that.LastErr.SetError(e)
|
|
||||||
_ = that.InitDb()
|
|
||||||
if that.LastErr.GetError() != nil {
|
|
||||||
return resl, that.LastErr
|
|
||||||
}
|
|
||||||
return that.Exec(query, args...)
|
return that.Exec(query, args...)
|
||||||
}
|
}
|
||||||
|
that.LastErr.SetError(e)
|
||||||
return resl, that.LastErr
|
return resl, that.LastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,11 +665,13 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
|||||||
data := ObjToSlice(qu[intQs])
|
data := ObjToSlice(qu[intQs])
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
k := data.GetString(i)
|
k := data.GetString(i)
|
||||||
if strings.Contains(k, " AS ") {
|
if strings.Contains(k, " AS ") ||
|
||||||
|
strings.Contains(k, ".") {
|
||||||
|
|
||||||
query += " " + k + " "
|
query += " " + k + " "
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
query += " `" + k + "` "
|
query += " `" + k + "` "
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,9 +703,9 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if reflect.ValueOf(qu[0]).Type().String() == "common.Slice" {
|
if reflect.ValueOf(qu[0]).Type().String() == "common.Slice" {
|
||||||
|
qu0 := ObjToSlice(qu[0])
|
||||||
for key, _ := range testQuData {
|
for key, _ := range qu0 {
|
||||||
v := testQuData.GetMap(key)
|
v := qu0.GetMap(key)
|
||||||
for k1, v1 := range v {
|
for k1, v1 := range v {
|
||||||
testQu = append(testQu, k1)
|
testQu = append(testQu, k1)
|
||||||
testQuData[k1] = v1
|
testQuData[k1] = v1
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
"name": "dgs-cms",
|
"name": "dgs-cms",
|
||||||
"password": "dasda8454456",
|
"password": "dasda8454456",
|
||||||
"port": "3306",
|
"port": "3306",
|
||||||
"prefix": "",
|
|
||||||
"user": "root"
|
"user": "root"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
. "code.hoteas.com/golang/hotime"
|
. "code.hoteas.com/golang/hotime"
|
||||||
"code.hoteas.com/golang/hotime/example/app"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -13,6 +12,6 @@ func main() {
|
|||||||
return isFinished
|
return isFinished
|
||||||
})
|
})
|
||||||
|
|
||||||
appIns.Run(Router{"app": app.AppProj})
|
appIns.Run(Router{})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user