Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 253cad35ef | |||
| 47c8736f34 | |||
| dcce8ace9e | |||
| 125ccc5c3b | |||
| 432d59d483 | |||
| 60f222b011 | |||
| 7a8b86ed12 | |||
| b940afa6b0 | |||
| 8afd00ff86 | |||
| 8992fd6d3a | |||
| 524a892480 | |||
| c420e23edb | |||
| 7419e03d67 | |||
| 9425544d1c | |||
| a8d78832df | |||
| adfb2236dc | |||
| 6034598bb4 | |||
| 6fe44cb1cb | |||
| 39d67d1775 | |||
| a8f9f12bb8 | |||
| 2c1abb1d11 | |||
| 21e0219568 | |||
| 952c3a1243 | |||
| 33cd7ebd6b | |||
| be02b3418d | |||
| f390617167 | |||
| f7410200e3 | |||
| 9cfdfbac78 | |||
| b015e78fa0 | |||
| bb9092c3e5 | |||
| cc1bad8d3f | |||
| 8f7380d796 | |||
| f37b9aee70 | |||
| 1ab9027c93 | |||
| 96d341aaab | |||
| 1f25f511cc | |||
| 07c7a628d1 | |||
| d7a59845eb |
+2
-1
@@ -1,3 +1,4 @@
|
||||
/.idea/*
|
||||
.idea
|
||||
/example/config/app.json
|
||||
/example/config/app.json
|
||||
/example/tpt/demo/
|
||||
|
||||
+25
-55
@@ -7,8 +7,8 @@ import (
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
. "code.hoteas.com/golang/hotime/log"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -23,7 +23,6 @@ type Application struct {
|
||||
MakeCodeRouter map[string]*code.MakeCode
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
Error
|
||||
Log *logrus.Logger
|
||||
WebConnectLog *logrus.Logger
|
||||
@@ -238,10 +237,8 @@ func (that *Application) SetConfig(configPath ...string) {
|
||||
|
||||
}
|
||||
|
||||
that.Log = GetLog(that.Config.GetString("logFile"), true)
|
||||
that.Error = Error{Logger: that.Log}
|
||||
if that.Config.Get("webConnectLogShow") == nil || that.Config.GetBool("webConnectLogShow") {
|
||||
that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false)
|
||||
if that.Error.GetError() != nil {
|
||||
fmt.Println(that.Error.GetError().Error())
|
||||
}
|
||||
|
||||
//文件如果损坏则不写入配置防止配置文件数据丢失
|
||||
@@ -268,6 +265,12 @@ func (that *Application) SetConfig(configPath ...string) {
|
||||
|
||||
}
|
||||
|
||||
that.Log = GetLog(that.Config.GetString("logFile"), true)
|
||||
that.Error = Error{Logger: that.Log}
|
||||
if that.Config.Get("webConnectLogShow") == nil || that.Config.GetBool("webConnectLogShow") {
|
||||
that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SetConnectListener 连接判断,返回false继续传输至控制层,true则停止传输
|
||||
@@ -563,13 +566,9 @@ func Init(config string) *Application {
|
||||
codeMake["name"] = codeMake.GetString("table")
|
||||
}
|
||||
|
||||
if appIns.Config.GetInt("mode") > 0 {
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
} else {
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
|
||||
}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
|
||||
//接入动态代码层
|
||||
if appIns.Router == nil {
|
||||
appIns.Router = Router{}
|
||||
@@ -616,6 +615,8 @@ func SetMysqlDB(appIns *Application, config Map) {
|
||||
appIns.Db.Type = "mysql"
|
||||
appIns.Db.DBName = config.GetString("name")
|
||||
appIns.Db.Prefix = config.GetString("prefix")
|
||||
appIns.Db.Log = appIns.Log
|
||||
appIns.Db.Mode = appIns.Config.GetCeilInt("mode")
|
||||
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
|
||||
//master数据库配置
|
||||
query := config.GetString("user") + ":" + config.GetString("password") +
|
||||
@@ -645,6 +646,8 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
|
||||
appIns.Db.Type = "sqlite"
|
||||
appIns.Db.Prefix = config.GetString("prefix")
|
||||
appIns.Db.Mode = appIns.Config.GetCeilInt("mode")
|
||||
appIns.Db.Log = appIns.Log
|
||||
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
|
||||
db, e := sql.Open("sqlite3", config.GetString("path"))
|
||||
if e != nil && len(err) != 0 {
|
||||
@@ -660,48 +663,6 @@ func setMakeCodeLintener(name string, appIns *Application) {
|
||||
appIns.SetConnectListener(func(context *Context) (isFinished bool) {
|
||||
|
||||
codeIns := appIns.MakeCodeRouter[name]
|
||||
//文件上传接口
|
||||
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
|
||||
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return true
|
||||
}
|
||||
//读取网络文件
|
||||
fi, fheader, err := context.Req.FormFile("file")
|
||||
if err != nil {
|
||||
context.Display(3, err)
|
||||
return true
|
||||
|
||||
}
|
||||
filePath := context.Config.GetString("filePath")
|
||||
if filePath == "" {
|
||||
filePath = "/file/2006/01/02/"
|
||||
}
|
||||
|
||||
path := time.Now().Format(filePath)
|
||||
e := os.MkdirAll(context.Config.GetString("tpt")+path, os.ModeDir)
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return true
|
||||
}
|
||||
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
||||
newFile, e := os.Create(context.Config.GetString("tpt") + filePath)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return true
|
||||
}
|
||||
|
||||
_, e = io.Copy(newFile, fi)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return true
|
||||
}
|
||||
|
||||
context.Display(0, filePath)
|
||||
return true
|
||||
}
|
||||
|
||||
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
|
||||
return isFinished
|
||||
@@ -715,6 +676,10 @@ func setMakeCodeLintener(name string, appIns *Application) {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return true
|
||||
@@ -732,6 +697,11 @@ func setMakeCodeLintener(name string, appIns *Application) {
|
||||
context.Req.Method != "POST" {
|
||||
return isFinished
|
||||
}
|
||||
//排除已有接口的无效操作
|
||||
if len(context.RouterString) == 3 && context.Router[context.RouterString[0]] != nil && context.Router[context.RouterString[0]][context.RouterString[1]] != nil && context.Router[context.RouterString[0]][context.RouterString[1]][context.RouterString[2]] != nil {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
//列表检索
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
@@ -2,7 +2,13 @@ package hotime
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
@@ -12,8 +18,10 @@ var TptProject = Proj{
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
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()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(tableName, data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) == 1 {
|
||||
@@ -24,7 +32,7 @@ var TptProject = Proj{
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(that.RouterString[1], str, where)
|
||||
re := that.Db.Get(tableName, str, where)
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
@@ -32,7 +40,7 @@ var TptProject = Proj{
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@@ -45,7 +53,7 @@ var TptProject = Proj{
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = that.RouterString[1]
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
@@ -54,7 +62,7 @@ var TptProject = Proj{
|
||||
//如果有table字段则代为link
|
||||
if re["table"] != nil && re["table_id"] != nil {
|
||||
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][re.GetString("table")]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][re.GetString("table")]
|
||||
v := re.GetCeilInt64("table_id")
|
||||
|
||||
seStr := "id," + column.GetString("value")
|
||||
@@ -65,7 +73,7 @@ var TptProject = Proj{
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = that.RouterString[1]
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
|
||||
@@ -74,67 +82,277 @@ var TptProject = Proj{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
that.Log = Map{"table": that.RouterString[1], "type": 1}
|
||||
tableName := that.RouterString[1]
|
||||
that.Log = Map{"table": tableName, "type": 1}
|
||||
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], data, that.Req)
|
||||
inData := that.MakeCodeRouter[hotimeName].Add(tableName, data, that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Insert(that.RouterString[1], inData)
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
if v.GetString("link") != "" {
|
||||
|
||||
if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
if inData["parent_id"] == nil && data[v.GetString("name")] != nil {
|
||||
inData["parent_id"] = data.GetCeilInt64(v.GetString("name"))
|
||||
pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"id": data.GetCeilInt64(v.GetString("name"))})
|
||||
inData["parent_ids"] = pre.GetString("parent_ids")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
|
||||
if linkAuth == nil {
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
if err != nil {
|
||||
that.Display(4, "找不到配置文件")
|
||||
return
|
||||
}
|
||||
linkAuth = Map{}
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
|
||||
}
|
||||
if v1["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
}
|
||||
}
|
||||
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
continue
|
||||
}
|
||||
if v2["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toDB := Map{}
|
||||
newAuth := inData.GetMap("auth")
|
||||
if newAuth == nil {
|
||||
inData["auth"] = linkAuth.ToJsonString()
|
||||
continue
|
||||
}
|
||||
|
||||
for k1, _ := range newAuth {
|
||||
v1 := newAuth.GetSlice(k1)
|
||||
if linkAuth.GetString(k1) == "" {
|
||||
continue
|
||||
}
|
||||
toDbli := Slice{}
|
||||
for k2, _ := range v1 {
|
||||
v2 := v1.GetString(k2)
|
||||
|
||||
if !strings.Contains(linkAuth.GetString(k1), `"`+v2+`"`) {
|
||||
continue
|
||||
}
|
||||
toDbli = append(toDbli, v2)
|
||||
}
|
||||
toDB[k1] = toDbli
|
||||
}
|
||||
|
||||
inData["auth"] = toDB.ToJsonString()
|
||||
//break
|
||||
}
|
||||
}
|
||||
|
||||
re := that.Db.Insert(tableName, inData)
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "无法插入对应数据")
|
||||
return
|
||||
}
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||||
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||||
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
|
||||
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||
} else if inData.GetString("index") != "" {
|
||||
inData["index"] = "," + ObjToStr(re) + ","
|
||||
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||
if inData.Get("parent_id") != nil && inData.GetString("parent_ids") != "" {
|
||||
index := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")})
|
||||
inData["parent_ids"] = index.GetString("parent_ids") + ObjToStr(re) + ","
|
||||
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||
} else if inData.GetString("parent_ids") != "" {
|
||||
inData["parent_ids"] = "," + ObjToStr(re) + ","
|
||||
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||
}
|
||||
that.Log["table_id"] = re
|
||||
that.Display(0, re)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
|
||||
that.Log = Map{"table": that.RouterString[1], "type": 2, "table_id": that.RouterString[2]}
|
||||
tableName := that.RouterString[1]
|
||||
that.Log = Map{"table": tableName, "type": 2, "table_id": that.RouterString[2]}
|
||||
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
|
||||
inData := that.MakeCodeRouter[hotimeName].Edit(tableName, that.Req)
|
||||
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
}
|
||||
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.GetString("index") != "" {
|
||||
if inData.Get("parent_id") != nil {
|
||||
Index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": that.RouterString[2]})
|
||||
parentIndex := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||||
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
|
||||
childNodes := that.Db.Select(that.RouterString[1], "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
//树状结构不允许修改自身的属性,修改别人的可以
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range childNodes {
|
||||
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
|
||||
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
|
||||
}
|
||||
} else {
|
||||
delete(inData, "index")
|
||||
conf := ObjToMap(string(btes))
|
||||
|
||||
stop := conf.GetSlice("stop")
|
||||
for k, _ := range stop {
|
||||
v := stop.GetString(k)
|
||||
//不能改对应行数据
|
||||
if tableName == v && data.GetCeilInt64(v+"_id") == ObjToCeilInt64(that.RouterString[2]) {
|
||||
that.Display(4, "你没有权限修改当前数据")
|
||||
return
|
||||
}
|
||||
//不能改自身对应的数据
|
||||
if tableName == fileConfig.GetString("table") && inData[v+"_id"] != nil {
|
||||
delete(inData, v+"_id")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
|
||||
if inData["auth"] != nil {
|
||||
menus := conf.GetSlice("menus")
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
|
||||
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
|
||||
if linkAuth == nil {
|
||||
|
||||
linkAuth = Map{}
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
continue
|
||||
}
|
||||
if v1["auth"] == nil {
|
||||
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
}
|
||||
}
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
continue
|
||||
}
|
||||
if v2["auth"] == nil {
|
||||
table := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)
|
||||
if table != nil {
|
||||
linkAuth[name] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(name)["auth"]
|
||||
} else {
|
||||
linkAuth[name] = Slice{"show"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toDB := Map{}
|
||||
newAuth := inData.GetMap("auth")
|
||||
if newAuth == nil || len(newAuth) == 0 {
|
||||
inData["auth"] = linkAuth.ToJsonString()
|
||||
break
|
||||
}
|
||||
//不可超出用户权限
|
||||
for k1, _ := range newAuth {
|
||||
v1 := newAuth.GetSlice(k1)
|
||||
if linkAuth.GetString(k1) == "" {
|
||||
continue
|
||||
}
|
||||
toDbli := Slice{}
|
||||
for k2, _ := range v1 {
|
||||
v2 := v1.GetString(k2)
|
||||
if !strings.Contains(linkAuth.GetString(k1), `"`+v2+`"`) {
|
||||
continue
|
||||
}
|
||||
toDbli = append(toDbli, v2)
|
||||
}
|
||||
toDB[k1] = toDbli
|
||||
}
|
||||
|
||||
inData["auth"] = toDB.ToJsonString()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.GetString("parent_ids") != "" {
|
||||
if inData.Get("parent_id") != nil {
|
||||
Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]})
|
||||
parentIndex := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")})
|
||||
inData["parent_ids"] = parentIndex.GetString("parent_ids") + that.RouterString[2] + ","
|
||||
|
||||
childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
|
||||
for _, v := range childNodes {
|
||||
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), inData.GetString("parent_ids"), -1)
|
||||
that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
|
||||
}
|
||||
} else {
|
||||
delete(inData, "parent_ids")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
re := that.Db.Update(tableName, inData, Map{"id": that.RouterString[2]})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "更新数据失败")
|
||||
@@ -144,19 +362,20 @@ var TptProject = Proj{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
that.Log = Map{"table": that.RouterString[1], "type": 3, "table_id": that.RouterString[2]}
|
||||
tableName := that.RouterString[1]
|
||||
that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]}
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(tableName, that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
re := int64(0)
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
||||
re = that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
if inData.Get("parent_id") != nil && inData.GetSlice("parent_ids") != nil {
|
||||
re = that.Db.Delete(tableName, Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
} else {
|
||||
re = that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
||||
}
|
||||
|
||||
if re == 0 {
|
||||
@@ -165,18 +384,19 @@ var TptProject = Proj{
|
||||
}
|
||||
that.Display(0, "删除成功")
|
||||
},
|
||||
|
||||
"search": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
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()})
|
||||
|
||||
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(tableName, data, that.Req, that.Db)
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
download := ObjToInt(that.Req.FormValue("download"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
@@ -185,31 +405,49 @@ var TptProject = Proj{
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||
var count int
|
||||
var reData []Map
|
||||
//是否下载
|
||||
if download == 0 {
|
||||
count = that.Db.Count(tableName, leftJoin, where)
|
||||
reData = that.Db.Page(page, pageSize).
|
||||
PageSelect(tableName, leftJoin, columnStr, where)
|
||||
}
|
||||
if download == 1 {
|
||||
reData = that.Db.Select(tableName, leftJoin, columnStr, where)
|
||||
}
|
||||
|
||||
for _, v := range reData {
|
||||
v.RangeSort(func(k string, v1 interface{}) (isEnd bool) {
|
||||
|
||||
for k, _ := range v {
|
||||
//v1:=v.GetMap(k)
|
||||
//v.RangeSort(func(k string, v1 interface{}) (isEnd bool) {
|
||||
//如果有table字段则代为link
|
||||
if v["table"] != nil && v["table_id"] != nil {
|
||||
|
||||
id := v.GetCeilInt64("table_id")
|
||||
tableName := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v.GetString("table")).GetString("label")
|
||||
v["table_table_name"] = strings.Replace(tableName, "管理", "", -1)
|
||||
parentC := that.Db.Get(v.GetString("table"), "name", Map{"id": id})
|
||||
tableNameLabel := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v.GetString("table")).GetString("label")
|
||||
//v["table_table_name"] = strings.Replace(tableNameLabel, "管理", "", -1)
|
||||
v["table_table_name"] = tableNameLabel
|
||||
sname := "name"
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("table")][sname] == nil {
|
||||
sname = "title"
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("table")][sname] == nil {
|
||||
sname = "id"
|
||||
}
|
||||
}
|
||||
|
||||
parentC := that.Db.Get(v.GetString("table"), sname, Map{"id": id})
|
||||
v["table_table_id_name"] = ""
|
||||
if parentC != nil {
|
||||
v["table_table_id_name"] = parentC.GetString("name")
|
||||
v["table_table_id_name"] = parentC.GetString(sname)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][k]
|
||||
|
||||
if column == nil {
|
||||
return isEnd
|
||||
break
|
||||
}
|
||||
|
||||
if (column["list"] == nil || column["list"] == true) && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||
@@ -221,14 +459,208 @@ var TptProject = Proj{
|
||||
}
|
||||
}
|
||||
|
||||
return isEnd
|
||||
})
|
||||
//return isEnd
|
||||
}
|
||||
}
|
||||
|
||||
if download == 1 {
|
||||
|
||||
tableNameLabel := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(tableName).GetString("label")
|
||||
f := excelize.NewFile()
|
||||
// 创建一个工作表
|
||||
f.NewSheet(tableNameLabel)
|
||||
|
||||
f.DeleteSheet("Sheet1")
|
||||
columns := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(tableName).GetSlice("columns")
|
||||
//单列
|
||||
n := 0
|
||||
for k, _ := range columns {
|
||||
v := columns.GetMap(k)
|
||||
if v["list"] != nil && v.GetBool("list") == false {
|
||||
continue
|
||||
}
|
||||
n++
|
||||
//第一个要加状态行
|
||||
//单行
|
||||
for k1, v1 := range reData {
|
||||
if k1 == 0 {
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+"1", v.GetString("label"))
|
||||
}
|
||||
|
||||
if v.GetString("link") != "" {
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+ObjToStr(k1+2), v1.GetString(v.GetString("link")+"_"+v.GetString("name")+"_"+v.GetString("value")))
|
||||
continue
|
||||
}
|
||||
|
||||
if v.GetString("name") == "table" {
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+ObjToStr(k1+2), v1.GetString("table_"+v.GetString("name")+"_name"))
|
||||
continue
|
||||
}
|
||||
|
||||
if v.GetString("name") == "table_id" {
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+ObjToStr(k1+2), v1.GetString("table_"+v.GetString("name")+"_name"))
|
||||
continue
|
||||
}
|
||||
|
||||
//select类型
|
||||
options := v.GetSlice("options")
|
||||
if len(options) != 0 {
|
||||
isEnd := false
|
||||
for ok, _ := range options {
|
||||
ov := options.GetMap(ok)
|
||||
if ov.GetString("value") == v1.GetString(v.GetString("name")) {
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+ObjToStr(k1+2), ov.GetString("name"))
|
||||
isEnd = true
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
if isEnd {
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
f.SetCellValue(tableNameLabel, convertToTitle(n)+ObjToStr(k1+2), v1.GetString(v.GetString("name")))
|
||||
}
|
||||
}
|
||||
filePath := that.Config.GetString("filePath")
|
||||
if filePath == "" {
|
||||
filePath = "/file/temp/"
|
||||
}
|
||||
|
||||
//path := time.Now().Format(filePath)
|
||||
e := os.MkdirAll(that.Config.GetString("tpt")+filePath, os.ModeDir)
|
||||
if e != nil {
|
||||
that.Display(3, e)
|
||||
return
|
||||
}
|
||||
filePath = filePath + tableName + time.Now().Format("2006-01-02-15-04-05") + ".xlsx"
|
||||
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs(that.Config.GetString("tpt") + filePath); err != nil {
|
||||
fmt.Println(err)
|
||||
that.Display(4, "输出异常")
|
||||
return
|
||||
}
|
||||
f.Save()
|
||||
//that.Resp.Header().Set("Location", filePath)
|
||||
//that.Resp.WriteHeader(307) //关键在这里!
|
||||
that.Display(0, filePath)
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
},
|
||||
"hotime": Ctr{
|
||||
"file": func(that *Context) {
|
||||
//文件上传接口
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
|
||||
that.Display(2, "你还没有登录")
|
||||
return
|
||||
}
|
||||
//读取网络文件
|
||||
fi, fheader, err := that.Req.FormFile("file")
|
||||
if err != nil {
|
||||
that.Display(3, err)
|
||||
return
|
||||
|
||||
}
|
||||
filePath := that.Config.GetString("filePath")
|
||||
if filePath == "" {
|
||||
filePath = "/file/2006/01/02/"
|
||||
}
|
||||
|
||||
path := time.Now().Format(filePath)
|
||||
e := os.MkdirAll(that.Config.GetString("tpt")+path, os.ModeDir)
|
||||
if e != nil {
|
||||
that.Display(3, e)
|
||||
return
|
||||
}
|
||||
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
||||
newFile, e := os.Create(that.Config.GetString("tpt") + filePath)
|
||||
|
||||
if e != nil {
|
||||
that.Display(3, e)
|
||||
return
|
||||
}
|
||||
|
||||
_, e = io.Copy(newFile, fi)
|
||||
|
||||
if e != nil {
|
||||
that.Display(3, e)
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, filePath)
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
tableName := fileConfig.GetString("table")
|
||||
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(tableName, data, that.Db)
|
||||
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(tableName, str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
seStr := "id," + column.GetString("value")
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
}
|
||||
//如果有table字段则代为link
|
||||
if re["table"] != nil && re["table_id"] != nil {
|
||||
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[tableName][re.GetString("table")]
|
||||
v := re.GetCeilInt64("table_id")
|
||||
|
||||
seStr := "id," + column.GetString("value")
|
||||
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil {
|
||||
seStr = seStr + ",phone"
|
||||
}
|
||||
|
||||
link := strings.Replace(column.GetString("name"), "_id", "", -1)
|
||||
if link == "parent" {
|
||||
link = tableName
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
|
||||
}
|
||||
re["table"] = fileConfig.GetString("table")
|
||||
that.Display(0, re)
|
||||
},
|
||||
"login": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@@ -239,7 +671,20 @@ var TptProject = Proj{
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
|
||||
where := Map{"name": name}
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||
where["phone"] = name
|
||||
where = Map{"OR": where, "password": Md5(password)}
|
||||
} else {
|
||||
where["password"] = Md5(password)
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
||||
|
||||
if user == nil {
|
||||
that.Display(5, "登录失败")
|
||||
@@ -248,8 +693,11 @@ var TptProject = Proj{
|
||||
that.Session(fileConfig.GetString("table")+"_id", user.GetCeilInt("id"))
|
||||
that.Session(fileConfig.GetString("table")+"_name", name)
|
||||
delete(user, "password")
|
||||
user["table"] = fileConfig.GetString("table")
|
||||
user["token"] = that.SessionId
|
||||
that.Display(0, user)
|
||||
},
|
||||
|
||||
"logout": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
@@ -257,45 +705,202 @@ var TptProject = Proj{
|
||||
that.Session(fileConfig.GetString("table")+"_name", nil)
|
||||
that.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
"config": func(that *Context) {
|
||||
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(fileConfig.GetString("table"), data, that.Db)
|
||||
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
re := that.Db.Get(fileConfig.GetString("table"), str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
if err != nil {
|
||||
that.Display(4, "找不到配置文件")
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")][k]
|
||||
if column == nil {
|
||||
continue
|
||||
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
delete(conf, "menus")
|
||||
delete(conf, "tables")
|
||||
//没有登录只需要返回这些信息
|
||||
that.Display(0, conf)
|
||||
return
|
||||
}
|
||||
//可读写配置
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").Data})
|
||||
|
||||
if user == nil {
|
||||
that.Display(2, "暂未登录")
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
if v.GetString("link") != "" {
|
||||
linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
|
||||
if linkHasAuth == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": user.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
//conf := ObjToMap(string(btes))
|
||||
//menus := conf.GetSlice("menus")
|
||||
if linkAuth == nil {
|
||||
linkAuth = Map{}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
//保证个人权限可用
|
||||
if fileConfig.GetString("table") == v1.GetString("table") {
|
||||
v1["auth"] = Slice{"info", "edit"}
|
||||
}
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
|
||||
if linkAuth[name] != nil {
|
||||
v1["auth"] = linkAuth[name]
|
||||
}
|
||||
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
//保证个人权限可用
|
||||
if fileConfig.GetString("table") == v2.GetString("table") {
|
||||
v2["auth"] = Slice{"info", "edit"}
|
||||
|
||||
}
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if linkAuth[name] != nil {
|
||||
v2["auth"] = linkAuth[name]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
}
|
||||
|
||||
//是角色表则取下角色值
|
||||
if column.GetString("link") == "role" {
|
||||
//不可读写数据
|
||||
config := DeepCopyMap(that.MakeCodeRouter[hotimeName].Config).(Map)
|
||||
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,auth,"+column.GetString("value"), Map{"id": v})
|
||||
config["menus"] = menus
|
||||
newTables := Map{}
|
||||
newTables[fileConfig.GetString("table")] = config.GetMap("tables").GetMap(fileConfig.GetString("table"))
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if config.GetMap("tables").GetMap(v1.GetString("table")) != nil && len(v1.GetSlice("auth")) != 0 {
|
||||
config.GetMap("tables").GetMap(v1.GetString("table"))["auth"] = Slice{}
|
||||
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("table"))
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1.GetSlice("menus") {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if config.GetMap("tables").GetMap(v2.GetString("table")) != nil && len(v2.GetSlice("auth")) != 0 {
|
||||
|
||||
} else {
|
||||
//有自定义配置文件
|
||||
if conf.GetMap("tables") != nil && conf.GetMap("tables").GetMap(v2.GetString("table")) != nil {
|
||||
|
||||
columns := config.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
|
||||
columnsConf := conf.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
|
||||
for k3, _ := range columns {
|
||||
v3 := columns.GetMap(k3)
|
||||
for k4, _ := range columnsConf {
|
||||
v4 := columnsConf.GetMap(k4)
|
||||
|
||||
if v3.GetString("name") == v4.GetString("name") {
|
||||
columns[k3] = columnsConf[k4]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
config.GetMap("tables").GetMap(v2.GetString("table"))["auth"] = Slice{}
|
||||
newTables[v2.GetString("table")] = config.GetMap("tables").GetMap(v2.GetString("table"))
|
||||
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
conf["tables"] = newTables
|
||||
|
||||
that.Display(0, conf)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func convertToTitle(columnNumber int) string {
|
||||
var res []byte
|
||||
for columnNumber > 0 {
|
||||
a := columnNumber % 26
|
||||
if a == 0 {
|
||||
a = 26
|
||||
}
|
||||
res = append(res, 'A'+byte(a-1))
|
||||
columnNumber = (columnNumber - a) / 26
|
||||
}
|
||||
// 上面输出的res是反着的,前后交换
|
||||
for i, n := 0, len(res); i < n/2; i++ {
|
||||
res[i], res[n-1-i] = res[n-1-i], res[i]
|
||||
}
|
||||
return string(res)
|
||||
}
|
||||
|
||||
+18
-6
@@ -5,12 +5,20 @@ import (
|
||||
)
|
||||
|
||||
var Config = Map{
|
||||
"name": "HoTimeDashBoard",
|
||||
"id": "2f92h3herh23rh2y8",
|
||||
"name": "HoTimeDashBoard",
|
||||
//"id": "2f92h3herh23rh2y8",
|
||||
"label": "HoTime管理平台",
|
||||
|
||||
"stop": Slice{"role", "org"}, //不更新的,同时不允许修改用户自身对应的表数据
|
||||
"labelConfig": Map{
|
||||
"show": "开启",
|
||||
"add": "添加",
|
||||
"delete": "删除",
|
||||
"edit": "编辑",
|
||||
"info": "查看详情",
|
||||
"download": "下载清单",
|
||||
},
|
||||
"menus": []Map{
|
||||
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
//{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
//{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
||||
//{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
|
||||
// "menus": []Map{
|
||||
@@ -40,6 +48,7 @@ var ColumnDataType = map[string]string{
|
||||
"float": "number",
|
||||
"double": "number",
|
||||
"decimal": "number",
|
||||
"integer": "number", //sqlite3
|
||||
"char": "text",
|
||||
"text": "text",
|
||||
"blob": "text",
|
||||
@@ -63,9 +72,10 @@ var ColumnNameType = []ColumnShow{
|
||||
//通用
|
||||
{"idcard", false, true, true, false, "", false},
|
||||
{"id", true, false, true, false, "", true},
|
||||
{"sn", true, false, true, false, "", false},
|
||||
{"parent_ids", false, false, false, false, "index", true},
|
||||
{"parent_id", true, true, true, false, "", true},
|
||||
{"amount", true, true, true, false, "money", true},
|
||||
{"content", false, false, false, false, "textArea", false},
|
||||
{"info", false, true, true, false, "textArea", false},
|
||||
//"sn"{true,true,true,""},
|
||||
{"status", true, true, true, false, "select", false},
|
||||
@@ -79,6 +89,7 @@ var ColumnNameType = []ColumnShow{
|
||||
{"longitude", false, true, true, false, "", false},
|
||||
|
||||
{"index", false, false, false, false, "index", false},
|
||||
|
||||
{"password", false, true, false, false, "password", false},
|
||||
{"pwd", false, true, false, false, "password", false},
|
||||
|
||||
@@ -88,7 +99,7 @@ var ColumnNameType = []ColumnShow{
|
||||
{"note", false, true, true, false, "", false},
|
||||
{"description", false, true, true, false, "", false},
|
||||
{"abstract", false, true, true, false, "", false},
|
||||
{"content", false, true, true, false, "", false},
|
||||
{"content", false, true, true, false, "textArea", false},
|
||||
{"address", true, true, true, false, "", false},
|
||||
{"full_name", false, true, true, false, "", false},
|
||||
{"create_time", false, false, true, false, "time", true},
|
||||
@@ -103,6 +114,7 @@ var ColumnNameType = []ColumnShow{
|
||||
{"time", true, true, true, false, "time", false},
|
||||
{"level", false, false, true, false, "", false},
|
||||
{"rule", true, true, true, false, "form", false},
|
||||
{"auth", false, true, true, false, "auth", true},
|
||||
{"table", true, false, true, false, "table", false},
|
||||
{"table_id", true, false, true, false, "table_id", false},
|
||||
}
|
||||
|
||||
+296
-151
@@ -27,6 +27,7 @@ type MakeCode struct {
|
||||
|
||||
func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
isMake := false
|
||||
//hasConfigFile := false
|
||||
idSlice := Slice{}
|
||||
that.FileConfig = config
|
||||
if that.TableColumns == nil {
|
||||
@@ -37,22 +38,25 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
|
||||
//加载配置文件
|
||||
btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||
|
||||
//btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||
var err error
|
||||
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 //系统配置
|
||||
}
|
||||
} else {
|
||||
that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
}
|
||||
//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{}
|
||||
@@ -80,38 +84,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
|
||||
that.IndexMenus = Map{}
|
||||
menusConfig := that.Config.GetSlice("menus")
|
||||
//将配置写入到内存中仅作为判断用
|
||||
if menusConfig != nil {
|
||||
for kmenu, _ := range menusConfig {
|
||||
menu := menusConfig.GetMap(kmenu)
|
||||
if menu != nil {
|
||||
mname := menu.GetString("table")
|
||||
if mname == "" { //如果为空则不是表格
|
||||
mname = menu.GetString("name")
|
||||
}
|
||||
that.IndexMenus[mname] = menu
|
||||
childMenus := menu.GetSlice("menus")
|
||||
if childMenus != nil {
|
||||
for ckmenu, _ := range childMenus {
|
||||
cmenu := childMenus.GetMap(ckmenu)
|
||||
if cmenu != nil {
|
||||
cname := cmenu.GetString("table")
|
||||
if cmenu.GetString("table") == "" {
|
||||
continue
|
||||
}
|
||||
that.IndexMenus[mname+"/"+cname] = cmenu
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
that.TableConfig = that.Config.GetMap("tables")
|
||||
if that.TableConfig == nil {
|
||||
that.TableConfig = Map{}
|
||||
@@ -172,7 +144,7 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.TableConfig[v.GetString("name")] = Map{
|
||||
"label": v.GetString("label"),
|
||||
"table": v.GetString("name"),
|
||||
"auth": []string{"show", "add", "delete", "edit", "info"},
|
||||
"auth": []string{"show", "add", "delete", "edit", "info", "download"},
|
||||
"columns": []Map{},
|
||||
"search": []Map{
|
||||
|
||||
@@ -181,6 +153,10 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||
},
|
||||
}
|
||||
|
||||
if v.GetString("name") == "logs" {
|
||||
that.TableConfig.GetMap(v.GetString("name"))["auth"] = []string{"show", "download"}
|
||||
}
|
||||
}
|
||||
|
||||
//初始化
|
||||
@@ -313,13 +289,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
//}
|
||||
|
||||
}
|
||||
//else {
|
||||
//
|
||||
// //if !(coloum.GetString("label") != "备注" && info.GetString("label") == "备注") {
|
||||
// // coloum["label"] = info.GetString("label")
|
||||
// //}
|
||||
// //coloum["type"] = info.GetString("type")
|
||||
//}
|
||||
|
||||
//暂时不关闭参数,保证表数据完全读取到
|
||||
that.TableColumns[v.GetString("name")][info.GetString("name")] = coloum
|
||||
@@ -352,83 +321,84 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
//生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一
|
||||
id := Md5(ObjToStr(idSlice))
|
||||
if id == that.Config.GetString("id") {
|
||||
if isMake { //有生成包文件
|
||||
fmt.Println("有新的业务代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
}
|
||||
//if id == that.Config.GetString("id") {
|
||||
if isMake { //有生成包文件
|
||||
fmt.Println("有新的业务代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
return
|
||||
}
|
||||
|
||||
//}
|
||||
//数据生成完后进一步解析
|
||||
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
|
||||
//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 {
|
||||
tablePrefixCode := strings.Index(fk, "_")
|
||||
isNewPrefix := false //假定表名没有前缀
|
||||
prefixName := ""
|
||||
//并且代表有前缀,根据数据表分库设定使用
|
||||
if tablePrefixCode != -1 {
|
||||
prefixName = fk[:tablePrefixCode]
|
||||
} else {
|
||||
prefixName = fk
|
||||
}
|
||||
//if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
//目录没有收录
|
||||
if !isMenusGet {
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
tablePrefixCode := strings.Index(fk, "_")
|
||||
isNewPrefix := false //假定表名没有前缀
|
||||
prefixName := ""
|
||||
//并且代表有前缀,根据数据表分库设定使用
|
||||
if tablePrefixCode != -1 {
|
||||
prefixName = fk[:tablePrefixCode]
|
||||
} else {
|
||||
prefixName = fk
|
||||
}
|
||||
//if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
if that.IndexMenus[prefixName+"/"+fk] == nil {
|
||||
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
} else {
|
||||
for k, v := range menuIns {
|
||||
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
||||
//写入Index
|
||||
that.IndexMenus[prefixName] = mMenu
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
}
|
||||
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"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
if that.IndexMenus[prefixName+"/"+fk] == nil {
|
||||
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
} else {
|
||||
for k, v := range menuIns {
|
||||
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
||||
//写入Index
|
||||
that.IndexMenus[prefixName] = mMenu
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
}
|
||||
//}
|
||||
|
||||
for k, v := range fv {
|
||||
|
||||
@@ -541,18 +511,21 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
sv := Map{"type": "tree", "label": v["label"], "name": v["name"], "value": v["value"], "link": v["link"]}
|
||||
that.TableConfig.GetMap(fk)["search"] = append(search, sv)
|
||||
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
if fk == that.FileConfig.GetString("table") && v["link"] != nil && that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
that.Config["stop"] = append(that.Config.GetSlice("stop"), v.GetString("link"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
that.Config["id"] = id
|
||||
//fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
//that.Config["id"] = id
|
||||
|
||||
if config.GetInt("mode") != 0 {
|
||||
//init文件初始化
|
||||
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
//myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
||||
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("name")+"/init.go", []byte(myInit), os.ModePerm)
|
||||
@@ -561,16 +534,36 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
}
|
||||
|
||||
//写入配置文件
|
||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
//配置文件
|
||||
if config.GetString("configDB") != "" {
|
||||
|
||||
that.Config["id"] = id
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("configDB")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("configDB"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
that.Logger.Warn("新建")
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("有新的代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
//不存在配置文件则生成,存在则不管
|
||||
_, err = ioutil.ReadFile(config.GetString("config"))
|
||||
if err != nil {
|
||||
|
||||
that.Config["id"] = id
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
newConfig := DeepCopyMap(that.Config).(Map)
|
||||
delete(newConfig, "tables")
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(newConfig.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
that.Logger.Warn("新建")
|
||||
|
||||
}
|
||||
//fmt.Println("有新的代码生成,请重新运行")
|
||||
//os.Exit(-1)
|
||||
|
||||
}
|
||||
|
||||
@@ -608,11 +601,21 @@ func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string,
|
||||
}
|
||||
if ruleData[v.GetString("link")] != nil {
|
||||
|
||||
parent_idsStr := ""
|
||||
parent_ids := that.TableColumns[v.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[v.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
if v.GetString("name") == "parent_id" {
|
||||
data["index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
data[parent_idsStr] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
|
||||
} else {
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{parent_idsStr: "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||
for _, v := range idMap {
|
||||
ids = append(ids, v.GetCeilInt("id"))
|
||||
@@ -645,9 +648,9 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
}
|
||||
if v.Get("add") == nil || v.GetBool("add") {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 0 {
|
||||
if len(req.Form[v.GetString("name")]) == 0 || req.FormValue(v.GetString("name")) == "" {
|
||||
|
||||
if user[v.GetString("name")] != nil {
|
||||
if v["link"] != nil && user[v.GetString("name")] != nil {
|
||||
data[v.GetString("name")] = user[v.GetString("name")]
|
||||
continue
|
||||
}
|
||||
@@ -657,6 +660,13 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
continue
|
||||
}
|
||||
|
||||
if user[v.GetString("name")] != nil {
|
||||
|
||||
data[v.GetString("name")] = user[v.GetString("name")]
|
||||
continue
|
||||
|
||||
}
|
||||
|
||||
if v.GetBool("must") {
|
||||
return nil
|
||||
} else {
|
||||
@@ -664,6 +674,7 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
|
||||
data[v.GetString("name")] = nil
|
||||
@@ -676,7 +687,16 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
|
||||
|
||||
}
|
||||
}
|
||||
//sn则自动生成
|
||||
if v.GetString("name") == "sn" {
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue == "" {
|
||||
data[v.GetString("name")] = Md5(ObjToStr(time.Now().UnixNano()))
|
||||
} else {
|
||||
data[v.GetString("name")] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
if v.GetString("name") == "create_time" {
|
||||
if v.GetString("type") == "unixTime" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
@@ -724,8 +744,14 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
data[v.GetString("name")] = reqValue
|
||||
}
|
||||
}
|
||||
|
||||
if v.GetString("name") == "modify_time" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
if v.GetString("type") == "unixTime" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
if v.GetString("type") == "time" {
|
||||
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,6 +803,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if v["list"] != false {
|
||||
|
||||
if v.GetString("link") != "" &&
|
||||
@@ -809,9 +836,17 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
reStr += table + "." + v.GetString("name") + ","
|
||||
}
|
||||
|
||||
if v["name"] == "parent_id" && v.GetString("link") != "" {
|
||||
leftJoin["[>]"+v.GetString("link")+" selfParent"] =
|
||||
"selfParent.id=" +
|
||||
v.GetString("link") + "." + v.GetString("name")
|
||||
reStr += "selfParent." + v.GetString("value") + " AS " + v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
|
||||
}
|
||||
|
||||
//准备加入索引权限
|
||||
if v.GetString("link") != "" &&
|
||||
userData != nil &&
|
||||
@@ -828,12 +863,22 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
}
|
||||
if ruleData[v.GetString("link")] != nil {
|
||||
parent_idsStr := ""
|
||||
parent_ids := that.TableColumns[v.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[v.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
if v.GetString("name") == "parent_id" {
|
||||
data[table+".index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
|
||||
data[table+"."+parent_idsStr] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
|
||||
} else {
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{parent_idsStr: "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||
for _, v := range idMap {
|
||||
ids = append(ids, v.GetCeilInt("id"))
|
||||
@@ -845,6 +890,38 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "text" {
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue != "" {
|
||||
data[table+"."+v.GetString("name")+"[~]"] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
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
|
||||
|
||||
} 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 v.GetString("type") == "text" {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
@@ -875,13 +952,37 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
search := that.TableConfig.GetMap(table).GetSlice("search")
|
||||
for k, _ := range search {
|
||||
|
||||
reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if reqValue == "" {
|
||||
continue
|
||||
}
|
||||
searchItem := search.GetMap(k)
|
||||
searchItemName := searchItem.GetString("name")
|
||||
parent_idsStr := ""
|
||||
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[searchItem.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
reqValue := req.Form[search.GetMap(k).GetString("name")]
|
||||
|
||||
//reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if len(reqValue) == 0 || reqValue[0] == "" {
|
||||
|
||||
if parent_idsStr != "" && userData[searchItem.GetString("name")] != nil {
|
||||
where := Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ","}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
reqValue = []string{}
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||
if searchItem.GetString("type") == "search" {
|
||||
@@ -894,7 +995,7 @@ 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["daterange"]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange")
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form["daterange"]) == 2 {
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
@@ -906,7 +1007,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 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["daterange"]) == 2 {
|
||||
t1 := time.Unix(ObjToCeilInt64(req.Form["daterange"][0]), 0).Format("2006-01-02 15:04:05")
|
||||
@@ -919,26 +1020,74 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
if searchItem.GetString("name") == "sort" {
|
||||
sortMap["ORDER"] = table + "." + reqValue
|
||||
sortMap["ORDER"] = table + "." + reqValue[0]
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
//树节点模式搜索
|
||||
if searchItemName == "parent_id" {
|
||||
//if parent_idsStr != "" {
|
||||
//
|
||||
// where := Map{}
|
||||
//
|
||||
// for _, v := range reqValue {
|
||||
// if len(where) == 0 {
|
||||
// where[parent_idsStr] = "," + v + ","
|
||||
// continue
|
||||
// }
|
||||
// where = Map{"OR": where, parent_idsStr: "," + v + ","}
|
||||
// }
|
||||
// //用户
|
||||
// if userData[searchItem.GetString("name")] != nil {
|
||||
// where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
// }
|
||||
// r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
// for _, v := range r {
|
||||
// reqValue = append(reqValue, v.GetString("id"))
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||
if parentID == 0 {
|
||||
parentID = userData.GetCeilInt(table + "_id")
|
||||
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
||||
} else {
|
||||
data[table+".parent_id"] = parentID
|
||||
data[table+".parent_id"] = reqValue
|
||||
}
|
||||
continue
|
||||
}
|
||||
//如果是树节点则需要判断是否符合权限
|
||||
if searchItem.GetString("type") == "tree" {
|
||||
|
||||
if parent_idsStr != "" {
|
||||
|
||||
where := Map{}
|
||||
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
}
|
||||
where = Map{"OR": where, parent_idsStr: "," + v + ","}
|
||||
}
|
||||
//用户
|
||||
if userData[searchItem.GetString("name")] != nil {
|
||||
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
|
||||
if sortMap["ORDER"] == nil {
|
||||
sortMap["ORDER"] = table + ".id DESC"
|
||||
}
|
||||
@@ -995,7 +1144,3 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
return reStr, leftJoin, where
|
||||
}
|
||||
|
||||
func setListener() {
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ func (that Map) GetBool(key string, err ...*Error) bool {
|
||||
|
||||
}
|
||||
|
||||
func (that Map) GetTime(key string, err ...*Error) time.Time {
|
||||
func (that Map) GetTime(key string, err ...*Error) *time.Time {
|
||||
|
||||
v := ObjToTime((that)[key], err...)
|
||||
return v
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ func (that *Obj) ToInt(err ...Error) int {
|
||||
return ObjToInt(that.Data, &that.Error)
|
||||
}
|
||||
|
||||
func (that *Obj) ToTime(err ...Error) time.Time {
|
||||
func (that *Obj) ToTime(err ...Error) *time.Time {
|
||||
if len(err) != 0 {
|
||||
that.Error = err[0]
|
||||
}
|
||||
|
||||
+16
-13
@@ -97,7 +97,7 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
||||
return v
|
||||
}
|
||||
|
||||
func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
||||
func ObjToTime(obj interface{}, e ...*Error) *time.Time {
|
||||
|
||||
tInt := ObjToInt64(obj)
|
||||
//字符串类型,只支持标准mysql datetime格式
|
||||
@@ -107,27 +107,27 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
||||
if len(tStr) > 18 {
|
||||
t, e := time.Parse("2006-01-02 15:04:05", tStr)
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 15 {
|
||||
t, e := time.Parse("2006-01-02 15:04", tStr)
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 12 {
|
||||
t, e := time.Parse("2006-01-02 15", tStr)
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 9 {
|
||||
t, e := time.Parse("2006-01-02", tStr)
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 6 {
|
||||
t, e := time.Parse("2006-01", tStr)
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,25 +135,28 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
||||
|
||||
//纳秒级别
|
||||
if len(ObjToStr(tInt)) > 16 {
|
||||
|
||||
return time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
||||
t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
||||
return &t
|
||||
//微秒级别
|
||||
} else if len(ObjToStr(tInt)) > 13 {
|
||||
return time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
||||
t := time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
||||
return &t
|
||||
//毫秒级别
|
||||
} else if len(ObjToStr(tInt)) > 10 {
|
||||
return time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
||||
t := time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
||||
return &t
|
||||
//秒级别
|
||||
} else if len(ObjToStr(tInt)) > 9 {
|
||||
return time.Time{}.Add(time.Second * time.Duration(tInt))
|
||||
t := time.Time{}.Add(time.Second * time.Duration(tInt))
|
||||
return &t
|
||||
} else if len(ObjToStr(tInt)) > 3 {
|
||||
t, e := time.Parse("2006", ObjToStr(tInt))
|
||||
if e == nil {
|
||||
return t
|
||||
return &t
|
||||
}
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ func (that Slice) GetString(key int, err ...*Error) string {
|
||||
return ObjToStr((that)[key])
|
||||
}
|
||||
|
||||
func (that Slice) GetTime(key int, err ...*Error) time.Time {
|
||||
func (that Slice) GetTime(key int, err ...*Error) *time.Time {
|
||||
|
||||
v := ObjToTime((that)[key], err...)
|
||||
return v
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/cache"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
"encoding/json"
|
||||
@@ -19,7 +18,7 @@ type Context struct {
|
||||
Db *HoTimeDB
|
||||
RespData Map
|
||||
RespFunc func()
|
||||
CacheIns
|
||||
//CacheIns
|
||||
SessionIns
|
||||
DataSize int
|
||||
HandlerStr string //复写请求url
|
||||
@@ -68,7 +67,7 @@ func (that *Context) View() {
|
||||
}
|
||||
//创建日志
|
||||
if that.Log != nil {
|
||||
that.Log["time"] = time.Now().Unix()
|
||||
that.Log["time"] = time.Now().Format("2006-01-02 15:04")
|
||||
if that.Session("admin_id").Data != nil {
|
||||
that.Log["admin_id"] = that.Session("admin_id").ToCeilInt()
|
||||
}
|
||||
|
||||
+398
-111
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
@@ -19,6 +20,7 @@ type HoTimeDB struct {
|
||||
ContextBase
|
||||
DBName string
|
||||
*cache.HoTimeCache
|
||||
Log *logrus.Logger
|
||||
Type string
|
||||
Prefix string
|
||||
LastQuery string
|
||||
@@ -28,6 +30,231 @@ type HoTimeDB struct {
|
||||
limit Slice
|
||||
*sql.Tx //事务对象
|
||||
SlaveDB *sql.DB
|
||||
Mode int //mode为0生产模式,1、为测试模式、2为开发模式
|
||||
}
|
||||
|
||||
type HotimeDBBuilder struct {
|
||||
HoTimeDB *HoTimeDB
|
||||
table string
|
||||
selects []interface{}
|
||||
join Slice
|
||||
where Map
|
||||
lastWhere Map
|
||||
page int
|
||||
pageRow int
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) Table(table string) *HotimeDBBuilder {
|
||||
|
||||
return &HotimeDBBuilder{HoTimeDB: that, table: table, where: Map{}}
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Get(qu ...interface{}) Map {
|
||||
|
||||
return that.HoTimeDB.Get(that.table, that.join, qu, that.where)
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Count() int {
|
||||
|
||||
return that.HoTimeDB.Count(that.table, that.join, that.where)
|
||||
}
|
||||
func (that *HotimeDBBuilder) Page(page, pageRow int) *HotimeDBBuilder {
|
||||
that.page = page
|
||||
that.pageRow = pageRow
|
||||
return that
|
||||
}
|
||||
func (that *HotimeDBBuilder) Select(qu ...interface{}) []Map {
|
||||
if that.page != 0 {
|
||||
return that.HoTimeDB.Page(that.page, that.pageRow).PageSelect(that.table, that.join, qu, that.where)
|
||||
}
|
||||
return that.HoTimeDB.Select(that.table, that.join, qu, that.where)
|
||||
}
|
||||
|
||||
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(k-1)] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
return that.HoTimeDB.Update(that.table, data, that.where)
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Delete() int64 {
|
||||
|
||||
return that.HoTimeDB.Delete(that.table, that.where)
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) LeftJoin(table, joinStr string) *HotimeDBBuilder {
|
||||
that.Join(Map{"[>]" + table: joinStr})
|
||||
return that
|
||||
|
||||
}
|
||||
func (that *HotimeDBBuilder) RightJoin(table, joinStr string) *HotimeDBBuilder {
|
||||
that.Join(Map{"[<]" + table: joinStr})
|
||||
return that
|
||||
|
||||
}
|
||||
func (that *HotimeDBBuilder) InnerJoin(table, joinStr string) *HotimeDBBuilder {
|
||||
that.Join(Map{"[><]" + table: joinStr})
|
||||
return that
|
||||
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) FullJoin(table, joinStr string) *HotimeDBBuilder {
|
||||
that.Join(Map{"[<>]" + table: joinStr})
|
||||
return that
|
||||
}
|
||||
|
||||
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(k-1)] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if that.join == nil {
|
||||
that.join = Slice{}
|
||||
}
|
||||
if data == nil {
|
||||
return that
|
||||
}
|
||||
|
||||
that.join = append(that.join, data)
|
||||
return that
|
||||
}
|
||||
|
||||
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(k-1)] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
|
||||
if that.lastWhere != nil {
|
||||
that.lastWhere["AND"] = where
|
||||
that.lastWhere = where
|
||||
return that
|
||||
}
|
||||
that.lastWhere = where
|
||||
that.where = Map{"AND": where}
|
||||
|
||||
return that
|
||||
}
|
||||
|
||||
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(k-1)] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
|
||||
if that.lastWhere != nil {
|
||||
that.lastWhere["OR"] = where
|
||||
that.lastWhere = where
|
||||
return that
|
||||
}
|
||||
that.lastWhere = where
|
||||
that.where = Map{"Or": where}
|
||||
|
||||
return that
|
||||
}
|
||||
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(k-1)] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
|
||||
if that.lastWhere != nil {
|
||||
that.lastWhere["AND"] = where
|
||||
that.lastWhere = where
|
||||
return that
|
||||
}
|
||||
that.lastWhere = where
|
||||
that.where = Map{"AND": that.lastWhere}
|
||||
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) From(table string) *HotimeDBBuilder {
|
||||
that.table = table
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Order(qu ...interface{}) *HotimeDBBuilder {
|
||||
that.where["ORDER"] = ObjToSlice(qu)
|
||||
return that
|
||||
}
|
||||
func (that *HotimeDBBuilder) Limit(qu ...interface{}) *HotimeDBBuilder {
|
||||
that.where["LIMIT"] = ObjToSlice(qu)
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Group(qu ...interface{}) *HotimeDBBuilder {
|
||||
that.where["GROUP"] = ObjToSlice(qu)
|
||||
return that
|
||||
}
|
||||
|
||||
// SetConnect 设置数据库配置连接
|
||||
@@ -44,7 +271,11 @@ func (that *HoTimeDB) GetType() string {
|
||||
|
||||
// Action 事务,如果action返回true则执行成功;false则回滚
|
||||
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()
|
||||
if err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
@@ -87,7 +318,7 @@ func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
||||
e := that.SlaveDB.Ping()
|
||||
that.LastErr.SetError(e)
|
||||
}
|
||||
|
||||
//that.DB.SetConnMaxLifetime(time.Second)
|
||||
return that.LastErr
|
||||
}
|
||||
|
||||
@@ -260,7 +491,7 @@ func (that *HoTimeDB) backupCol(tt string) string {
|
||||
for k := range data[0] {
|
||||
|
||||
if tempLthData == lthCol-1 {
|
||||
str += "`" + k + "`)"
|
||||
str += "`" + k + "`) "
|
||||
} else {
|
||||
str += "`" + k + "`,"
|
||||
}
|
||||
@@ -284,7 +515,7 @@ func (that *HoTimeDB) backupCol(tt string) string {
|
||||
}
|
||||
|
||||
if m == lthCol-1 {
|
||||
str += v + ")"
|
||||
str += v + ") "
|
||||
|
||||
} else {
|
||||
str += v + ","
|
||||
@@ -306,7 +537,11 @@ func (that *HoTimeDB) md5(query string, args ...interface{}) string {
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
|
||||
defer func() {
|
||||
if that.Mode != 0 {
|
||||
that.Log.Info("SQL:"+that.LastQuery, " DATA:", that.LastData, " ERROR:", that.LastErr.GetError())
|
||||
}
|
||||
}()
|
||||
//fmt.Println(query)
|
||||
var err error
|
||||
var resl *sql.Rows
|
||||
@@ -331,16 +566,18 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
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)
|
||||
if err != nil {
|
||||
if err = db.Ping(); err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = db.Ping(); err == nil {
|
||||
return that.Query(query, args...)
|
||||
}
|
||||
that.LastErr.SetError(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -348,7 +585,11 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
}
|
||||
|
||||
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
|
||||
|
||||
defer func() {
|
||||
if that.Mode != 0 {
|
||||
that.Log.Info("SQL: "+that.LastQuery, " DATA: ", that.LastData, " ERROR: ", that.LastErr.GetError())
|
||||
}
|
||||
}()
|
||||
that.LastQuery = query
|
||||
that.LastData = args
|
||||
var e error
|
||||
@@ -366,19 +607,19 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
||||
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)
|
||||
|
||||
//判断是否连接断开了
|
||||
if e != nil {
|
||||
|
||||
if e = that.DB.Ping(); e != nil {
|
||||
that.LastErr.SetError(e)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return resl, that.LastErr
|
||||
}
|
||||
if e = that.DB.Ping(); e == nil {
|
||||
return that.Exec(query, args...)
|
||||
}
|
||||
that.LastErr.SetError(e)
|
||||
return resl, that.LastErr
|
||||
}
|
||||
|
||||
return resl, that.LastErr
|
||||
@@ -421,17 +662,20 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
if reflect.ValueOf(qu[intQs]).Type().String() == "string" {
|
||||
query += " " + qu[intQs].(string)
|
||||
} else {
|
||||
for i := 0; i < len(qu[intQs].(Slice)); i++ {
|
||||
k := qu[intQs].(Slice)[i].(string)
|
||||
if strings.Contains(k, " AS ") {
|
||||
data := ObjToSlice(qu[intQs])
|
||||
for i := 0; i < len(data); i++ {
|
||||
k := data.GetString(i)
|
||||
if strings.Contains(k, " AS ") ||
|
||||
strings.Contains(k, ".") {
|
||||
|
||||
query += " " + k + " "
|
||||
|
||||
} else {
|
||||
|
||||
query += " `" + k + "` "
|
||||
}
|
||||
|
||||
if i+1 != len(qu[intQs].(Slice)) {
|
||||
if i+1 != len(data) {
|
||||
query = query + ", "
|
||||
}
|
||||
|
||||
@@ -442,33 +686,75 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
query += " *"
|
||||
}
|
||||
if !strings.Contains(table, ".") && !strings.Contains(table, " AS ") {
|
||||
query += " FROM `" + that.Prefix + table + "`"
|
||||
query += " FROM `" + that.Prefix + table + "` "
|
||||
} else {
|
||||
query += " FROM " + that.Prefix + table
|
||||
query += " FROM " + that.Prefix + table + " "
|
||||
}
|
||||
|
||||
if join {
|
||||
var testQu = []string{}
|
||||
testQuData := qu[0].(Map)
|
||||
for key, _ := range testQuData {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
testQuData := Map{}
|
||||
if reflect.ValueOf(qu[0]).Type().String() == "common.Map" {
|
||||
testQuData = qu[0].(Map)
|
||||
for key, _ := range testQuData {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
}
|
||||
|
||||
if reflect.ValueOf(qu[0]).Type().String() == "common.Slice" {
|
||||
|
||||
for key, _ := range testQuData {
|
||||
v := testQuData.GetMap(key)
|
||||
for k1, v1 := range v {
|
||||
testQu = append(testQu, k1)
|
||||
testQuData[k1] = v1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
switch Substr(k, 0, 3) {
|
||||
case "[>]":
|
||||
query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
|
||||
func() {
|
||||
table := Substr(k, 3, len(k)-3)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " LEFT JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
case "[<]":
|
||||
query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
|
||||
func() {
|
||||
table := Substr(k, 3, len(k)-3)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " RIGHT JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
}
|
||||
switch Substr(k, 0, 4) {
|
||||
case "[<>]":
|
||||
query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
|
||||
func() {
|
||||
table := Substr(k, 4, len(k)-4)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " FULL JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
case "[><]":
|
||||
query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
|
||||
func() {
|
||||
table := Substr(k, 4, len(k)-4)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " INNER JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -479,7 +765,7 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
|
||||
temp, resWhere := that.where(where)
|
||||
|
||||
query += temp
|
||||
query += temp + ";"
|
||||
qs = append(qs, resWhere...)
|
||||
md5 := that.md5(query, qs...)
|
||||
|
||||
@@ -606,8 +892,7 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
if v != nil && reflect.ValueOf(v).Type().String() == "common.Slice" && len(v.(Slice)) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if v != nil && reflect.ValueOf(v).Type().String() == "[]interface {}" && len(v.([]interface{})) == 0 {
|
||||
if v != nil && strings.Contains(reflect.ValueOf(v).Type().String(), "[]") && len(ObjToSlice(v)) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -620,7 +905,16 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
}
|
||||
|
||||
if len(where) != 0 {
|
||||
where = " WHERE " + where
|
||||
hasWhere := true
|
||||
for _, v := range vcond {
|
||||
if strings.Index(where, v) == 0 {
|
||||
hasWhere = false
|
||||
}
|
||||
}
|
||||
|
||||
if hasWhere {
|
||||
where = " WHERE " + where + " "
|
||||
}
|
||||
}
|
||||
|
||||
//特殊字符
|
||||
@@ -636,31 +930,31 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
v := data[k]
|
||||
if vcond[j] == k {
|
||||
if k == "ORDER" {
|
||||
where += " " + k + " BY "
|
||||
where += k + " BY "
|
||||
//fmt.Println(reflect.ValueOf(v).Type())
|
||||
|
||||
//break
|
||||
} else if k == "GROUP" {
|
||||
|
||||
where += " " + k + " BY "
|
||||
where += k + " BY "
|
||||
} else {
|
||||
|
||||
where += " " + k
|
||||
where += k
|
||||
}
|
||||
|
||||
if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
where += " " + ObjToStr(v.(Slice)[i])
|
||||
where += " " + ObjToStr(v.(Slice)[i]) + " "
|
||||
|
||||
if len(v.(Slice)) != i+1 {
|
||||
where += ","
|
||||
where += ", "
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
//fmt.Println(v)
|
||||
where += " " + ObjToStr(v)
|
||||
where += " " + ObjToStr(v) + " "
|
||||
}
|
||||
|
||||
break
|
||||
@@ -688,48 +982,48 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
case "[>]":
|
||||
k = strings.Replace(k, "[>]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + ">? "
|
||||
res = append(res, v)
|
||||
case "[<]":
|
||||
k = strings.Replace(k, "[<]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + "<? "
|
||||
res = append(res, v)
|
||||
case "[!]":
|
||||
k = strings.Replace(k, "[!]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where, res = that.notIn(k, v, where, res)
|
||||
case "[#]":
|
||||
k = strings.Replace(k, "[#]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += " " + k + "=" + ObjToStr(v)
|
||||
where += " " + k + "=" + ObjToStr(v) + " "
|
||||
case "[##]": //直接添加value到sql,需要考虑防注入,value比如:"a>b"
|
||||
|
||||
where += " " + ObjToStr(v)
|
||||
case "[#!]":
|
||||
k = strings.Replace(k, "[#!]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += " " + k + "!=" + ObjToStr(v)
|
||||
where += " " + k + "!=" + ObjToStr(v) + " "
|
||||
case "[!#]":
|
||||
k = strings.Replace(k, "[!#]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += " " + k + "!=" + ObjToStr(v)
|
||||
where += " " + k + "!=" + ObjToStr(v) + " "
|
||||
case "[~]":
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = "%" + ObjToStr(v) + "%"
|
||||
@@ -737,15 +1031,15 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
case "[!~]": //左边任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = "%" + ObjToStr(v)
|
||||
v = "%" + ObjToStr(v) + ""
|
||||
res = append(res, v)
|
||||
case "[~!]": //右边任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
v = ObjToStr(v) + "%"
|
||||
@@ -753,7 +1047,7 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
case "[~~]": //手动任意
|
||||
k = strings.Replace(k, "[~]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " LIKE ? "
|
||||
//v = ObjToStr(v)
|
||||
@@ -767,21 +1061,21 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
case "[>=]":
|
||||
k = strings.Replace(k, "[>=]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + ">=? "
|
||||
res = append(res, v)
|
||||
case "[<=]":
|
||||
k = strings.Replace(k, "[<=]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + "<=? "
|
||||
res = append(res, v)
|
||||
case "[><]":
|
||||
k = strings.Replace(k, "[><]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " NOT BETWEEN ? AND ? "
|
||||
res = append(res, v.(Slice)[0])
|
||||
@@ -789,29 +1083,31 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
case "[<>]":
|
||||
k = strings.Replace(k, "[<>]", "", -1)
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
where += k + " BETWEEN ? AND ? "
|
||||
res = append(res, v.(Slice)[0])
|
||||
res = append(res, v.(Slice)[1])
|
||||
default:
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
|
||||
vs := ObjToSlice(v)
|
||||
if len(vs) == 0 {
|
||||
return where, res
|
||||
}
|
||||
|
||||
where += k + " IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
if len(v.(Slice)) == 0 {
|
||||
where += ") "
|
||||
} else {
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
if i+1 != len(v.(Slice)) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
res = append(res, vs...)
|
||||
|
||||
for i := 0; i < len(vs); i++ {
|
||||
if i+1 != len(vs) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -825,35 +1121,28 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
} else {
|
||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||
if !strings.Contains(k, ".") {
|
||||
k = "`" + k + "`"
|
||||
k = "`" + k + "` "
|
||||
}
|
||||
if v == nil {
|
||||
where += k + " IS NULL"
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
|
||||
where += k + " IS NULL "
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
|
||||
vs := ObjToSlice(v)
|
||||
//fmt.Println(v)
|
||||
where += k + " IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
if i+1 != len(v.(Slice)) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
if len(vs) == 0 {
|
||||
return where, res
|
||||
}
|
||||
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
|
||||
where += k + " IN ("
|
||||
res = append(res, vs...)
|
||||
|
||||
where += k + " IN ("
|
||||
res = append(res, v.([]interface{})...)
|
||||
for i := 0; i < len(v.([]interface{})); i++ {
|
||||
if i+1 != len(v.([]interface{})) {
|
||||
for i := 0; i < len(vs); i++ {
|
||||
if i+1 != len(vs) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
where += k + "=? "
|
||||
@@ -873,28 +1162,23 @@ func (that *HoTimeDB) notIn(k string, v interface{}, where string, res []interfa
|
||||
|
||||
where += k + " IS NOT NULL "
|
||||
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" {
|
||||
} else if reflect.ValueOf(v).Type().String() == "common.Slice" || strings.Contains(reflect.ValueOf(v).Type().String(), "[]") {
|
||||
vs := ObjToSlice(v)
|
||||
if len(vs) == 0 {
|
||||
return where, res
|
||||
}
|
||||
where += k + " NOT IN ("
|
||||
res = append(res, v.(Slice)...)
|
||||
for i := 0; i < len(v.(Slice)); i++ {
|
||||
if i+1 != len(v.(Slice)) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
} else if reflect.ValueOf(v).Type().String() == "[]interface {}" {
|
||||
where += k + " NOT IN ("
|
||||
res = append(res, v.([]interface{})...)
|
||||
for i := 0; i < len(v.([]interface{})); i++ {
|
||||
if i+1 != len(v.([]interface{})) {
|
||||
res = append(res, vs...)
|
||||
|
||||
for i := 0; i < len(vs); i++ {
|
||||
if i+1 != len(vs) {
|
||||
where += "?,"
|
||||
} else {
|
||||
where += "?) "
|
||||
}
|
||||
//res=append(res,(v.(Slice))[i])
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
where += k + " !=? "
|
||||
@@ -941,7 +1225,10 @@ func (that *HoTimeDB) cond(tag string, data Map) (string, []interface{}) {
|
||||
if x == len(condition) {
|
||||
|
||||
tv, vv := that.varCond(k, v)
|
||||
|
||||
if tv == "" {
|
||||
lens--
|
||||
continue
|
||||
}
|
||||
res = append(res, vv...)
|
||||
if lens--; lens <= 0 {
|
||||
where += tv + ""
|
||||
@@ -972,7 +1259,7 @@ func (that *HoTimeDB) Update(table string, data Map, where Map) int64 {
|
||||
} else {
|
||||
qs = append(qs, v)
|
||||
}
|
||||
query += "`" + k + "`=" + vstr + ""
|
||||
query += "`" + k + "`=" + vstr + " "
|
||||
if tp--; tp != 0 {
|
||||
query += ", "
|
||||
}
|
||||
@@ -981,7 +1268,7 @@ func (that *HoTimeDB) Update(table string, data Map, where Map) int64 {
|
||||
temp, resWhere := that.where(where)
|
||||
//fmt.Println(resWhere)
|
||||
|
||||
query += temp
|
||||
query += temp + ";"
|
||||
qs = append(qs, resWhere...)
|
||||
|
||||
res, err := that.Exec(query, qs...)
|
||||
@@ -1006,7 +1293,7 @@ func (that *HoTimeDB) Delete(table string, data map[string]interface{}) int64 {
|
||||
query := "DELETE FROM " + that.Prefix + table + " "
|
||||
|
||||
temp, resWhere := that.where(data)
|
||||
query += temp
|
||||
query += temp + ";"
|
||||
|
||||
res, err := that.Exec(query, resWhere...)
|
||||
rows := int64(0)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ArticleCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
article := that.Db.Get("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "article.*,ctg_article.ctg_id AS sctg_id", Map{"ctg_article.sn": sn})
|
||||
if article == nil {
|
||||
that.Display(4, "找不到对应数据")
|
||||
return
|
||||
}
|
||||
ctgId := article.GetCeilInt64("sctg_id")
|
||||
ctg := that.Db.Get("ctg", "*", Map{"id": ctgId})
|
||||
parents := []Map{}
|
||||
parentId := ctg.GetCeilInt64("parent_id")
|
||||
article["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
|
||||
for true {
|
||||
|
||||
if parentId == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
|
||||
parents = append(parents, parent)
|
||||
parentId = parent.GetCeilInt64("parent_id")
|
||||
|
||||
}
|
||||
|
||||
ctg["parents"] = parents
|
||||
|
||||
article["ctg"] = ctg
|
||||
that.Display(0, article)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("ctg_sn") //ctgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
lunbo := ObjToInt(that.Req.FormValue("lunbo"))
|
||||
|
||||
sort := that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"article.push_time[<]": time.Now().Format("2006-01-02 15:04"), "article.state": 0}
|
||||
if sn != "" {
|
||||
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
|
||||
if ctg != nil {
|
||||
where["ctg_article.ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
startTime := that.Req.FormValue("start_time") //ctgsn
|
||||
finishTime := that.Req.FormValue("finish_time") //ctgsn
|
||||
|
||||
if lunbo != 0 {
|
||||
where["article.lunbo"] = lunbo
|
||||
}
|
||||
|
||||
if len(startTime) > 5 {
|
||||
where["article.push_time[>=]"] = startTime
|
||||
}
|
||||
if len(finishTime) > 5 {
|
||||
where["article.push_time[<=]"] = finishTime
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"article.title[~]": keywords, "article.description[~]": keywords, "article.author[~]": keywords, "article.sn[~]": keywords, "article.origin[~]": keywords, "article.url[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
if sort == "" {
|
||||
where["ORDER"] = Slice{"article.sort DESC", "article.push_time DESC"}
|
||||
}
|
||||
|
||||
if sort == "time" {
|
||||
where["ORDER"] = "article.push_time DESC"
|
||||
}
|
||||
count := that.Db.Count("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, where)
|
||||
article := that.Db.Page(page, pageSize).PageSelect("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "ctg_article.sn,article.img,article.title,article.description,article.push_time,article.lunbo,article.author,article.origin,article.url", where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": article})
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var CtgCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": sn})
|
||||
parents := []Map{}
|
||||
parentId := ctg.GetCeilInt64("parent_id")
|
||||
ctg["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
|
||||
for true {
|
||||
|
||||
if parentId == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
|
||||
parents = append(parents, parent)
|
||||
parentId = parent.GetCeilInt64("parent_id")
|
||||
|
||||
}
|
||||
|
||||
if ctg.GetCeilInt64("article_id") != 0 {
|
||||
ctg["article"] = that.Db.Get("article", "*", Map{"id": ctg.GetCeilInt64("article_id")})
|
||||
}
|
||||
|
||||
ctg["parents"] = parents
|
||||
that.Display(0, ctg)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn") //ctgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 50
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
//sort:=that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"state": 0}
|
||||
if sn != "" {
|
||||
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
|
||||
if ctg != nil {
|
||||
where["parent_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"name[~]": keywords, "url[~]": keywords, "sn[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
where["ORDER"] = Slice{"sort DESC", "id DESC"}
|
||||
|
||||
article := that.Db.Page(page, pageSize).PageSelect("ctg", "name,sn,sort,url,img", where)
|
||||
|
||||
that.Display(0, article)
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AppProj = Proj{
|
||||
"article": ArticleCtr,
|
||||
"org": OrgCtr,
|
||||
"ctg": CtgCtr,
|
||||
"mail": MailCtr,
|
||||
"test": {
|
||||
"test": func(that *Context) {
|
||||
//data:=that.Db.Table("admin").Order("id DESC").Select("*")
|
||||
//data1:=that.Db.Table("admin").Where(Map{"name[~]":"m"}).Order("id DESC").Select("*")
|
||||
//
|
||||
//data3:=that.Db.Select("admin","*",Map{"name[~]":"m"})
|
||||
data2 := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Page(1, 10).Select("*")
|
||||
c := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Group("title").Select("*")
|
||||
//that.Display(0,Slice{data1,data,data3,data2})
|
||||
that.Display(0, Slice{data2, c})
|
||||
},
|
||||
"res": func(that *Context) {
|
||||
ebw_res := that.Db.Select("ebw_res", "*")
|
||||
|
||||
for _, v := range ebw_res {
|
||||
data := Map{"id": v.GetCeilInt("id"), "name": v.GetString("name"),
|
||||
"parent_id": v.GetCeilInt64("pid"),
|
||||
"sn": v.GetString("url"), "create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if data.GetCeilInt("parent_id") == 0 {
|
||||
data["parent_id"] = nil
|
||||
}
|
||||
that.Db.Insert("ctg", data)
|
||||
}
|
||||
|
||||
that.Db.Exec("UPDATE ctg SET parent_id =NULL WHERE parent_id=id")
|
||||
|
||||
ss(0, that)
|
||||
|
||||
that.Display(0, len(ebw_res))
|
||||
|
||||
},
|
||||
"news": func(that *Context) {
|
||||
ebw_news := that.Db.Select("ebw_news", "*")
|
||||
|
||||
for _, v := range ebw_news {
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("type")})
|
||||
data := Map{"sn": v.GetString("id"), "title": v.GetString("title"),
|
||||
"content": v.GetString("content"), "push_time": v.GetString("timedate"),
|
||||
"author": v.GetString("owner"), "origin": v.GetString("source"), "click_num": v.GetString("readtime"),
|
||||
"sort": v.GetCeilInt("zhiding"), "create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if ctg != nil {
|
||||
data["ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
that.Db.Insert("article", data)
|
||||
}
|
||||
|
||||
that.Display(0, len(ebw_news))
|
||||
|
||||
},
|
||||
"res2news": func(that *Context) {
|
||||
ebw_news_addition_res := that.Db.Select("ebw_news_addition_res", "*")
|
||||
|
||||
for _, v := range ebw_news_addition_res {
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("fk_res")})
|
||||
article := that.Db.Get("article", "*", Map{"sn": v.GetString("fk_newsid")})
|
||||
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if ctg != nil {
|
||||
data["ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
if article != nil {
|
||||
data["article_id"] = article.GetCeilInt("id")
|
||||
}
|
||||
that.Db.Insert("ctg_article", data)
|
||||
}
|
||||
|
||||
that.Display(0, len(ebw_news_addition_res))
|
||||
},
|
||||
//将文章没有关联的ctg_article进行关联
|
||||
"article": func(that *Context) {
|
||||
articles := that.Db.Select("article", "id,ctg_id")
|
||||
for _, v := range articles {
|
||||
ctg_article := that.Db.Get("ctg_article", "id", Map{"article_id": v.GetCeilInt("id")})
|
||||
if ctg_article == nil {
|
||||
|
||||
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if v.GetCeilInt("ctg_id") == 0 || v.GetCeilInt("id") == 0 {
|
||||
continue
|
||||
}
|
||||
data["ctg_id"] = v.GetCeilInt("ctg_id")
|
||||
data["article_id"] = v.GetCeilInt("id")
|
||||
that.Db.Insert("ctg_article", data)
|
||||
}
|
||||
|
||||
}
|
||||
that.Display(0, len(articles))
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func ss(parent_id int, that *Context) {
|
||||
var ctgs []Map
|
||||
ctg := that.Db.Get("ctg", "*", Map{"id": parent_id})
|
||||
if parent_id == 0 {
|
||||
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": nil})
|
||||
} else {
|
||||
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": parent_id})
|
||||
}
|
||||
|
||||
for _, v := range ctgs {
|
||||
if ctg == nil {
|
||||
ctg = Map{"parent_ids": ","}
|
||||
}
|
||||
ids := ctg.GetString("parent_ids") + ObjToStr(v.GetCeilInt("id")) + ","
|
||||
that.Db.Update("ctg", Map{"parent_ids": ids}, Map{"id": v.GetCeilInt("id")})
|
||||
ss(v.GetCeilInt("id"), that)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var MailCtr = Ctr{
|
||||
"add": func(that *Context) {
|
||||
title := that.Req.FormValue("title")
|
||||
name := that.Req.FormValue("name")
|
||||
phone := that.Req.FormValue("phone")
|
||||
content := that.Req.FormValue("content")
|
||||
|
||||
tp := ObjToInt(that.Req.FormValue("type"))
|
||||
show := ObjToInt(that.Req.FormValue("show"))
|
||||
|
||||
if len(title) < 5 {
|
||||
that.Display(3, "标题过短")
|
||||
return
|
||||
}
|
||||
if len(name) < 2 {
|
||||
that.Display(3, "姓名错误")
|
||||
return
|
||||
}
|
||||
if len(phone) < 8 {
|
||||
that.Display(3, "联系方式错误")
|
||||
return
|
||||
}
|
||||
if len(content) < 10 {
|
||||
that.Display(3, "内容过短")
|
||||
return
|
||||
}
|
||||
|
||||
data := Map{
|
||||
"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"name": name, "title": title, "phone": phone, "content": content, "type": tp, "show": show,
|
||||
"modify_time[#]": "NOW()", "create_time[#]": "NOW()",
|
||||
}
|
||||
id := that.Db.Insert("mail", data)
|
||||
if id == 0 {
|
||||
that.Display(4, "创建失败")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, "成功")
|
||||
return
|
||||
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
|
||||
mail := that.Db.Get("mail", "*", Map{"sn": sn})
|
||||
|
||||
that.Display(0, mail)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
//keywords:=that.Req.FormValue("keywords")
|
||||
|
||||
//sort:=that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"state": 0, "show": 1}
|
||||
|
||||
//if keywords!=""{
|
||||
// where["OR"]=Map{"title[~]":keywords,"description[~]":keywords,"author[~]":keywords,"sn[~]":keywords,"origin[~]":keywords,"url[~]":keywords}
|
||||
//}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
//if sort==""{
|
||||
// where["ORDER"]=Slice{"sort DESC","push_time DESC"}
|
||||
//}
|
||||
//
|
||||
//if sort=="time"{
|
||||
where["ORDER"] = "create_time DESC"
|
||||
//}
|
||||
count := that.Db.Count("mail", where)
|
||||
mail := that.Db.Page(page, pageSize).PageSelect("mail", "*", where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": mail})
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var OrgCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
article := that.Db.Get("article", "*", Map{"sn": sn})
|
||||
that.Display(0, article)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn") //orgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 50
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
sort := that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"push_time[<=]": time.Now().Format("2006-01-02 15:04"), "state": 0}
|
||||
if sn != "" {
|
||||
org := that.Db.Get("org", "id", Map{"sn": sn})
|
||||
if org != nil {
|
||||
where["org_id"] = org.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "author[~]": keywords, "sn[~]": keywords, "origin[~]": keywords, "url[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
if sort == "" {
|
||||
where["ORDER"] = Slice{"sort DESC", "id DESC"}
|
||||
}
|
||||
|
||||
if sort == "time" {
|
||||
where["ORDER"] = "push_time DESC"
|
||||
}
|
||||
|
||||
article := that.Db.Page(page, pageSize).PageSelect("article", "sn,title,description,push_time,lunbo,author,origin,url", where)
|
||||
|
||||
that.Display(0, article)
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"cache": {
|
||||
"db": {
|
||||
"db": false,
|
||||
"session": true,
|
||||
"timeout": 7200
|
||||
},
|
||||
"memory": {
|
||||
"db": true,
|
||||
"session": true,
|
||||
"timeout": 7200
|
||||
}
|
||||
},
|
||||
"codeConfig": [
|
||||
{
|
||||
"config": "config/admin.json",
|
||||
"configDB": "config/adminDB.json",
|
||||
"mode": 0,
|
||||
"name": "",
|
||||
"rule": "config/rule.json",
|
||||
"table": "admin"
|
||||
}
|
||||
],
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.2.20",
|
||||
"name": "gov_crawler",
|
||||
"password": "fh22y8b882d",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
"user": "root"
|
||||
}
|
||||
},
|
||||
"defFile": [
|
||||
"index.html",
|
||||
"index.htm"
|
||||
],
|
||||
"error": {
|
||||
"1": "内部系统异常",
|
||||
"2": "访问权限异常",
|
||||
"3": "请求参数异常",
|
||||
"4": "数据处理异常",
|
||||
"5": "数据结果异常"
|
||||
},
|
||||
"mode": 2,
|
||||
"port": "8081",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "tpt"
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"cache": {
|
||||
"db": {
|
||||
"db": "默认false,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
||||
"timeout": "默认60 * 60 * 24 * 30,非必须,过期时间,超时自动删除"
|
||||
},
|
||||
"memory": {
|
||||
"db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
||||
"timeout": "默认60 * 60 * 2,非必须,过期时间,超时自动删除"
|
||||
},
|
||||
"redis": {
|
||||
"db": "默认true,非必须,缓存数据库,启用后能减少数据库的读写压力",
|
||||
"host": "默认服务ip:127.0.0.1,必须,如果需要使用redis服务时配置,",
|
||||
"password": "默认密码空,必须,如果需要使用redis服务时配置,默认密码空",
|
||||
"port": "默认服务端口:6379,必须,如果需要使用redis服务时配置,",
|
||||
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
|
||||
"timeout": "默认60 * 60 * 24 * 15,非必须,过期时间,超时自动删除"
|
||||
},
|
||||
"注释": "可配置memory,db,redis,默认启用memory,默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致,缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用"
|
||||
},
|
||||
"codeConfig": [
|
||||
"注释:配置即启用,非必须,默认无",
|
||||
{
|
||||
"config": "默认config/app.json,必须,接口描述配置文件",
|
||||
"configDB": "默认无,非必须,有则每次将数据库数据生成到此目录用于配置读写,无则不生成",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"table": "默认admin,必须,根据数据库内当前表名做为用户生成数据"
|
||||
}
|
||||
],
|
||||
"crossDomain": "默认空 非必须,空字符串为不开启,如果需要跨域设置,auto为智能开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域",
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "默认127.0.0.1,必须,数据库ip地址",
|
||||
"name": "默认test,必须,数据库名称",
|
||||
"password": "默认root,必须,数据库密码",
|
||||
"port": "默认3306,必须,数据库端口",
|
||||
"prefix": "默认空,非必须,数据表前缀",
|
||||
"slave": {
|
||||
"host": "默认127.0.0.1,必须,数据库ip地址",
|
||||
"name": "默认test,必须,数据库名称",
|
||||
"password": "默认root,必须,数据库密码",
|
||||
"port": "默认3306,必须,数据库端口",
|
||||
"user": "默认root,必须,数据库用户名",
|
||||
"注释": "从数据库配置,mysql里配置slave项即启用主从读写,减少数据库压力"
|
||||
},
|
||||
"user": "默认root,必须,数据库用户名",
|
||||
"注释": "除prefix及主从数据库slave项,其他全部必须"
|
||||
},
|
||||
"sqlite": {
|
||||
"path": "默认config/data.db,必须,数据库位置"
|
||||
},
|
||||
"注释": "配置即启用,非必须,默认使用sqlite数据库"
|
||||
},
|
||||
"defFile": "默认访问index.html或者index.htm文件,必须,默认访问文件类型",
|
||||
"error": {
|
||||
"1": "内部系统异常,在环境配置,文件访问权限等基础运行环境条件不足造成严重错误时使用",
|
||||
"2": "访问权限异常,没有登录或者登录异常等时候使用",
|
||||
"3": "请求参数异常,request参数不满足要求,比如参数不足,参数类型错误,参数不满足要求等时候使用",
|
||||
"4": "数据处理异常,数据库操作或者三方请求返回的结果非正常结果,比如数据库突然中断等时候使用",
|
||||
"5": "数据结果异常,一般用于无法给出response要求的格式要求下使用,比如response需要的是string格式但你只能提供int数据时",
|
||||
"注释": "web服务内置错误提示,自定义异常建议10开始"
|
||||
},
|
||||
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"logLevel": "默认0,必须,0关闭,1打印,日志等级",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存",
|
||||
"modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配",
|
||||
"port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80",
|
||||
"sessionName": "默认HOTIME,必须,设置session的cookie名",
|
||||
"tlsCert": "默认空,非必须,https证书",
|
||||
"tlsKey": "默认空,非必须,https密钥",
|
||||
"tlsPort": "默认空,非必须,web服务https端口,0为不启用https服务",
|
||||
"tpt": "默认tpt,必须,web静态文件目录,默认为程序目录下tpt目录",
|
||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能"
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
"code.hoteas.com/golang/hotime/example/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
appIns := Init("config/config.json")
|
||||
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
|
||||
|
||||
return isFinished
|
||||
})
|
||||
|
||||
appIns.Run(Router{"app": app.AppProj})
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ module code.hoteas.com/golang/hotime
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1
|
||||
github.com/garyburd/redigo v1.6.3
|
||||
github.com/go-pay/gopay v1.5.78
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
|
||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
@@ -21,6 +23,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
|
||||
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -33,6 +37,7 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
|
||||
+22
-3
@@ -82,10 +82,29 @@ func findCaller(skip int) string {
|
||||
for i := 0; i < 10; i++ {
|
||||
file, line = getCaller(skip + i)
|
||||
if !strings.HasPrefix(file, "logrus") {
|
||||
|
||||
if file == "common/error.go" {
|
||||
file, line = getCaller(skip + i + 1)
|
||||
j := 0
|
||||
for true {
|
||||
j++
|
||||
if file == "common/error.go" {
|
||||
file, line = getCaller(skip + i + j)
|
||||
}
|
||||
if file == "db/hotimedb.go" {
|
||||
file, line = getCaller(skip + i + j)
|
||||
}
|
||||
if file == "code/makecode.go" {
|
||||
file, line = getCaller(skip + i + j)
|
||||
}
|
||||
if strings.Index(file, "common/") == 0 {
|
||||
file, line = getCaller(skip + i + j)
|
||||
}
|
||||
if strings.Contains(file, "application.go") {
|
||||
file, line = getCaller(skip + i + j)
|
||||
}
|
||||
if j == 5 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ var Config = Map{
|
||||
Map{
|
||||
"table": "admin", //默认admin,必须,有则根据数据库内当前表名做为用户生成数据
|
||||
"name": "", //默认admin,非必须,有则生成代码到此目录,无则采用缺省模式使用表名
|
||||
"config": "config/app.json", //默认config/app.json,必须,接口描述配置文件
|
||||
"config": "config/app.json", //默认config/app.json,必须,接口描述配置文件,无则自动生成
|
||||
"rule": "config/rule.json", //默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成
|
||||
"mode": 0, //默认0,非必须,0为内嵌代码模式,1为生成代码模式
|
||||
},
|
||||
@@ -65,11 +65,12 @@ var ConfigNote = Map{
|
||||
"注释:配置即启用,非必须,默认无",
|
||||
Map{ //默认无,必须,接口类别名称
|
||||
//"注释": "", //
|
||||
"table": "默认admin,必须,根据数据库内当前表名做为用户生成数据",
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"config": "默认config/app.json,必须,接口描述配置文件", //
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
"table": "默认admin,必须,根据数据库内当前表名做为用户生成数据",
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"config": "默认config/app.json,必须,接口描述配置文件", //
|
||||
"configDB": "默认无,非必须,有则每次将数据库数据生成到此目录用于配置读写,无则不生成", //
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
},
|
||||
},
|
||||
"db": Map{
|
||||
|
||||
Vendored
+5
@@ -1,3 +1,6 @@
|
||||
# github.com/360EntSecGroup-Skylar/excelize v1.4.1
|
||||
## explicit
|
||||
github.com/360EntSecGroup-Skylar/excelize
|
||||
# github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
|
||||
github.com/bradfitz/gomemcache/memcache
|
||||
# github.com/fatih/structs v1.1.0
|
||||
@@ -25,6 +28,8 @@ github.com/gomodule/redigo/redis
|
||||
# github.com/mattn/go-sqlite3 v1.14.12
|
||||
## explicit
|
||||
github.com/mattn/go-sqlite3
|
||||
# github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||
github.com/mohae/deepcopy
|
||||
# github.com/silenceper/wechat/v2 v2.1.2
|
||||
## explicit
|
||||
github.com/silenceper/wechat/v2
|
||||
|
||||
Reference in New Issue
Block a user