Compare commits

...

83 Commits

Author SHA1 Message Date
hoteas 8265e24add 使用go mod 2022-03-13 01:00:59 +08:00
hoteas 283985df52 删除无关代码 2022-03-13 00:26:01 +08:00
hoteas 95adca04bd 删除无关代码 2022-03-13 00:24:36 +08:00
hoteas 87039524a7 政企超链接开始集成 2022-03-12 23:52:42 +08:00
hoteas 66cd21c35f 政企超链接开始集成 2022-03-12 23:52:25 +08:00
hoteas 7e64131931 政企超链接开始集成 2022-03-06 23:55:14 +08:00
hoteas e30d40cfbb 政企超链接开始集成 2022-03-04 00:06:26 +08:00
hoteas 751ed0003d 政企超链接开始集成 2022-03-04 00:06:04 +08:00
hoteas 6d9f89a1d4 政企超链接开始集成 2022-03-03 21:23:57 +08:00
hoteas bc329be03b 政企超链接开始集成 2022-03-02 18:19:15 +08:00
hoteas 4597a0a50d 政企超链接开始集成 2022-03-02 12:14:07 +08:00
hoteas 3dda86d170 政企超链接开始集成 2022-02-28 19:37:52 +08:00
hoteas d847da7591 政企超链接开始集成 2022-02-28 19:08:48 +08:00
hoteas e1eca90835 政企超链接开始集成 2022-02-28 09:59:05 +08:00
hoteas 9283b8c284 政企超链接开始集成 2022-02-28 08:53:38 +08:00
hoteas d8d9afa4d2 政企超链接开始集成 2022-02-24 06:26:36 +08:00
hoteas 4d3829c345 简阳版本 2022-02-19 21:38:35 +08:00
hoteas a23037a437 简阳版本 2022-02-19 21:38:17 +08:00
hoteas 181295e54e 更新研发 2022-02-17 04:10:53 +08:00
hoteas 8cc2499e21 更新研发 2022-02-14 19:11:38 +08:00
hoteas a2c49452b4 更新研发 2022-02-14 19:10:58 +08:00
hoteas ebf0df5ca8 更新研发 2022-01-27 23:41:40 +08:00
hoteas 73bf691ccc 更新研发 2022-01-26 11:45:17 +08:00
hoteas b2e9701826 更新研发 2022-01-23 05:13:19 +08:00
hoteas 789b0a14d1 更新研发 2022-01-22 16:12:02 +08:00
hoteas 3ee64fcd8c 更新研发 2022-01-20 07:15:14 +08:00
hoteas 527503b0d9 企业画像 2022-01-19 05:38:49 +08:00
hoteas a95b2fccd7 更新研发 2022-01-17 04:47:39 +08:00
hoteas 7e2abb43e3 权限模块开发 2022-01-12 17:33:20 +08:00
hoteas 48fd753a96 权限模块开发 2022-01-10 13:23:39 +08:00
hoteas 136232dd57 修复太过于严格的bug 2022-01-03 01:42:35 +08:00
hoteas 008f19355c 增加自适应模式 2021-12-31 02:38:51 +08:00
hoteas 1fc0a5bbbc 增加自适应模式 2021-12-30 22:19:52 +08:00
hoteas ce099b8fc8 增加自适应模式 2021-12-29 00:46:07 +08:00
hoteas 9c00ac6ba1 增加自适应模式 2021-12-28 09:26:26 +08:00
hoteas a5c002bbce 增加自适应模式 2021-12-27 21:30:33 +08:00
hoteas cf50a699a6 增加自适应模式 2021-12-27 21:30:24 +08:00
hoteas 662003c0ca 增加自适应模式 2021-12-27 20:40:16 +08:00
hoteas f24de2562a 优化系统 2021-12-27 18:21:41 +08:00
hoteas b84bd7e16f 优化系统 2021-12-27 14:09:49 +08:00
hoteas 2fb6abf53a Merge branch 'master' into myhs
# Conflicts:
#	example/admin/init.go
#	example/bzyy.exe
#	example/main.go
2021-12-27 14:02:39 +08:00
hoteas 2eab29f428 优化系统 2021-12-27 14:01:04 +08:00
hoteas 84ee0d259f 优化系统 2021-12-27 14:00:08 +08:00
hoteas eccab42fc8 优化系统 2021-12-18 00:07:35 +08:00
hoteas 1465ba36d3 优化系统 2021-12-17 14:37:41 +08:00
hoteas 8380b097b2 调试 2021-12-17 01:21:08 +08:00
hoteas 6b8f901163 调试 2021-12-16 13:40:19 +08:00
hoteas bb16f0a75b 调试 2021-12-16 13:24:31 +08:00
hoteas 84dbc5d71e 出入库完成 2021-12-16 10:49:35 +08:00
hoteas 166eeee64c 出入库完成 2021-12-15 09:24:41 +08:00
hoteas 7a649fd652 出入库完成 2021-12-15 05:56:31 +08:00
hoteas 94ae568526 书写前端接口 2021-12-12 04:22:30 +08:00
hoteas 9ec597f26c 书写前端接口 2021-12-11 23:53:47 +08:00
hoteas 388bc5006d 书写前端代码 2021-12-11 17:59:02 +08:00
hoteas 0e33c2ad9d ocr增加 2021-12-09 11:16:15 +08:00
hoteas af726fbcfb ocr增加 2021-12-09 10:58:53 +08:00
hoteas 1e82a5964d 优化makecode 2021-11-29 03:27:07 +08:00
hoteas d62ba8b0cd 优化makecode 2021-11-23 18:31:00 +08:00
hoteas 320ebe25ec 优化makecode 2021-11-18 12:22:14 +08:00
hoteas 68257d1742 绵阳宏升代码优化 2021-11-15 03:35:13 +08:00
hoteas 80d167cb1b 绵阳宏升代码优化 2021-11-15 03:34:45 +08:00
hoteas cd911e8fa4 巴中代码提交 2021-11-15 03:32:50 +08:00
hoteas faa6fcb00c 初次提交 2021-11-15 03:30:21 +08:00
hoteas 836c1f461f 初次提交 2021-11-15 03:28:14 +08:00
hoteas 97b2f54383 初次提交 2021-11-15 03:26:54 +08:00
hoteas 9d5f8438c5 初次提交 2021-11-13 21:06:29 +08:00
hoteas 3f7963e7cf 初次提交 2021-11-08 09:16:28 +08:00
hoteas 269df85d27 初次提交 2021-11-08 09:15:52 +08:00
hoteas d28c6863e4 初次提交 2021-11-08 06:50:37 +08:00
hoteas bba4990ccc 完善访问日志 2021-11-08 06:49:34 +08:00
hoteas c57afd6a5d 修复短信发送bug 2021-10-27 00:27:24 +08:00
hoteas 25f355c8d0 增加天府通办登录 2021-10-25 23:18:27 +08:00
hoteas b1b0673e69 修复bug 2021-10-21 23:20:58 +08:00
hoteas 72c086d726 修复bug 2021-10-21 23:19:32 +08:00
hoteas 3810ba6c0b 修复bug 2021-10-21 22:52:40 +08:00
hoteas 5c775b4539 修复bug 2021-10-18 04:49:55 +08:00
hoteas deb3e54cc3 修复bug 2021-09-25 04:36:07 +08:00
hoteas d1a8f6c668 短信变更 2021-09-24 15:01:03 +08:00
hoteas 2291ba7402 巴中恩阳适配 2021-09-24 10:49:07 +08:00
hoteas 20390091f2 巴中恩阳适配 2021-09-17 04:45:43 +08:00
hoteas 123d819b0f 开始新增代码生成配置2.0功能,配置文件格式规定完成 2021-09-17 04:00:49 +08:00
hoteas 30e275a27d 开始新增代码生成配置2.0功能,配置文件格式规定完成 2021-09-16 04:33:10 +08:00
hoteas 1a53f587e8 增加表关联新建功能,同时修复数据库bug 2021-09-12 06:14:01 +08:00
36 changed files with 1561 additions and 847 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
/.idea/* /.idea/*
.idea .idea
/example/config/app.json
+260 -38
View File
@@ -8,6 +8,7 @@ import (
. "./log" . "./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"
@@ -15,10 +16,12 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time"
) )
type Application struct { type Application struct {
*code.MakeCode *code.MakeCode
MakeCodeRouter Router
MethodRouter MethodRouter
Router Router
ContextBase ContextBase
@@ -63,15 +66,21 @@ func (that *Application) Run(router Router) {
// //
//} //}
that.Router = router //that.Router = router
if that.Router == nil {
that.Router = Router{}
}
for k, v := range router {
that.Router[k] = v
}
//重新设置MethodRouter//直达路由 //重新设置MethodRouter//直达路由
that.MethodRouter = MethodRouter{} that.MethodRouter = MethodRouter{}
modeRouterStrict := true modeRouterStrict := true
if that.Config.GetBool("modeRouterStrict") == false { if that.Config.GetBool("modeRouterStrict") == false {
modeRouterStrict = false modeRouterStrict = false
} }
if router != nil { if that.Router != nil {
for pk, pv := range router { for pk, pv := range that.Router {
if !modeRouterStrict { if !modeRouterStrict {
pk = strings.ToLower(pk) pk = strings.ToLower(pk)
} }
@@ -281,6 +290,7 @@ func (that *Application) urlSer(url string) (string, []string) {
//访问 //访问
func (that *Application) handler(w http.ResponseWriter, req *http.Request) { func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
nowUnixTime := time.Now()
_, s := that.urlSer(req.RequestURI) _, s := that.urlSer(req.RequestURI)
//获取cookie //获取cookie
@@ -292,21 +302,22 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
// 没有保存就生成随机的session // 没有保存就生成随机的session
cookie, err := req.Cookie(that.Config.GetString("sessionName")) cookie, err := req.Cookie(that.Config.GetString("sessionName"))
sessionId := Md5(strconv.Itoa(Rand(10))) sessionId := Md5(strconv.Itoa(Rand(10)))
token := req.FormValue("token") needSetCookie := ""
token := req.Header.Get("Authorization")
if len(token) != 32 {
if err != nil || (len(token) == 32 && cookie.Value != token) { token = req.FormValue("token")
if len(token) == 32 { }
sessionId = token //没有cookie或者cookie不等于token
} //有token优先token
//没有跨域设置 if len(token) == 32 {
if that.Config.GetString("crossDomain") == "" { sessionId = token
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"}) //没有token,则查阅session
} else { } else if err == nil && cookie.Value != "" {
//跨域允许需要设置cookie的允许跨域https才有效果
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; SameSite=None; Secure")
}
} else {
sessionId = cookie.Value sessionId = cookie.Value
//session也没有则判断是否创建cookie
} else {
needSetCookie = sessionId
} }
unescapeUrl, err := url.QueryUnescape(req.RequestURI) unescapeUrl, err := url.QueryUnescape(req.RequestURI)
@@ -325,11 +336,26 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
context.HandlerStr, context.RouterString = that.urlSer(context.HandlerStr) context.HandlerStr, context.RouterString = that.urlSer(context.HandlerStr)
//跨域设置 //跨域设置
that.crossDomain(&context) that.crossDomain(&context, needSetCookie)
//是否展示日志
if that.WebConnectLog != nil { defer func() {
that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")), context.Req.Method, context.HandlerStr) //是否展示日志
} 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")
}
}
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
"time cost:", ObjToFloat64(time.Now().UnixNano()-nowUnixTime.UnixNano())/1000000.00, "ms",
"data length:", ObjToFloat64(context.DataSize)/1000.00, "KB", context.HandlerStr)
}
}()
//访问拦截true继续false暂停 //访问拦截true继续false暂停
connectListenerLen := len(that.connectListener) connectListenerLen := len(that.connectListener)
@@ -394,8 +420,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
header.Set("Cache-Control", "no-cache") header.Set("Cache-Control", "no-cache")
} }
if strings.Index(path, ".m3u8") != -1 { t := strings.LastIndex(path, ".")
header.Add("Content-Type", "audio/mpegurl") if t != -1 {
tt := path[t:]
if MimeMaps[tt] != "" {
header.Add("Content-Type", MimeMaps[tt])
}
} }
//w.Write(data) //w.Write(data)
@@ -403,35 +435,66 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
} }
func (that *Application) crossDomain(context *Context) { func (that *Application) crossDomain(context *Context, sessionId string) {
//没有跨域设置 //没有跨域设置
if context.Config.GetString("crossDomain") == "" { if context.Config.GetString("crossDomain") == "" {
if sessionId != "" {
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
}
return return
} }
header := context.Resp.Header() header := context.Resp.Header()
//header.Set("Access-Control-Allow-Origin", "*")
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
header.Set("Access-Control-Allow-Credentials", "true")
header.Set("Access-Control-Expose-Headers", "*")
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
//不跨域,则不设置
remoteHost := context.Req.Host
if context.Config.GetString("port") == "80" || context.Config.GetString("port") == "443" {
remoteHost = remoteHost + ":" + context.Config.GetString("port")
}
if context.Config.GetString("crossDomain") != "auto" { if context.Config.GetString("crossDomain") != "auto" {
//不跨域,则不设置
if strings.Contains(context.Config.GetString("crossDomain"), remoteHost) {
if sessionId != "" {
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
}
return
}
header.Set("Access-Control-Allow-Origin", that.Config.GetString("crossDomain")) header.Set("Access-Control-Allow-Origin", that.Config.GetString("crossDomain"))
// 后端设置,2592000单位秒,这里是30天 // 后端设置,2592000单位秒,这里是30天
header.Set("Access-Control-Max-Age", "2592000") header.Set("Access-Control-Max-Age", "2592000")
//header.Set("Access-Control-Allow-Origin", "*")
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
header.Set("Access-Control-Allow-Credentials", "true")
header.Set("Access-Control-Expose-Headers", "*")
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
if sessionId != "" {
//跨域允许需要设置cookie的允许跨域https才有效果
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
}
return return
} }
origin := context.Req.Header.Get("Origin") origin := context.Req.Header.Get("Origin")
if origin != "" {
header.Set("Access-Control-Allow-Origin", origin) refer := context.Req.Header.Get("Referer")
if (origin != "" && strings.Contains(origin, remoteHost)) || strings.Contains(refer, remoteHost) {
if sessionId != "" {
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
}
return return
} }
refer := context.Req.Header.Get("Referer") if origin != "" {
if refer != "" { header.Set("Access-Control-Allow-Origin", origin)
//return
} else if refer != "" {
tempInt := 0 tempInt := 0
lastInt := strings.IndexFunc(refer, func(r rune) bool { lastInt := strings.IndexFunc(refer, func(r rune) bool {
if r == '/' && tempInt > 8 { if r == '/' && tempInt > 8 {
@@ -446,7 +509,20 @@ func (that *Application) crossDomain(context *Context) {
} }
refer = Substr(refer, 0, lastInt) refer = Substr(refer, 0, lastInt)
header.Set("Access-Control-Allow-Origin", refer) header.Set("Access-Control-Allow-Origin", refer)
//header.Set("Access-Control-Allow-Origin", "*")
} }
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
header.Set("Access-Control-Allow-Credentials", "true")
header.Set("Access-Control-Expose-Headers", "*")
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
if sessionId != "" {
//跨域允许需要设置cookie的允许跨域https才有效果
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
}
} }
//Init 初始化application //Init 初始化application
@@ -459,13 +535,31 @@ func Init(config string) Application {
appIns.SetCache() appIns.SetCache()
appIns.MakeCode = &code.MakeCode{} appIns.MakeCode = &code.MakeCode{}
codeConfig := appIns.Config.GetMap("codeConfig") codeConfig := appIns.Config.GetMap("codeConfig")
if codeConfig != nil { appIns.MakeCodeRouter = Router{}
if codeConfig != nil {
for k, _ := range codeConfig { for k, _ := range codeConfig {
if appIns.Config.GetInt("mode") == 2{ if appIns.Config.GetInt("mode") == 2 {
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db) appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, true)
}else{ appIns.MakeCodeRouter[k] = Proj{}
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil) } else if appIns.Config.GetInt("mode") == 3 {
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, false)
appIns.MakeCodeRouter[k] = Proj{}
} else {
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil, false)
appIns.MakeCodeRouter[k] = Proj{}
} }
//接入动态代码层
if appIns.Router == nil {
appIns.Router = Router{}
}
appIns.Router[k] = TptProject
for k1, _ := range appIns.MakeCode.TableColumns {
appIns.Router[k][k1] = appIns.Router[k]["hotimeCommon"]
}
setMakeCodeLintener(k, &appIns)
} }
} }
@@ -529,3 +623,131 @@ func SetSqliteDB(appIns *Application, config Map) {
return master, slave return master, slave
}) })
} }
func setMakeCodeLintener(name string, appIns *Application) {
appIns.SetConnectListener(func(context *Context) bool {
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
return true
}
if len(context.RouterString) > 1 && context.RouterString[0] == name {
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
return true
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
return true
}
if context.Session(name+"_id").Data == nil {
context.Display(2, "你还没有登录")
return false
}
}
//文件上传接口
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
if context.Session(name+"_id").Data == nil {
context.Display(2, "你还没有登录")
return false
}
//读取网络文件
fi, fheader, err := context.Req.FormFile("file")
if err != nil {
context.Display(3, err)
return false
}
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 false
}
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 false
}
_, e = io.Copy(newFile, fi)
if e != nil {
context.Display(3, e)
return false
}
context.Display(0, filePath)
return false
}
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
!(context.Router[context.RouterString[0]] != nil &&
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
return true
}
//排除无效操作
if len(context.RouterString) == 2 &&
context.Req.Method != "GET" &&
context.Req.Method != "POST" {
return true
}
//列表检索
if len(context.RouterString) == 2 &&
context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
}
//新建
if len(context.RouterString) == 2 &&
context.Req.Method == "POST" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
}
if len(context.RouterString) == 3 &&
context.Req.Method == "POST" {
return true
}
//查询单条
if len(context.RouterString) == 3 &&
context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
}
//更新
if len(context.RouterString) == 3 &&
context.Req.Method == "PUT" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
}
//移除
if len(context.RouterString) == 3 &&
context.Req.Method == "DELETE" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
}
context.View()
return false
})
}
+17 -17
View File
@@ -21,7 +21,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
//内存缓存有 //内存缓存有
if that.memoryCache != nil && that.memoryCache.SessionSet { if that.memoryCache != nil && that.memoryCache.SessionSet {
reData = that.memoryCache.Cache(key, data...) reData = that.memoryCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
return reData return reData
} }
} }
@@ -29,9 +29,9 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
//redis缓存有 //redis缓存有
if that.redisCache != nil && that.redisCache.SessionSet { if that.redisCache != nil && that.redisCache.SessionSet {
reData = that.redisCache.Cache(key, data...) reData = that.redisCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil && that.memoryCache.SessionSet { if that.memoryCache != nil && that.memoryCache.SessionSet {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
return reData return reData
} }
@@ -40,12 +40,12 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
//db缓存有 //db缓存有
if that.dbCache != nil && that.dbCache.SessionSet { if that.dbCache != nil && that.dbCache.SessionSet {
reData = that.dbCache.Cache(key, data...) reData = that.dbCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil && that.memoryCache.SessionSet { if that.memoryCache != nil && that.memoryCache.SessionSet {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
if that.redisCache != nil && that.redisCache.SessionSet { if that.redisCache != nil && that.redisCache.SessionSet {
that.redisCache.Cache(key, reData) that.redisCache.Cache(key, reData.Data)
} }
return reData return reData
@@ -76,7 +76,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
//内存缓存有 //内存缓存有
if that.memoryCache != nil && that.memoryCache.DbSet { if that.memoryCache != nil && that.memoryCache.DbSet {
reData = that.memoryCache.Cache(key, data...) reData = that.memoryCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
return reData return reData
} }
} }
@@ -84,9 +84,9 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
//redis缓存有 //redis缓存有
if that.redisCache != nil && that.redisCache.DbSet { if that.redisCache != nil && that.redisCache.DbSet {
reData = that.redisCache.Cache(key, data...) reData = that.redisCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil && that.memoryCache.DbSet { if that.memoryCache != nil && that.memoryCache.DbSet {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
return reData return reData
} }
@@ -95,13 +95,13 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
//redis缓存有 //redis缓存有
if that.dbCache != nil && that.dbCache.DbSet { if that.dbCache != nil && that.dbCache.DbSet {
reData = that.dbCache.Cache(key, data...) reData = that.dbCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil && that.memoryCache.DbSet { if that.memoryCache != nil && that.memoryCache.DbSet {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
if that.redisCache != nil && that.redisCache.DbSet { if that.redisCache != nil && that.redisCache.DbSet {
that.redisCache.Cache(key, reData) that.redisCache.Cache(key, reData.Data)
} }
return reData return reData
@@ -140,10 +140,10 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
//redis缓存有 //redis缓存有
if that.redisCache != nil { if that.redisCache != nil {
reData = that.redisCache.Cache(key, data...) reData = that.redisCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil { if that.memoryCache != nil {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
return reData return reData
} }
@@ -152,12 +152,12 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
//redis缓存有 //redis缓存有
if that.dbCache != nil { if that.dbCache != nil {
reData = that.dbCache.Cache(key, data...) reData = that.dbCache.Cache(key, data...)
if reData != nil { if reData.Data != nil {
if that.memoryCache != nil { if that.memoryCache != nil {
that.memoryCache.Cache(key, reData) that.memoryCache.Cache(key, reData.Data)
} }
if that.redisCache != nil { if that.redisCache != nil {
that.redisCache.Cache(key, reData) that.redisCache.Cache(key, reData.Data)
} }
return reData return reData
} }
+232
View File
@@ -0,0 +1,232 @@
package hotime
import (
. "./common"
"strings"
)
// Project 管理端项目
var TptProject = Proj{
//"user": UserCtr,
"hotimeCommon": Ctr{
"info": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]}
if len(inData) == 1 {
inData["id"] = where["id"]
where = Map{"AND": inData}
} else if len(inData) > 1 {
where["OR"] = inData
where = Map{"AND": where}
}
re := that.Db.Get(that.RouterString[1], str, where)
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
if column == nil {
continue
}
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
"add": func(that *Context) {
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re := that.Db.Insert(that.RouterString[1], inData)
if re == 0 {
that.Display(4, "无法插入对应数据")
return
}
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
} else if inData.GetString("index") != "" {
inData["index"] = "," + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
}
that.Display(0, re)
},
"update": func(that *Context) {
inData := that.MakeCode.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)
},
"remove": func(that *Context) {
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re := int64(0)
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
re = that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
} else {
re = that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
}
if re == 0 {
that.Display(4, "删除数据失败")
return
}
that.Display(0, "删除成功")
},
"search": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
count := that.Db.Count(that.RouterString[1], leftJoin, where)
reData := that.Db.Page(page, pageSize).
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
for _, v := range reData {
for k, _ := range v {
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
if column == nil {
continue
}
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
if parentC != nil {
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
}
}
}
}
that.Display(0, Map{"count": count, "data": reData})
},
},
"hotime": Ctr{
"login": func(this *Context) {
hotimeName := this.RouterString[0]
name := this.Req.FormValue("name")
password := this.Req.FormValue("password")
if name == "" || password == "" {
this.Display(3, "参数不足")
return
}
user := this.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
if user == nil {
this.Display(5, "登录失败")
return
}
this.Session(hotimeName+"_id", user.GetCeilInt("id"))
this.Session(hotimeName+"_name", name)
delete(user, "password")
this.Display(0, user)
},
"logout": func(this *Context) {
hotimeName := this.RouterString[0]
this.Session(hotimeName+"_id", nil)
this.Session(hotimeName+"_name", nil)
this.Display(0, "退出登录成功")
},
"info": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
str, inData := that.MakeCode.Info(hotimeName, data, that.Db)
where := Map{"id": that.Session(hotimeName + "_id").ToCeilInt()}
if len(inData) == 1 {
inData["id"] = where["id"]
where = Map{"AND": inData}
} else if len(inData) > 1 {
where["OR"] = inData
where = Map{"AND": where}
}
re := that.Db.Get(hotimeName, str, where)
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column := that.MakeCode.TableColumns[hotimeName][k]
if column == nil {
continue
}
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
//是角色表则取下角色值
if column.GetString("link") == "role" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,auth,"+column.GetString("value"), Map{"id": v})
} else {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
}
}
}
that.Display(0, re)
},
},
}
+16 -6
View File
@@ -8,12 +8,19 @@ var Config = Map{
"name": "HoTimeDashBoard", "name": "HoTimeDashBoard",
"id": "2f92h3herh23rh2y8", "id": "2f92h3herh23rh2y8",
"label": "HoTime管理平台", "label": "HoTime管理平台",
"menus": []Map{ "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": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
//{"label": "系统管理", "name": "setting", "icon": "el-icon-setting", //{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
// "menus": []Map{ // "menus": []Map{
// {"label": "用户管理", "table": "user"}, // {"label": "用户管理", "table": "user",
// "default": {
// "path": "info",
// "id": "1"
// },
// "auth": ["show","edit","info","add","delete"],
// },
// {"label": "组织管理", "table": "organization"}, // {"label": "组织管理", "table": "organization"},
// {"label": "地区管理", "table": "area"}, // {"label": "地区管理", "table": "area"},
// {"label": "角色管理", "table": "role"}, // {"label": "角色管理", "table": "role"},
@@ -56,9 +63,10 @@ var ColumnNameType = []ColumnShow{
//通用 //通用
{"idcard", false, true, true, false, "", false}, {"idcard", false, true, true, false, "", false},
{"id", true, false, true, false, "", true}, {"id", true, false, true, false, "", true},
{"parent_id", true, true, true, false, "", true},
//"sn"{true,true,true,""}, //"sn"{true,true,true,""},
{"status", true, true, true, false, "select", false}, {"status", true, true, true, false, "select", false},
{"state", false, true, true, false, "select", false}, {"state", true, true, true, false, "select", false},
{"sex", true, true, true, false, "select", false}, {"sex", true, true, true, false, "select", false},
{"delete", false, false, false, false, "", false}, {"delete", false, false, false, false, "", false},
@@ -67,7 +75,7 @@ var ColumnNameType = []ColumnShow{
{"latitude", false, true, true, false, "", false}, {"latitude", false, true, true, false, "", false},
{"longitude", false, true, true, false, "", false}, {"longitude", false, true, true, false, "", false},
{"index", false, false, false, false, "", false}, {"index", false, false, false, false, "index", false},
{"password", false, true, false, false, "password", false}, {"password", false, true, false, false, "password", false},
{"pwd", false, true, false, false, "password", false}, {"pwd", false, true, false, false, "password", false},
{"info", false, true, true, false, "", false}, {"info", false, true, true, false, "", false},
@@ -80,14 +88,16 @@ var ColumnNameType = []ColumnShow{
{"content", false, true, true, false, "", false}, {"content", false, true, true, false, "", false},
{"address", false, true, true, false, "", false}, {"address", false, true, true, false, "", false},
{"full_name", false, true, true, false, "", false}, {"full_name", false, true, true, false, "", false},
{"create_time", false, false, true, false, "", false}, {"create_time", false, false, true, false, "time", true},
{"modify_time", false, false, true, false, "", false}, {"modify_time", true, false, true, false, "time", true},
{"image", false, true, true, false, "image", false}, {"image", false, true, true, false, "image", false},
{"img", false, true, true, false, "image", false}, {"img", false, true, true, false, "image", false},
{"icon", false, true, true, false, "image", false},
{"avatar", false, true, true, false, "image", false}, {"avatar", false, true, true, false, "image", false},
{"file", false, true, true, false, "file", false}, {"file", false, true, true, false, "file", false},
{"age", false, true, true, false, "", false}, {"age", false, true, true, false, "", false},
{"email", false, true, true, false, "", false}, {"email", false, true, true, false, "", false},
{"time", true, false, true, false, "", false}, {"time", true, true, true, true, "time", false},
{"level", false, false, true, false, "", false}, {"level", false, false, true, false, "", false},
{"rule", true, true, true, false, "form", false},
} }
+264 -100
View File
@@ -10,6 +10,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
type MakeCode struct { type MakeCode struct {
@@ -21,7 +22,7 @@ type MakeCode struct {
Error Error
} }
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) { func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCode bool) {
isMake := false isMake := false
idSlice := Slice{} idSlice := Slice{}
@@ -112,7 +113,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
} }
if db==nil{ if db == nil {
return return
} }
@@ -140,30 +141,17 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
that.TableConfig[v.GetString("name")] = Map{ that.TableConfig[v.GetString("name")] = Map{
"label": v.GetString("label"), "label": v.GetString("label"),
"table": v.GetString("name"), "table": v.GetString("name"),
"auth": []string{"add", "delete", "edit", "info"}, "auth": []string{"show", "add", "delete", "edit", "info"},
"columns": []Map{}, "columns": []Map{},
"search": []Map{ "search": []Map{
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil}, {"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
{"type": "search", "name": "daterange", "label": "时间段", "value": nil}, {"type": "search", "name": "daterange", "label": "时间段", "value": nil},
{"type": "search", "name": "sort", "label": "排序", "value": nil}, {"type": "search", "name": "sort", "label": "排序", "value": nil},
//{"type": "select", "name": "state", "label": "状态", "value": nil,
// "options": []Map{
// {"name": "正常", "value": 0},
// {"name": "异常", "value": 1},
// {"name": "全部", "value": nil},
// },
//},
}, },
} }
} }
//else {
// if !(that.TableConfig.GetMap(v.GetString("name")).GetString("label") != "备注" &&
// v.GetString("label") == "备注") {
// that.TableConfig.GetMap(v.GetString("name"))["label"] = v.GetString("label")
// }
//
//}
//初始化 //初始化
if that.TableColumns[v.GetString("name")] == nil { if that.TableColumns[v.GetString("name")] == nil {
that.TableColumns[v.GetString("name")] = make(map[string]Map) that.TableColumns[v.GetString("name")] = make(map[string]Map)
@@ -183,7 +171,8 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
} }
idSlice = append(idSlice, tableInfo) idSlice = append(idSlice, tableInfo)
for _, info := range tableInfo { for _, info1 := range tableInfo {
info := DeepCopyMap(info1).(Map)
if info.GetString("label") == "" { if info.GetString("label") == "" {
info["label"] = info.GetString("name") info["label"] = info.GetString("name")
} }
@@ -191,10 +180,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
if coloum == nil { if coloum == nil {
//根据类型判断真实类型 //根据类型判断真实类型
for k, v := range ColumnDataType { for k, v1 := range ColumnDataType {
if strings.Contains(info.GetString("type"), k) || strings.Contains(info.GetString("name"), k) { if strings.Contains(info.GetString("name"), k) || strings.Contains(info.GetString("type"), k) {
info["type"] = v info["type"] = v1
break
} }
} }
@@ -205,36 +193,53 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
//"add": false, "info": false, "edit": false, "list": true, //"add": false, "info": false, "edit": false, "list": true,
//"must": false, //"must": false,
} }
//备注以空格隔开,空格后的是其他备注 //备注以空格隔开,空格后的是其他备注
indexNum := strings.Index(info.GetString("label"), ":") indexNum := strings.Index(info.GetString("label"), " ")
if indexNum > 0 { if indexNum > -1 {
coloum["label"] = info.GetString("label")[:indexNum] coloum["label"] = info.GetString("label")[:indexNum]
} }
//去除数据信息,是用:号分割的
indexNum = strings.Index(coloum.GetString("label"), ":")
if indexNum > -1 {
coloum["label"] = coloum.GetString("label")[:indexNum]
}
for _, v := range ColumnNameType { for _, ColumnName := range ColumnNameType {
if (v.Strict && coloum.GetString("name") == v.Name) || (!v.Strict && strings.Contains(coloum.GetString("name"), v.Name)) { if (ColumnName.Strict && coloum.GetString("name") == ColumnName.Name) ||
(!ColumnName.Strict && strings.Contains(coloum.GetString("name"), ColumnName.Name)) {
//全部都不需要则不加入 //全部都不需要则不加入
if v.Edit == false && v.List == false && v.Info == false { if ColumnName.Edit == false && ColumnName.List == false && ColumnName.Info == false {
coloum["notUse"] = true coloum["notUse"] = true
//continue
}
coloum["info"] = ColumnName.Info
coloum["edit"] = ColumnName.Edit
coloum["add"] = ColumnName.Edit
coloum["list"] = ColumnName.List
coloum["must"] = ColumnName.Must
if ColumnName.Info {
delete(coloum, "info")
}
if ColumnName.Edit {
delete(coloum, "edit")
delete(coloum, "add")
}
if ColumnName.List {
delete(coloum, "list")
}
if ColumnName.Must {
delete(coloum, "must")
}
if ColumnName.Type != "" {
coloum["type"] = ColumnName.Type
}
if ColumnName.Strict && coloum.GetString("name") == ColumnName.Name {
break break
} }
if v.Info == false {
coloum["info"] = v.Info
}
if v.Edit == false {
coloum["edit"] = v.Edit
coloum["add"] = v.Edit
}
if v.List == false {
coloum["list"] = v.List
}
if v.Must == true {
coloum["must"] = v.Must
}
if v.Type != "" {
coloum["type"] = v.Type
}
break
} }
} }
@@ -243,9 +248,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
coloum["sortable"] = true coloum["sortable"] = true
} }
if !coloum.GetBool("notUse") { //if !coloum.GetBool("notUse") {
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum) that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
} //}
//如果是select类型需要设置options //如果是select类型需要设置options
//if coloum.GetString("type") == "select" { //if coloum.GetString("type") == "select" {
@@ -286,22 +291,25 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
} }
//创建模块文件 if makeCode {
//判断文件是否存在 //创建模块文件
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm) //判断文件是否存在
_, err := os.Stat(name + "/" + v.GetString("name") + ".go") //_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
if err != nil { //文件不存在,则根据模板创建 _, err := os.Stat(name + "/" + v.GetString("name") + ".go")
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1) if err != nil { //文件不存在,则根据模板创建
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1) myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1)
_ = os.MkdirAll(name, os.ModeDir) myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm) _ = os.MkdirAll(name, os.ModeDir)
if err != nil { err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
that.Error.SetError(err) if err != nil {
that.Error.SetError(err)
}
isMake = true
} }
isMake = true
}
ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n " ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n "
}
} }
@@ -309,7 +317,6 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
//生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一 //生成id,判断数据库是否有改变,以保证数据库和配置文件匹配唯一
id := Md5(ObjToStr(idSlice)) id := Md5(ObjToStr(idSlice))
if id == that.Config.GetString("id") { if id == that.Config.GetString("id") {
if isMake { //有生成包文件 if isMake { //有生成包文件
fmt.Println("有新的业务代码生成,请重新运行") fmt.Println("有新的业务代码生成,请重新运行")
@@ -324,6 +331,10 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
isMenusGet := false //判断是否被目录收录 isMenusGet := false //判断是否被目录收录
for indexKey, _ := range that.IndexMenus { for indexKey, _ := range that.IndexMenus {
indexCode := strings.Index(indexKey, fk) indexCode := strings.Index(indexKey, fk)
if indexCode == 0 || indexCode == 4 {
isMenusGet = false
continue
}
//如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串) //如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) { if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
isMenusGet = true isMenusGet = true
@@ -340,16 +351,21 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
//并且代表有前缀,根据数据表分库设定使用 //并且代表有前缀,根据数据表分库设定使用
if tablePrefixCode != -1 { if tablePrefixCode != -1 {
prefixName = fk[:tablePrefixCode] prefixName = fk[:tablePrefixCode]
} else {
prefixName = fk
} }
if tablePrefixCode != -1 { //if tablePrefixCode != -1 {
for ck, _ := range that.TableColumns { for ck, _ := range that.TableColumns {
//判断不止一个前缀相同 //判断不止一个前缀相同
if strings.Index(ck, prefixName) == 0 && ck != prefixName && ck != fk { if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
isNewPrefix = true isNewPrefix = true
break break
}
} }
} }
//}
prefixName = DefaultMenuParentName + ":" + prefixName
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk} 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"} mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
@@ -361,8 +377,15 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
} }
//没有新前缀 //没有新前缀
if that.IndexMenus[prefixName] != nil { if that.IndexMenus[prefixName] != nil {
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns) if that.IndexMenus[prefixName+"/"+fk] == nil {
that.IndexMenus[prefixName+"/"+fk] = menuIns that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
that.IndexMenus[prefixName+"/"+fk] = menuIns
} else {
for k, v := range menuIns {
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
}
}
} else { } else {
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置 that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
@@ -395,23 +418,29 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
if oldTableName == "parent" { if oldTableName == "parent" {
oldTableName = fk oldTableName = fk
} }
//如果本身匹配则不再继续精简匹配
if that.TableConfig[oldTableName] == nil {
//如果依然找不到则查询system_org是否存在 //如果依然找不到则查询system_org是否存在
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil { if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName oldTableName = DefaultMenuParentName + "_" + oldTableName
} }
//字段有动词前缀,自动进行解析 //字段有动词前缀,自动进行解析
prefixColumn := strings.Index(oldTableName, "_") prefixColumn := strings.Index(oldTableName, "_")
//sys_org_id oldTableName即为sys此处判断为org表存在 //sys_org_id oldTableName即为sys此处判断为org表存在
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil { if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
oldTableName = oldTableName[prefixColumn+1:] oldTableName = oldTableName[prefixColumn+1:]
} }
//如果依然找不到则查询system_org是否存在 if prefixColumn >= len(oldTableName) {
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil { prefixColumn = -1
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:] }
//如果依然找不到则查询system_org是否存在
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
}
} }
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分, //普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
@@ -476,13 +505,16 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
fmt.Println(id, "---", that.Config.GetString("id")) fmt.Println(id, "---", that.Config.GetString("id"))
that.Config["id"] = id that.Config["id"] = id
//init文件初始化
myInit = strings.Replace(myInit, "{{id}}", id, -1) if makeCode {
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1) //init文件初始化
_ = os.MkdirAll(name, os.ModeDir) myInit = strings.Replace(myInit, "{{id}}", id, -1)
err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm) myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
if err != nil { _ = os.MkdirAll(name, os.ModeDir)
that.Error.SetError(err) err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm)
if err != nil {
that.Error.SetError(err)
}
} }
//写入配置文件 //写入配置文件
//var configByte bytes.Buffer //var configByte bytes.Buffer
@@ -495,14 +527,49 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
} }
fmt.Println("有新的代码生成,请重新运行") fmt.Println("有新的代码生成,请重新运行")
os.Exit(-1) os.Exit(-1)
} }
func (that *MakeCode) Info(table string) string { func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string, Map) {
reStr := "" reStr := ""
data := Map{}
var ruleData Map
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
if v == nil { if v == nil {
continue continue
} }
//准备加入索引权限
if v.GetString("link") != "" &&
userData != nil &&
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
//初始化ruleData
if ruleData == nil {
ruleData = Map{}
for _, v := range that.TableColumns["admin"] {
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" &&
userData.Get(v.GetString("name")) != nil {
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
}
}
}
if ruleData[v.GetString("link")] != nil {
if v.GetString("name") == "parent_id" {
data["index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
} else {
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
for _, v := range idMap {
ids = append(ids, v.GetCeilInt("id"))
}
data[v.GetString("name")] = ids
}
}
}
if v.Get("info") == nil || v.GetBool("info") { if v.Get("info") == nil || v.GetBool("info") {
reStr += "`" + v.GetString("name") + "`," reStr += "`" + v.GetString("name") + "`,"
} }
@@ -510,19 +577,28 @@ func (that *MakeCode) Info(table string) string {
if len(reStr) != 0 { if len(reStr) != 0 {
reStr = reStr[:len(reStr)-1] reStr = reStr[:len(reStr)-1]
} }
return reStr return reStr, data
} }
func (that *MakeCode) Add(table string, req *http.Request) Map { func (that *MakeCode) Add(table string, req *http.Request) Map {
data := Map{} data := Map{}
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = ","
}
continue continue
} }
if v.Get("add") == nil || v.GetBool("add") { if v.Get("add") == nil || v.GetBool("add") {
if len(req.Form[v.GetString("name")]) == 0 { if len(req.Form[v.GetString("name")]) == 0 {
return nil if v.GetBool("must") {
return nil
} else {
continue
}
} }
reqValue := req.FormValue(v.GetString("name")) reqValue := req.FormValue(v.GetString("name"))
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") { if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
@@ -535,7 +611,15 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
} }
} }
}
if v.GetString("name") == "create_time" {
data[v.GetString("name")] = time.Now().Unix()
continue
}
if v.GetString("name") == "modify_time" {
data[v.GetString("name")] = time.Now().Unix()
} }
} }
if len(data) == 0 { if len(data) == 0 {
@@ -549,8 +633,12 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { if v.GetBool("notUse") {
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
data[v.GetString("name")] = ","
}
continue continue
} }
if v.Get("edit") == nil || v.GetBool("edit") { if v.Get("edit") == nil || v.GetBool("edit") {
reqValue := req.FormValue(v.GetString("name")) reqValue := req.FormValue(v.GetString("name"))
if reqValue == "" || reqValue == "null" { if reqValue == "" || reqValue == "null" {
@@ -562,6 +650,9 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
data[v.GetString("name")] = reqValue data[v.GetString("name")] = reqValue
} }
} }
if v.GetString("name") == "modify_time" {
data[v.GetString("name")] = time.Now().Unix()
}
} }
if len(data) == 0 { if len(data) == 0 {
@@ -570,19 +661,36 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
return data return data
} }
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
}
func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (string, Map, Map) { }
return data
}
func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
reStr := "" reStr := ""
leftJoin := Map{} leftJoin := Map{}
data := Map{} data := Map{}
keyword := Map{} keyword := Map{}
daterange := Map{} daterange := Map{}
sort := Map{} sort := Map{}
var ruleData Map
hasUser := false
keywordStr := req.FormValue("keyword") keywordStr := req.FormValue("keyword")
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { if v.GetBool("notUse") {
continue continue
} }
if v["list"] != false { if v["list"] != false {
@@ -590,17 +698,59 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
if v.GetString("link") != "" && if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" { v.GetString("name") != "parent_id" {
reStr += v.GetString("link") + "." + reStr += table + "." + v.GetString("name") + "," +
v.GetString("value") + " AS " + v.GetString("link") + "." + v.GetString("value") + " AS " +
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + "," v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
leftJoin["[>]"+v.GetString("link")] = leftJoin["[>]"+v.GetString("link")] =
table + "." + v.GetString("name") + "=" + table + "." + v.GetString("name") + "=" +
v.GetString("link") + ".id" v.GetString("link") + ".id"
if v.GetString("link") == "admin" {
hasUser = true
}
reqValue := req.FormValue(v.GetString("name"))
if reqValue != "" {
data[table+"."+v.GetString("name")] = reqValue
}
} else { } else {
reStr += table + "." + v.GetString("name") + "," reStr += table + "." + v.GetString("name") + ","
} }
//准备加入索引权限
if v.GetString("link") != "" &&
userData != nil &&
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
//初始化ruleData
if ruleData == nil {
ruleData = Map{}
for _, v := range that.TableColumns["admin"] {
if v.GetString("link") != "" &&
v.GetString("name") != "parent_id" &&
userData.Get(v.GetString("name")) != nil {
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
}
}
}
if ruleData[v.GetString("link")] != nil {
if v.GetString("name") == "parent_id" {
data[table+".index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
} else {
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
for _, v := range idMap {
ids = append(ids, v.GetCeilInt("id"))
}
data[table+"."+v.GetString("name")] = ids
}
}
}
if keywordStr != "" { if keywordStr != "" {
if v.GetString("type") == "text" { if v.GetString("type") == "text" {
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
@@ -647,7 +797,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
} }
//日期类型 //日期类型
if searchItemName == "daterange" && v.GetString("type") == "time" { if searchItemName == "daterange" && v.GetString("type") == "time" {
fmt.Println(req.Form["daterange"]) //fmt.Println(req.Form["daterange"])
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
} }
} }
@@ -662,7 +812,8 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
if searchItemName == "parent_id" { if searchItemName == "parent_id" {
parentID := ObjToInt(req.FormValue("parent_id")) parentID := ObjToInt(req.FormValue("parent_id"))
if parentID == 0 { if parentID == 0 {
data["OR"] = Map{table + ".parent_id[#]": 0, table + ".parent_id": nil} parentID = userData.GetCeilInt(table + "_id")
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
} else { } else {
data[table+".parent_id"] = parentID data[table+".parent_id"] = parentID
} }
@@ -672,6 +823,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
data[table+"."+searchItemName] = reqValue data[table+"."+searchItemName] = reqValue
} }
if sort["ORDER"] == nil {
sort["ORDER"] = table + ".id DESC"
}
where := Map{} where := Map{}
@@ -709,6 +863,12 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
where = data where = data
} }
if len(where) == 0 && hasUser {
//where["admin.id"] = userData["id"]
}
if len(sort) != 0 { if len(sort) != 0 {
for k, v := range sort { for k, v := range sort {
where[k] = v where[k] = v
@@ -717,3 +877,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
return reStr, leftJoin, where return reStr, leftJoin, where
} }
func setListener() {
}
+120 -40
View File
@@ -15,26 +15,55 @@ var Project = Proj{
{{tablesCtr}} {{tablesCtr}}
"hotime":Ctr{ "hotime":Ctr{
"login": func(this *Context) { "login": func(this *Context) {
name:=this.Req.FormValue("name") name := this.Req.FormValue("name")
password:=this.Req.FormValue("password") password := this.Req.FormValue("password")
if name==""||password==""{ if name == "" || password == "" {
this.Display(3,"参数不足") this.Display(3, "参数不足")
return return
} }
user:=this.Db.Get("{{name}}","*",Map{"AND":Map{"name":name,"password":Md5(password)}}) user := this.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
if user==nil{ if user == nil {
this.Display(5,"登录失败") this.Display(5, "登录失败")
return return
} }
this.Session("id",user.GetCeilInt("id")) this.Session("admin_id", user.GetCeilInt("id"))
this.Session("name",name) this.Session("admin_name", name)
this.Display(0,"登录成功") this.Display(0, this.SessionId)
}, },
"logout": func(this *Context) { "logout": func(this *Context) {
this.Session("id",nil) this.Session("admin_id", nil)
this.Session("name",nil) this.Session("admin_name", nil)
this.Display(0,"退出登录成功") this.Display(0, "退出登录成功")
}, },
"info": func(that *Context) {
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info("admin", data, that.Db)
where := Map{"id": that.Session("admin_id").ToCeilInt()}
if len(inData) ==1 {
inData["id"] =where["id"]
where = Map{"AND": inData}
}else if len(inData) >1 {
where["OR"]=inData
where = Map{"AND": where}
}
re := that.Db.Get("admin", str, where)
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column := that.MakeCode.TableColumns["admin"][k]
if column == nil {
continue
}
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"),"id," +column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
},
} }
` `
var CtrTpt = `package {{name}} var CtrTpt = `package {{name}}
@@ -42,11 +71,24 @@ var CtrTpt = `package {{name}}
import ( import (
. "../../../hotime" . "../../../hotime"
. "../../../hotime/common" . "../../../hotime/common"
"strings"
) )
var {{table}}Ctr = Ctr{ var {{table}}Ctr = Ctr{
"info": func(that *Context) { "info": func(that *Context) {
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]}
if len(inData) ==1 {
inData["id"] =where["id"]
where = Map{"AND": inData}
}else if len(inData) >1 {
where["OR"]=inData
where = Map{"AND": where}
}
re := that.Db.Get(that.RouterString[1], str, where)
if re == nil { if re == nil {
that.Display(4, "找不到对应信息") that.Display(4, "找不到对应信息")
@@ -54,13 +96,12 @@ var {{table}}Ctr = Ctr{
} }
for k, v := range re { for k, v := range re {
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
column:=that.MakeCode.TableColumns[that.RouterString[1]][k] if column == nil {
if column==nil{
continue continue
} }
if (column["list"]==nil||column.GetBool("list"))&&column.GetString("link")!=""{ if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
} }
} }
@@ -72,12 +113,23 @@ var {{table}}Ctr = Ctr{
that.Display(3, "请求参数不足") that.Display(3, "请求参数不足")
return return
} }
re := that.Db.Insert(that.RouterString[1], inData) re := that.Db.Insert(that.RouterString[1], inData)
if re == 0 { if re == 0 {
that.Display(4, "无法插入对应数据") that.Display(4, "无法插入对应数据")
return return
} }
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
index := that.Db.Get(that.RouterString[1], "` + "`index`" + `", Map{"id": inData.Get("parent_id")})
inData["index"] = index.GetString("index")+ObjToStr(re)+","
that.Db.Update(that.RouterString[1],Map{"index":inData["index"]},Map{"id":re})
}else if inData.GetString("index") != ""{
inData["index"] = "," + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
}
that.Display(0, re) that.Display(0, re)
}, },
@@ -87,6 +139,22 @@ var {{table}}Ctr = Ctr{
that.Display(3, "没有找到要更新的数据") that.Display(3, "没有找到要更新的数据")
return return
} }
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
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")})
}
}
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
if re == 0 { if re == 0 {
@@ -97,54 +165,66 @@ var {{table}}Ctr = Ctr{
that.Display(0, re) that.Display(0, re)
}, },
"remove": func(that *Context) { "remove": func(that *Context) {
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re :=int64(0)
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
re=that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
}else {
re=that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
}
if re == 0 { if re == 0 {
that.Display(4, "删除数据失败") that.Display(4, "删除数据失败")
return return
} }
that.Display(0, re) that.Display(0, "删除成功")
}, },
"search": func(that *Context) { "search": func(that *Context) {
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db) columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
page:=ObjToInt(that.Req.FormValue("page"))
pageSize:=ObjToInt(that.Req.FormValue("pageSize"))
if page<1{ page := ObjToInt(that.Req.FormValue("page"))
page=1 pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
} }
if pageSize<=0{ if pageSize <= 0 {
pageSize=20 pageSize = 20
} }
count:=that.Db.Count(that.RouterString[1],leftJoin,where) count := that.Db.Count(that.RouterString[1], leftJoin, where)
reData := that.Db.Page(page, pageSize). reData := that.Db.Page(page, pageSize).
PageSelect(that.RouterString[1],leftJoin,columnStr, where) PageSelect(that.RouterString[1], leftJoin, columnStr, where)
for _, v := range reData { for _, v := range reData {
for k, _ := range v { for k, _ := range v {
column:=that.MakeCode.TableColumns[that.RouterString[1]][k] column := that.MakeCode.TableColumns[that.RouterString[1]][k]
if column==nil{ if column == nil {
continue continue
} }
if column["list"]!=false&&column["name"]=="parent_id"&&column.GetString("link")!=""{ if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]="" v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
if parentC!=nil{ if parentC != nil {
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=parentC.GetString(column.GetString("value")) v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
} }
} }
} }
} }
that.Display(0, Map{"count":count,"data":reData}) that.Display(0, Map{"count": count, "data": reData})
}, },
} }
` `
+36
View File
@@ -36,6 +36,42 @@ func StrFirstToUpper(str string) string {
return strings.ToUpper(first) + other return strings.ToUpper(first) + other
} }
//相似度计算 ld compares two strings and returns the levenshtein distance between them.
func StrLd(s, t string, ignoreCase bool) int {
if ignoreCase {
s = strings.ToLower(s)
t = strings.ToLower(t)
}
d := make([][]int, len(s)+1)
for i := range d {
d[i] = make([]int, len(t)+1)
}
for i := range d {
d[i][0] = i
}
for j := range d[0] {
d[0][j] = j
}
for j := 1; j <= len(t); j++ {
for i := 1; i <= len(s); i++ {
if s[i-1] == t[j-1] {
d[i][j] = d[i-1][j-1]
} else {
min := d[i-1][j]
if d[i][j-1] < min {
min = d[i][j-1]
}
if d[i-1][j-1] < min {
min = d[i-1][j-1]
}
d[i][j] = min + 1
}
}
}
return d[len(s)][len(t)]
}
// Substr 字符串截取 // Substr 字符串截取
func Substr(str string, start int, length int) string { func Substr(str string, start int, length int) string {
rs := []rune(str) rs := []rune(str)
+9
View File
@@ -135,6 +135,15 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 {
err = errors.New("没有合适的转换对象!") err = errors.New("没有合适的转换对象!")
} }
} }
if math.IsNaN(v) {
err = errors.New("float64 is NaN")
v = 0
}
if math.IsInf(v, 0) {
err = errors.New("float64 is Inf")
v = 0
}
if len(e) != 0 { if len(e) != 0 {
e[0].SetError(err) e[0].SetError(err)
} }
+4
View File
@@ -18,6 +18,7 @@ type Context struct {
RespData Map RespData Map
CacheIns CacheIns
SessionIns SessionIns
DataSize int
HandlerStr string //复写请求url HandlerStr string //复写请求url
} }
@@ -56,6 +57,7 @@ func (that *Context) Display(statu int, data interface{}) {
} }
func (that *Context) View() { func (that *Context) View() {
if that.RespData == nil { if that.RespData == nil {
return return
} }
@@ -63,6 +65,8 @@ func (that *Context) View() {
if err != nil { if err != nil {
return return
} }
that.DataSize = len(d)
that.RespData = nil that.RespData = nil
that.Resp.Write(d) that.Resp.Write(d)
return
} }
+4 -5
View File
@@ -652,8 +652,10 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
where := "" where := ""
res := make([]interface{}, 0) res := make([]interface{}, 0)
length := len(k) length := len(k)
if k == "[#]" {
if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' { k = strings.Replace(k, "[#]", "", -1)
where += " " + ObjToStr(v) + " "
} else if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
def := false def := false
switch Substr(k, length-3, 3) { switch Substr(k, length-3, 3) {
@@ -791,9 +793,6 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
} }
} }
} else if k == "[#]" {
k = strings.Replace(k, "[#]", "", -1)
where += " " + ObjToStr(v) + " "
} else { } else {
//fmt.Println(reflect.ValueOf(v).Type().String()) //fmt.Println(reflect.ValueOf(v).Type().String())
if !strings.Contains(k, ".") { if !strings.Contains(k, ".") {
+138
View File
@@ -0,0 +1,138 @@
package aliyun
import (
. "../../common"
"fmt"
"io/ioutil"
"net/http"
//"fmt"
)
type Company struct {
ApiCode string
Url string
}
func (this *Company) Init(apiCode string) {
//"06c6a07e89dd45c88de040ee1489eef7"
this.ApiCode = apiCode
this.Url = "http://api.81api.com"
}
// GetCompanyBaseInfo 获取企业基础信息
func (this *Company) GetCompanyOtherAll(name string) Map {
res := Map{}
data, e := this.GetCompanyPatentsInfo(name) //获取专利信息
if e != nil {
fmt.Println(e)
} else {
res["PatentsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
if e != nil {
fmt.Println(e)
} else {
res["OtherCopyrightsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyTrademarksInfo(name) //获取商标
if e != nil {
fmt.Println(e)
} else {
res["TrademarksInfo"] = data.GetMap("data")
}
data, e = this.GetCompanySoftwareCopyrightsInfo(name) //获取软著
if e != nil {
fmt.Println(e)
} else {
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
}
data, e = this.GetCompanyProfileTags(name) //获取大数据标签
if e != nil {
fmt.Println(e)
} else {
res["ProfileTags"] = data.GetSlice("data")
}
return res
}
// GetCompanyBaseInfo 获取企业基础信息
func (this *Company) GetCompanyBaseInfo(name string) (Map, error) {
url := "/getCompanyBaseInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// GetCompanyPatentsInfo 获取专利信息
func (this *Company) GetCompanyPatentsInfo(name string) (Map, error) {
url := "/getCompanyPatentsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取商标信息
func (this *Company) GetCompanyTrademarksInfo(name string) (Map, error) {
url := "/getCompanyTrademarksInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取软著信息
func (this *Company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
url := "/getCompanySoftwareCopyrightsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取其他著作信息
func (this *Company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
url := "/getCompanyOtherCopyrightsInfo/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
// 获取大数据标签
func (this *Company) GetCompanyProfileTags(name string) (Map, error) {
url := "/getCompanyProfileTags/"
body, err := this.basePost(url, name)
return ObjToMap(body), err
}
func (this *Company) basePost(url string, name string) (string, error) {
client := &http.Client{}
reqest, err := http.NewRequest("GET", this.Url+url+name+"/?isRaiseErrorCode=1", nil)
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
reqest.Header.Add("Authorization", "APPCODE "+this.ApiCode)
response, err := client.Do(reqest)
defer response.Body.Close()
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
res := string(body)
fmt.Println(res)
return res, err
}
var DefaultCompany Company
func init() {
DefaultCompany = Company{}
}
+58
View File
@@ -0,0 +1,58 @@
package baidu
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
type BaiduMap struct {
Ak string
Url string
}
func (this *BaiduMap) Init(Ak string) {
//"ak=ZeT902EZvVgIoGVWEFK3osUm"
this.Ak = Ak
this.Url = "https://api.map.baidu.com/place/v2/suggestion?output=json" + "&ak=" + Ak
//query
}
// GetPosition 获取定位列表
func (this *BaiduMap) GetPosition(name string, region string) (string, error) {
client := &http.Client{}
if region == "" {
region = "全国"
}
reqest, err := http.NewRequest("GET", this.Url+"&query="+url.PathEscape(name)+"&region="+url.PathEscape(region), nil)
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
response, err := client.Do(reqest)
defer response.Body.Close()
if err != nil {
fmt.Println("Fatal error ", err.Error())
return "", err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
//fmt.Println(string(body))
return string(body), err
}
var DefaultBaiDuMap BaiduMap
func init() {
DefaultBaiDuMap = BaiduMap{}
}
+9 -3
View File
@@ -18,8 +18,8 @@ type DDY struct {
func (this *DDY) Init(apikey string) { func (this *DDY) Init(apikey string) {
this.ApiKey = apikey this.ApiKey = apikey
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/single_send" this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
this.TzUrl = "https://api.dingdongcloud.com/v1/sms/notice/multi_send" this.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
} }
//发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败 //发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
@@ -34,7 +34,7 @@ func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bo
//发送通知 //发送通知
func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) { func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
for k, v := range data { for k, v := range data {
tpt = strings.Replace(tpt, "["+k+"]", v, -1) tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
} }
umobleStr := "" umobleStr := ""
for i, v := range umoblie { for i, v := range umoblie {
@@ -89,3 +89,9 @@ func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
return string(body), nil return string(body), nil
} }
var DefaultDDY DDY
func init() {
DefaultDDY = DDY{}
}
+143
View File
@@ -0,0 +1,143 @@
package rsa
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/asn1"
"encoding/pem"
"fmt"
"os"
)
func FileGet(path string) []byte {
file, err := os.Open(path)
if err != nil {
panic(err)
}
defer file.Close()
//读取文件的内容
info, _ := file.Stat()
buf := make([]byte, info.Size())
file.Read(buf)
return buf
}
//RSA加密
// plainText 要加密的数据
// path 公钥匙文件地址
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
//pem解码
block, _ := pem.Decode(buf)
//x509解码
publicKeyInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
panic(err)
}
//类型断言
publicKey := publicKeyInterface.(*rsa.PublicKey)
//对明文进行加密
cipherText, err := rsa.EncryptPKCS1v15(rand.Reader, publicKey, plainText)
if err != nil {
panic(err)
}
//返回密文
return cipherText
}
//RSA解密
// cipherText 需要解密的byte数据
// path 私钥文件路径
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
//pem解码
block, _ := pem.Decode(buf)
//X509解码
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
panic(err)
}
//对密文进行解密
//plainText,_:=rsa.DecryptPKCS1v15(rand.Reader,privateKey,cipherText)
v, err := rsa.DecryptPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), cipherText)
//返回明文
return v
}
func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte {
info := struct {
Version int
PrivateKeyAlgorithm []asn1.ObjectIdentifier
PrivateKey []byte
}{}
info.Version = 0
info.PrivateKeyAlgorithm = make([]asn1.ObjectIdentifier, 1)
info.PrivateKeyAlgorithm[0] = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
info.PrivateKey = x509.MarshalPKCS1PrivateKey(key)
k, err := asn1.Marshal(info)
if err != nil {
panic(err.Error())
}
return k
}
func Demo() {
//生成密钥对,保存到文件
GenerateRSAKey(2048, "./")
//加密
data := []byte("hello world")
encrypt := RSA_Encrypt(data, FileGet("public.pem"))
fmt.Println(string(encrypt))
// 解密
decrypt := RSA_Decrypt(encrypt, FileGet("private.pem"))
fmt.Println(string(decrypt))
}
//生成RSA私钥和公钥,保存到文件中
// bits 证书大小
func GenerateRSAKey(bits int, path string) {
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
//Reader是一个全局、共享的密码用强随机数生成器
privateKey, err := rsa.GenerateKey(rand.Reader, bits)
if err != nil {
panic(err)
}
//保存私钥
//通过x509标准将得到的ras私钥序列化为ASN.1 的 DER编码字符串
X509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey)
//使用pem格式对x509输出的内容进行编码
//创建文件保存私钥
privateFile, err := os.Create(path + "private.pem")
if err != nil {
panic(err)
}
defer privateFile.Close()
//构建一个pem.Block结构体对象
privateBlock := pem.Block{Type: "RSA Private Key", Bytes: X509PrivateKey}
//将数据保存到文件
pem.Encode(privateFile, &privateBlock)
//保存公钥
//获取公钥的数据
publicKey := privateKey.PublicKey
//X509对公钥编码
X509PublicKey, err := x509.MarshalPKIXPublicKey(&publicKey)
if err != nil {
panic(err)
}
//pem格式编码
//创建用于保存公钥的文件
publicFile, err := os.Create(path + "public.pem")
if err != nil {
panic(err)
}
defer publicFile.Close()
//创建一个pem.Block结构体对象
publicBlock := pem.Block{Type: "RSA Public Key", Bytes: X509PublicKey}
//保存到文件
pem.Encode(publicFile, &publicBlock)
}
+103
View File
@@ -0,0 +1,103 @@
package tencent
import (
. "../../common"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
gourl "net/url"
"strings"
"time"
)
func calcAuthorization(source string, secretId string, secretKey string) (auth string, datetime string, err error) {
timeLocation, _ := time.LoadLocation("Etc/GMT")
datetime = time.Now().In(timeLocation).Format("Mon, 02 Jan 2006 15:04:05 GMT")
signStr := fmt.Sprintf("x-date: %s\nx-source: %s", datetime, source)
// hmac-sha1
mac := hmac.New(sha1.New, []byte(secretKey))
mac.Write([]byte(signStr))
sign := base64.StdEncoding.EncodeToString(mac.Sum(nil))
auth = fmt.Sprintf("hmac id=\"%s\", algorithm=\"hmac-sha1\", headers=\"x-date x-source\", signature=\"%s\"",
secretId, sign)
return auth, datetime, nil
}
func urlencode(params map[string]string) string {
var p = gourl.Values{}
for k, v := range params {
p.Add(k, v)
}
return p.Encode()
}
func GetCompany(secretId, secretKey, name string) Map {
// 云市场分配的密钥Id
//secretId := "xxxx"
//// 云市场分配的密钥Key
//secretKey := "xxxx"
source := "market"
// 签名
auth, datetime, _ := calcAuthorization(source, secretId, secretKey)
// 请求方法
method := "GET"
// 请求头
headers := map[string]string{"X-Source": source, "X-Date": datetime, "Authorization": auth}
// 查询参数
queryParams := make(map[string]string)
queryParams["keyword"] = name
// body参数
bodyParams := make(map[string]string)
// url参数拼接
url := "https://service-3jnh3ku8-1256140209.gz.apigw.tencentcs.com/release/business4/geet"
if len(queryParams) > 0 {
url = fmt.Sprintf("%s?%s", url, urlencode(queryParams))
}
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
var body io.Reader = nil
if bodyMethods[method] {
body = strings.NewReader(urlencode(bodyParams))
headers["Content-Type"] = "application/x-www-form-urlencoded"
}
client := &http.Client{
Timeout: 5 * time.Second,
}
request, err := http.NewRequest(method, url, body)
if err != nil {
fmt.Println(err)
return nil
}
for k, v := range headers {
request.Header.Set(k, v)
}
response, err := client.Do(request)
if err != nil {
fmt.Println(err)
return nil
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
return nil
}
res := string(bodyBytes)
fmt.Println(res)
return ObjToMap(res)
}
+88
View File
@@ -0,0 +1,88 @@
package tencent
import (
"fmt"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
)
var credential = common.NewCredential(
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
)
func OCRCOMPANY(base64Str string) string {
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
request := ocr.NewBizLicenseOCRRequest()
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
request.ImageBase64 = common.StringPtr(base64Str)
response, err := client.BizLicenseOCR(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Println("An API error has returned: %s", err)
return ""
}
if err != nil {
fmt.Println("An API error has returned: %s", err)
return ""
}
//fmt.Printf("%s", response.ToJsonString())
return response.ToJsonString()
}
func OCR(base64Str string) string {
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
request := ocr.NewGeneralAccurateOCRRequest()
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
request.ImageBase64 = common.StringPtr(base64Str)
response, err := client.GeneralAccurateOCR(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Println("An API error has returned: %s", err)
return ""
}
if err != nil {
fmt.Println("An API error has returned: %s", err)
return ""
}
//fmt.Printf("%s", response.ToJsonString())
return response.ToJsonString()
}
func Qrcode(base64Str string) string {
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
request := ocr.NewQrcodeOCRRequest()
request.ImageBase64 = common.StringPtr(base64Str)
response, err := client.QrcodeOCR(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Println("An API error has returned: %s", err)
return ""
}
if err != nil {
fmt.Println("An API error has returned: %s", err)
return ""
}
//fmt.Printf("%s", response.ToJsonString())
return response.ToJsonString()
}
-64
View File
@@ -1,64 +0,0 @@
package admin
import (
. "../../../hotime"
. "../../../hotime/common"
)
var ID = "3c5fc9732b8ddcb0a91b428976f2ce86"
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"admin": adminCtr,
"category": categoryCtr,
"ctg_order_date": ctg_order_dateCtr,
"order": orderCtr,
"org": orgCtr,
"role": roleCtr,
"user": userCtr,
"hotime": Ctr{
"login": func(this *Context) {
name := this.Req.FormValue("name")
password := this.Req.FormValue("password")
if name == "" || password == "" {
this.Display(3, "参数不足")
return
}
user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}})
if user == nil {
this.Display(5, "登录失败")
return
}
this.Session("admin_id", user.GetCeilInt("id"))
this.Session("admin_name", name)
this.Display(0, this.SessionId)
},
"logout": func(this *Context) {
this.Session("admin_id", nil)
this.Session("admin_name", nil)
this.Display(0, "退出登录成功")
},
"info": func(that *Context) {
re := that.Db.Get("admin", that.MakeCode.Info("admin"), Map{"id": that.Session("admin_id").ToCeilInt()})
if re == nil {
that.Display(4, "找不到对应信息")
return
}
for k, v := range re {
column := that.MakeCode.TableColumns["admin"][k]
if column == nil {
continue
}
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
},
}
-34
View File
@@ -1,34 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
)
var categoryCtr = Ctr{
"info": func(that *Context) {
parentId := ObjToInt(that.Req.FormValue("id"))
//parentId := ObjToInt(that.RouterString[2])
childData:=[]Map{}
if parentId == 0 {
childData1 := that.Db.Select("category", "*", Map{"parent_id": nil})
for _, v := range childData1 {
data := that.Db.Get("category", "*", Map{"parent_id": v.GetCeilInt("id")})
childData=append(childData,data)
}
}else{
childData = that.Db.Select("category", "*", Map{"parent_id": parentId})
}
for _, v := range childData {
v["child"] = that.Db.Select("category", "*", Map{"parent_id": v.GetCeilInt("id")})
}
that.Display(0, childData)
},
}
-104
View File
@@ -1,104 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"fmt"
"time"
)
var ctg_order_dateCtr = Ctr{
"info": func(that *Context) {
//today:=time.Now().Weekday()
id := ObjToInt(that.Req.FormValue("id"))
category := that.Db.Get("category", "*", Map{"id": id})
if category == nil {
that.Display(4, "找不到该类别!")
return
}
todayPMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
todayAMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02"+" 09:00"))
weekDay := 1
switch time.Now().Weekday().String() {
case "Monday":
weekDay = 1
case "Tuesday":
weekDay = 2
case "Wednesday":
weekDay = 3
case "Thursday":
weekDay = 4
case "Friday":
weekDay = 5
case "Saturday":
weekDay = 6
case "Sunday":
weekDay = 7
}
////future:=that.Db.Select("ctg_order_date","*",Map{"category_id":that.RouterString[2],"date[>]":time})
date := Slice{}
for i := 0; i < 7; i++ {
day := weekDay + i + 1
if day > 7 {
day = day - 7
}
if day == 6 || day == 7 {
continue
}
//fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1)))
dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"),
"date": todayAMTime.Unix() + int64(24*60*60*(i+1))}})
if dayAM == nil {
dayAM = Map{"name": "9:00-12:00",
"date": todayAMTime.Unix() + int64(24*60*60*(i+1)),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"start_sn": category.GetCeilInt("start_sn"),
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("am"+ObjToStr(day)),
"now_sn": category.GetCeilInt("start_sn"),
"category_id": category.GetCeilInt("id"),
}
dayAM["id"] = that.Db.Insert("ctg_order_date", dayAM)
if dayAM.GetCeilInt64("id") == 0 {
that.Display(4, "内部错误!")
return
}
}
dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"), "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}})
fmt.Println(that.Db.LastQuery, that.Db.LastData, dayPM, that.Db.LastErr)
if dayPM == nil {
fmt.Println("dasdasdasda")
dayPM = Map{"name": "14:00-16:00",
"date": todayPMTime.Unix() + int64(24*60*60*(i+1)),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"start_sn": category.GetCeilInt("start_sn"),
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("pm"+ObjToStr(day)),
"now_sn": category.GetCeilInt("start_sn"),
"category_id": category.GetCeilInt("id"),
}
dayPM["id"] = that.Db.Insert("ctg_order_date", dayPM)
if dayPM.GetCeilInt64("id") == 0 {
that.Display(4, "内部错误!")
return
}
}
date = append(date, Map{"name": "星期" + ObjToStr(day) + "(" + time.Unix(todayPMTime.Unix()+int64(24*60*60*(i+1)), 0).Format("01-02") + ")",
"am": dayAM,
"pm": dayPM,
})
}
that.Display(0, date)
},
}
-86
View File
@@ -1,86 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"time"
)
var ID = "aad1472b19e575a71ee8f75629e27867"
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"category": categoryCtr,
"ctg_order_date": ctg_order_dateCtr,
"order": orderCtr,
"user": userCtr,
"sms": Sms,
}
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}
func tencentSendYzm(umobile, code string) error {
random := RandX(999999, 9999999)
url := "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=1400235813&random=" + ObjToStr(random)
fmt.Println("URL:>", url)
h := sha256.New()
h.Write([]byte(`appkey=d511de15e5ccb43fc171772dbb8b599f&random=` + ObjToStr(random) + `&time=` + ObjToStr(time.Now().Unix()) + `&mobile=` + umobile))
bs := h.Sum(nil)
s256 := hex.EncodeToString(bs)
//json序列化
post := `{
"ext": "",
"extend": "",
"params": [
"` + code + `"
],
"sig": "` + s256 + `",
"sign": "乐呵呵旅游网",
"tel": {
"mobile": "` + umobile + `",
"nationcode": "86"
},
"time": ` + ObjToStr(time.Now().Unix()) + `,
"tpl_id": 378916
}`
fmt.Println(url, "post", post)
var jsonStr = []byte(post)
fmt.Println("jsonStr", jsonStr)
fmt.Println("new_str", bytes.NewBuffer(jsonStr))
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
// req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
return nil
}
-70
View File
@@ -1,70 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var orderCtr = Ctr{
"count": func(this *Context) {
if this.Session("id").ToCeilInt() == 0 {
this.Display(2, "没有登录!")
return
}
re := Map{}
re["total"] = this.Db.Count("order", Map{"user_id": this.Session("id").ToCeilInt()})
re["finish"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 2}})
re["late"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 3}})
this.Display(0, re)
},
"add": func(this *Context) {
if this.Session("id").ToCeilInt() == 0 {
this.Display(2, "没有登录!")
return
}
ctgOrderDateId := ObjToInt(this.Req.FormValue("ctg_order_date_id"))
//ctgId:=ObjToInt(this.Req.FormValue("category_id"))
ctgOrderDate := this.Db.Get("ctg_order_date", "*", Map{"id": ctgOrderDateId})
if ctgOrderDate.GetCeilInt64("now_sn")+1 > ctgOrderDate.GetCeilInt64("max_sn") {
this.Display(5, "当前排号已经用完")
return
}
data := Map{"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"user_id": this.Session("id").ToCeilInt(),
"date": ctgOrderDate.GetString("date"),
"sn": ctgOrderDate.GetCeilInt64("now_sn") + 1,
"category_id": ctgOrderDate.GetCeilInt("category_id"),
"admin_id": 1,
"status": 1,
"name": time.Unix(ctgOrderDate.GetCeilInt64("date"), 0).Format("2006-01-02 ") + ctgOrderDate.GetString("name"),
}
data["id"] = this.Db.Insert("order", data)
if data.GetCeilInt("id") == 0 {
this.Display(5, "预约失败")
return
}
this.Db.Update("ctg_order_date", Map{"now_sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, "modify_time": time.Now().Unix()}, Map{"id": ctgOrderDate.GetCeilInt("id")})
this.Display(0, data)
},
"search": func(that *Context) {
if that.Session("id").ToCeilInt() == 0 {
that.Display(2, "没有登录!")
return
}
data := that.Db.Select("order", "*", Map{"user_id": that.Session("id").ToCeilInt()})
for _, v := range data {
v["category"] = that.Db.Get("category", "*", Map{"id": v.GetCeilInt("category_id")})
v["parent_category"] = that.Db.Get("category", "id,name", Map{"id": v.GetMap("category").GetCeilInt("parent_id")})
}
that.Display(0, data)
},
}
-32
View File
@@ -1,32 +0,0 @@
package app
import (
. "../../../hotime"
)
var Sms = Ctr{
//只允许微信验证过的或者登录成功的发送短信
"send": func(this *Context) {
//if this.Session("uid").Data == nil && this.Session("wechatInfo").Data == nil {
// this.Display(2, "没有授权")
// return
//}
if len(this.Req.FormValue("token")) != 32 {
this.Display(2, "没有授权")
return
}
phone := this.Req.FormValue("phone")
if len(phone) < 11 {
this.Display(3, "手机号格式错误")
return
}
code := getCode()
this.Session("phone", phone)
this.Session("code", code)
tencentSendYzm(phone, code)
this.Display(0, "发送成功")
},
}
-54
View File
@@ -1,54 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var userCtr = Ctr{
"token": func(this *Context) {
this.Display(0, this.SessionId)
},
"test": func(this *Context) {
this.Session("id", 1)
},
"add": func(this *Context) {
if this.Req.FormValue("code") != this.Session("code").ToStr() ||
this.Req.FormValue("phone") != this.Session("phone").ToStr() {
this.Display(3, "短信验证不通过")
return
}
phone := this.Req.FormValue("phone")
idcard := this.Req.FormValue("idcard")
name := this.Req.FormValue("name")
user := this.Db.Get("user", "*", Map{"phone": phone})
if user == nil {
user = Map{"phone": phone, "idcard": idcard, "name": name, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()}
user["id"] = this.Db.Insert("user", user)
} else {
user["phone"] = phone
user["idcard"] = idcard
user["name"] = name
user["modify_time"] = time.Now().Unix()
re := this.Db.Update("user", user, Map{"id": user.GetCeilInt64("id")})
if re == 0 {
this.Display(4, "系统错误")
return
}
}
if user.GetCeilInt64("id") == 0 {
this.Display(5, "登录失败")
return
}
this.Session("id", user.GetCeilInt("id"))
this.Display(0, "登录成功")
},
}
+11 -4
View File
@@ -1,4 +1,5 @@
{ {
"avatarPath": "avatar/2006/01/02/",
"cache": { "cache": {
"db": { "db": {
"db": false, "db": false,
@@ -24,7 +25,7 @@
"db": { "db": {
"mysql": { "mysql": {
"host": "192.168.6.253", "host": "192.168.6.253",
"name": "bzyy", "name": "iedc_dev",
"password": "dasda8454456", "password": "dasda8454456",
"port": "3306", "port": "3306",
"prefix": "", "prefix": "",
@@ -42,8 +43,14 @@
"4": "数据处理异常", "4": "数据处理异常",
"5": "数据结果异常" "5": "数据结果异常"
}, },
"mode": 0, "imgPath": "img/2006/01/02/",
"port": "80", "mode": 3,
"port": "8081",
"sessionName": "HOTIME", "sessionName": "HOTIME",
"tpt": "tpt" "smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa",
"smsLogin": "【政企超链接】您的验证码为:{code},请在5分钟内使用,切勿将验证码泄露于他人,如非本人操作请忽略。",
"tpt": "tpt",
"wechatAppID": "wx2edb802f5c3ae1ae",
"wechatAppSecret": "4ff97e523c3de6bad47051b568522386",
"wxFilePath": "wxfile/2006/01/02/"
} }
+1 -1
View File
@@ -59,7 +59,7 @@
}, },
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", "logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
"logLevel": "默认0,必须,0关闭,1打印,日志等级", "logLevel": "默认0,必须,0关闭,1打印,日志等级",
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", "mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存",
"modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配", "modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配",
"port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80", "port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80",
"sessionName": "默认HOTIME,必须,设置session的cookie名", "sessionName": "默认HOTIME,必须,设置session的cookie名",
Binary file not shown.
+4 -182
View File
@@ -2,192 +2,14 @@ package main
import ( import (
"../../hotime" "../../hotime"
"../../hotime/common" //"../dri/aliyun"
"./admin"
"./app"
"fmt" "fmt"
"io"
"os"
"strings"
"time" "time"
) )
func main() { func main() {
fmt.Println(time.Now().Weekday().String()) date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
fmt.Println(date, date.Unix())
//fmt.Println("0123456"[1:7])
appIns := hotime.Init("config/config.json") appIns := hotime.Init("config/config.json")
//RESTfull接口适配
appIns.SetConnectListener(func(context *hotime.Context) bool {
if len(context.RouterString)>1&& context.RouterString[0] == "admin" {
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
return true
}
if context.Session("admin_id").Data == nil {
context.Display(2, "你还没有登录")
return false
}
}
//文件上传接口
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
//读取网络文件
fi, fheader, err := context.Req.FormFile("file")
if err != nil {
context.Display(3, err)
return false
}
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 false
}
filePath = path + common.Md5(common.ObjToStr(common.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 false
}
_, e = io.Copy(newFile, fi)
if e != nil {
context.Display(3, e)
return false
}
context.Display(0, filePath)
return false
}
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
!(context.Router[context.RouterString[0]] != nil &&
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
return true
}
//排除无效操作
if len(context.RouterString) == 2 &&
context.Req.Method != "GET" &&
context.Req.Method != "POST" {
return true
}
//列表检索
if len(context.RouterString) == 2 &&
context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
}
//新建
if len(context.RouterString) == 2 &&
context.Req.Method == "POST" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
}
if len(context.RouterString) == 3 &&
context.Req.Method == "POST" {
return true
}
//查询单条
if len(context.RouterString) == 3 &&
context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
}
//更新
if len(context.RouterString) == 3 &&
context.Req.Method == "PUT" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
}
//移除
if len(context.RouterString) == 3 &&
context.Req.Method == "DELETE" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
return true
}
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
}
context.View()
return false
})
//makeCode := code.MakeCode{}
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
appIns.Run(hotime.Router{
"admin": admin.Project,
"app": app.Project,
//"app": hotime.Proj{
// "index": hotime.Ctr{
// "test": func(this *hotime.Context) {
//
// data := this.Db.Get("cached", "*")
// fmt.Println(data)
// fmt.Println(this.Session("test").ToCeilInt())
// this.Session("test1", 98984984)
// fmt.Println(this.Session("test1").Data)
// this.Error.SetError(errors.New("dasdasdas"))
// //fmt.Println(this.Db.GetTag())
// //this.Application.Log.Error("dasdasdas")
// //this.Log.Error("dadasdasd")
// //x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
// //
// // db.Insert("user",hotime.Map{"unickname":"dasdas"})
// //
// // return true
// //})
// //hotime.LogError("dasdasdasdasdas")
// this.Display(5, "dsadas")
// },
// "websocket": func(this *hotime.Context) {
// hdler := websocket.Handler(func(ws *websocket.Conn) {
// for true {
// msg := make([]byte, 5120)
// n, err := ws.Read(msg)
// go func() {
// time.Sleep(time.Second * 5)
// ws.Write([]byte("dsadasdasgregergrerge"))
//
// }()
// if err != nil {
// return
// }
// fmt.Printf("Receive: %s\n", msg[:n])
//
// send_msg := "[" + string(msg[:n]) + "]"
// m, err := ws.Write([]byte(send_msg))
// if err != nil {
// return
// }
// fmt.Printf("Send: %s\n", msg[:m])
// }
// })
// hdler.ServeHTTP(this.Resp, this.Req)
// },
// },
//},
})
} }
@@ -1 +0,0 @@
h3[data-v-b9167eee]{margin:40px 0 0}ul[data-v-b9167eee]{list-style-type:none;padding:0}li[data-v-b9167eee]{display:inline-block;margin:0 10px}a[data-v-b9167eee]{color:#42b983}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.
Binary file not shown.
-3
View File
@@ -1,3 +0,0 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>hotime</title><style>body{
margin: 0px;
}</style><link href="css/chunk-038340db.e4ca99de.css" rel="prefetch"><link href="css/chunk-0524801b.1e910850.css" rel="prefetch"><link href="css/chunk-1c438cad.2fd7d31d.css" rel="prefetch"><link href="css/chunk-1d1a12b6.8c684de3.css" rel="prefetch"><link href="css/chunk-2c1d9b2f.78c69bda.css" rel="prefetch"><link href="css/chunk-5ccac4d0.5f1c91ca.css" rel="prefetch"><link href="css/chunk-c569a38e.01bc1b83.css" rel="prefetch"><link href="css/chunk-c7a51d14.4a0871eb.css" rel="prefetch"><link href="js/chunk-038340db.3c8b0cb6.js" rel="prefetch"><link href="js/chunk-0524801b.de9b433f.js" rel="prefetch"><link href="js/chunk-14f17cfa.c5104e8c.js" rel="prefetch"><link href="js/chunk-1c438cad.72a22c19.js" rel="prefetch"><link href="js/chunk-1d1a12b6.6900cc01.js" rel="prefetch"><link href="js/chunk-2c1d9b2f.39065c9e.js" rel="prefetch"><link href="js/chunk-5b2ead63.af868ff8.js" rel="prefetch"><link href="js/chunk-5ccac4d0.98ff45de.js" rel="prefetch"><link href="js/chunk-68815fbc.04152d5f.js" rel="prefetch"><link href="js/chunk-c569a38e.16d55c64.js" rel="prefetch"><link href="js/chunk-c7a51d14.3cd28dc4.js" rel="prefetch"><link href="css/app.5e2eb449.css" rel="preload" as="style"><link href="js/app.f5f26baa.js" rel="preload" as="script"><link href="css/app.5e2eb449.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but hotime doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/app.f5f26baa.js"></script></body></html>
+13
View File
@@ -0,0 +1,13 @@
module code.hoteas.com/golang/hotime
go 1.16
require (
github.com/garyburd/redigo v1.6.3
github.com/go-sql-driver/mysql v1.6.0
github.com/mattn/go-sqlite3 v1.14.12
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
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
)
+27
View File
@@ -0,0 +1,27 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
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/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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
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=
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/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
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=
+2 -2
View File
@@ -10,7 +10,7 @@ var App = map[string]*Application{} //整个项目
//var Db = HoTimeDB{} //数据库实例 //var Db = HoTimeDB{} //数据库实例
var Config = Map{ var Config = Map{
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式 "mode": 3, //模式 0生产模式,1,测试模式,2,开发模式,3,内嵌代码模式
"codeConfig": Map{ "codeConfig": Map{
"admin": "config/app.json", "admin": "config/app.json",
}, },
@@ -51,7 +51,7 @@ var ConfigNote = Map{
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", "logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能", "webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置", "webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启 "mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
"codeConfig": Map{ "codeConfig": Map{
"注释": "配置即启用,非必须,默认无", "注释": "配置即启用,非必须,默认无",
//"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件", //"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",