技术性调整

This commit is contained in:
hoteas 2022-07-08 09:55:02 +08:00
parent 96d341aaab
commit 1ab9027c93
2 changed files with 87 additions and 43 deletions

View File

@ -8,7 +8,6 @@ import (
. "code.hoteas.com/golang/hotime/log" . "code.hoteas.com/golang/hotime/log"
"database/sql" "database/sql"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
@ -660,48 +659,6 @@ func setMakeCodeLintener(name string, appIns *Application) {
appIns.SetConnectListener(func(context *Context) (isFinished bool) { appIns.SetConnectListener(func(context *Context) (isFinished bool) {
codeIns := appIns.MakeCodeRouter[name] 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 { if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
return isFinished return isFinished

87
code.go
View File

@ -2,7 +2,10 @@ package hotime
import ( import (
. "code.hoteas.com/golang/hotime/common" . "code.hoteas.com/golang/hotime/common"
"io"
"os"
"strings" "strings"
"time"
) )
// Project 管理端项目 // Project 管理端项目
@ -229,6 +232,49 @@ var TptProject = Proj{
}, },
}, },
"hotime": Ctr{ "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) { "login": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
@ -258,6 +304,7 @@ var TptProject = Proj{
that.Display(0, "退出登录成功") that.Display(0, "退出登录成功")
}, },
"info": func(that *Context) { "info": func(that *Context) {
that.Log = Map{"table": that.RouterString[1], "type": 2, "table_id": that.RouterString[2]}
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig 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) that.Display(0, re)
}, },
}, },