Compare commits

..

61 Commits

Author SHA1 Message Date
hoteas 2f3a5a0a59 增加壁纸及壁纸地址缓存 2022-10-08 16:52:42 +08:00
hoteas c2468a7389 增加两个参数 2022-09-16 07:10:45 +08:00
hoteas b6ba3486d6 IP获取真实条件修改 2022-09-02 00:04:23 +08:00
hoteas f59e909d30 修复下载插件bug 2022-08-31 19:15:47 +08:00
hoteas 3bb47de45a 修复下载插件bug 2022-08-31 19:10:41 +08:00
hoteas c71973850e 修复下载插件bug 2022-08-31 19:10:08 +08:00
hoteas 65f062b860 数据库操作bug 2022-08-31 11:20:58 +08:00
hoteas 7b502fed36 数据库操作bug 2022-08-31 11:14:45 +08:00
hoteas fd6b15bdaf 修正查询bug 2022-08-30 06:21:46 +08:00
hoteas f31bf24ec2 增加mongodb驱动,简单版本 2022-08-30 04:44:37 +08:00
hoteas 30edb4d9fa 增加mongodb驱动,简单版本 2022-08-30 04:05:17 +08:00
hoteas a32c3a1589 增加mongodb驱动,简单版本 2022-08-30 03:30:27 +08:00
hoteas 127e027940 修复重复执行context.View()的bug 2022-08-25 14:06:31 +08:00
hoteas 2ee0838d8a 树状结构优化 2022-08-25 13:06:26 +08:00
hoteas 72c23499f2 树状结构优化 2022-08-25 13:02:44 +08:00
hoteas 96d8868694 数据库错误操作优化 2022-08-25 05:01:50 +08:00
hoteas 1533a57cb8 数据库错误操作优化 2022-08-25 03:48:09 +08:00
hoteas 615f52d2e4 数据库错误操作优化 2022-08-25 03:44:58 +08:00
hoteas f7dfd4ec77 增加记录IP 2022-08-21 03:49:56 +08:00
hoteas 2276aa12ef Merge remote-tracking branch 'origin/master' 2022-08-20 22:38:40 +08:00
hoteas 6505594fd0 增加记录IP 2022-08-20 22:38:15 +08:00
hoteas c55e26021b 数据库错误操作优化 2022-08-20 11:20:03 +08:00
hoteas 78420a692f 检索升级 2022-08-19 17:58:18 +08:00
hoteas 6d9af149ad 数据库错误操作优化 2022-08-18 13:40:02 +08:00
hoteas 253cad35ef 数据库错误操作优化 2022-08-18 13:28:02 +08:00
hoteas 47c8736f34 数据库错误操作优化 2022-08-18 12:33:01 +08:00
hoteas dcce8ace9e 数据库事务操作优化 2022-08-18 11:36:23 +08:00
hoteas 125ccc5c3b 数据库操作优化 2022-08-17 17:10:12 +08:00
hoteas 432d59d483 数据库操作优化 2022-08-17 16:42:46 +08:00
hoteas 60f222b011 数据库操作优化 2022-08-17 16:35:52 +08:00
hoteas 7a8b86ed12 数据库操作优化,优化系统管理后台代码生成逻辑 2022-08-17 16:02:36 +08:00
hoteas b940afa6b0 数据库操作优化 2022-08-15 05:59:06 +08:00
hoteas 8afd00ff86 修复登录bug 2022-08-11 10:41:35 +08:00
hoteas 8992fd6d3a 解决BUG 2022-08-11 10:18:48 +08:00
hoteas 524a892480 修复bug 2022-08-08 04:34:26 +08:00
hoteas c420e23edb 修复bug 2022-08-08 02:37:15 +08:00
hoteas 7419e03d67 解决bug 2022-08-04 12:14:18 +08:00
hoteas 9425544d1c 修复bug 2022-08-04 02:41:41 +08:00
hoteas a8d78832df 修复配置bug 2022-08-03 12:07:55 +08:00
hoteas adfb2236dc V2.0封测 2022-08-02 03:02:57 +08:00
hoteas 6034598bb4 权限管理优化 2022-08-01 18:48:08 +08:00
hoteas 6fe44cb1cb 权限管理优化 2022-08-01 16:45:24 +08:00
hoteas 39d67d1775 增加导出功能 2022-08-01 03:40:09 +08:00
hoteas a8f9f12bb8 大岗山水电站初版完成 2022-07-28 12:08:47 +08:00
hoteas 2c1abb1d11 大岗山水电站初版完成 2022-07-28 11:08:51 +08:00
hoteas 21e0219568 V2半封测 2022-07-27 17:09:56 +08:00
hoteas 952c3a1243 技术性调整 2022-07-26 17:37:17 +08:00
hoteas 33cd7ebd6b 技术性调整 2022-07-25 05:44:38 +08:00
hoteas be02b3418d 技术性调整 2022-07-25 05:37:19 +08:00
hoteas f390617167 技术性调整 2022-07-24 00:00:36 +08:00
hoteas f7410200e3 增加权限管理 2022-07-21 00:24:39 +08:00
hoteas 9cfdfbac78 增加权限管理 2022-07-18 19:45:06 +08:00
hoteas b015e78fa0 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	example/config/configNote.json
#	var.go
2022-07-18 19:44:52 +08:00
hoteas bb9092c3e5 增加权限管理 2022-07-18 19:44:00 +08:00
hoteas cc1bad8d3f 技术性调整 2022-07-18 08:46:09 +08:00
hoteas 8f7380d796 优化日志及config 2022-07-11 19:13:20 +08:00
hoteas f37b9aee70 优化日志及config 2022-07-11 11:07:17 +08:00
hoteas 1ab9027c93 技术性调整 2022-07-08 09:55:02 +08:00
hoteas 96d341aaab 修复数据库及时间bug 2022-06-21 00:06:34 +08:00
hoteas 1f25f511cc 增加mysql断线重连优化 2022-06-14 11:29:54 +08:00
hoteas 07c7a628d1 增加time兼容性 2022-06-14 09:52:49 +08:00
23 changed files with 2191 additions and 573 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
/.idea/*
.idea
/example/config/app.json
/example/config/app.json
/example/tpt/demo/
+43 -72
View File
@@ -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则停止传输
@@ -354,14 +357,18 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
defer func() {
//是否展示日志
if that.WebConnectLog != nil {
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
//负载均衡优化
if ipStr == "127.0.0.1" {
if req.Header.Get("X-Forwarded-For") != "" {
ipStr = req.Header.Get("X-Forwarded-For")
} else if req.Header.Get("X-Real-IP") != "" {
ipStr = req.Header.Get("X-Real-IP")
}
ipStr := ""
if req.Header.Get("X-Forwarded-For") != "" {
ipStr = req.Header.Get("X-Forwarded-For")
} else if req.Header.Get("X-Real-IP") != "" {
ipStr = req.Header.Get("X-Real-IP")
}
//负载均衡优化
if ipStr == "" {
//RemoteAddr := that.Req.RemoteAddr
ipStr = Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
}
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
@@ -371,15 +378,17 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
}()
//访问拦截true继续false暂停
connectListenerLen := len(that.connectListener)
for i := connectListenerLen - 1; i >= 0; i-- {
if that.connectListener[i](&context) {
connectListenerLen := len(that.connectListener) - 1
for true {
if connectListenerLen < 0 {
break
}
if that.connectListener[connectListenerLen](&context) {
context.View()
return
}
connectListenerLen--
}
//接口服务
@@ -563,13 +572,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{}
@@ -588,9 +593,7 @@ func Init(config string) *Application {
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
}
go func() {
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
}()
setMakeCodeListener(codeMake.GetString("name"), &appIns)
}
@@ -616,6 +619,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 +650,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 {
@@ -656,52 +663,10 @@ func SetSqliteDB(appIns *Application, config Map) {
})
}
func setMakeCodeLintener(name string, appIns *Application) {
func setMakeCodeListener(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 +680,12 @@ func setMakeCodeLintener(name string, appIns *Application) {
return isFinished
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
return isFinished
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "wallpaper" {
return isFinished
}
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
context.Display(2, "你还没有登录")
return true
@@ -788,7 +759,7 @@ func setMakeCodeLintener(name string, appIns *Application) {
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
}
context.View()
//context.View()
return true
})
}
+760 -85
View File
File diff suppressed because it is too large Load Diff
+18 -6
View File
@@ -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},
}
+465 -266
View File
@@ -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,11 @@ 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配置文件不存在,或者配置出错,使用缺省默认配置"))
}
//加载规则文件
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
that.RuleConfig = []Map{}
@@ -80,38 +70,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,15 +130,20 @@ 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{
{"type": "search", "name": "keywordtable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
{"type": "search", "name": "daterangetable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
{"type": "search", "name": "sort", "label": "排序", "value": nil},
},
}
if v.GetString("name") == "logs" {
that.TableConfig.GetMap(v.GetString("name"))["auth"] = []string{"show", "download"}
}
}
//初始化
@@ -313,13 +276,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,180 +308,192 @@ 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
//目录没有收录
//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]
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": "Setting"}
//表名有前缀
if !isNewPrefix {
//是否已有对应前缀,已经有对应的menu只需要push进去即可
prefixName = DefaultMenuParentName
mMenu = Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": "系统管理", "name": prefixName, "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 {
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
for k, v := range menuIns {
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
}
}
//}
prefixName = DefaultMenuParentName + ":" + prefixName
} else {
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
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
//写入Index
that.IndexMenus[prefixName] = mMenu
that.IndexMenus[prefixName+"/"+fk] = menuIns
}
//}
search := that.TableConfig.GetMap(fk).GetSlice("search")
for k, v := range fv {
//虚招后缀是_id结尾的表字段 假设org_id
if !(len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3) {
//普通表匹配 org_id匹配为org
oldTableName := k[:len(k)-3]
//上级ID匹配
if oldTableName == "parent" {
oldTableName = fk
}
//如果本身匹配则不再继续精简匹配
if that.TableConfig[oldTableName] == nil {
//如果依然找不到则查询system_org是否存在
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName
}
//字段有动词前缀,自动进行解析
prefixColumn := strings.Index(oldTableName, "_")
//sys_org_id oldTableName即为sys此处判断为org表存在
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
oldTableName = oldTableName[prefixColumn+1:]
}
if prefixColumn >= len(oldTableName) {
prefixColumn = -1
}
//如果依然找不到则查询system_org是否存在
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
}
}
} else {
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
//比如表sys_user 字段org_id,查询不到sys_org表则查询org表,org表查询不到则查询默认前缀system_org表
//都查询不到则找不到,
prefix := strings.Index(fk, "_")
tableName := oldTableName
if prefix > 0 {
//表模块前缀sys_user sys即为前缀 sys_org
tableName = fk[:prefix+1] + oldTableName
if that.TableConfig[tableName] == nil || that.TableConfig[oldTableName] != nil {
//不存在则改为org
tableName = oldTableName
}
//表前缀+去除字段前缀
prefixColumn := strings.Index(oldTableName, "_")
if prefixColumn > -1 {
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
if that.TableConfig[tableName] == nil {
tableName = oldTableName
}
}
}
//如果数据匹配则写入到配置中
if that.TableConfig[tableName] != nil {
v["link"] = tableName
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
if that.TableColumns[tableName]["name"] != nil {
v["value"] = "name"
continue
}
if that.TableColumns[tableName]["label"] != nil {
v["value"] = "label"
continue
}
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
isGet := true
for k2, _ := range tempC {
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
v["value"] = tempC.GetMap(k2).GetString("name")
isGet = false
break
}
}
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
continue
}
}
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
//写入Index
that.IndexMenus[prefixName] = mMenu
that.IndexMenus[prefixName+"/"+fk] = menuIns
}
}
for k, v := range fv {
//搜索服务
if that.SearchColumns[fk][v.GetString("name")] == nil &&
v.GetString("type") == "select" {
search := that.TableConfig.GetMap(fk).GetSlice("search")
//search := that.TableConfig.GetMap(fk).GetSlice("search")
sv := DeepCopyMap(v).(Map)
sv["value"] = nil
sv["options"] = append(sv.GetSlice("options"), Map{"name": "全部", "value": nil})
that.TableConfig.GetMap(fk)["search"] = append(search, sv)
search = append(search, sv)
that.TableConfig.GetMap(fk)["search"] = search
that.SearchColumns[fk][k] = sv
}
//虚招后缀是_id结尾的表字段 假设org_id
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
continue
//搜索关键字
if strings.Contains(v.GetString("type"), "text") || v.GetString("name") == "id" {
keyWordSearchData := search.GetMap(0)
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
search[0] = keyWordSearchData
}
//普通表匹配 org_id匹配为org
oldTableName := k[:len(k)-3]
//上级ID匹配
if oldTableName == "parent" {
oldTableName = fk
}
//如果本身匹配则不再继续精简匹配
if that.TableConfig[oldTableName] == nil {
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" {
//如果依然找不到则查询system_org是否存在
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName
}
//字段有动词前缀,自动进行解析
prefixColumn := strings.Index(oldTableName, "_")
//sys_org_id oldTableName即为sys此处判断为org表存在
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
oldTableName = oldTableName[prefixColumn+1:]
}
if prefixColumn >= len(oldTableName) {
prefixColumn = -1
}
//如果依然找不到则查询system_org是否存在
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
}
keyWordSearchData := search.GetMap(0)
name := strings.Replace(that.TableConfig.GetMap(v.GetString("link")).GetString("label"), "管理", "", -1)
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": name, "value": v.GetString("name")})
search[0] = keyWordSearchData
}
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
//比如表sys_user 字段org_id,查询不到sys_org表则查询org表,org表查询不到则查询默认前缀system_org表
//都查询不到则找不到,
prefix := strings.Index(fk, "_")
tableName := oldTableName
if prefix > 0 {
//表模块前缀sys_user sys即为前缀 sys_org
tableName = fk[:prefix+1] + oldTableName
if that.TableConfig[tableName] == nil || that.TableConfig[oldTableName] != nil {
//不存在则改为org
tableName = oldTableName
}
//表前缀+去除字段前缀
prefixColumn := strings.Index(oldTableName, "_")
if prefixColumn > -1 {
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
if that.TableConfig[tableName] == nil {
tableName = oldTableName
}
}
}
//搜索时间
if strings.Contains(v.GetString("type"), "time") {
daterangeData := search.GetMap(1)
//如果数据匹配则写入到配置中
if that.TableConfig[tableName] != nil {
v["link"] = tableName
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
if that.TableColumns[tableName]["name"] != nil {
v["value"] = "name"
continue
}
if that.TableColumns[tableName]["label"] != nil {
v["value"] = "label"
continue
}
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
isGet := true
for k2, _ := range tempC {
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
v["value"] = tempC.GetMap(k2).GetString("name")
isGet = false
break
}
}
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
continue
}
daterangeData["options"] = append(daterangeData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
search[1] = daterangeData
}
@@ -541,18 +509,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 +532,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 +599,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 +646,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 +658,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 +672,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 +685,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()
@@ -707,15 +725,18 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = ","
}
//if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
// data[v.GetString("name")] = ","
//}
continue
}
if v.Get("edit") == nil || v.GetBool("edit") {
if len(req.Form[v.GetString("name")]) == 0 {
continue
}
reqValue := req.FormValue(v.GetString("name"))
if reqValue == "" || reqValue == "null" {
if reqValue == "null" {
continue
}
if v.GetString("type") == "password" {
@@ -724,8 +745,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")
}
}
}
@@ -737,16 +764,16 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
}
func (that *MakeCode) Delete(table string, req *http.Request) Map {
data := Map{}
for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = ","
}
continue
}
}
//for _, v := range that.TableColumns[table] {
// //不可使用,未在前端展示,但在内存中保持有
// if v.GetBool("notUse") {
// //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
// // data[v.GetString("name")] = ","
// //}
// continue
// }
//
//}
return data
}
@@ -761,6 +788,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
hasUser := false
keywordStr := req.FormValue("keyword")
keywordTableStr := req.FormValue("keywordtable")
daterangeTableStr := req.FormValue("daterangetable")
testQu := []string{}
testQuData := that.TableColumns[table]
@@ -769,7 +798,6 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := testQuData[k]
//不可使用,未在前端展示,但在内存中保持有
@@ -777,6 +805,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
continue
}
if v["list"] != false {
if v.GetString("link") != "" &&
@@ -809,9 +838,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 +865,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,29 +892,44 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
}
if keywordStr != "" {
if v.GetString("type") == "text" {
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
}
}
if v.GetString("name") == "id" {
keyword[table+"."+v.GetString("name")] = keywordStr
}
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" {
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
childIds := Slice{}
for _, cv := range childs {
childIds = append(childIds, cv.GetString("id"))
}
if len(childIds) != 0 {
keyword[v.GetString("link")+".id"] = childIds
}
}
if strings.Contains(v.GetString("type"), "text") {
reqValue := req.FormValue(v.GetString("name"))
if reqValue != "" {
data[table+"."+v.GetString("name")+"[~]"] = reqValue
}
}
if v.GetString("type") == "unixtime" {
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"])
}
//fmt.Println(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 len(reStr) != 0 {
reStr = reStr[:len(reStr)-1]
@@ -875,26 +937,59 @@ 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")
if data[table+"."+searchItemName] != nil {
delete(data, table+"."+searchItemName)
}
reqValue := req.Form[searchItemName]
parent_idsStr := ""
if searchItem.GetString("link") != "" {
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.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" {
for _, v := range that.TableColumns[table] {
if v["list"] == false {
continue
}
//if v["list"] == false {
// continue
//}
//日期类型
if searchItemName == "daterange" {
if daterangeTableStr != "" && daterangeTableStr != v.GetString("name") {
continue
}
if v.GetString("type") == "unixtime" {
//fmt.Println(req.Form["daterange"])
if len(req.Form["daterange"]) == 1 {
daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange")
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
} else if len(req.Form["daterange"]) == 2 {
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
@@ -903,10 +998,10 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
if v.GetString("type") == "time" {
//fmt.Println(req.Form["daterange"])
if len(req.Form["daterange"]) == 1 {
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
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")
@@ -916,14 +1011,57 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
}
}
if searchItemName == "keyword" && keywordStr != "" {
if keywordTableStr != "" {
if keywordTableStr == v.GetString("name") {
data[table+"."+keywordTableStr+"[~]"] = keywordStr
}
if keywordTableStr == v.GetString("value") {
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
childIds := Slice{}
for _, cv := range childs {
childIds = append(childIds, cv.GetString("id"))
}
if len(childIds) != 0 {
data[v.GetString("link")+".id"] = childIds
}
}
continue
}
if strings.Contains(v.GetString("type"), "text") {
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
}
if v.GetString("name") == "id" {
keyword[table+"."+v.GetString("name")] = keywordStr
}
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" {
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
childIds := Slice{}
for _, cv := range childs {
childIds = append(childIds, cv.GetString("id"))
}
if len(childIds) != 0 {
keyword[v.GetString("link")+".id"] = childIds
}
}
}
}
if searchItem.GetString("name") == "sort" {
sortMap["ORDER"] = table + "." + reqValue
if len(reqValue) != 0 && searchItem.GetString("name") == "sort" && reqValue[0] != "" {
sortMap["ORDER"] = table + "." + reqValue[0]
}
continue
}
//树节点模式搜索
if searchItemName == "parent_id" {
parentID := ObjToInt(req.FormValue("parent_id"))
@@ -931,14 +1069,78 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
parentID = userData.GetCeilInt(table + "_id")
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
} else {
data[table+".parent_id"] = parentID
//是否展示全部子级
where := Map{}
if req.FormValue("showall") == "1" {
for _, v := range reqValue {
if len(where) == 0 {
where[table+"."+parent_idsStr] = "," + v + ","
continue
}
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
}
} else {
where[table+".parent_id"] = reqValue
}
//是否展示自己
if req.FormValue("showself") == "1" {
if len(where) == 0 {
data["OR"] = Map{table + ".id": reqValue}
} else {
data["OR"] = Map{"OR": where, table + ".id": reqValue}
}
} else {
if len(where) != 0 {
data["OR"] = where
}
}
}
continue
}
//如果是树节点则需要判断是否符合权限
if searchItem.GetString("type") == "tree" {
data[table+"."+searchItemName] = reqValue
if parent_idsStr != "" {
where := Map{}
//是否全部展示
if req.FormValue("showall") != "1" {
where[table+"."+searchItem.GetString("name")] = reqValue
} else {
for _, v := range reqValue {
if len(where) == 0 {
where[searchItem.GetString("link")+"."+parent_idsStr] = "," + v + ","
continue
}
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
}
}
//用户
if userData[searchItem.GetString("name")] != nil {
where = Map{"AND": Map{searchItem.GetString("link") + "." + parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
}
data["OR"] = where
continue
//r := db.Select(searchItem.GetString("link"), "id", where)
//for _, v := range r {
// reqValue = append(reqValue, v.GetString("id"))
//}
}
}
if len(reqValue) != 0 && reqValue[0] != "" {
data[table+"."+searchItemName] = reqValue
}
}
if sortMap["ORDER"] == nil {
sortMap["ORDER"] = table + ".id DESC"
}
@@ -950,6 +1152,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
data[k] = v
}
}
if len(keyword) > 1 {
if data["OR"] != nil {
data = Map{"AND": data, "OR": keyword}
@@ -995,7 +1198,3 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
return reStr, leftJoin, where
}
func setListener() {
}
+37
View File
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"math"
"strings"
"time"
)
//安全锁
@@ -36,6 +37,42 @@ func StrFirstToUpper(str string) string {
return strings.ToUpper(first) + other
}
// 时间转字符串,第二个参数支持1-5对应显示年月日时分秒
func Time2Str(t *time.Time, qu ...interface{}) string {
if t == nil || t.Unix() < 0 {
return ""
}
tp := 5
if len(qu) != 0 {
tp = (qu[0]).(int)
}
switch tp {
case 1:
return t.Format("2006-01")
case 2:
return t.Format("2006-01-02")
case 3:
return t.Format("2006-01-02 15")
case 4:
return t.Format("2006-01-02 15:04")
case 5:
return t.Format("2006-01-02 15:04:05")
case 12:
return t.Format("01-02")
case 14:
return t.Format("01-02 15:04")
case 15:
return t.Format("01-02 15:04:05")
case 34:
return t.Format("15:04")
case 35:
return t.Format("15:04:05")
}
return t.Format("2006-01-02 15:04:05")
}
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
func StrLd(s, t string, ignoreCase bool) int {
if ignoreCase {
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
+16 -3
View File
@@ -1,11 +1,11 @@
package hotime
import (
. "code.hoteas.com/golang/hotime/cache"
. "code.hoteas.com/golang/hotime/common"
. "code.hoteas.com/golang/hotime/db"
"encoding/json"
"net/http"
"strings"
"time"
)
@@ -19,7 +19,7 @@ type Context struct {
Db *HoTimeDB
RespData Map
RespFunc func()
CacheIns
//CacheIns
SessionIns
DataSize int
HandlerStr string //复写请求url
@@ -68,13 +68,26 @@ 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()
}
if that.Session("user_id").Data != nil {
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
}
//负载均衡优化
ipStr := ""
if that.Req.Header.Get("X-Forwarded-For") != "" {
ipStr = that.Req.Header.Get("X-Forwarded-For")
} else if that.Req.Header.Get("X-Real-IP") != "" {
ipStr = that.Req.Header.Get("X-Real-IP")
}
//负载均衡优化
if ipStr == "" {
//RemoteAddr := that.Req.RemoteAddr
ipStr = Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
}
that.Log["ip"] = ipStr
that.Db.Insert("logs", that.Log)
}
+398 -111
View File
@@ -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(qu[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(qu[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(qu[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(qu[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(qu[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" {
qu0 := ObjToSlice(qu[0])
for key, _ := range qu0 {
v := qu0.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)
+3 -3
View File
@@ -18,13 +18,13 @@ func Down(url, path, name string, e ...*Error) bool {
}
out, err := os.Create(path + name)
if err != nil && e[0] != nil {
if err != nil && len(e) != 0 {
e[0].SetError(err)
return false
}
defer out.Close()
resp, err := http.Get(url)
if err != nil && e[0] != nil {
if err != nil && len(e) != 0 {
e[0].SetError(err)
return false
}
@@ -32,7 +32,7 @@ func Down(url, path, name string, e ...*Error) bool {
pix, err := ioutil.ReadAll(resp.Body)
_, err = io.Copy(out, bytes.NewReader(pix))
if err != nil && e[0] != nil {
if err != nil && len(e) != 0 {
e[0].SetError(err)
return false
}
+149
View File
@@ -0,0 +1,149 @@
package mongodb
import (
. "code.hoteas.com/golang/hotime/common"
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type MongoDb struct {
Client *mongo.Client
Ctx context.Context
DataBase *mongo.Database
Connect *mongo.Collection
LastErr error
}
func GetMongoDb(database, url string) (*MongoDb, error) {
db := MongoDb{}
clientOptions := options.Client().ApplyURI(url)
db.Ctx = context.TODO()
// Connect to MongoDb
var err error
db.Client, err = mongo.Connect(db.Ctx, clientOptions)
if err != nil {
return nil, err
}
// Check the connection
err = db.Client.Ping(db.Ctx, nil)
if err != nil {
return nil, err
}
fmt.Println("Connected to MongoDb!")
//databases, err := db.Client.ListDatabaseNames(db.Ctx, bson.M{})
//if err != nil {
// return nil, err
//}
//fmt.Println(databases)
db.DataBase = db.Client.Database(database)
return &db, nil
}
func (that *MongoDb) Insert(table string, data interface{}) string {
collection := that.DataBase.Collection(table)
re, err := collection.InsertOne(that.Ctx, data)
if err != nil {
that.LastErr = err
return ""
}
return ObjToStr(re.InsertedID)
}
func (that *MongoDb) InsertMany(table string, data ...interface{}) Slice {
collection := that.DataBase.Collection(table)
re, err := collection.InsertMany(that.Ctx, data)
if err != nil {
that.LastErr = err
return Slice{}
}
return ObjToSlice(re.InsertedIDs)
}
func (that *MongoDb) Update(table string, data Map, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.UpdateMany(that.Ctx, where, data)
if err != nil {
that.LastErr = err
return 0
}
return re.ModifiedCount
}
func (that *MongoDb) Delete(table string, where Map) int64 {
collection := that.DataBase.Collection(table)
re, err := collection.DeleteMany(that.Ctx, where)
if err != nil {
that.LastErr = err
return 0
}
return re.DeletedCount
}
func (that *MongoDb) Get(table string, where Map) Map {
results := []Map{}
var cursor *mongo.Cursor
var err error
collection := that.DataBase.Collection(table)
if cursor, err = collection.Find(that.Ctx, where, options.Find().SetSkip(0), options.Find().SetLimit(2)); err != nil {
that.LastErr = err
return nil
}
//延迟关闭游标
defer func() {
if err := cursor.Close(that.Ctx); err != nil {
that.LastErr = err
}
}()
//这里的结果遍历可以使用另外一种更方便的方式:
if err = cursor.All(that.Ctx, &results); err != nil {
that.LastErr = err
return nil
}
if len(results) > 0 {
return results[0]
}
return nil
}
func (that MongoDb) Select(table string, where Map, page, pageRow int64) []Map {
page = (page - 1) * pageRow
if page < 0 {
page = 0
}
results := []Map{}
var cursor *mongo.Cursor
var err error
collection := that.DataBase.Collection(table)
if cursor, err = collection.Find(that.Ctx, where, options.Find().SetSkip(page), options.Find().SetLimit(pageRow)); err != nil {
that.LastErr = err
return results
}
//延迟关闭游标
defer func() {
if err := cursor.Close(that.Ctx); err != nil {
that.LastErr = err
}
}()
//这里的结果遍历可以使用另外一种更方便的方式:
if err = cursor.All(that.Ctx, &results); err != nil {
that.LastErr = err
return results
}
return results
}
+48
View File
@@ -0,0 +1,48 @@
{
"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.6.253",
"name": "dgs-cms",
"password": "dasda8454456",
"port": "3306",
"user": "root"
}
},
"defFile": [
"index.html",
"index.htm"
],
"error": {
"1": "内部系统异常",
"2": "访问权限异常",
"3": "请求参数异常",
"4": "数据处理异常",
"5": "数据结果异常"
},
"mode": 2,
"port": "8081",
"sessionName": "HOTIME",
"tpt": "tpt"
}
+79
View File
@@ -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": "默认服务ip127.0.0.1,必须,如果需要使用redis服务时配置,",
"password": "默认密码空,必须,如果需要使用redis服务时配置,默认密码空",
"port": "默认服务端口:6379,必须,如果需要使用redis服务时配置,",
"session": "默认true,非必须,缓存web session,同时缓存session保持的用户缓存",
"timeout": "默认60 * 60 * 24 * 15,非必须,过期时间,超时自动删除"
},
"注释": "可配置memorydbredis,默认启用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.
+17
View File
@@ -0,0 +1,17 @@
package main
import (
. "code.hoteas.com/golang/hotime"
)
func main() {
appIns := Init("config/config.json")
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
return isFinished
})
appIns.Run(Router{})
}
+2
View File
@@ -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
@@ -11,5 +12,6 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364
go.mongodb.org/mongo-driver v1.10.1
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
)
+35
View File
@@ -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=
@@ -12,17 +14,29 @@ github.com/go-pay/gopay v1.5.78 h1:wIHp8g/jK0ik5bZo2MWt3jAQsktT3nkdXZxlRZvljko=
github.com/go-pay/gopay v1.5.78/go.mod h1:M6Nlk2VdZHCbWphOw3rtbnz4SiOk6Xvxg6mxwDfg+Ps=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/gomodule/redigo v1.8.5 h1:nRAxCa+SVsyjSBrtZmG/cqb6VbTmuRzpg/PoTFlpumc=
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
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/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/silenceper/wechat/v2 v2.1.2 h1:+QfIMiYfwST2ZloTwmYp0O0p5Y1LYRZxfLWfMuSE30k=
@@ -33,21 +47,38 @@ 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.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 h1:X1Jws4XqrTH+p7FBQ7BpjW4qFXObKHWm0/XhW/GvqRs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 h1:kbor60vo37v7Hu+i17gooox9Rw281fVHNna8zwtDG1w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364/go.mod h1:LeIUBOLhc+Y5YCEpZrULPD9lgoXXV4/EmIcoEvmHz9c=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.mongodb.org/mongo-driver v1.10.1 h1:NujsPveKwHaWuKUer/ceo9DzEe7HIj1SlJ6uvXZG0S4=
go.mongodb.org/mongo-driver v1.10.1/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -61,12 +92,16 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+22 -3
View File
@@ -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
}
}
+7 -6
View File
@@ -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{
+71 -1
View File
@@ -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
@@ -20,11 +23,26 @@ github.com/go-pay/gopay/wechat/v3
# github.com/go-sql-driver/mysql v1.6.0
## explicit
github.com/go-sql-driver/mysql
# github.com/golang/snappy v0.0.1
github.com/golang/snappy
# github.com/gomodule/redigo v1.8.5
github.com/gomodule/redigo/redis
# github.com/klauspost/compress v1.13.6
github.com/klauspost/compress
github.com/klauspost/compress/fse
github.com/klauspost/compress/huff0
github.com/klauspost/compress/internal/snapref
github.com/klauspost/compress/zstd
github.com/klauspost/compress/zstd/internal/xxhash
# 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/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe
github.com/montanaflynn/stats
# github.com/pkg/errors v0.9.1
github.com/pkg/errors
# github.com/silenceper/wechat/v2 v2.1.2
## explicit
github.com/silenceper/wechat/v2
@@ -101,13 +119,65 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions
# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364
## explicit
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119
# golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
# github.com/xdg-go/pbkdf2 v1.0.0
github.com/xdg-go/pbkdf2
# github.com/xdg-go/scram v1.1.1
github.com/xdg-go/scram
# github.com/xdg-go/stringprep v1.0.3
github.com/xdg-go/stringprep
# github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d
github.com/youmark/pkcs8
# go.mongodb.org/mongo-driver v1.10.1
## explicit
go.mongodb.org/mongo-driver/bson
go.mongodb.org/mongo-driver/bson/bsoncodec
go.mongodb.org/mongo-driver/bson/bsonoptions
go.mongodb.org/mongo-driver/bson/bsonrw
go.mongodb.org/mongo-driver/bson/bsontype
go.mongodb.org/mongo-driver/bson/primitive
go.mongodb.org/mongo-driver/event
go.mongodb.org/mongo-driver/internal
go.mongodb.org/mongo-driver/internal/randutil
go.mongodb.org/mongo-driver/internal/randutil/rand
go.mongodb.org/mongo-driver/internal/uuid
go.mongodb.org/mongo-driver/mongo
go.mongodb.org/mongo-driver/mongo/address
go.mongodb.org/mongo-driver/mongo/description
go.mongodb.org/mongo-driver/mongo/options
go.mongodb.org/mongo-driver/mongo/readconcern
go.mongodb.org/mongo-driver/mongo/readpref
go.mongodb.org/mongo-driver/mongo/writeconcern
go.mongodb.org/mongo-driver/tag
go.mongodb.org/mongo-driver/version
go.mongodb.org/mongo-driver/x/bsonx
go.mongodb.org/mongo-driver/x/bsonx/bsoncore
go.mongodb.org/mongo-driver/x/mongo/driver
go.mongodb.org/mongo-driver/x/mongo/driver/auth
go.mongodb.org/mongo-driver/x/mongo/driver/auth/internal/awsv4
go.mongodb.org/mongo-driver/x/mongo/driver/auth/internal/gssapi
go.mongodb.org/mongo-driver/x/mongo/driver/connstring
go.mongodb.org/mongo-driver/x/mongo/driver/dns
go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt
go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt/options
go.mongodb.org/mongo-driver/x/mongo/driver/ocsp
go.mongodb.org/mongo-driver/x/mongo/driver/operation
go.mongodb.org/mongo-driver/x/mongo/driver/session
go.mongodb.org/mongo-driver/x/mongo/driver/topology
go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage
# golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
golang.org/x/crypto/ocsp
golang.org/x/crypto/pbkdf2
golang.org/x/crypto/pkcs12
golang.org/x/crypto/pkcs12/internal/rc2
# golang.org/x/net v0.0.0-20220225172249-27dd8689420f
## explicit
golang.org/x/net/websocket
# golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sync/errgroup
# golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
golang.org/x/sys/internal/unsafeheader
golang.org/x/sys/unix
golang.org/x/sys/windows
# golang.org/x/text v0.3.7
golang.org/x/text/transform
golang.org/x/text/unicode/norm