技术性调整

This commit is contained in:
hoteas
2022-07-08 09:55:02 +08:00
parent f5af9424f0
commit 83acef93a9
2 changed files with 87 additions and 43 deletions
+87
View File
@@ -2,7 +2,10 @@ package hotime
import (
. "code.hoteas.com/golang/hotime/common"
"io"
"os"
"strings"
"time"
)
// Project 管理端项目
@@ -229,6 +232,49 @@ var TptProject = Proj{
},
},
"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)
},
"login": func(that *Context) {
hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
@@ -258,6 +304,7 @@ var TptProject = Proj{
that.Display(0, "退出登录成功")
},
"info": func(that *Context) {
that.Log = Map{"table": that.RouterString[1], "type": 2, "table_id": that.RouterString[2]}
hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
@@ -295,6 +342,46 @@ var TptProject = Proj{
}
}
that.Display(0, re)
},
"update": func(that *Context) {
that.Log = Map{"table": that.RouterString[1], "type": 2, "table_id": that.RouterString[2]}
hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], 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] + ","
childNodes := that.Db.Select(that.RouterString[1], "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
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")
}
}
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
if re == 0 {
that.Display(4, "更新数据失败")
return
}
that.Display(0, re)
},
},