修复部分bug,增加DB SUM函数,以及优化IN性能,增加分析接口

This commit is contained in:
hoteas
2023-03-10 15:22:03 +08:00
parent 734d1b4be9
commit 68ea5d5203
4 changed files with 432 additions and 21 deletions
+168
View File
@@ -8,6 +8,7 @@ import (
"io/ioutil"
"net/http"
"os"
"sort"
"strings"
"time"
)
@@ -686,6 +687,173 @@ var TptProject = Proj{
that.Display(0, Map{"count": count, "data": reData})
},
"analyse": func(that *Context) {
hotimeName := that.RouterString[0]
//hotimeName := "super"
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
tableName := that.RouterString[1]
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
where := Map{}
//树状结构不允许修改自身的属性,修改别人的可以
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
if err != nil {
that.Display(4, "找不到权限配置文件")
return
}
conf := ObjToMap(string(btes))
//相同则
//if tableName!=fileConfig.GetString("table"){
flow := conf.GetMap("flow").GetMap(tableName)
if flow != nil && flow.GetMap("sql") != nil {
sql := ObjToMap(DeepCopyMap(flow.GetMap("sql")))
for k, _ := range sql {
//for uk,_:=range data{
// if sql[uk]==nil{
// continue
// }
// uv:=data.GetString(uk)
//
// tv:=strings.Replace(sql.GetString(uk),uk,uv,-1)
// if tv!=uv{
// where[k]=tv
// break
// }
//}
if k == "parent_ids[~]" && tableName == fileConfig.GetString("table") {
where[k] = strings.Replace(sql.GetString(k), "id", data.GetString("id"), -1)
continue
}
if k == "parent_ids[~]" && data[tableName+"_id"] != nil {
where[k] = strings.Replace(sql.GetString(k), tableName+"_id", data.GetString(tableName+"_id"), -1)
continue
}
if data[sql.GetString(k)] != nil {
where[k] = data[sql.GetString(k)]
}
}
}
//}
_, where = that.MakeCodeRouter[hotimeName].Search(tableName, data, where, that.Req, that.Db)
delete(where, "ORDER")
//page := ObjToInt(that.Req.FormValue("page"))
//pageSize := ObjToInt(that.Req.FormValue("pageSize"))
//download := ObjToInt(that.Req.FormValue("download"))
//
//if page < 1 {
// page = 1
//}
//
//if pageSize <= 0 {
// pageSize = 20
//}
redData := Map{}
data["count"] = that.Db.Count(tableName, where)
testQu := []string{}
testQuData := that.MakeCodeRouter[hotimeName].TableColumns[tableName]
for key, _ := range testQuData {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := testQuData[k]
//不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") {
continue
}
if strings.Contains(k, "state") {
continue
}
if strings.Contains(k, "scope") {
continue
}
if strings.Contains(k, "_code") {
continue
}
//检索查询
if v.GetString("type") == "select" {
ops := v.GetSlice("options")
for k1, _ := range ops {
v1 := ops.GetMap(k1)
where1 := DeepCopyMap(where).(Map)
if where1["AND"] != nil {
and := where1.GetMap("AND")
and[k] = v1.GetString("value")
} else {
where1[k] = v1.GetString("value")
where1 = Map{"AND": where1}
}
v1["count"] = that.Db.Count(tableName, where1)
ops[k1] = v1
}
redData[k] = ops
}
//检索查询
if v.GetString("type") == "number" {
if strings.Contains(k, "area_id") {
areas := that.Db.Select("area", "id,name", Map{"parent_id": 533301})
for ak, av := range areas {
where1 := DeepCopyMap(where).(Map)
if where1["AND"] != nil {
and := where1.GetMap("AND")
and["area_id"] = av.GetCeilInt64("id")
} else {
where1["area_id"] = av.GetCeilInt64("id")
where1 = Map{"AND": where1}
}
av["count"] = that.Db.Count(tableName, where1)
areas[ak] = av
}
redData["area"] = areas
continue
}
if strings.Contains(k, "_id") {
continue
}
if k == "id" {
continue
}
if strings.Contains(k, "percent") {
continue
}
if strings.Contains(k, "exp_") {
continue
}
if strings.Contains(k, "side") {
continue
}
if strings.Contains(k, "lat") {
continue
}
if strings.Contains(k, "lng") {
continue
}
if strings.Contains(k, "distance") {
continue
}
where1 := DeepCopyMap(where).(Map)
redData[k] = that.Db.Sum(tableName, k, where1)
}
}
that.Display(0, redData)
},
},
"hotime": Ctr{
"file": func(that *Context) {