Compare commits
No commits in common. "master" and "master_v1" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,2 @@
|
||||
/.idea/*
|
||||
.idea
|
||||
/example/config/app.json
|
||||
/example/tpt/demo/
|
||||
|
2
LICENSE
2
LICENSE
@ -142,7 +142,7 @@ any additional terms or conditions. Notwithstanding the above, nothing herein
|
||||
shall supersede or modify the terms of any separate license agreement you
|
||||
may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. that License does not grant permission to use the trade names,
|
||||
6. Trademarks. This License does not grant permission to use the trade names,
|
||||
trademarks, service marks, or product names of the Licensor, except as required
|
||||
for reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
265
application.go
265
application.go
@ -1,14 +1,14 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/cache"
|
||||
"code.hoteas.com/golang/hotime/code"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
. "code.hoteas.com/golang/hotime/log"
|
||||
. "./cache"
|
||||
"./code"
|
||||
. "./common"
|
||||
. "./db"
|
||||
. "./log"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -20,15 +20,17 @@ import (
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
MakeCodeRouter map[string]*code.MakeCode
|
||||
*code.MakeCode
|
||||
MakeCodeRouter Router
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
Error
|
||||
Log *logrus.Logger
|
||||
WebConnectLog *logrus.Logger
|
||||
Port string //端口号
|
||||
TLSPort string //ssl访问端口号
|
||||
connectListener []func(that *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||
connectListener []func(this *Context) bool //所有的访问监听,true按原计划继续使用,false表示有监听器处理
|
||||
connectDbFunc func(err ...*Error) (master, slave *sql.DB)
|
||||
configPath string
|
||||
Config Map
|
||||
@ -68,25 +70,9 @@ func (that *Application) Run(router Router) {
|
||||
if that.Router == nil {
|
||||
that.Router = Router{}
|
||||
}
|
||||
for k, _ := range router {
|
||||
v := router[k]
|
||||
if that.Router[k] == nil {
|
||||
for k, v := range router {
|
||||
that.Router[k] = v
|
||||
}
|
||||
//直达接口层复用
|
||||
for k1, _ := range v {
|
||||
v1 := v[k1]
|
||||
if that.Router[k][k1] == nil {
|
||||
that.Router[k][k1] = v1
|
||||
}
|
||||
|
||||
for k2, _ := range v1 {
|
||||
v2 := v1[k2]
|
||||
that.Router[k][k1][k2] = v2
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//重新设置MethodRouter//直达路由
|
||||
that.MethodRouter = MethodRouter{}
|
||||
modeRouterStrict := true
|
||||
@ -239,8 +225,10 @@ func (that *Application) SetConfig(configPath ...string) {
|
||||
|
||||
}
|
||||
|
||||
if that.Error.GetError() != nil {
|
||||
fmt.Println(that.Error.GetError().Error())
|
||||
that.Log = GetLog(that.Config.GetString("logFile"), true)
|
||||
that.Error = Error{Logger: that.Log}
|
||||
if that.Config.Get("webConnectLogShow") == nil || that.Config.GetBool("webConnectLogShow") {
|
||||
that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false)
|
||||
}
|
||||
|
||||
//文件如果损坏则不写入配置防止配置文件数据丢失
|
||||
@ -267,21 +255,15 @@ func (that *Application) SetConfig(configPath ...string) {
|
||||
|
||||
}
|
||||
|
||||
that.Log = GetLog(that.Config.GetString("logFile"), true)
|
||||
that.Error = Error{Logger: that.Log}
|
||||
if that.Config.Get("webConnectLogShow") == nil || that.Config.GetBool("webConnectLogShow") {
|
||||
that.WebConnectLog = GetLog(that.Config.GetString("webConnectLogFile"), false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// SetConnectListener 连接判断,返回false继续传输至控制层,true则停止传输
|
||||
func (that *Application) SetConnectListener(lis func(that *Context) (isFinished bool)) {
|
||||
// SetConnectListener 连接判断,返回true继续传输至控制层,false则停止传输
|
||||
func (that *Application) SetConnectListener(lis func(this *Context) bool) {
|
||||
that.connectListener = append(that.connectListener, lis)
|
||||
}
|
||||
|
||||
//网络错误
|
||||
//func (that *Application) session(w http.ResponseWriter, req *http.Request) {
|
||||
//func (this *Application) session(w http.ResponseWriter, req *http.Request) {
|
||||
//
|
||||
//}
|
||||
|
||||
@ -331,9 +313,6 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
if len(token) == 32 {
|
||||
sessionId = token
|
||||
//没有token,则查阅session
|
||||
if cookie == nil || cookie.Value != sessionId {
|
||||
needSetCookie = sessionId
|
||||
}
|
||||
} else if err == nil && cookie.Value != "" {
|
||||
sessionId = cookie.Value
|
||||
//session也没有则判断是否创建cookie
|
||||
@ -362,18 +341,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
defer func() {
|
||||
//是否展示日志
|
||||
if that.WebConnectLog != nil {
|
||||
|
||||
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
//负载均衡优化
|
||||
ipStr := ""
|
||||
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")
|
||||
}
|
||||
//负载均衡优化
|
||||
if ipStr == "" {
|
||||
//RemoteAddr := that.Req.RemoteAddr
|
||||
ipStr = Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
}
|
||||
|
||||
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||
@ -383,17 +358,16 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
}()
|
||||
|
||||
//访问拦截true继续false暂停
|
||||
connectListenerLen := len(that.connectListener) - 1
|
||||
connectListenerLen := len(that.connectListener)
|
||||
if connectListenerLen != 0 {
|
||||
for i := 0; i < connectListenerLen; i++ {
|
||||
|
||||
if !that.connectListener[i](&context) {
|
||||
|
||||
for true {
|
||||
if connectListenerLen < 0 {
|
||||
break
|
||||
}
|
||||
if that.connectListener[connectListenerLen](&context) {
|
||||
context.View()
|
||||
return
|
||||
}
|
||||
connectListenerLen--
|
||||
}
|
||||
}
|
||||
|
||||
//接口服务
|
||||
@ -446,14 +420,8 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
header.Set("Cache-Control", "no-cache")
|
||||
}
|
||||
|
||||
t := strings.LastIndex(path, ".")
|
||||
if t != -1 {
|
||||
tt := path[t:]
|
||||
|
||||
if MimeMaps[tt] != "" {
|
||||
|
||||
header.Add("Content-Type", MimeMaps[tt])
|
||||
}
|
||||
if strings.Index(path, ".m3u8") != -1 {
|
||||
header.Add("Content-Type", "audio/mpegurl")
|
||||
}
|
||||
|
||||
//w.Write(data)
|
||||
@ -467,7 +435,6 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
if context.Config.GetString("crossDomain") == "" {
|
||||
if sessionId != "" {
|
||||
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
//context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||
}
|
||||
|
||||
return
|
||||
@ -497,7 +464,7 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
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,Authorization,Cookie,Set-Cookie")
|
||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||
|
||||
if sessionId != "" {
|
||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||
@ -512,8 +479,7 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
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: "/"})
|
||||
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
}
|
||||
|
||||
return
|
||||
@ -544,7 +510,7 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
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,Authorization,Cookie,Set-Cookie")
|
||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||
|
||||
if sessionId != "" {
|
||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||
@ -554,71 +520,40 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
}
|
||||
|
||||
//Init 初始化application
|
||||
func Init(config string) *Application {
|
||||
func Init(config string) Application {
|
||||
appIns := Application{}
|
||||
//手动模式,
|
||||
appIns.SetConfig(config)
|
||||
|
||||
SetDB(&appIns)
|
||||
appIns.SetCache()
|
||||
codeConfig := appIns.Config.GetSlice("codeConfig")
|
||||
|
||||
appIns.MakeCode = &code.MakeCode{}
|
||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
||||
if codeConfig != nil {
|
||||
|
||||
for k, _ := range codeConfig {
|
||||
codeMake := codeConfig.GetMap(k)
|
||||
if codeMake == nil {
|
||||
continue
|
||||
if appIns.Config.GetInt("mode") == 2 {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, true)
|
||||
} else if appIns.Config.GetInt("mode") == 3 {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, false)
|
||||
} else {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil, false)
|
||||
}
|
||||
//codeMake["table"] = k
|
||||
if appIns.MakeCodeRouter == nil {
|
||||
appIns.MakeCodeRouter = map[string]*code.MakeCode{}
|
||||
}
|
||||
|
||||
if codeMake.GetString("name") == "" {
|
||||
codeMake["name"] = codeMake.GetString("table")
|
||||
}
|
||||
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
|
||||
//接入动态代码层
|
||||
if appIns.Router == nil {
|
||||
appIns.Router = Router{}
|
||||
}
|
||||
|
||||
//appIns.Router[codeMake.GetString("name")] = TptProject
|
||||
appIns.Router[codeMake.GetString("name")] = Proj{}
|
||||
|
||||
for k2, _ := range TptProject {
|
||||
if appIns.Router[codeMake.GetString("name")][k2] == nil {
|
||||
appIns.Router[codeMake.GetString("name")][k2] = Ctr{}
|
||||
}
|
||||
for k3, _ := range TptProject[k2] {
|
||||
v3 := TptProject[k2][k3]
|
||||
appIns.Router[codeMake.GetString("name")][k2][k3] = v3
|
||||
}
|
||||
appIns.Router[k] = TptProject
|
||||
for k1, _ := range appIns.MakeCode.TableColumns {
|
||||
appIns.Router[k][k1] = appIns.Router[k]["hotimeCommon"]
|
||||
}
|
||||
|
||||
for k1, _ := range appIns.MakeCodeRouter[codeMake.GetString("name")].TableColumns {
|
||||
if appIns.Router[codeMake.GetString("name")][k1] == nil {
|
||||
appIns.Router[codeMake.GetString("name")][k1] = Ctr{}
|
||||
}
|
||||
|
||||
for k2, _ := range appIns.Router[codeMake.GetString("name")]["hotimeCommon"] {
|
||||
//golang毛病
|
||||
v2 := appIns.Router[codeMake.GetString("name")]["hotimeCommon"][k2]
|
||||
appIns.Router[codeMake.GetString("name")][k1][k2] = v2
|
||||
}
|
||||
}
|
||||
|
||||
setMakeCodeListener(codeMake.GetString("name"), &appIns)
|
||||
setMakeCodeLintener(k, &appIns)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return &appIns
|
||||
return appIns
|
||||
}
|
||||
|
||||
// SetDB 智能数据库设置
|
||||
@ -638,8 +573,6 @@ func SetMysqlDB(appIns *Application, config Map) {
|
||||
appIns.Db.Type = "mysql"
|
||||
appIns.Db.DBName = config.GetString("name")
|
||||
appIns.Db.Prefix = config.GetString("prefix")
|
||||
appIns.Db.Log = appIns.Log
|
||||
appIns.Db.Mode = appIns.Config.GetCeilInt("mode")
|
||||
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
|
||||
//master数据库配置
|
||||
query := config.GetString("user") + ":" + config.GetString("password") +
|
||||
@ -669,8 +602,6 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
|
||||
appIns.Db.Type = "sqlite"
|
||||
appIns.Db.Prefix = config.GetString("prefix")
|
||||
appIns.Db.Mode = appIns.Config.GetCeilInt("mode")
|
||||
appIns.Db.Log = appIns.Log
|
||||
appIns.SetConnectDB(func(err ...*Error) (master, slave *sql.DB) {
|
||||
db, e := sql.Open("sqlite3", config.GetString("path"))
|
||||
if e != nil && len(err) != 0 {
|
||||
@ -682,56 +613,81 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
})
|
||||
}
|
||||
|
||||
func setMakeCodeListener(name string, appIns *Application) {
|
||||
appIns.SetConnectListener(func(context *Context) (isFinished bool) {
|
||||
|
||||
codeIns := appIns.MakeCodeRouter[name]
|
||||
|
||||
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
func setMakeCodeLintener(name string, appIns *Application) {
|
||||
appIns.SetConnectListener(func(context *Context) bool {
|
||||
if len(context.RouterString) > 1 && context.RouterString[0] == name {
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
|
||||
return isFinished
|
||||
}
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
|
||||
return isFinished
|
||||
}
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "wallpaper" {
|
||||
return isFinished
|
||||
}
|
||||
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return true
|
||||
}
|
||||
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 isFinished
|
||||
return true
|
||||
}
|
||||
//排除无效操作
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method != "GET" &&
|
||||
context.Req.Method != "POST" {
|
||||
return isFinished
|
||||
return true
|
||||
}
|
||||
//排除已有接口的无效操作
|
||||
if len(context.RouterString) == 3 && context.Router[context.RouterString[0]] != nil && context.Router[context.RouterString[0]][context.RouterString[1]] != nil && context.Router[context.RouterString[0]][context.RouterString[1]][context.RouterString[2]] != nil {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
//列表检索
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "GET" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
||||
return isFinished
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
||||
}
|
||||
@ -745,24 +701,14 @@ func setMakeCodeListener(name string, appIns *Application) {
|
||||
}
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "POST" {
|
||||
return isFinished
|
||||
}
|
||||
//分析
|
||||
if len(context.RouterString) == 3 && context.RouterString[2] == "analyse" &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["analyse"] == nil {
|
||||
return isFinished
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["analyse"](context)
|
||||
return true
|
||||
}
|
||||
//查询单条
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
||||
return isFinished
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
||||
@ -787,8 +733,7 @@ func setMakeCodeListener(name string, appIns *Application) {
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
||||
}
|
||||
|
||||
//context.View()
|
||||
return true
|
||||
context.View()
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
2
cache/cache.go
vendored
2
cache/cache.go
vendored
@ -1,7 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
"errors"
|
||||
)
|
||||
|
||||
|
28
cache/cache_db.go
vendored
28
cache/cache_db.go
vendored
@ -1,7 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
@ -30,14 +30,14 @@ type CacheDb struct {
|
||||
isInit bool
|
||||
}
|
||||
|
||||
func (that *CacheDb) GetError() *Error {
|
||||
func (this *CacheDb) GetError() *Error {
|
||||
|
||||
return that.Error
|
||||
return this.Error
|
||||
|
||||
}
|
||||
|
||||
func (that *CacheDb) SetError(err *Error) {
|
||||
that.Error = err
|
||||
func (this *CacheDb) SetError(err *Error) {
|
||||
this.Error = err
|
||||
}
|
||||
|
||||
func (that *CacheDb) initDbTable() {
|
||||
@ -58,7 +58,7 @@ func (that *CacheDb) initDbTable() {
|
||||
return
|
||||
}
|
||||
|
||||
_, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(60) DEFAULT NULL, `value` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8")
|
||||
_, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ckey` varchar(60) DEFAULT NULL, `cvalue` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8")
|
||||
if e.GetError() == nil {
|
||||
that.isInit = true
|
||||
}
|
||||
@ -74,8 +74,8 @@ func (that *CacheDb) initDbTable() {
|
||||
}
|
||||
_, e := that.Db.Exec(`CREATE TABLE "` + that.Db.GetPrefix() + `cached" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"key" TEXT(60),
|
||||
"value" TEXT(2000),
|
||||
"ckey" TEXT(60),
|
||||
"cvalue" TEXT(2000),
|
||||
"time" integer,
|
||||
"endtime" integer
|
||||
);`)
|
||||
@ -90,7 +90,7 @@ func (that *CacheDb) initDbTable() {
|
||||
//获取Cache键只能为string类型
|
||||
func (that *CacheDb) get(key string) interface{} {
|
||||
|
||||
cached := that.Db.Get("cached", "*", Map{"key": key})
|
||||
cached := that.Db.Get("cached", "*", Map{"ckey": key})
|
||||
|
||||
if cached == nil {
|
||||
return nil
|
||||
@ -103,7 +103,7 @@ func (that *CacheDb) get(key string) interface{} {
|
||||
}
|
||||
|
||||
data := Map{}
|
||||
data.JsonToMap(cached.GetString("value"))
|
||||
data.JsonToMap(cached.GetString("cvalue"))
|
||||
|
||||
return data.Get("data")
|
||||
}
|
||||
@ -113,9 +113,9 @@ func (that *CacheDb) set(key string, value interface{}, tim int64) {
|
||||
|
||||
bte, _ := json.Marshal(Map{"data": value})
|
||||
|
||||
num := that.Db.Update("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"key": key})
|
||||
num := that.Db.Update("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"ckey": key})
|
||||
if num == int64(0) {
|
||||
that.Db.Insert("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "key": key})
|
||||
that.Db.Insert("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "ckey": key})
|
||||
}
|
||||
|
||||
//随机执行删除命令
|
||||
@ -130,10 +130,10 @@ func (that *CacheDb) delete(key string) {
|
||||
//如果通配删除
|
||||
if del != -1 {
|
||||
key = Substr(key, 0, del)
|
||||
that.Db.Delete("cached", Map{"key": key + "%"})
|
||||
that.Db.Delete("cached", Map{"ckey": key + "%"})
|
||||
|
||||
} else {
|
||||
that.Db.Delete("cached", Map{"key": key})
|
||||
that.Db.Delete("cached", Map{"ckey": key})
|
||||
}
|
||||
}
|
||||
|
||||
|
199
cache/cache_memory.go
vendored
199
cache/cache_memory.go
vendored
@ -1,115 +1,158 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CacheMemory 基于 sync.Map 的缓存实现
|
||||
type CacheMemory struct {
|
||||
TimeOut int64
|
||||
DbSet bool
|
||||
SessionSet bool
|
||||
Map
|
||||
*Error
|
||||
cache sync.Map // 替代传统的 Map
|
||||
ContextBase
|
||||
mutex *sync.RWMutex
|
||||
}
|
||||
|
||||
func (that *CacheMemory) GetError() *Error {
|
||||
func (this *CacheMemory) GetError() *Error {
|
||||
|
||||
return that.Error
|
||||
return this.Error
|
||||
|
||||
}
|
||||
|
||||
func (that *CacheMemory) SetError(err *Error) {
|
||||
that.Error = err
|
||||
}
|
||||
func (c *CacheMemory) get(key string) (res *Obj) {
|
||||
|
||||
res = &Obj{
|
||||
Error: *c.Error,
|
||||
}
|
||||
value, ok := c.cache.Load(key)
|
||||
if !ok {
|
||||
return res // 缓存不存在
|
||||
func (this *CacheMemory) SetError(err *Error) {
|
||||
this.Error = err
|
||||
}
|
||||
|
||||
data := value.(cacheData)
|
||||
//获取Cache键只能为string类型
|
||||
func (this *CacheMemory) get(key string) interface{} {
|
||||
this.Error.SetError(nil)
|
||||
if this.Map == nil {
|
||||
this.Map = Map{}
|
||||
}
|
||||
|
||||
if this.Map[key] == nil {
|
||||
return nil
|
||||
}
|
||||
data := this.Map.Get(key, this.Error).(cacheData)
|
||||
if this.Error.GetError() != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 检查是否过期
|
||||
if data.time < time.Now().Unix() {
|
||||
c.cache.Delete(key) // 删除过期缓存
|
||||
return res
|
||||
delete(this.Map, key)
|
||||
return nil
|
||||
}
|
||||
res.Data = data.data
|
||||
return res
|
||||
return data.data
|
||||
}
|
||||
func (c *CacheMemory) set(key string, value interface{}, expireAt int64) {
|
||||
data := cacheData{
|
||||
data: value,
|
||||
time: expireAt,
|
||||
}
|
||||
c.cache.Store(key, data)
|
||||
}
|
||||
func (c *CacheMemory) delete(key string) {
|
||||
if strings.Contains(key, "*") {
|
||||
// 通配符删除
|
||||
prefix := strings.TrimSuffix(key, "*")
|
||||
c.cache.Range(func(k, v interface{}) bool {
|
||||
if strings.HasPrefix(k.(string), prefix) {
|
||||
c.cache.Delete(k)
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
// 精确删除
|
||||
c.cache.Delete(key)
|
||||
}
|
||||
}
|
||||
func (c *CacheMemory) refreshMap() {
|
||||
go func() {
|
||||
now := time.Now().Unix()
|
||||
c.cache.Range(func(key, value interface{}) bool {
|
||||
data := value.(cacheData)
|
||||
if data.time <= now {
|
||||
c.cache.Delete(key) // 删除过期缓存
|
||||
}
|
||||
return true
|
||||
})
|
||||
}()
|
||||
}
|
||||
func (c *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||
now := time.Now().Unix()
|
||||
|
||||
// 随机触发刷新
|
||||
if x := RandX(1, 100000); x > 99950 {
|
||||
c.refreshMap()
|
||||
func (this *CacheMemory) refreshMap() {
|
||||
|
||||
go func() {
|
||||
this.mutex.Lock()
|
||||
defer this.mutex.Unlock()
|
||||
for key, v := range this.Map {
|
||||
data := v.(cacheData)
|
||||
if data.time <= time.Now().Unix() {
|
||||
delete(this.Map, key)
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
//key value ,时间为时间戳
|
||||
func (this *CacheMemory) set(key string, value interface{}, time int64) {
|
||||
this.Error.SetError(nil)
|
||||
var data cacheData
|
||||
|
||||
if this.Map == nil {
|
||||
this.Map = Map{}
|
||||
}
|
||||
|
||||
dd := this.Map[key]
|
||||
|
||||
if dd == nil {
|
||||
data = cacheData{}
|
||||
} else {
|
||||
data = dd.(cacheData)
|
||||
}
|
||||
|
||||
data.time = time
|
||||
data.data = value
|
||||
|
||||
this.Map.Put(key, data)
|
||||
}
|
||||
|
||||
func (this *CacheMemory) delete(key string) {
|
||||
del := strings.Index(key, "*")
|
||||
//如果通配删除
|
||||
if del != -1 {
|
||||
key = Substr(key, 0, del)
|
||||
for k, _ := range this.Map {
|
||||
if strings.Index(k, key) != -1 {
|
||||
delete(this.Map, k)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
delete(this.Map, key)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (this *CacheMemory) Cache(key string, data ...interface{}) *Obj {
|
||||
|
||||
x := RandX(1, 100000)
|
||||
if x > 99950 {
|
||||
this.refreshMap()
|
||||
}
|
||||
if this.mutex == nil {
|
||||
this.mutex = &sync.RWMutex{}
|
||||
}
|
||||
|
||||
reData := &Obj{Data: nil}
|
||||
|
||||
if len(data) == 0 {
|
||||
// 读操作
|
||||
return c.get(key)
|
||||
this.mutex.RLock()
|
||||
reData.Data = this.get(key)
|
||||
this.mutex.RUnlock()
|
||||
return reData
|
||||
}
|
||||
tim := time.Now().Unix()
|
||||
|
||||
if len(data) == 1 && data[0] == nil {
|
||||
// 删除操作
|
||||
c.delete(key)
|
||||
return nil
|
||||
this.mutex.Lock()
|
||||
this.delete(key)
|
||||
this.mutex.Unlock()
|
||||
return reData
|
||||
}
|
||||
|
||||
// 写操作
|
||||
expireAt := now + c.TimeOut
|
||||
if len(data) == 1 {
|
||||
|
||||
tim = tim + this.TimeOut
|
||||
|
||||
}
|
||||
if len(data) == 2 {
|
||||
if customExpire, ok := data[1].(int64); ok {
|
||||
if customExpire > now {
|
||||
expireAt = customExpire
|
||||
} else {
|
||||
expireAt = now + customExpire
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], this.Error)
|
||||
|
||||
if tempt > tim {
|
||||
|
||||
tim = tempt
|
||||
} else if this.Error.GetError() == nil {
|
||||
|
||||
tim = tim + tempt
|
||||
}
|
||||
}
|
||||
this.mutex.Lock()
|
||||
this.set(key, data[0], tim)
|
||||
this.mutex.Unlock()
|
||||
return reData
|
||||
|
||||
c.set(key, data[0], expireAt)
|
||||
return nil
|
||||
}
|
||||
|
102
cache/cache_redis.go
vendored
102
cache/cache_redis.go
vendored
@ -1,7 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"strings"
|
||||
"time"
|
||||
@ -20,65 +20,65 @@ type CacheRedis struct {
|
||||
*Error
|
||||
}
|
||||
|
||||
func (that *CacheRedis) GetError() *Error {
|
||||
func (this *CacheRedis) GetError() *Error {
|
||||
|
||||
return that.Error
|
||||
return this.Error
|
||||
|
||||
}
|
||||
|
||||
func (that *CacheRedis) SetError(err *Error) {
|
||||
that.Error = err
|
||||
func (this *CacheRedis) SetError(err *Error) {
|
||||
this.Error = err
|
||||
}
|
||||
|
||||
//唯一标志
|
||||
func (that *CacheRedis) GetTag() int64 {
|
||||
func (this *CacheRedis) GetTag() int64 {
|
||||
|
||||
if that.tag == int64(0) {
|
||||
that.tag = time.Now().UnixNano()
|
||||
if this.tag == int64(0) {
|
||||
this.tag = time.Now().UnixNano()
|
||||
}
|
||||
return that.tag
|
||||
return this.tag
|
||||
}
|
||||
|
||||
func (that *CacheRedis) reCon() bool {
|
||||
func (this *CacheRedis) reCon() bool {
|
||||
var err error
|
||||
that.conn, err = redis.Dial("tcp", that.Host+":"+ObjToStr(that.Port))
|
||||
this.conn, err = redis.Dial("tcp", this.Host+":"+ObjToStr(this.Port))
|
||||
if err != nil {
|
||||
that.conn = nil
|
||||
that.Error.SetError(err)
|
||||
this.conn = nil
|
||||
this.Error.SetError(err)
|
||||
return false
|
||||
}
|
||||
|
||||
if that.Pwd != "" {
|
||||
_, err = that.conn.Do("AUTH", that.Pwd)
|
||||
if this.Pwd != "" {
|
||||
_, err = this.conn.Do("AUTH", this.Pwd)
|
||||
if err != nil {
|
||||
that.conn = nil
|
||||
that.Error.SetError(err)
|
||||
this.conn = nil
|
||||
this.Error.SetError(err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
func (that *CacheRedis) del(key string) {
|
||||
func (this *CacheRedis) del(key string) {
|
||||
del := strings.Index(key, "*")
|
||||
if del != -1 {
|
||||
val, err := redis.Strings(that.conn.Do("KEYS", key))
|
||||
val, err := redis.Strings(this.conn.Do("KEYS", key))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
that.conn.Send("MULTI")
|
||||
this.conn.Send("MULTI")
|
||||
for i, _ := range val {
|
||||
that.conn.Send("DEL", val[i])
|
||||
this.conn.Send("DEL", val[i])
|
||||
}
|
||||
that.conn.Do("EXEC")
|
||||
this.conn.Do("EXEC")
|
||||
} else {
|
||||
_, err := that.conn.Do("DEL", key)
|
||||
_, err := this.conn.Do("DEL", key)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
_, err = that.conn.Do("PING")
|
||||
this.Error.SetError(err)
|
||||
_, err = this.conn.Do("PING")
|
||||
if err != nil {
|
||||
if that.reCon() {
|
||||
_, err = that.conn.Do("DEL", key)
|
||||
if this.reCon() {
|
||||
_, err = this.conn.Do("DEL", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,32 +86,32 @@ func (that *CacheRedis) del(key string) {
|
||||
}
|
||||
|
||||
//key value ,时间为时间戳
|
||||
func (that *CacheRedis) set(key string, value string, time int64) {
|
||||
_, err := that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||
func (this *CacheRedis) set(key string, value string, time int64) {
|
||||
_, err := this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||
if err != nil {
|
||||
|
||||
that.Error.SetError(err)
|
||||
_, err = that.conn.Do("PING")
|
||||
this.Error.SetError(err)
|
||||
_, err = this.conn.Do("PING")
|
||||
if err != nil {
|
||||
if that.reCon() {
|
||||
_, err = that.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||
if this.reCon() {
|
||||
_, err = this.conn.Do("SET", key, value, "EX", ObjToStr(time))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (that *CacheRedis) get(key string) *Obj {
|
||||
func (this *CacheRedis) get(key string) *Obj {
|
||||
reData := &Obj{}
|
||||
var err error
|
||||
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
||||
if err != nil {
|
||||
reData.Data = nil
|
||||
if !strings.Contains(err.Error(), "nil returned") {
|
||||
that.Error.SetError(err)
|
||||
_, err = that.conn.Do("PING")
|
||||
this.Error.SetError(err)
|
||||
_, err = this.conn.Do("PING")
|
||||
if err != nil {
|
||||
if that.reCon() {
|
||||
reData.Data, err = redis.String(that.conn.Do("GET", key))
|
||||
if this.reCon() {
|
||||
reData.Data, err = redis.String(this.conn.Do("GET", key))
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,10 +121,10 @@ func (that *CacheRedis) get(key string) *Obj {
|
||||
return reData
|
||||
}
|
||||
|
||||
func (that *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||
func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||
reData := &Obj{}
|
||||
if that.conn == nil {
|
||||
re := that.reCon()
|
||||
if this.conn == nil {
|
||||
re := this.reCon()
|
||||
if !re {
|
||||
return reData
|
||||
}
|
||||
@ -132,38 +132,38 @@ func (that *CacheRedis) Cache(key string, data ...interface{}) *Obj {
|
||||
//查询缓存
|
||||
if len(data) == 0 {
|
||||
|
||||
reData = that.get(key)
|
||||
reData = this.get(key)
|
||||
return reData
|
||||
|
||||
}
|
||||
tim := int64(0)
|
||||
//删除缓存
|
||||
if len(data) == 1 && data[0] == nil {
|
||||
that.del(key)
|
||||
this.del(key)
|
||||
return reData
|
||||
}
|
||||
//添加缓存
|
||||
if len(data) == 1 {
|
||||
|
||||
if that.TimeOut == 0 {
|
||||
//that.Time = Config.GetInt64("cacheShortTime")
|
||||
if this.TimeOut == 0 {
|
||||
//this.Time = Config.GetInt64("cacheShortTime")
|
||||
}
|
||||
|
||||
tim += that.TimeOut
|
||||
tim += this.TimeOut
|
||||
}
|
||||
if len(data) == 2 {
|
||||
that.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], that.Error)
|
||||
this.Error.SetError(nil)
|
||||
tempt := ObjToInt64(data[1], this.Error)
|
||||
if tempt > tim {
|
||||
|
||||
tim = tempt
|
||||
} else if that.GetError() == nil {
|
||||
} else if this.GetError() == nil {
|
||||
|
||||
tim = tim + tempt
|
||||
}
|
||||
}
|
||||
|
||||
that.set(key, ObjToStr(data[0]), tim)
|
||||
this.set(key, ObjToStr(data[0]), tim)
|
||||
|
||||
return reData
|
||||
|
||||
|
2
cache/type.go
vendored
2
cache/type.go
vendored
@ -1,7 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
)
|
||||
|
||||
type CacheIns interface {
|
||||
|
189
code/config.go
189
code/config.go
@ -1,34 +1,20 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../common"
|
||||
)
|
||||
|
||||
var Config = Map{
|
||||
"name": "HoTimeDashBoard",
|
||||
//"id": "2f92h3herh23rh2y8",
|
||||
"id": "2f92h3herh23rh2y8",
|
||||
"label": "HoTime管理平台",
|
||||
"stop": Slice{"role", "org"}, //不更新的,同时不允许修改用户自身对应的表数据
|
||||
"labelConfig": Map{
|
||||
"show": "开启",
|
||||
"add": "添加",
|
||||
"delete": "删除",
|
||||
"edit": "编辑",
|
||||
"info": "查看详情",
|
||||
"download": "下载清单",
|
||||
},
|
||||
|
||||
"menus": []Map{
|
||||
//{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
//{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
||||
//{"label": "系统管理", "name": "setting", "icon": "el-icon-setting",
|
||||
// "menus": []Map{
|
||||
// {"label": "用户管理", "table": "user",
|
||||
// "default": {
|
||||
// "path": "info",
|
||||
// "id": "1"
|
||||
// },
|
||||
// "auth": ["show","edit","info","add","delete"],
|
||||
// },
|
||||
// {"label": "用户管理", "table": "user"},
|
||||
// {"label": "组织管理", "table": "organization"},
|
||||
// {"label": "地区管理", "table": "area"},
|
||||
// {"label": "角色管理", "table": "role"},
|
||||
@ -48,7 +34,6 @@ var ColumnDataType = map[string]string{
|
||||
"float": "number",
|
||||
"double": "number",
|
||||
"decimal": "number",
|
||||
"integer": "number", //sqlite3
|
||||
"char": "text",
|
||||
"text": "text",
|
||||
"blob": "text",
|
||||
@ -59,130 +44,54 @@ var ColumnDataType = map[string]string{
|
||||
}
|
||||
|
||||
type ColumnShow struct {
|
||||
Name string //名称
|
||||
|
||||
List bool //列表权限
|
||||
Edit bool //新增和编辑权限
|
||||
Info bool //详情权限
|
||||
Must bool //字段全匹配
|
||||
Name string
|
||||
List bool
|
||||
Edit bool
|
||||
Info bool
|
||||
Must bool
|
||||
Type string //空字符串表示
|
||||
Strict bool //name严格匹配必须是这个词才行
|
||||
}
|
||||
|
||||
var RuleConfig = []Map{
|
||||
{"name": "idcard", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "id", "add": false, "list": true, "edit": false, "info": true, "must": false, "strict": true, "type": ""},
|
||||
{"name": "sn", "add": false, "list": true, "edit": false, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "parent_ids", "add": false, "list": false, "edit": false, "info": false, "must": false, "strict": true, "type": "index"},
|
||||
{"name": "index", "add": false, "list": false, "edit": false, "info": false, "must": false, "strict": true, "type": "index"},
|
||||
var ColumnNameType = []ColumnShow{
|
||||
//通用
|
||||
{"idcard", false, true, true, false, "", false},
|
||||
{"id", true, false, true, false, "", true},
|
||||
{"parent_id", true, true, true, false, "", true},
|
||||
//"sn"{true,true,true,""},
|
||||
{"status", true, true, true, false, "select", false},
|
||||
{"state", true, true, true, false, "select", false},
|
||||
{"sex", true, true, true, false, "select", false},
|
||||
{"delete", false, false, false, false, "", false},
|
||||
|
||||
{"name": "parent_id", "add": true, "list": true, "edit": true, "info": true, "must": false, "true": false, "type": ""},
|
||||
{"lat", false, true, true, false, "", false},
|
||||
{"lng", false, true, true, false, "", false},
|
||||
{"latitude", false, true, true, false, "", false},
|
||||
{"longitude", false, true, true, false, "", false},
|
||||
|
||||
{"name": "amount", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": true, "type": "money"},
|
||||
|
||||
{"name": "info", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "textArea"},
|
||||
|
||||
{"name": "status", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": "select"},
|
||||
{"name": "state", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": "select"},
|
||||
{"name": "sex", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": "select"},
|
||||
|
||||
{"name": "delete", "add": false, "list": false, "edit": false, "info": false, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "lat", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "lng", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "latitude", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "longitude", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "password", "add": true, "list": false, "edit": true, "info": false, "must": false, "strict": false, "type": "password"},
|
||||
{"name": "pwd", "add": true, "list": false, "edit": true, "info": false, "must": false, "strict": false, "type": "password"},
|
||||
|
||||
{"name": "version", "add": false, "list": false, "edit": false, "info": false, "must": false, "strict": false, "type": ""},
|
||||
{"name": "seq", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "sort", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "note", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "description", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "abstract", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "content", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "textArea"},
|
||||
|
||||
{"name": "address", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "full_name", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
|
||||
{"name": "create_time", "add": false, "list": false, "edit": false, "info": true, "must": false, "strict": true, "type": "time"},
|
||||
{"name": "modify_time", "add": false, "list": true, "edit": false, "info": true, "must": false, "strict": true, "type": "time"},
|
||||
|
||||
{"name": "image", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "image"},
|
||||
|
||||
{"name": "img", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "image"},
|
||||
{"name": "avatar", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "image"},
|
||||
{"name": "icon", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "image"},
|
||||
|
||||
{"name": "file", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "file"},
|
||||
|
||||
{"name": "age", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "email", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "time", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": "time"},
|
||||
|
||||
{"name": "level", "add": false, "list": false, "edit": false, "info": true, "must": false, "strict": false, "type": ""},
|
||||
{"name": "rule", "add": true, "list": true, "edit": true, "info": true, "must": false, "strict": false, "type": "form"},
|
||||
|
||||
{"name": "auth", "add": true, "list": false, "edit": true, "info": true, "must": false, "strict": false, "type": "auth"},
|
||||
|
||||
{"name": "table", "add": false, "list": true, "edit": false, "info": true, "must": false, "strict": false, "type": "table"},
|
||||
{"name": "table_id", "add": false, "list": true, "edit": false, "info": true, "must": false, "strict": false, "type": "table_id"},
|
||||
{"index", false, false, false, false, "index", false},
|
||||
{"password", false, true, false, false, "password", false},
|
||||
{"pwd", false, true, false, false, "password", false},
|
||||
{"info", false, true, true, false, "", false},
|
||||
{"version", false, false, false, false, "", false},
|
||||
{"seq", false, true, true, false, "", false},
|
||||
{"sort", false, true, true, false, "", false},
|
||||
{"note", false, true, true, false, "", false},
|
||||
{"description", false, true, true, false, "", false},
|
||||
{"abstract", false, true, true, false, "", false},
|
||||
{"content", false, true, true, false, "", false},
|
||||
{"address", false, true, true, false, "", false},
|
||||
{"full_name", false, true, true, false, "", false},
|
||||
{"create_time", false, false, true, false, "time", true},
|
||||
{"modify_time", true, false, true, false, "time", true},
|
||||
{"image", 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},
|
||||
{"file", false, true, true, false, "file", false},
|
||||
{"age", false, true, true, false, "", false},
|
||||
{"email", false, true, true, false, "", false},
|
||||
{"time", true, true, true, true, "time", false},
|
||||
{"level", false, false, true, false, "", false},
|
||||
{"rule", true, true, true, false, "form", false},
|
||||
}
|
||||
|
||||
//var ColumnNameType = []ColumnShow{
|
||||
// //通用
|
||||
// {"idcard", false, true, true, false, "", false},
|
||||
// {"id", true, false, true, false, "", true},
|
||||
// {"sn", true, false, true, false, "", false},
|
||||
// {"parent_ids", false, false, false, false, "index", true},
|
||||
// {"parent_id", true, true, true, false, "", true},
|
||||
// {"amount", true, true, true, false, "money", true},
|
||||
// {"info", false, true, true, false, "textArea", false},
|
||||
// //"sn"{true,true,true,""},
|
||||
// {"status", true, true, true, false, "select", false},
|
||||
// {"state", true, true, true, false, "select", false},
|
||||
// {"sex", true, true, true, false, "select", false},
|
||||
// {"delete", false, false, false, false, "", false},
|
||||
//
|
||||
// {"lat", false, true, true, false, "", false},
|
||||
// {"lng", false, true, true, false, "", false},
|
||||
// {"latitude", false, true, true, false, "", false},
|
||||
// {"longitude", false, true, true, false, "", false},
|
||||
//
|
||||
// {"index", false, false, false, false, "index", false},
|
||||
//
|
||||
// {"password", false, true, false, false, "password", false},
|
||||
// {"pwd", false, true, false, false, "password", false},
|
||||
//
|
||||
// {"version", false, false, false, false, "", false},
|
||||
// {"seq", false, true, true, false, "", false},
|
||||
// {"sort", false, true, true, false, "", false},
|
||||
// {"note", false, true, true, false, "", false},
|
||||
// {"description", false, true, true, false, "", false},
|
||||
// {"abstract", false, true, true, false, "", false},
|
||||
// {"content", false, true, true, false, "textArea", false},
|
||||
// {"address", true, true, true, false, "", false},
|
||||
// {"full_name", false, true, true, false, "", false},
|
||||
// {"create_time", false, false, true, false, "time", true},
|
||||
// {"modify_time", true, false, true, false, "time", true},
|
||||
// {"image", 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},
|
||||
// {"file", false, true, true, false, "file", false},
|
||||
// {"age", false, true, true, false, "", false},
|
||||
// {"email", false, true, true, false, "", false},
|
||||
// {"time", true, true, true, false, "time", false},
|
||||
// {"level", false, false, true, false, "", false},
|
||||
// {"rule", true, true, true, false, "form", false},
|
||||
// {"auth", false, true, true, false, "auth", true},
|
||||
// {"table", true, false, true, false, "table", false},
|
||||
// {"table_id", true, false, true, false, "table_id", false},
|
||||
//}
|
||||
|
967
code/makecode.go
967
code/makecode.go
File diff suppressed because it is too large
Load Diff
@ -3,8 +3,8 @@ package code
|
||||
var InitTpt = `package {{name}}
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
)
|
||||
|
||||
var ID = "{{id}}"
|
||||
@ -14,32 +14,30 @@ var Project = Proj{
|
||||
//"user": UserCtr,
|
||||
{{tablesCtr}}
|
||||
"hotime":Ctr{
|
||||
"login": func(that *Context) {
|
||||
|
||||
name := that.Req.FormValue("name")
|
||||
password := that.Req.FormValue("password")
|
||||
"login": func(this *Context) {
|
||||
name := this.Req.FormValue("name")
|
||||
password := this.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
that.Display(3, "参数不足")
|
||||
this.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := that.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
||||
user := this.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
||||
if user == nil {
|
||||
that.Display(5, "登录失败")
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
that.Session("admin_id", user.GetCeilInt("id"))
|
||||
that.Session("admin_name", name)
|
||||
that.Display(0, that.SessionId)
|
||||
this.Session("admin_id", user.GetCeilInt("id"))
|
||||
this.Session("admin_name", name)
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"logout": func(that *Context) {
|
||||
that.Session("admin_id", nil)
|
||||
that.Session("admin_name", nil)
|
||||
that.Display(0, "退出登录成功")
|
||||
"logout": func(this *Context) {
|
||||
this.Session("admin_id", nil)
|
||||
this.Session("admin_name", nil)
|
||||
this.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info("admin", data, that.Db)
|
||||
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"]
|
||||
@ -54,7 +52,7 @@ var Project = Proj{
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns["admin"][k]
|
||||
column := that.MakeCode.TableColumns["admin"][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@ -71,16 +69,15 @@ var Project = Proj{
|
||||
var CtrTpt = `package {{name}}
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var {{table}}Ctr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) ==1 {
|
||||
@ -99,7 +96,7 @@ var {{table}}Ctr = Ctr{
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@ -111,8 +108,7 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], that.Req)
|
||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -138,8 +134,7 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
@ -170,8 +165,7 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -192,10 +186,10 @@ var {{table}}Ctr = Ctr{
|
||||
},
|
||||
|
||||
"search": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
|
||||
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, 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"))
|
||||
@ -214,7 +208,7 @@ var {{table}}Ctr = Ctr{
|
||||
|
||||
for _, v := range reData {
|
||||
for k, _ := range v {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ type ContextBase struct {
|
||||
}
|
||||
|
||||
//唯一标志
|
||||
func (that *ContextBase) GetTag() string {
|
||||
func (this *ContextBase) GetTag() string {
|
||||
|
||||
if that.tag == "" {
|
||||
that.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
||||
if this.tag == "" {
|
||||
this.tag = ObjToStr(time.Now().Unix()) + ":" + ObjToStr(Random())
|
||||
}
|
||||
return that.tag
|
||||
return this.tag
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"encoding/hex"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//安全锁
|
||||
@ -37,43 +36,7 @@ func StrFirstToUpper(str string) string {
|
||||
return strings.ToUpper(first) + other
|
||||
}
|
||||
|
||||
// 时间转字符串,第二个参数支持1-5对应显示年月日时分秒
|
||||
func Time2Str(t time.Time, qu ...interface{}) string {
|
||||
if t.Unix() < 0 {
|
||||
return ""
|
||||
}
|
||||
tp := 5
|
||||
if len(qu) != 0 {
|
||||
tp = (qu[0]).(int)
|
||||
}
|
||||
|
||||
switch tp {
|
||||
case 1:
|
||||
return t.Format("2006-01")
|
||||
case 2:
|
||||
return t.Format("2006-01-02")
|
||||
case 3:
|
||||
return t.Format("2006-01-02 15")
|
||||
case 4:
|
||||
return t.Format("2006-01-02 15:04")
|
||||
case 5:
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
case 12:
|
||||
return t.Format("01-02")
|
||||
case 14:
|
||||
return t.Format("01-02 15:04")
|
||||
case 15:
|
||||
return t.Format("01-02 15:04:05")
|
||||
case 34:
|
||||
return t.Format("15:04")
|
||||
case 35:
|
||||
return t.Format("15:04:05")
|
||||
}
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
|
||||
}
|
||||
|
||||
// StrLd 相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||
//相似度计算 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)
|
||||
@ -179,7 +142,7 @@ func Md5(req string) string {
|
||||
return hex.EncodeToString(cipherStr)
|
||||
}
|
||||
|
||||
// Rand 随机数
|
||||
//随机数
|
||||
func Rand(count int) int {
|
||||
res := Random()
|
||||
for i := 0; i < count; i++ {
|
||||
@ -204,7 +167,7 @@ func Random() float64 {
|
||||
|
||||
}
|
||||
|
||||
// RandX 随机数范围
|
||||
//随机数范围
|
||||
func RandX(small int, max int) int {
|
||||
res := 0
|
||||
//随机对象
|
||||
@ -256,7 +219,7 @@ func RandX(small int, max int) int {
|
||||
// GetDb()
|
||||
//}
|
||||
|
||||
// DeepCopyMap 复制返回数组
|
||||
//复制返回数组
|
||||
func DeepCopyMap(value interface{}) interface{} {
|
||||
if valueMap, ok := value.(Map); ok {
|
||||
newMap := make(Map)
|
||||
@ -315,7 +278,7 @@ func DeepCopyMap(value interface{}) interface{} {
|
||||
// }
|
||||
//}
|
||||
|
||||
// Round 浮点数四舍五入保留小数
|
||||
//浮点数四舍五入保留小数
|
||||
func Round(f float64, n int) float64 {
|
||||
pow10_n := math.Pow10(n)
|
||||
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
|
||||
|
106
common/map.go
106
common/map.go
@ -4,140 +4,114 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
//hotime的常用map
|
||||
type Map map[string]interface{}
|
||||
|
||||
//获取string
|
||||
func (that Map) GetString(key string, err ...*Error) string {
|
||||
func (this Map) GetString(key string, err ...*Error) string {
|
||||
|
||||
if len(err) != 0 {
|
||||
err[0].SetError(nil)
|
||||
}
|
||||
return ObjToStr((that)[key])
|
||||
return ObjToStr((this)[key])
|
||||
|
||||
}
|
||||
|
||||
func (that *Map) Pointer() *Map {
|
||||
func (this *Map) Pointer() *Map {
|
||||
|
||||
return that
|
||||
return this
|
||||
}
|
||||
|
||||
//增加接口
|
||||
func (that Map) Put(key string, value interface{}) {
|
||||
//if that==nil{
|
||||
// that=Map{}
|
||||
func (this Map) Put(key string, value interface{}) {
|
||||
//if this==nil{
|
||||
// this=Map{}
|
||||
//}
|
||||
that[key] = value
|
||||
this[key] = value
|
||||
}
|
||||
|
||||
//删除接口
|
||||
func (that Map) Delete(key string) {
|
||||
delete(that, key)
|
||||
func (this Map) Delete(key string) {
|
||||
delete(this, key)
|
||||
|
||||
}
|
||||
|
||||
//获取Int
|
||||
func (that Map) GetInt(key string, err ...*Error) int {
|
||||
v := ObjToInt((that)[key], err...)
|
||||
func (this Map) GetInt(key string, err ...*Error) int {
|
||||
v := ObjToInt((this)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取Int
|
||||
func (that Map) GetInt64(key string, err ...*Error) int64 {
|
||||
v := ObjToInt64((that)[key], err...)
|
||||
func (this Map) GetInt64(key string, err ...*Error) int64 {
|
||||
v := ObjToInt64((this)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取向上取整Int64
|
||||
func (that Map) GetCeilInt64(key string, err ...*Error) int64 {
|
||||
v := ObjToCeilInt64((that)[key], err...)
|
||||
func (this Map) GetCeilInt64(key string, err ...*Error) int64 {
|
||||
v := ObjToCeilInt64((this)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取向上取整Int
|
||||
func (that Map) GetCeilInt(key string, err ...*Error) int {
|
||||
v := ObjToCeilInt((that)[key], err...)
|
||||
func (this Map) GetCeilInt(key string, err ...*Error) int {
|
||||
v := ObjToCeilInt((this)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取向上取整float64
|
||||
func (that Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
||||
v := ObjToCeilFloat64((that)[key], err...)
|
||||
func (this Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
||||
v := ObjToCeilFloat64((this)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
//获取Float64
|
||||
func (that Map) GetFloat64(key string, err ...*Error) float64 {
|
||||
func (this Map) GetFloat64(key string, err ...*Error) float64 {
|
||||
|
||||
v := ObjToFloat64((that)[key], err...)
|
||||
v := ObjToFloat64((this)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (that Map) GetSlice(key string, err ...*Error) Slice {
|
||||
func (this Map) GetSlice(key string, err ...*Error) Slice {
|
||||
|
||||
//var v Slice
|
||||
v := ObjToSlice((that)[key], err...)
|
||||
v := ObjToSlice((this)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
func (that Map) GetBool(key string, err ...*Error) bool {
|
||||
func (this Map) GetBool(key string, err ...*Error) bool {
|
||||
|
||||
//var v Slice
|
||||
v := ObjToBool((that)[key], err...)
|
||||
v := ObjToBool((this)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (that Map) GetTime(key string, err ...*Error) *time.Time {
|
||||
|
||||
v := ObjToTime((that)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (that Map) RangeSort(callback func(k string, v interface{}) (isEnd bool)) {
|
||||
testQu := []string{}
|
||||
//testQuData:= qu[0].(Map)
|
||||
for key, _ := range that {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
for _, k := range testQu {
|
||||
re := callback(k, that[k])
|
||||
if re {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (that Map) GetMap(key string, err ...*Error) Map {
|
||||
func (this Map) GetMap(key string, err ...*Error) Map {
|
||||
//var data Slice
|
||||
|
||||
v := ObjToMap((that)[key], err...)
|
||||
v := ObjToMap((this)[key], err...)
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (that Map) Get(key string, err ...*Error) interface{} {
|
||||
func (this Map) Get(key string, err ...*Error) interface{} {
|
||||
|
||||
if v, ok := (that)[key]; ok {
|
||||
if v, ok := (this)[key]; ok {
|
||||
return v
|
||||
}
|
||||
e := errors.New("没有存储key及对应的数据")
|
||||
@ -150,10 +124,10 @@ func (that Map) Get(key string, err ...*Error) interface{} {
|
||||
}
|
||||
|
||||
//请传递指针过来
|
||||
func (that Map) ToStruct(stct interface{}) {
|
||||
func (this Map) ToStruct(stct interface{}) {
|
||||
|
||||
data := reflect.ValueOf(stct).Elem()
|
||||
for k, v := range that {
|
||||
for k, v := range this {
|
||||
ks := StrFirstToUpper(k)
|
||||
dkey := data.FieldByName(ks)
|
||||
if !dkey.IsValid() {
|
||||
@ -161,13 +135,13 @@ func (that Map) ToStruct(stct interface{}) {
|
||||
}
|
||||
switch dkey.Type().String() {
|
||||
case "int":
|
||||
dkey.SetInt(that.GetInt64(k))
|
||||
dkey.SetInt(this.GetInt64(k))
|
||||
case "int64":
|
||||
dkey.Set(reflect.ValueOf(that.GetInt64(k)))
|
||||
dkey.Set(reflect.ValueOf(this.GetInt64(k)))
|
||||
case "float64":
|
||||
dkey.Set(reflect.ValueOf(that.GetFloat64(k)))
|
||||
dkey.Set(reflect.ValueOf(this.GetFloat64(k)))
|
||||
case "string":
|
||||
dkey.Set(reflect.ValueOf(that.GetString(k)))
|
||||
dkey.Set(reflect.ValueOf(this.GetString(k)))
|
||||
case "interface{}":
|
||||
dkey.Set(reflect.ValueOf(v))
|
||||
}
|
||||
@ -175,13 +149,13 @@ func (that Map) ToStruct(stct interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func (that Map) ToJsonString() string {
|
||||
return ObjToStr(that)
|
||||
func (this Map) ToJsonString() string {
|
||||
return ObjToStr(this)
|
||||
|
||||
}
|
||||
|
||||
func (that Map) JsonToMap(jsonStr string, err ...*Error) {
|
||||
e := json.Unmarshal([]byte(jsonStr), &that)
|
||||
func (this Map) JsonToMap(jsonStr string, err ...*Error) {
|
||||
e := json.Unmarshal([]byte(jsonStr), &this)
|
||||
if e != nil && len(err) != 0 {
|
||||
err[0].SetError(e)
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package common
|
||||
|
||||
import "time"
|
||||
|
||||
//对象封装方便取用
|
||||
type Obj struct {
|
||||
Data interface{}
|
||||
@ -20,13 +18,6 @@ func (that *Obj) ToInt(err ...Error) int {
|
||||
return ObjToInt(that.Data, &that.Error)
|
||||
}
|
||||
|
||||
func (that *Obj) ToTime(err ...Error) *time.Time {
|
||||
if len(err) != 0 {
|
||||
that.Error = err[0]
|
||||
}
|
||||
return ObjToTime(that.Data, &that.Error)
|
||||
}
|
||||
|
||||
func (that *Obj) ToInt64(err ...Error) int64 {
|
||||
if len(err) != 0 {
|
||||
that.Error = err[0]
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"errors"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
//仅限于hotime.Slice
|
||||
@ -98,87 +96,6 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
||||
return v
|
||||
}
|
||||
|
||||
func ObjToTime(obj interface{}, e ...*Error) *time.Time {
|
||||
|
||||
tInt := ObjToInt64(obj)
|
||||
//字符串类型,只支持标准mysql datetime格式
|
||||
if tInt == 0 {
|
||||
tStr := ObjToStr(obj)
|
||||
timeNewStr := ""
|
||||
timeNewStrs := strings.Split(tStr, "-")
|
||||
for _, v := range timeNewStrs {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if len(v) == 1 {
|
||||
v = "0" + v
|
||||
}
|
||||
if timeNewStr == "" {
|
||||
timeNewStr = v
|
||||
continue
|
||||
}
|
||||
timeNewStr = timeNewStr + "-" + v
|
||||
}
|
||||
tStr = timeNewStr
|
||||
if len(tStr) > 18 {
|
||||
t, e := time.Parse("2006-01-02 15:04:05", tStr)
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 15 {
|
||||
t, e := time.Parse("2006-01-02 15:04", tStr)
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 12 {
|
||||
t, e := time.Parse("2006-01-02 15", tStr)
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 9 {
|
||||
t, e := time.Parse("2006-01-02", tStr)
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
} else if len(tStr) > 6 {
|
||||
t, e := time.Parse("2006-01", tStr)
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//纳秒级别
|
||||
if len(ObjToStr(tInt)) > 16 {
|
||||
//t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
||||
t := time.UnixMicro(tInt / 1000)
|
||||
return &t
|
||||
//微秒级别
|
||||
} else if len(ObjToStr(tInt)) > 13 {
|
||||
//t := time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
||||
t := time.UnixMicro(tInt)
|
||||
return &t
|
||||
//毫秒级别
|
||||
} else if len(ObjToStr(tInt)) > 10 {
|
||||
//t := time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
||||
t := time.UnixMilli(tInt)
|
||||
return &t
|
||||
//秒级别
|
||||
} else if len(ObjToStr(tInt)) > 9 {
|
||||
//t := time.Time{}.Add(time.Second * time.Duration(tInt))
|
||||
t := time.Unix(tInt, 0)
|
||||
return &t
|
||||
} else if len(ObjToStr(tInt)) > 3 {
|
||||
t, e := time.Parse("2006", ObjToStr(tInt))
|
||||
if e == nil {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
||||
var err error
|
||||
v := float64(0)
|
||||
@ -218,15 +135,6 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
||||
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 {
|
||||
e[0].SetError(err)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Slice []interface{}
|
||||
@ -15,13 +14,6 @@ func (that Slice) GetString(key int, err ...*Error) string {
|
||||
return ObjToStr((that)[key])
|
||||
}
|
||||
|
||||
func (that Slice) GetTime(key int, err ...*Error) *time.Time {
|
||||
|
||||
v := ObjToTime((that)[key], err...)
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
// GetInt 获取Int
|
||||
func (that Slice) GetInt(key int, err ...*Error) int {
|
||||
v := ObjToInt((that)[key], err...)
|
||||
|
42
context.go
42
context.go
@ -1,25 +1,22 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
. "./cache"
|
||||
. "./common"
|
||||
. "./db"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
*Application
|
||||
Resp http.ResponseWriter
|
||||
Req *http.Request
|
||||
Log Map //日志有则创建
|
||||
RouterString []string
|
||||
Config Map
|
||||
Db *HoTimeDB
|
||||
RespData Map
|
||||
RespFunc func()
|
||||
//CacheIns
|
||||
CacheIns
|
||||
SessionIns
|
||||
DataSize int
|
||||
HandlerStr string //复写请求url
|
||||
@ -60,41 +57,12 @@ func (that *Context) Display(statu int, data interface{}) {
|
||||
}
|
||||
|
||||
func (that *Context) View() {
|
||||
if that.RespFunc != nil {
|
||||
that.RespFunc()
|
||||
}
|
||||
|
||||
if that.RespData == nil {
|
||||
return
|
||||
}
|
||||
//创建日志
|
||||
if that.Log != nil {
|
||||
that.Log["time"] = time.Now().Format("2006-01-02 15:04")
|
||||
if that.Session("admin_id").Data != nil {
|
||||
that.Log["admin_id"] = that.Session("admin_id").ToCeilInt()
|
||||
}
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
|
||||
}
|
||||
//负载均衡优化
|
||||
ipStr := ""
|
||||
if that.Req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = that.Req.Header.Get("X-Forwarded-For")
|
||||
} else if that.Req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = that.Req.Header.Get("X-Real-IP")
|
||||
}
|
||||
//负载均衡优化
|
||||
if ipStr == "" {
|
||||
//RemoteAddr := that.Req.RemoteAddr
|
||||
ipStr = Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
|
||||
}
|
||||
that.Log["ip"] = ipStr
|
||||
that.Db.Insert("logs", that.Log)
|
||||
}
|
||||
|
||||
d, err := json.Marshal(that.RespData)
|
||||
if err != nil {
|
||||
that.Display(1, err.Error())
|
||||
that.View()
|
||||
return
|
||||
}
|
||||
that.DataSize = len(d)
|
||||
|
@ -1,431 +0,0 @@
|
||||
# HoTimeDB API 快速参考
|
||||
|
||||
## ⚠️ 重要语法说明
|
||||
|
||||
**条件查询语法规则:**
|
||||
- 单个条件:可以直接写在Map中
|
||||
- 多个条件:必须使用`AND`或`OR`包装
|
||||
- 特殊条件:`ORDER`、`GROUP`、`LIMIT`与条件同级
|
||||
|
||||
```go
|
||||
// ✅ 正确:单个条件
|
||||
Map{"status": 1}
|
||||
|
||||
// ✅ 正确:多个条件用AND包装
|
||||
Map{
|
||||
"AND": Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
}
|
||||
|
||||
// ✅ 正确:条件 + 特殊参数
|
||||
Map{
|
||||
"AND": Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
"ORDER": "id DESC",
|
||||
"LIMIT": 10,
|
||||
}
|
||||
|
||||
// ❌ 错误:多个条件不用AND包装
|
||||
Map{
|
||||
"status": 1,
|
||||
"age[>]": 18, // 这样写不支持!
|
||||
}
|
||||
```
|
||||
|
||||
## 基本方法
|
||||
|
||||
### 数据库连接
|
||||
```go
|
||||
db.SetConnect(func() (master, slave *sql.DB) { ... })
|
||||
db.InitDb()
|
||||
```
|
||||
|
||||
### 链式查询构建器
|
||||
```go
|
||||
// 创建查询构建器
|
||||
builder := db.Table("tablename")
|
||||
|
||||
// 设置条件
|
||||
builder.Where(key, value)
|
||||
builder.And(key, value) 或 builder.And(map)
|
||||
builder.Or(key, value) 或 builder.Or(map)
|
||||
|
||||
// JOIN操作
|
||||
builder.LeftJoin(table, condition)
|
||||
builder.RightJoin(table, condition)
|
||||
builder.InnerJoin(table, condition)
|
||||
builder.FullJoin(table, condition)
|
||||
builder.Join(map) // 通用JOIN
|
||||
|
||||
// 排序和分组
|
||||
builder.Order(fields...)
|
||||
builder.Group(fields...)
|
||||
builder.Limit(args...)
|
||||
|
||||
// 分页
|
||||
builder.Page(page, pageSize)
|
||||
|
||||
// 执行查询
|
||||
builder.Select(fields...) // 返回 []Map
|
||||
builder.Get(fields...) // 返回 Map
|
||||
builder.Count() // 返回 int
|
||||
builder.Update(data) // 返回 int64
|
||||
builder.Delete() // 返回 int64
|
||||
```
|
||||
|
||||
## CRUD 操作
|
||||
|
||||
### 查询 (Select)
|
||||
```go
|
||||
// 基本查询
|
||||
data := db.Select("table")
|
||||
data := db.Select("table", "field1,field2")
|
||||
data := db.Select("table", []string{"field1", "field2"})
|
||||
data := db.Select("table", "*", whereMap)
|
||||
|
||||
// 带JOIN查询
|
||||
data := db.Select("table", joinSlice, "fields", whereMap)
|
||||
```
|
||||
|
||||
### 获取单条 (Get)
|
||||
```go
|
||||
// 自动添加 LIMIT 1
|
||||
row := db.Get("table", "fields", whereMap)
|
||||
```
|
||||
|
||||
### 插入 (Insert)
|
||||
```go
|
||||
id := db.Insert("table", dataMap)
|
||||
// 返回新插入记录的ID
|
||||
```
|
||||
|
||||
### 更新 (Update)
|
||||
```go
|
||||
affected := db.Update("table", dataMap, whereMap)
|
||||
// 返回受影响的行数
|
||||
```
|
||||
|
||||
### 删除 (Delete)
|
||||
```go
|
||||
affected := db.Delete("table", whereMap)
|
||||
// 返回删除的行数
|
||||
```
|
||||
|
||||
## 聚合函数
|
||||
|
||||
### 计数
|
||||
```go
|
||||
count := db.Count("table")
|
||||
count := db.Count("table", whereMap)
|
||||
count := db.Count("table", joinSlice, whereMap)
|
||||
```
|
||||
|
||||
### 求和
|
||||
```go
|
||||
sum := db.Sum("table", "column")
|
||||
sum := db.Sum("table", "column", whereMap)
|
||||
sum := db.Sum("table", "column", joinSlice, whereMap)
|
||||
```
|
||||
|
||||
## 分页查询
|
||||
```go
|
||||
// 设置分页
|
||||
db.Page(page, pageSize)
|
||||
|
||||
// 分页查询
|
||||
data := db.Page(page, pageSize).PageSelect("table", "fields", whereMap)
|
||||
```
|
||||
|
||||
## 条件语法参考
|
||||
|
||||
### 比较操作符
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field": value` | `field = ?` | 等于 |
|
||||
| `"field[!]": value` | `field != ?` | 不等于 |
|
||||
| `"field[>]": value` | `field > ?` | 大于 |
|
||||
| `"field[>=]": value` | `field >= ?` | 大于等于 |
|
||||
| `"field[<]": value` | `field < ?` | 小于 |
|
||||
| `"field[<=]": value` | `field <= ?` | 小于等于 |
|
||||
|
||||
### 模糊查询
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field[~]": "keyword"` | `field LIKE '%keyword%'` | 包含 |
|
||||
| `"field[~!]": "keyword"` | `field LIKE 'keyword%'` | 以...开头 |
|
||||
| `"field[!~]": "keyword"` | `field LIKE '%keyword'` | 以...结尾 |
|
||||
| `"field[~~]": "%keyword%"` | `field LIKE '%keyword%'` | 手动LIKE |
|
||||
|
||||
### 范围查询
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field[<>]": [min, max]` | `field BETWEEN ? AND ?` | 区间内 |
|
||||
| `"field[><]": [min, max]` | `field NOT BETWEEN ? AND ?` | 区间外 |
|
||||
|
||||
### 集合查询
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field": [v1, v2, v3]` | `field IN (?, ?, ?)` | 在集合中 |
|
||||
| `"field[!]": [v1, v2, v3]` | `field NOT IN (?, ?, ?)` | 不在集合中 |
|
||||
|
||||
### NULL查询
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field": nil` | `field IS NULL` | 为空 |
|
||||
| `"field[!]": nil` | `field IS NOT NULL` | 不为空 |
|
||||
|
||||
### 直接SQL
|
||||
| 写法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field[#]": "NOW()"` | `field = NOW()` | 直接SQL函数 |
|
||||
| `"[##]": "a > b"` | `a > b` | 直接SQL片段 |
|
||||
| `"field[#!]": "1"` | `field != 1` | 不等于(不参数化) |
|
||||
|
||||
## 逻辑连接符
|
||||
|
||||
### AND 条件
|
||||
```go
|
||||
whereMap := Map{
|
||||
"AND": Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### OR 条件
|
||||
```go
|
||||
whereMap := Map{
|
||||
"OR": Map{
|
||||
"status": 1,
|
||||
"type": 2,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### 嵌套条件
|
||||
```go
|
||||
whereMap := Map{
|
||||
"AND": Map{
|
||||
"status": 1,
|
||||
"OR": Map{
|
||||
"age[<]": 30,
|
||||
"level[>]": 5,
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
## JOIN 语法
|
||||
|
||||
### 传统语法
|
||||
```go
|
||||
joinSlice := Slice{
|
||||
Map{"[>]profile": "user.id = profile.user_id"}, // LEFT JOIN
|
||||
Map{"[<]department": "user.dept_id = department.id"}, // RIGHT JOIN
|
||||
Map{"[><]role": "user.role_id = role.id"}, // INNER JOIN
|
||||
Map{"[<>]group": "user.group_id = group.id"}, // FULL JOIN
|
||||
}
|
||||
```
|
||||
|
||||
### 链式语法
|
||||
```go
|
||||
builder.LeftJoin("profile", "user.id = profile.user_id")
|
||||
builder.RightJoin("department", "user.dept_id = department.id")
|
||||
builder.InnerJoin("role", "user.role_id = role.id")
|
||||
builder.FullJoin("group", "user.group_id = group.id")
|
||||
```
|
||||
|
||||
## 特殊字段语法
|
||||
|
||||
### ORDER BY
|
||||
```go
|
||||
Map{
|
||||
"ORDER": []string{"created_time DESC", "id ASC"},
|
||||
}
|
||||
// 或
|
||||
Map{
|
||||
"ORDER": "created_time DESC",
|
||||
}
|
||||
```
|
||||
|
||||
### GROUP BY
|
||||
```go
|
||||
Map{
|
||||
"GROUP": []string{"department", "level"},
|
||||
}
|
||||
// 或
|
||||
Map{
|
||||
"GROUP": "department",
|
||||
}
|
||||
```
|
||||
|
||||
### LIMIT
|
||||
```go
|
||||
Map{
|
||||
"LIMIT": []int{10, 20}, // offset 10, limit 20
|
||||
}
|
||||
// 或
|
||||
Map{
|
||||
"LIMIT": 20, // limit 20
|
||||
}
|
||||
```
|
||||
|
||||
## 事务处理
|
||||
```go
|
||||
success := db.Action(func(tx HoTimeDB) bool {
|
||||
// 在这里执行数据库操作
|
||||
// 返回 true 提交事务
|
||||
// 返回 false 回滚事务
|
||||
|
||||
id := tx.Insert("table", data)
|
||||
if id == 0 {
|
||||
return false // 回滚
|
||||
}
|
||||
|
||||
affected := tx.Update("table2", data2, where2)
|
||||
if affected == 0 {
|
||||
return false // 回滚
|
||||
}
|
||||
|
||||
return true // 提交
|
||||
})
|
||||
```
|
||||
|
||||
## 原生SQL执行
|
||||
|
||||
### 查询
|
||||
```go
|
||||
results := db.Query("SELECT * FROM user WHERE age > ?", 18)
|
||||
```
|
||||
|
||||
### 执行
|
||||
```go
|
||||
result, err := db.Exec("UPDATE user SET status = ? WHERE id = ?", 1, 100)
|
||||
affected, _ := result.RowsAffected()
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
```go
|
||||
// 检查最后的错误
|
||||
if db.LastErr.GetError() != nil {
|
||||
fmt.Println("错误:", db.LastErr.GetError())
|
||||
}
|
||||
|
||||
// 查看最后执行的SQL
|
||||
fmt.Println("SQL:", db.LastQuery)
|
||||
fmt.Println("参数:", db.LastData)
|
||||
```
|
||||
|
||||
## 工具方法
|
||||
|
||||
### 数据库信息
|
||||
```go
|
||||
prefix := db.GetPrefix() // 获取表前缀
|
||||
dbType := db.GetType() // 获取数据库类型
|
||||
```
|
||||
|
||||
### 设置模式
|
||||
```go
|
||||
db.Mode = 0 // 生产模式
|
||||
db.Mode = 1 // 测试模式
|
||||
db.Mode = 2 // 开发模式(输出SQL日志)
|
||||
```
|
||||
|
||||
## 常用查询模式
|
||||
|
||||
### 分页列表查询
|
||||
```go
|
||||
// 获取总数
|
||||
total := db.Count("user", Map{"status": 1})
|
||||
|
||||
// 分页数据
|
||||
users := db.Table("user").
|
||||
Where("status", 1).
|
||||
Order("created_time DESC").
|
||||
Page(page, pageSize).
|
||||
Select("id,name,email,created_time")
|
||||
|
||||
// 计算分页信息
|
||||
totalPages := (total + pageSize - 1) / pageSize
|
||||
```
|
||||
|
||||
### 关联查询
|
||||
```go
|
||||
orders := db.Table("order").
|
||||
LeftJoin("user", "order.user_id = user.id").
|
||||
LeftJoin("product", "order.product_id = product.id").
|
||||
Where("order.status", "paid").
|
||||
Select(`
|
||||
order.*,
|
||||
user.name as user_name,
|
||||
product.title as product_title
|
||||
`)
|
||||
```
|
||||
|
||||
### 统计查询
|
||||
```go
|
||||
stats := db.Select("order",
|
||||
"user_id, COUNT(*) as order_count, SUM(amount) as total_amount",
|
||||
Map{
|
||||
"AND": Map{
|
||||
"status": "paid",
|
||||
"created_time[>]": "2023-01-01",
|
||||
},
|
||||
"GROUP": "user_id",
|
||||
"ORDER": "total_amount DESC",
|
||||
})
|
||||
```
|
||||
|
||||
### 条件组合查询
|
||||
```go
|
||||
products := db.Table("product").
|
||||
Where("status", 1).
|
||||
And(Map{
|
||||
"OR": Map{
|
||||
"category_id": []int{1, 2, 3},
|
||||
"tags[~]": "热销",
|
||||
},
|
||||
}).
|
||||
And(Map{
|
||||
"price[<>]": []float64{10.0, 1000.0},
|
||||
}).
|
||||
Order("sort DESC", "created_time DESC").
|
||||
Limit(0, 20).
|
||||
Select()
|
||||
```
|
||||
|
||||
## 链式调用完整示例
|
||||
|
||||
```go
|
||||
// 复杂查询链式调用
|
||||
result := db.Table("order").
|
||||
LeftJoin("user", "order.user_id = user.id").
|
||||
LeftJoin("product", "order.product_id = product.id").
|
||||
Where("order.status", "paid").
|
||||
And("order.created_time[>]", "2023-01-01").
|
||||
And(Map{
|
||||
"OR": Map{
|
||||
"user.level": "vip",
|
||||
"order.amount[>]": 1000,
|
||||
},
|
||||
}).
|
||||
Group("user.id").
|
||||
Order("total_amount DESC").
|
||||
Page(1, 20).
|
||||
Select(`
|
||||
user.id,
|
||||
user.name,
|
||||
user.email,
|
||||
COUNT(order.id) as order_count,
|
||||
SUM(order.amount) as total_amount
|
||||
`)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*快速参考版本: 1.0*
|
@ -1,890 +0,0 @@
|
||||
# HoTimeDB ORM 使用说明书
|
||||
|
||||
## 概述
|
||||
|
||||
HoTimeDB是一个基于Golang实现的轻量级ORM框架,参考PHP Medoo设计,提供简洁的数据库操作接口。支持MySQL、SQLite等数据库,并集成了缓存、事务、链式查询等功能。
|
||||
|
||||
## 目录
|
||||
|
||||
- [快速开始](#快速开始)
|
||||
- [数据库配置](#数据库配置)
|
||||
- [基本操作](#基本操作)
|
||||
- [查询(Select)](#查询select)
|
||||
- [获取单条记录(Get)](#获取单条记录get)
|
||||
- [插入(Insert)](#插入insert)
|
||||
- [更新(Update)](#更新update)
|
||||
- [删除(Delete)](#删除delete)
|
||||
- [链式查询构建器](#链式查询构建器)
|
||||
- [条件查询语法](#条件查询语法)
|
||||
- [JOIN操作](#join操作)
|
||||
- [分页查询](#分页查询)
|
||||
- [聚合函数](#聚合函数)
|
||||
- [事务处理](#事务处理)
|
||||
- [缓存机制](#缓存机制)
|
||||
- [高级特性](#高级特性)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 初始化数据库连接
|
||||
|
||||
```go
|
||||
import (
|
||||
"code.hoteas.com/golang/hotime/db"
|
||||
"code.hoteas.com/golang/hotime/common"
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// 创建连接函数
|
||||
func createConnection() (master, slave *sql.DB) {
|
||||
master, _ = sql.Open("mysql", "user:password@tcp(localhost:3306)/database")
|
||||
// slave是可选的,用于读写分离
|
||||
slave = master // 或者连接到从数据库
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化HoTimeDB
|
||||
db := &db.HoTimeDB{}
|
||||
db.SetConnect(createConnection)
|
||||
```
|
||||
|
||||
## 数据库配置
|
||||
|
||||
### 基本配置
|
||||
|
||||
```go
|
||||
type HoTimeDB struct {
|
||||
*sql.DB
|
||||
ContextBase
|
||||
DBName string
|
||||
*cache.HoTimeCache
|
||||
Log *logrus.Logger
|
||||
Type string // 数据库类型
|
||||
Prefix string // 表前缀
|
||||
LastQuery string // 最后执行的SQL
|
||||
LastData []interface{} // 最后的参数
|
||||
ConnectFunc func(err ...*Error) (*sql.DB, *sql.DB)
|
||||
LastErr *Error
|
||||
limit Slice
|
||||
*sql.Tx // 事务对象
|
||||
SlaveDB *sql.DB // 从数据库
|
||||
Mode int // 0生产模式,1测试模式,2开发模式
|
||||
}
|
||||
```
|
||||
|
||||
### 设置表前缀
|
||||
|
||||
```go
|
||||
db.Prefix = "app_"
|
||||
```
|
||||
|
||||
### 设置运行模式
|
||||
|
||||
```go
|
||||
db.Mode = 2 // 开发模式,会输出SQL日志
|
||||
```
|
||||
|
||||
## 基本操作
|
||||
|
||||
### 查询(Select)
|
||||
|
||||
#### 基本查询
|
||||
|
||||
```go
|
||||
// 查询所有字段
|
||||
users := db.Select("user")
|
||||
|
||||
// 查询指定字段
|
||||
users := db.Select("user", "id,name,email")
|
||||
|
||||
// 查询指定字段(数组形式)
|
||||
users := db.Select("user", []string{"id", "name", "email"})
|
||||
|
||||
// 单条件查询
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"status": 1,
|
||||
})
|
||||
|
||||
// 多条件查询(必须使用AND包装)
|
||||
users = db.Select("user", "*", common.Map{
|
||||
"AND": common.Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
#### 复杂条件查询
|
||||
|
||||
**重要说明:多个条件必须使用AND或OR包装,不能直接在根Map中写多个字段条件**
|
||||
|
||||
```go
|
||||
// AND条件(多个条件必须用AND包装)
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"AND": common.Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
"name[~]": "张",
|
||||
},
|
||||
})
|
||||
|
||||
// OR条件
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"OR": common.Map{
|
||||
"status": 1,
|
||||
"type": 2,
|
||||
},
|
||||
})
|
||||
|
||||
// 混合条件(嵌套AND/OR)
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"AND": common.Map{
|
||||
"status": 1,
|
||||
"OR": common.Map{
|
||||
"age[<]": 30,
|
||||
"level[>]": 5,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 带ORDER BY、LIMIT等特殊条件
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"AND": common.Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
"ORDER": "id DESC",
|
||||
"LIMIT": 10,
|
||||
})
|
||||
|
||||
// 带多个特殊条件
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"OR": common.Map{
|
||||
"level": "vip",
|
||||
"balance[>]": 1000,
|
||||
},
|
||||
"ORDER": []string{"created_time DESC", "id ASC"},
|
||||
"GROUP": "department",
|
||||
"LIMIT": []int{0, 20}, // offset 0, limit 20
|
||||
})
|
||||
```
|
||||
|
||||
### 获取单条记录(Get)
|
||||
|
||||
```go
|
||||
// 获取单个用户
|
||||
user := db.Get("user", "*", common.Map{
|
||||
"id": 1,
|
||||
})
|
||||
|
||||
// 获取指定字段
|
||||
user := db.Get("user", "id,name,email", common.Map{
|
||||
"status": 1,
|
||||
})
|
||||
```
|
||||
|
||||
### 插入(Insert)
|
||||
|
||||
```go
|
||||
// 基本插入
|
||||
id := db.Insert("user", common.Map{
|
||||
"name": "张三",
|
||||
"email": "zhangsan@example.com",
|
||||
"age": 25,
|
||||
"status": 1,
|
||||
"created_time[#]": "NOW()", // [#]表示直接插入SQL函数
|
||||
})
|
||||
|
||||
// 返回插入的ID
|
||||
fmt.Println("插入的用户ID:", id)
|
||||
```
|
||||
|
||||
### 更新(Update)
|
||||
|
||||
```go
|
||||
// 基本更新
|
||||
affected := db.Update("user", common.Map{
|
||||
"name": "李四",
|
||||
"email": "lisi@example.com",
|
||||
"updated_time[#]": "NOW()",
|
||||
}, common.Map{
|
||||
"id": 1,
|
||||
})
|
||||
|
||||
// 条件更新
|
||||
affected := db.Update("user", common.Map{
|
||||
"status": 0,
|
||||
}, common.Map{
|
||||
"age[<]": 18,
|
||||
"status": 1,
|
||||
})
|
||||
|
||||
fmt.Println("更新的记录数:", affected)
|
||||
```
|
||||
|
||||
### 删除(Delete)
|
||||
|
||||
```go
|
||||
// 根据ID删除
|
||||
affected := db.Delete("user", common.Map{
|
||||
"id": 1,
|
||||
})
|
||||
|
||||
// 条件删除
|
||||
affected := db.Delete("user", common.Map{
|
||||
"status": 0,
|
||||
"created_time[<]": "2023-01-01",
|
||||
})
|
||||
|
||||
fmt.Println("删除的记录数:", affected)
|
||||
```
|
||||
|
||||
## 链式查询构建器
|
||||
|
||||
HoTimeDB提供了链式查询构建器,让查询更加直观:
|
||||
|
||||
```go
|
||||
// 基本链式查询
|
||||
users := db.Table("user").
|
||||
Where("status", 1).
|
||||
And("age[>]", 18).
|
||||
Order("created_time DESC").
|
||||
Limit(10, 20). // offset, limit
|
||||
Select()
|
||||
|
||||
// 链式获取单条记录
|
||||
user := db.Table("user").
|
||||
Where("id", 1).
|
||||
Get()
|
||||
|
||||
// 链式更新
|
||||
affected := db.Table("user").
|
||||
Where("id", 1).
|
||||
Update(common.Map{
|
||||
"name": "新名称",
|
||||
"updated_time[#]": "NOW()",
|
||||
})
|
||||
|
||||
// 链式删除
|
||||
affected := db.Table("user").
|
||||
Where("status", 0).
|
||||
Delete()
|
||||
|
||||
// 链式统计
|
||||
count := db.Table("user").
|
||||
Where("status", 1).
|
||||
Count()
|
||||
```
|
||||
|
||||
### 链式条件组合
|
||||
|
||||
```go
|
||||
// 复杂条件组合
|
||||
users := db.Table("user").
|
||||
Where("status", 1).
|
||||
And("age[>=]", 18).
|
||||
Or(common.Map{
|
||||
"level[>]": 5,
|
||||
"vip": 1,
|
||||
}).
|
||||
Order("created_time DESC", "id ASC").
|
||||
Group("department").
|
||||
Limit(0, 20).
|
||||
Select("id,name,email,age")
|
||||
```
|
||||
|
||||
## 条件查询语法
|
||||
|
||||
HoTimeDB支持丰富的条件查询语法,类似于Medoo:
|
||||
|
||||
### 基本比较
|
||||
|
||||
```go
|
||||
// 等于
|
||||
"id": 1
|
||||
|
||||
// 不等于
|
||||
"id[!]": 1
|
||||
|
||||
// 大于
|
||||
"age[>]": 18
|
||||
|
||||
// 大于等于
|
||||
"age[>=]": 18
|
||||
|
||||
// 小于
|
||||
"age[<]": 60
|
||||
|
||||
// 小于等于
|
||||
"age[<=]": 60
|
||||
```
|
||||
|
||||
### 模糊查询
|
||||
|
||||
```go
|
||||
// LIKE %keyword%
|
||||
"name[~]": "张"
|
||||
|
||||
// LIKE keyword% (右边任意)
|
||||
"name[~!]": "张"
|
||||
|
||||
// LIKE %keyword (左边任意)
|
||||
"name[!~]": "san"
|
||||
|
||||
// 手动LIKE(需要手动添加%)
|
||||
"name[~~]": "%张%"
|
||||
```
|
||||
|
||||
### 区间查询
|
||||
|
||||
```go
|
||||
// BETWEEN
|
||||
"age[<>]": []int{18, 60}
|
||||
|
||||
// NOT BETWEEN
|
||||
"age[><]": []int{18, 25}
|
||||
```
|
||||
|
||||
### IN查询
|
||||
|
||||
```go
|
||||
// IN
|
||||
"id": []int{1, 2, 3, 4, 5}
|
||||
|
||||
// NOT IN
|
||||
"id[!]": []int{1, 2, 3}
|
||||
```
|
||||
|
||||
### NULL查询
|
||||
|
||||
```go
|
||||
// IS NULL
|
||||
"deleted_at": nil
|
||||
|
||||
// IS NOT NULL
|
||||
"deleted_at[!]": nil
|
||||
```
|
||||
|
||||
### 直接SQL
|
||||
|
||||
```go
|
||||
// 直接插入SQL表达式(注意防注入)
|
||||
"created_time[#]": "> DATE_SUB(NOW(), INTERVAL 1 DAY)"
|
||||
|
||||
// 字段直接赋值(不使用参数化查询)
|
||||
"update_time[#]": "NOW()"
|
||||
|
||||
// 直接SQL片段
|
||||
"[##]": "user.status = 1 AND user.level > 0"
|
||||
```
|
||||
|
||||
## JOIN操作
|
||||
|
||||
### 链式JOIN
|
||||
|
||||
```go
|
||||
// LEFT JOIN
|
||||
users := db.Table("user").
|
||||
LeftJoin("profile", "user.id = profile.user_id").
|
||||
LeftJoin("department", "user.dept_id = department.id").
|
||||
Where("user.status", 1).
|
||||
Select("user.*, profile.avatar, department.name AS dept_name")
|
||||
|
||||
// RIGHT JOIN
|
||||
users := db.Table("user").
|
||||
RightJoin("order", "user.id = order.user_id").
|
||||
Select()
|
||||
|
||||
// INNER JOIN
|
||||
users := db.Table("user").
|
||||
InnerJoin("profile", "user.id = profile.user_id").
|
||||
Select()
|
||||
|
||||
// FULL JOIN
|
||||
users := db.Table("user").
|
||||
FullJoin("profile", "user.id = profile.user_id").
|
||||
Select()
|
||||
```
|
||||
|
||||
### 传统JOIN语法
|
||||
|
||||
```go
|
||||
users := db.Select("user",
|
||||
common.Slice{
|
||||
common.Map{"[>]profile": "user.id = profile.user_id"},
|
||||
common.Map{"[>]department": "user.dept_id = department.id"},
|
||||
},
|
||||
"user.*, profile.avatar, department.name AS dept_name",
|
||||
common.Map{
|
||||
"user.status": 1,
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
### JOIN类型说明
|
||||
|
||||
- `[>]`: LEFT JOIN
|
||||
- `[<]`: RIGHT JOIN
|
||||
- `[><]`: INNER JOIN
|
||||
- `[<>]`: FULL JOIN
|
||||
|
||||
## 分页查询
|
||||
|
||||
### 基本分页
|
||||
|
||||
```go
|
||||
// 设置分页:页码3,每页20条
|
||||
users := db.Page(3, 20).PageSelect("user", "*", common.Map{
|
||||
"status": 1,
|
||||
})
|
||||
|
||||
// 链式分页
|
||||
users := db.Table("user").
|
||||
Where("status", 1).
|
||||
Page(2, 15). // 第2页,每页15条
|
||||
Select()
|
||||
```
|
||||
|
||||
### 分页信息获取
|
||||
|
||||
```go
|
||||
// 获取总数
|
||||
total := db.Count("user", common.Map{
|
||||
"status": 1,
|
||||
})
|
||||
|
||||
// 计算分页信息
|
||||
page := 2
|
||||
pageSize := 20
|
||||
offset := (page - 1) * pageSize
|
||||
totalPages := (total + pageSize - 1) / pageSize
|
||||
|
||||
fmt.Printf("总记录数: %d, 总页数: %d, 当前页: %d\n", total, totalPages, page)
|
||||
```
|
||||
|
||||
## 聚合函数
|
||||
|
||||
### 计数
|
||||
|
||||
```go
|
||||
// 总数统计
|
||||
total := db.Count("user")
|
||||
|
||||
// 条件统计
|
||||
activeUsers := db.Count("user", common.Map{
|
||||
"status": 1,
|
||||
})
|
||||
|
||||
// JOIN统计
|
||||
count := db.Count("user",
|
||||
common.Slice{
|
||||
common.Map{"[>]profile": "user.id = profile.user_id"},
|
||||
},
|
||||
common.Map{
|
||||
"user.status": 1,
|
||||
"profile.verified": 1,
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
### 求和
|
||||
|
||||
```go
|
||||
// 基本求和
|
||||
totalAmount := db.Sum("order", "amount")
|
||||
|
||||
// 条件求和
|
||||
paidAmount := db.Sum("order", "amount", common.Map{
|
||||
"status": "paid",
|
||||
"created_time[>]": "2023-01-01",
|
||||
})
|
||||
|
||||
// JOIN求和
|
||||
sum := db.Sum("order", "amount",
|
||||
common.Slice{
|
||||
common.Map{"[>]user": "order.user_id = user.id"},
|
||||
},
|
||||
common.Map{
|
||||
"user.level": "vip",
|
||||
"order.status": "paid",
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
## 事务处理
|
||||
|
||||
```go
|
||||
// 事务操作
|
||||
success := db.Action(func(tx db.HoTimeDB) bool {
|
||||
// 在事务中执行多个操作
|
||||
|
||||
// 扣减用户余额
|
||||
affected1 := tx.Update("user", common.Map{
|
||||
"balance[#]": "balance - 100",
|
||||
}, common.Map{
|
||||
"id": 1,
|
||||
})
|
||||
|
||||
if affected1 == 0 {
|
||||
return false // 回滚
|
||||
}
|
||||
|
||||
// 创建订单
|
||||
orderId := tx.Insert("order", common.Map{
|
||||
"user_id": 1,
|
||||
"amount": 100,
|
||||
"status": "paid",
|
||||
"created_time[#]": "NOW()",
|
||||
})
|
||||
|
||||
if orderId == 0 {
|
||||
return false // 回滚
|
||||
}
|
||||
|
||||
// 添加订单详情
|
||||
detailId := tx.Insert("order_detail", common.Map{
|
||||
"order_id": orderId,
|
||||
"product_id": 1001,
|
||||
"quantity": 1,
|
||||
"price": 100,
|
||||
})
|
||||
|
||||
if detailId == 0 {
|
||||
return false // 回滚
|
||||
}
|
||||
|
||||
return true // 提交
|
||||
})
|
||||
|
||||
if success {
|
||||
fmt.Println("事务执行成功")
|
||||
} else {
|
||||
fmt.Println("事务回滚")
|
||||
fmt.Println("错误:", db.LastErr.GetError())
|
||||
}
|
||||
```
|
||||
|
||||
## 缓存机制
|
||||
|
||||
HoTimeDB集成了缓存功能,可以自动缓存查询结果:
|
||||
|
||||
### 缓存配置
|
||||
|
||||
```go
|
||||
import "code.hoteas.com/golang/hotime/cache"
|
||||
|
||||
// 设置缓存
|
||||
db.HoTimeCache = &cache.HoTimeCache{
|
||||
// 缓存配置
|
||||
}
|
||||
```
|
||||
|
||||
### 缓存行为
|
||||
|
||||
- 查询操作会自动检查缓存
|
||||
- 增删改操作会自动清除相关缓存
|
||||
- 缓存键格式:`表名:查询MD5`
|
||||
- `cached`表不会被缓存
|
||||
|
||||
### 缓存清理
|
||||
|
||||
```go
|
||||
// 手动清除表缓存
|
||||
db.HoTimeCache.Db("user*", nil) // 清除user表所有缓存
|
||||
```
|
||||
|
||||
## 高级特性
|
||||
|
||||
### 调试模式
|
||||
|
||||
```go
|
||||
// 设置调试模式
|
||||
db.Mode = 2
|
||||
|
||||
// 查看最后执行的SQL
|
||||
fmt.Println("最后的SQL:", db.LastQuery)
|
||||
fmt.Println("参数:", db.LastData)
|
||||
fmt.Println("错误:", db.LastErr.GetError())
|
||||
```
|
||||
|
||||
### 主从分离
|
||||
|
||||
```go
|
||||
func createConnection() (master, slave *sql.DB) {
|
||||
// 主库连接
|
||||
master, _ = sql.Open("mysql", "user:password@tcp(master:3306)/database")
|
||||
|
||||
// 从库连接
|
||||
slave, _ = sql.Open("mysql", "user:password@tcp(slave:3306)/database")
|
||||
|
||||
return master, slave
|
||||
}
|
||||
|
||||
db.SetConnect(createConnection)
|
||||
// 查询会自动使用从库,增删改使用主库
|
||||
```
|
||||
|
||||
### 原生SQL执行
|
||||
|
||||
```go
|
||||
// 执行查询SQL
|
||||
results := db.Query("SELECT * FROM user WHERE age > ? AND status = ?", 18, 1)
|
||||
|
||||
// 执行更新SQL
|
||||
result, err := db.Exec("UPDATE user SET last_login = NOW() WHERE id = ?", 1)
|
||||
if err.GetError() == nil {
|
||||
affected, _ := result.RowsAffected()
|
||||
fmt.Println("影响行数:", affected)
|
||||
}
|
||||
```
|
||||
|
||||
### 数据类型处理
|
||||
|
||||
```go
|
||||
// 时间戳插入
|
||||
db.Insert("log", common.Map{
|
||||
"user_id": 1,
|
||||
"action": "login",
|
||||
"created_time[#]": "UNIX_TIMESTAMP()",
|
||||
})
|
||||
|
||||
// JSON数据
|
||||
db.Insert("user", common.Map{
|
||||
"name": "张三",
|
||||
"preferences": `{"theme": "dark", "language": "zh-CN"}`,
|
||||
})
|
||||
```
|
||||
|
||||
### 数据行处理
|
||||
|
||||
HoTimeDB内部的`Row`方法会自动处理不同数据类型:
|
||||
|
||||
```go
|
||||
// 自动转换[]uint8为字符串
|
||||
// 保持其他类型的原始值
|
||||
// 处理NULL值
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
|
||||
```go
|
||||
// 检查错误
|
||||
users := db.Select("user", "*", common.Map{"status": 1})
|
||||
if db.LastErr.GetError() != nil {
|
||||
fmt.Println("查询错误:", db.LastErr.GetError())
|
||||
return
|
||||
}
|
||||
|
||||
// 插入时检查错误
|
||||
id := db.Insert("user", common.Map{
|
||||
"name": "test",
|
||||
"email": "test@example.com",
|
||||
})
|
||||
|
||||
if id == 0 && db.LastErr.GetError() != nil {
|
||||
fmt.Println("插入失败:", db.LastErr.GetError())
|
||||
}
|
||||
```
|
||||
|
||||
## 性能优化
|
||||
|
||||
### IN查询优化
|
||||
|
||||
HoTimeDB会自动优化IN查询,将连续的数字转换为BETWEEN查询以提高性能:
|
||||
|
||||
```go
|
||||
// 这个查询会被自动优化(单个IN条件)
|
||||
users := db.Select("user", "*", common.Map{
|
||||
"id": []int{1, 2, 3, 4, 5, 10, 11, 12},
|
||||
// 自动转为 (id BETWEEN 1 AND 5) OR (id BETWEEN 10 AND 12)
|
||||
})
|
||||
```
|
||||
|
||||
### 批量操作
|
||||
|
||||
```go
|
||||
// 使用事务进行批量插入
|
||||
success := db.Action(func(tx db.HoTimeDB) bool {
|
||||
for i := 0; i < 1000; i++ {
|
||||
id := tx.Insert("user", common.Map{
|
||||
"name": fmt.Sprintf("User%d", i),
|
||||
"email": fmt.Sprintf("user%d@example.com", i),
|
||||
"created_time[#]": "NOW()",
|
||||
})
|
||||
if id == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
```
|
||||
|
||||
## 特殊语法详解
|
||||
|
||||
### 条件标记符说明
|
||||
|
||||
| 标记符 | 功能 | 示例 | 生成SQL |
|
||||
|--------|------|------|---------|
|
||||
| `[>]` | 大于 | `"age[>]": 18` | `age > 18` |
|
||||
| `[<]` | 小于 | `"age[<]": 60` | `age < 60` |
|
||||
| `[>=]` | 大于等于 | `"age[>=]": 18` | `age >= 18` |
|
||||
| `[<=]` | 小于等于 | `"age[<=]": 60` | `age <= 60` |
|
||||
| `[!]` | 不等于/NOT IN | `"id[!]": 1` | `id != 1` |
|
||||
| `[~]` | LIKE模糊查询 | `"name[~]": "张"` | `name LIKE '%张%'` |
|
||||
| `[!~]` | 左模糊 | `"name[!~]": "张"` | `name LIKE '%张'` |
|
||||
| `[~!]` | 右模糊 | `"name[~!]": "张"` | `name LIKE '张%'` |
|
||||
| `[~~]` | 手动LIKE | `"name[~~]": "%张%"` | `name LIKE '%张%'` |
|
||||
| `[<>]` | BETWEEN | `"age[<>]": [18,60]` | `age BETWEEN 18 AND 60` |
|
||||
| `[><]` | NOT BETWEEN | `"age[><]": [18,25]` | `age NOT BETWEEN 18 AND 25` |
|
||||
| `[#]` | 直接SQL | `"time[#]": "NOW()"` | `time = NOW()` |
|
||||
| `[##]` | SQL片段 | `"[##]": "a > b"` | `a > b` |
|
||||
| `[#!]` | 不等于直接SQL | `"status[#!]": "1"` | `status != 1` |
|
||||
| `[!#]` | 不等于直接SQL | `"status[!#]": "1"` | `status != 1` |
|
||||
|
||||
## 与PHP Medoo的差异
|
||||
|
||||
1. **类型系统**: Golang的强类型要求使用`common.Map`和`common.Slice`
|
||||
2. **语法差异**: 某些条件语法可能略有不同
|
||||
3. **错误处理**: 使用Golang的错误处理模式
|
||||
4. **并发安全**: 需要注意并发使用时的安全性
|
||||
5. **缓存集成**: 内置了缓存功能
|
||||
6. **链式调用**: 提供了更丰富的链式API
|
||||
|
||||
## 完整示例
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"database/sql"
|
||||
"code.hoteas.com/golang/hotime/db"
|
||||
"code.hoteas.com/golang/hotime/common"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 初始化数据库
|
||||
database := &db.HoTimeDB{
|
||||
Prefix: "app_",
|
||||
Mode: 2, // 开发模式
|
||||
}
|
||||
|
||||
database.SetConnect(func(err ...*common.Error) (master, slave *sql.DB) {
|
||||
master, _ = sql.Open("mysql", "root:password@tcp(localhost:3306)/testdb")
|
||||
return master, master
|
||||
})
|
||||
|
||||
// 查询用户列表
|
||||
users := database.Table("user").
|
||||
Where("status", 1).
|
||||
And("age[>=]", 18).
|
||||
Order("created_time DESC").
|
||||
Limit(0, 10).
|
||||
Select("id,name,email,age")
|
||||
|
||||
for _, user := range users {
|
||||
fmt.Printf("用户: %s, 邮箱: %s, 年龄: %v\n",
|
||||
user.GetString("name"),
|
||||
user.GetString("email"),
|
||||
user.Get("age"))
|
||||
}
|
||||
|
||||
// 创建新用户
|
||||
userId := database.Insert("user", common.Map{
|
||||
"name": "新用户",
|
||||
"email": "new@example.com",
|
||||
"age": 25,
|
||||
"status": 1,
|
||||
"created_time[#]": "NOW()",
|
||||
})
|
||||
|
||||
fmt.Printf("创建用户ID: %d\n", userId)
|
||||
|
||||
// 更新用户
|
||||
affected := database.Table("user").
|
||||
Where("id", userId).
|
||||
Update(common.Map{
|
||||
"last_login[#]": "NOW()",
|
||||
"login_count[#]": "login_count + 1",
|
||||
})
|
||||
|
||||
fmt.Printf("更新记录数: %d\n", affected)
|
||||
|
||||
// 复杂查询示例
|
||||
orders := database.Table("order").
|
||||
LeftJoin("user", "order.user_id = user.id").
|
||||
LeftJoin("product", "order.product_id = product.id").
|
||||
Where("order.status", "paid").
|
||||
And("order.created_time[>]", "2023-01-01").
|
||||
And(common.Map{
|
||||
"OR": common.Map{
|
||||
"user.level": "vip",
|
||||
"order.amount[>]": 1000,
|
||||
},
|
||||
}).
|
||||
Order("order.created_time DESC").
|
||||
Group("user.id").
|
||||
Select("user.name, user.email, SUM(order.amount) as total_amount, COUNT(*) as order_count")
|
||||
|
||||
// 事务示例
|
||||
success := database.Action(func(tx db.HoTimeDB) bool {
|
||||
// 在事务中执行操作
|
||||
orderId := tx.Insert("order", common.Map{
|
||||
"user_id": userId,
|
||||
"total": 100.50,
|
||||
"status": "pending",
|
||||
"created_time[#]": "NOW()",
|
||||
})
|
||||
|
||||
if orderId == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
detailId := tx.Insert("order_detail", common.Map{
|
||||
"order_id": orderId,
|
||||
"product_id": 1,
|
||||
"quantity": 2,
|
||||
"price": 50.25,
|
||||
})
|
||||
|
||||
return detailId > 0
|
||||
})
|
||||
|
||||
if success {
|
||||
fmt.Println("订单创建成功")
|
||||
} else {
|
||||
fmt.Println("订单创建失败:", database.LastErr.GetError())
|
||||
}
|
||||
|
||||
// 统计示例
|
||||
totalUsers := database.Count("user", common.Map{"status": 1})
|
||||
totalAmount := database.Sum("order", "amount", common.Map{"status": "paid"})
|
||||
|
||||
fmt.Printf("活跃用户数: %d, 总交易额: %.2f\n", totalUsers, totalAmount)
|
||||
}
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q1: 如何处理事务中的错误?
|
||||
A1: 在`Action`函数中返回`false`即可触发回滚,所有操作都会被撤销。
|
||||
|
||||
### Q2: 缓存何时会被清除?
|
||||
A2: 执行`Insert`、`Update`、`Delete`操作时会自动清除对应表的缓存。
|
||||
|
||||
### Q3: 如何执行复杂的原生SQL?
|
||||
A3: 使用`Query`方法执行查询,使用`Exec`方法执行更新操作。
|
||||
|
||||
### Q4: 主从分离如何工作?
|
||||
A4: 查询操作自动使用从库(如果配置了),增删改操作使用主库。
|
||||
|
||||
### Q5: 如何处理NULL值?
|
||||
A5: 使用`nil`作为值,查询时使用`"field": nil`表示`IS NULL`。
|
||||
|
||||
---
|
||||
|
||||
*文档版本: 1.0*
|
||||
*最后更新: 2024年*
|
||||
|
||||
> 本文档基于HoTimeDB源码分析生成,如有疑问请参考源码实现。该ORM框架参考了PHP Medoo的设计理念,但根据Golang语言特性进行了适配和优化。
|
252
db/README.md
252
db/README.md
@ -1,252 +0,0 @@
|
||||
# HoTimeDB ORM 文档集合
|
||||
|
||||
这是HoTimeDB ORM框架的完整文档集合,包含使用说明、API参考、示例代码和测试数据。
|
||||
|
||||
## ⚠️ 重要更新说明
|
||||
|
||||
**语法修正通知**:经过对源码的深入分析,发现HoTimeDB的条件查询语法有特定规则:
|
||||
- ✅ **单个条件**:可以直接写在Map中
|
||||
- ⚠️ **多个条件**:必须使用`AND`或`OR`包装
|
||||
- 📝 所有文档和示例代码已按正确语法更新
|
||||
|
||||
## 📚 文档列表
|
||||
|
||||
### 1. [HoTimeDB_使用说明.md](./HoTimeDB_使用说明.md)
|
||||
**完整使用说明书** - 详细的功能介绍和使用指南
|
||||
- 🚀 快速开始
|
||||
- ⚙️ 数据库配置
|
||||
- 🔧 基本操作 (CRUD)
|
||||
- 🔗 链式查询构建器
|
||||
- 🔍 条件查询语法
|
||||
- 🔄 JOIN操作
|
||||
- 📄 分页查询
|
||||
- 📊 聚合函数
|
||||
- 🔐 事务处理
|
||||
- 💾 缓存机制
|
||||
- ⚡ 高级特性
|
||||
|
||||
### 2. [HoTimeDB_API参考.md](./HoTimeDB_API参考.md)
|
||||
**快速API参考手册** - 开发时的速查手册
|
||||
- 📖 基本方法
|
||||
- 🔧 CRUD操作
|
||||
- 📊 聚合函数
|
||||
- 📄 分页查询
|
||||
- 🔍 条件语法参考
|
||||
- 🔗 JOIN语法
|
||||
- 🔐 事务处理
|
||||
- 🛠️ 工具方法
|
||||
|
||||
### 3. [示例代码文件](../examples/hotimedb_examples.go)
|
||||
**完整示例代码集合** - 可运行的实际应用示例(语法已修正)
|
||||
- 🏗️ 基本初始化和配置
|
||||
- 📝 基本CRUD操作
|
||||
- 🔗 链式查询操作
|
||||
- 🤝 JOIN查询操作
|
||||
- 🔍 条件查询语法
|
||||
- 📄 分页查询
|
||||
- 📊 聚合函数查询
|
||||
- 🔐 事务处理
|
||||
- 💾 缓存机制
|
||||
- 🔧 原生SQL执行
|
||||
- 🚨 错误处理和调试
|
||||
- ⚡ 性能优化技巧
|
||||
- 🎯 完整应用示例
|
||||
|
||||
### 4. [test_tables.sql](./test_tables.sql)
|
||||
**测试数据库结构** - 快速搭建测试环境
|
||||
- 🏗️ 完整的表结构定义
|
||||
- 📊 测试数据插入
|
||||
- 🔍 索引优化
|
||||
- 👁️ 视图示例
|
||||
- 🔧 存储过程示例
|
||||
|
||||
## 🎯 核心特性
|
||||
|
||||
### 🌟 主要优势
|
||||
- **类Medoo语法**: 参考PHP Medoo设计,语法简洁易懂
|
||||
- **链式查询**: 支持流畅的链式查询构建器
|
||||
- **条件丰富**: 支持丰富的条件查询语法
|
||||
- **事务支持**: 完整的事务处理机制
|
||||
- **缓存集成**: 内置查询结果缓存
|
||||
- **读写分离**: 支持主从数据库配置
|
||||
- **类型安全**: 基于Golang的强类型系统
|
||||
|
||||
### 🔧 支持的数据库
|
||||
- ✅ MySQL
|
||||
- ✅ SQLite
|
||||
- ✅ 其他标准SQL数据库
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 1. 安装依赖
|
||||
```bash
|
||||
go mod init your-project
|
||||
go get github.com/go-sql-driver/mysql
|
||||
go get github.com/sirupsen/logrus
|
||||
```
|
||||
|
||||
### 2. 创建测试数据库
|
||||
```bash
|
||||
mysql -u root -p < test_tables.sql
|
||||
```
|
||||
|
||||
### 3. 基本使用
|
||||
```go
|
||||
import (
|
||||
"code.hoteas.com/golang/hotime/db"
|
||||
"code.hoteas.com/golang/hotime/common"
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// 初始化数据库
|
||||
database := &db.HoTimeDB{
|
||||
Prefix: "app_",
|
||||
Mode: 2, // 开发模式
|
||||
}
|
||||
|
||||
database.SetConnect(func() (master, slave *sql.DB) {
|
||||
master, _ = sql.Open("mysql", "user:pass@tcp(localhost:3306)/dbname")
|
||||
return master, master
|
||||
})
|
||||
|
||||
// 链式查询(链式语法支持单独Where然后用And添加条件)
|
||||
users := database.Table("user").
|
||||
Where("status", 1). // 链式中可以单独Where
|
||||
And("age[>]", 18). // 用And添加更多条件
|
||||
Order("created_time DESC").
|
||||
Limit(0, 10).
|
||||
Select("id,name,email")
|
||||
|
||||
// 或者使用传统语法(多个条件必须用AND包装)
|
||||
users2 := database.Select("user", "id,name,email", common.Map{
|
||||
"AND": common.Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
"ORDER": "created_time DESC",
|
||||
"LIMIT": []int{0, 10},
|
||||
})
|
||||
```
|
||||
|
||||
## ⚠️ 重要语法规则
|
||||
|
||||
**条件查询语法规则:**
|
||||
- ✅ **单个条件**:可以直接写在Map中
|
||||
- ✅ **多个条件**:必须使用`AND`或`OR`包装
|
||||
- ✅ **特殊参数**:`ORDER`、`GROUP`、`LIMIT`与条件同级
|
||||
|
||||
```go
|
||||
// ✅ 正确:单个条件
|
||||
Map{"status": 1}
|
||||
|
||||
// ✅ 正确:多个条件用AND包装
|
||||
Map{
|
||||
"AND": Map{
|
||||
"status": 1,
|
||||
"age[>]": 18,
|
||||
},
|
||||
"ORDER": "id DESC",
|
||||
}
|
||||
|
||||
// ❌ 错误:多个条件不用AND包装
|
||||
Map{
|
||||
"status": 1,
|
||||
"age[>]": 18, // 不支持!
|
||||
}
|
||||
```
|
||||
|
||||
## 📝 条件查询语法速查
|
||||
|
||||
| 语法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"field": value` | `field = ?` | 等于 |
|
||||
| `"field[!]": value` | `field != ?` | 不等于 |
|
||||
| `"field[>]": value` | `field > ?` | 大于 |
|
||||
| `"field[>=]": value` | `field >= ?` | 大于等于 |
|
||||
| `"field[<]": value` | `field < ?` | 小于 |
|
||||
| `"field[<=]": value` | `field <= ?` | 小于等于 |
|
||||
| `"field[~]": "keyword"` | `field LIKE '%keyword%'` | 包含 |
|
||||
| `"field[<>]": [min, max]` | `field BETWEEN ? AND ?` | 区间内 |
|
||||
| `"field": [v1, v2, v3]` | `field IN (?, ?, ?)` | 在集合中 |
|
||||
| `"field": nil` | `field IS NULL` | 为空 |
|
||||
| `"field[#]": "NOW()"` | `field = NOW()` | 直接SQL |
|
||||
|
||||
## 🔗 JOIN语法速查
|
||||
|
||||
| 语法 | SQL | 说明 |
|
||||
|------|-----|------|
|
||||
| `"[>]table"` | `LEFT JOIN` | 左连接 |
|
||||
| `"[<]table"` | `RIGHT JOIN` | 右连接 |
|
||||
| `"[><]table"` | `INNER JOIN` | 内连接 |
|
||||
| `"[<>]table"` | `FULL JOIN` | 全连接 |
|
||||
|
||||
## 🛠️ 链式方法速查
|
||||
|
||||
```go
|
||||
db.Table("table") // 指定表名
|
||||
.Where(key, value) // WHERE条件
|
||||
.And(key, value) // AND条件
|
||||
.Or(map) // OR条件
|
||||
.LeftJoin(table, on) // LEFT JOIN
|
||||
.Order(fields...) // ORDER BY
|
||||
.Group(fields...) // GROUP BY
|
||||
.Limit(offset, limit) // LIMIT
|
||||
.Page(page, pageSize) // 分页
|
||||
.Select(fields...) // 查询
|
||||
.Get(fields...) // 获取单条
|
||||
.Count() // 计数
|
||||
.Update(data) // 更新
|
||||
.Delete() // 删除
|
||||
```
|
||||
|
||||
## ⚡ 性能优化建议
|
||||
|
||||
### 🔍 查询优化
|
||||
- 使用合适的索引字段作为查询条件
|
||||
- IN查询会自动优化为BETWEEN(连续数字)
|
||||
- 避免SELECT *,指定需要的字段
|
||||
- 合理使用LIMIT限制结果集大小
|
||||
|
||||
### 💾 缓存使用
|
||||
- 查询结果会自动缓存
|
||||
- 增删改操作会自动清除缓存
|
||||
- `cached`表不参与缓存
|
||||
|
||||
### 🔐 事务处理
|
||||
- 批量操作使用事务提高性能
|
||||
- 事务中避免长时间操作
|
||||
- 合理设置事务隔离级别
|
||||
|
||||
## 🚨 注意事项
|
||||
|
||||
### 🔒 安全相关
|
||||
- 使用参数化查询防止SQL注入
|
||||
- `[#]`语法需要注意防止注入
|
||||
- 敏感数据加密存储
|
||||
|
||||
### 🎯 最佳实践
|
||||
- 开发时设置`Mode = 2`便于调试
|
||||
- 生产环境设置`Mode = 0`
|
||||
- 合理设置表前缀
|
||||
- 定期检查慢查询日志
|
||||
|
||||
## 🤝 与PHP Medoo的差异
|
||||
|
||||
1. **类型系统**: 使用`common.Map`和`common.Slice`
|
||||
2. **错误处理**: Golang风格的错误处理
|
||||
3. **链式调用**: 提供更丰富的链式API
|
||||
4. **缓存集成**: 内置缓存功能
|
||||
5. **并发安全**: 需要注意并发使用
|
||||
|
||||
## 📞 技术支持
|
||||
|
||||
- 📧 查看源码:`hotimedb.go`
|
||||
- 📖 参考文档:本目录下的各个文档文件
|
||||
- 🔧 示例代码:运行`HoTimeDB_示例代码.go`中的示例
|
||||
|
||||
---
|
||||
|
||||
**HoTimeDB ORM框架 - 让数据库操作更简单!** 🎉
|
||||
|
||||
> 本文档基于HoTimeDB源码分析生成,参考了PHP Medoo的设计理念,并根据Golang语言特性进行了优化。
|
816
db/hotimedb.go
816
db/hotimedb.go
File diff suppressed because it is too large
Load Diff
@ -1,332 +0,0 @@
|
||||
-- HoTimeDB 测试表结构
|
||||
-- 用于测试和示例的MySQL表结构定义
|
||||
-- 请根据实际需要修改表结构和字段类型
|
||||
|
||||
-- 创建数据库(可选)
|
||||
CREATE DATABASE IF NOT EXISTS `hotimedb_test` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE `hotimedb_test`;
|
||||
|
||||
-- 用户表
|
||||
DROP TABLE IF EXISTS `app_user`;
|
||||
CREATE TABLE `app_user` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '用户姓名',
|
||||
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '邮箱地址',
|
||||
`password` varchar(255) NOT NULL DEFAULT '' COMMENT '密码hash',
|
||||
`phone` varchar(20) NOT NULL DEFAULT '' COMMENT '手机号',
|
||||
`age` int(11) NOT NULL DEFAULT '0' COMMENT '年龄',
|
||||
`gender` tinyint(4) NOT NULL DEFAULT '0' COMMENT '性别 0-未知 1-男 2-女',
|
||||
`avatar` varchar(500) NOT NULL DEFAULT '' COMMENT '头像URL',
|
||||
`level` varchar(20) NOT NULL DEFAULT 'normal' COMMENT '用户等级 normal-普通 vip-会员 svip-超级会员',
|
||||
`balance` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '账户余额',
|
||||
`login_count` int(11) NOT NULL DEFAULT '0' COMMENT '登录次数',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 1-正常 0-禁用 -1-删除',
|
||||
`last_login` datetime DEFAULT NULL COMMENT '最后登录时间',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted_at` datetime DEFAULT NULL COMMENT '删除时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_email` (`email`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_level` (`level`),
|
||||
KEY `idx_created_time` (`created_time`),
|
||||
KEY `idx_deleted_at` (`deleted_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户表';
|
||||
|
||||
-- 用户资料表
|
||||
DROP TABLE IF EXISTS `app_profile`;
|
||||
CREATE TABLE `app_profile` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
|
||||
`real_name` varchar(50) NOT NULL DEFAULT '' COMMENT '真实姓名',
|
||||
`id_card` varchar(20) NOT NULL DEFAULT '' COMMENT '身份证号',
|
||||
`address` varchar(500) NOT NULL DEFAULT '' COMMENT '地址',
|
||||
`bio` text COMMENT '个人简介',
|
||||
`verified` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否认证 1-是 0-否',
|
||||
`preferences` json DEFAULT NULL COMMENT '用户偏好设置JSON',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_id` (`user_id`),
|
||||
KEY `idx_verified` (`verified`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户资料表';
|
||||
|
||||
-- 部门表
|
||||
DROP TABLE IF EXISTS `app_department`;
|
||||
CREATE TABLE `app_department` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '部门ID',
|
||||
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '部门名称',
|
||||
`parent_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '上级部门ID',
|
||||
`manager_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '部门经理ID',
|
||||
`description` text COMMENT '部门描述',
|
||||
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 1-正常 0-禁用',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_parent_id` (`parent_id`),
|
||||
KEY `idx_manager_id` (`manager_id`),
|
||||
KEY `idx_status` (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='部门表';
|
||||
|
||||
-- 商品表
|
||||
DROP TABLE IF EXISTS `app_product`;
|
||||
CREATE TABLE `app_product` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID',
|
||||
`title` varchar(200) NOT NULL DEFAULT '' COMMENT '商品标题',
|
||||
`description` text COMMENT '商品描述',
|
||||
`price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品价格',
|
||||
`stock` int(11) NOT NULL DEFAULT '0' COMMENT '库存数量',
|
||||
`category_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '分类ID',
|
||||
`brand` varchar(100) NOT NULL DEFAULT '' COMMENT '品牌',
|
||||
`tags` varchar(500) NOT NULL DEFAULT '' COMMENT '标签,逗号分隔',
|
||||
`images` json DEFAULT NULL COMMENT '商品图片JSON数组',
|
||||
`attributes` json DEFAULT NULL COMMENT '商品属性JSON',
|
||||
`sales_count` int(11) NOT NULL DEFAULT '0' COMMENT '销售数量',
|
||||
`view_count` int(11) NOT NULL DEFAULT '0' COMMENT '浏览数量',
|
||||
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 1-上架 0-下架',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_category_id` (`category_id`),
|
||||
KEY `idx_price` (`price`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_created_time` (`created_time`),
|
||||
FULLTEXT KEY `ft_title_description` (`title`,`description`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商品表';
|
||||
|
||||
-- 订单表
|
||||
DROP TABLE IF EXISTS `app_order`;
|
||||
CREATE TABLE `app_order` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
|
||||
`order_no` varchar(50) NOT NULL DEFAULT '' COMMENT '订单号',
|
||||
`user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
|
||||
`product_id` bigint(20) unsigned NOT NULL COMMENT '商品ID',
|
||||
`quantity` int(11) NOT NULL DEFAULT '1' COMMENT '数量',
|
||||
`price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单价',
|
||||
`amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '总金额',
|
||||
`discount_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '优惠金额',
|
||||
`final_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实付金额',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT '订单状态 pending-待付款 paid-已付款 shipped-已发货 completed-已完成 cancelled-已取消',
|
||||
`payment_method` varchar(20) NOT NULL DEFAULT '' COMMENT '支付方式',
|
||||
`shipping_address` json DEFAULT NULL COMMENT '收货地址JSON',
|
||||
`remark` text COMMENT '订单备注',
|
||||
`paid_time` datetime DEFAULT NULL COMMENT '支付时间',
|
||||
`shipped_time` datetime DEFAULT NULL COMMENT '发货时间',
|
||||
`completed_time` datetime DEFAULT NULL COMMENT '完成时间',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_order_no` (`order_no`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_product_id` (`product_id`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_created_time` (`created_time`),
|
||||
KEY `idx_paid_time` (`paid_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单表';
|
||||
|
||||
-- 订单详情表
|
||||
DROP TABLE IF EXISTS `app_order_detail`;
|
||||
CREATE TABLE `app_order_detail` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`order_id` bigint(20) unsigned NOT NULL COMMENT '订单ID',
|
||||
`product_id` bigint(20) unsigned NOT NULL COMMENT '商品ID',
|
||||
`product_title` varchar(200) NOT NULL DEFAULT '' COMMENT '商品标题',
|
||||
`product_image` varchar(500) NOT NULL DEFAULT '' COMMENT '商品图片',
|
||||
`price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单价',
|
||||
`quantity` int(11) NOT NULL DEFAULT '1' COMMENT '数量',
|
||||
`amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '小计',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_order_id` (`order_id`),
|
||||
KEY `idx_product_id` (`product_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单详情表';
|
||||
|
||||
-- 支付日志表
|
||||
DROP TABLE IF EXISTS `app_payment_log`;
|
||||
CREATE TABLE `app_payment_log` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`user_id` bigint(20) unsigned NOT NULL COMMENT '用户ID',
|
||||
`order_id` bigint(20) unsigned DEFAULT NULL COMMENT '订单ID',
|
||||
`transaction_id` varchar(100) NOT NULL DEFAULT '' COMMENT '交易ID',
|
||||
`type` varchar(20) NOT NULL DEFAULT '' COMMENT '类型 order_payment-订单支付 recharge-充值 refund-退款',
|
||||
`amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
|
||||
`method` varchar(20) NOT NULL DEFAULT '' COMMENT '支付方式 balance-余额 alipay-支付宝 wechat-微信',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT '状态 pending-处理中 success-成功 failed-失败',
|
||||
`description` varchar(255) NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`extra_data` json DEFAULT NULL COMMENT '额外数据JSON',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_order_id` (`order_id`),
|
||||
KEY `idx_transaction_id` (`transaction_id`),
|
||||
KEY `idx_type` (`type`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_created_time` (`created_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='支付日志表';
|
||||
|
||||
-- 转账日志表
|
||||
DROP TABLE IF EXISTS `app_transfer_log`;
|
||||
CREATE TABLE `app_transfer_log` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`from_user_id` bigint(20) unsigned NOT NULL COMMENT '转出用户ID',
|
||||
`to_user_id` bigint(20) unsigned NOT NULL COMMENT '转入用户ID',
|
||||
`amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '转账金额',
|
||||
`type` varchar(20) NOT NULL DEFAULT 'transfer' COMMENT '类型',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'success' COMMENT '状态',
|
||||
`description` varchar(255) NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_from_user_id` (`from_user_id`),
|
||||
KEY `idx_to_user_id` (`to_user_id`),
|
||||
KEY `idx_created_time` (`created_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='转账日志表';
|
||||
|
||||
-- 操作日志表
|
||||
DROP TABLE IF EXISTS `app_operation_log`;
|
||||
CREATE TABLE `app_operation_log` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`user_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
|
||||
`module` varchar(50) NOT NULL DEFAULT '' COMMENT '模块',
|
||||
`action` varchar(50) NOT NULL DEFAULT '' COMMENT '操作',
|
||||
`description` varchar(255) NOT NULL DEFAULT '' COMMENT '描述',
|
||||
`ip` varchar(45) NOT NULL DEFAULT '' COMMENT 'IP地址',
|
||||
`user_agent` varchar(500) NOT NULL DEFAULT '' COMMENT '用户代理',
|
||||
`request_data` json DEFAULT NULL COMMENT '请求数据JSON',
|
||||
`response_data` json DEFAULT NULL COMMENT '响应数据JSON',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态 1-成功 0-失败',
|
||||
`execution_time` int(11) NOT NULL DEFAULT '0' COMMENT '执行时间(毫秒)',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_module` (`module`),
|
||||
KEY `idx_action` (`action`),
|
||||
KEY `idx_created_time` (`created_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='操作日志表';
|
||||
|
||||
-- 缓存表(HoTimeDB内置缓存使用)
|
||||
DROP TABLE IF EXISTS `app_cached`;
|
||||
CREATE TABLE `app_cached` (
|
||||
`key` varchar(255) NOT NULL COMMENT '缓存键',
|
||||
`value` longtext COMMENT '缓存值',
|
||||
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`key`),
|
||||
KEY `idx_expire_time` (`expire_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='缓存表';
|
||||
|
||||
-- 批量用户表(用于批量操作示例)
|
||||
DROP TABLE IF EXISTS `app_user_batch`;
|
||||
CREATE TABLE `app_user_batch` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '用户姓名',
|
||||
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '邮箱地址',
|
||||
`status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态',
|
||||
`created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_created_time` (`created_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='批量用户表';
|
||||
|
||||
-- 插入测试数据
|
||||
INSERT INTO `app_user` (`name`, `email`, `password`, `age`, `level`, `balance`, `status`, `created_time`) VALUES
|
||||
('张三', 'zhangsan@example.com', 'hashed_password_1', 25, 'normal', 1000.00, 1, '2023-01-15 10:30:00'),
|
||||
('李四', 'lisi@example.com', 'hashed_password_2', 30, 'vip', 5000.00, 1, '2023-02-20 14:20:00'),
|
||||
('王五', 'wangwu@example.com', 'hashed_password_3', 28, 'svip', 10000.00, 1, '2023-03-10 16:45:00'),
|
||||
('赵六', 'zhaoliu@example.com', 'hashed_password_4', 35, 'normal', 500.00, 1, '2023-04-05 09:15:00'),
|
||||
('钱七', 'qianqi@example.com', 'hashed_password_5', 22, 'vip', 2500.00, 0, '2023-05-12 11:30:00');
|
||||
|
||||
INSERT INTO `app_profile` (`user_id`, `real_name`, `verified`) VALUES
|
||||
(1, '张三', 1),
|
||||
(2, '李四', 1),
|
||||
(3, '王五', 1),
|
||||
(4, '赵六', 0),
|
||||
(5, '钱七', 0);
|
||||
|
||||
INSERT INTO `app_department` (`name`, `parent_id`, `description`) VALUES
|
||||
('技术部', 0, '负责技术开发和维护'),
|
||||
('产品部', 0, '负责产品设计和规划'),
|
||||
('市场部', 0, '负责市场推广和销售'),
|
||||
('前端组', 1, '负责前端开发'),
|
||||
('后端组', 1, '负责后端开发');
|
||||
|
||||
INSERT INTO `app_product` (`title`, `description`, `price`, `stock`, `category_id`, `brand`, `sales_count`) VALUES
|
||||
('苹果手机', '最新款苹果手机,性能强劲', 6999.00, 100, 1, '苹果', 50),
|
||||
('华为手机', '国产精品手机,拍照出色', 4999.00, 200, 1, '华为', 80),
|
||||
('小米手机', '性价比之王,配置丰富', 2999.00, 300, 1, '小米', 120),
|
||||
('联想笔记本', '商务办公首选,稳定可靠', 5999.00, 50, 2, '联想', 30),
|
||||
('戴尔笔记本', '游戏性能出色,散热良好', 8999.00, 30, 2, '戴尔', 15);
|
||||
|
||||
INSERT INTO `app_order` (`order_no`, `user_id`, `product_id`, `quantity`, `price`, `amount`, `final_amount`, `status`, `created_time`) VALUES
|
||||
('ORD202301150001', 1, 1, 1, 6999.00, 6999.00, 6999.00, 'paid', '2023-01-15 15:30:00'),
|
||||
('ORD202301160001', 2, 2, 2, 4999.00, 9998.00, 9998.00, 'paid', '2023-01-16 10:20:00'),
|
||||
('ORD202301170001', 3, 3, 1, 2999.00, 2999.00, 2999.00, 'completed', '2023-01-17 14:15:00'),
|
||||
('ORD202301180001', 1, 4, 1, 5999.00, 5999.00, 5999.00, 'pending', '2023-01-18 16:45:00'),
|
||||
('ORD202301190001', 4, 5, 1, 8999.00, 8999.00, 8999.00, 'cancelled', '2023-01-19 11:30:00');
|
||||
|
||||
INSERT INTO `app_order_detail` (`order_id`, `product_id`, `product_title`, `price`, `quantity`, `amount`) VALUES
|
||||
(1, 1, '苹果手机', 6999.00, 1, 6999.00),
|
||||
(2, 2, '华为手机', 4999.00, 2, 9998.00),
|
||||
(3, 3, '小米手机', 2999.00, 1, 2999.00),
|
||||
(4, 4, '联想笔记本', 5999.00, 1, 5999.00),
|
||||
(5, 5, '戴尔笔记本', 8999.00, 1, 8999.00);
|
||||
|
||||
INSERT INTO `app_payment_log` (`user_id`, `order_id`, `type`, `amount`, `method`, `status`, `description`) VALUES
|
||||
(1, 1, 'order_payment', 6999.00, 'balance', 'success', '订单支付'),
|
||||
(2, 2, 'order_payment', 9998.00, 'alipay', 'success', '订单支付'),
|
||||
(3, 3, 'order_payment', 2999.00, 'wechat', 'success', '订单支付'),
|
||||
(2, NULL, 'recharge', 10000.00, 'alipay', 'success', '账户充值'),
|
||||
(3, NULL, 'recharge', 5000.00, 'wechat', 'success', '账户充值');
|
||||
|
||||
-- 创建索引优化查询性能
|
||||
CREATE INDEX idx_user_email_status ON app_user(email, status);
|
||||
CREATE INDEX idx_order_user_status ON app_order(user_id, status);
|
||||
CREATE INDEX idx_order_created_status ON app_order(created_time, status);
|
||||
CREATE INDEX idx_product_category_status ON app_product(category_id, status);
|
||||
|
||||
-- 创建视图(可选)
|
||||
CREATE OR REPLACE VIEW v_user_order_stats AS
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
u.name as user_name,
|
||||
u.email,
|
||||
u.level,
|
||||
COUNT(o.id) as order_count,
|
||||
COALESCE(SUM(o.final_amount), 0) as total_amount,
|
||||
COALESCE(AVG(o.final_amount), 0) as avg_amount,
|
||||
MAX(o.created_time) as last_order_time
|
||||
FROM app_user u
|
||||
LEFT JOIN app_order o ON u.id = o.user_id AND o.status IN ('paid', 'completed')
|
||||
WHERE u.status = 1
|
||||
GROUP BY u.id;
|
||||
|
||||
-- 存储过程示例(可选)
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE GetUserOrderSummary(IN p_user_id BIGINT)
|
||||
BEGIN
|
||||
SELECT
|
||||
u.name,
|
||||
u.email,
|
||||
u.level,
|
||||
u.balance,
|
||||
COUNT(o.id) as order_count,
|
||||
COALESCE(SUM(CASE WHEN o.status = 'paid' THEN o.final_amount END), 0) as paid_amount,
|
||||
COALESCE(SUM(CASE WHEN o.status = 'completed' THEN o.final_amount END), 0) as completed_amount
|
||||
FROM app_user u
|
||||
LEFT JOIN app_order o ON u.id = o.user_id
|
||||
WHERE u.id = p_user_id AND u.status = 1
|
||||
GROUP BY u.id;
|
||||
END //
|
||||
DELIMITER ;
|
||||
|
||||
-- 显示表结构信息
|
||||
SELECT
|
||||
TABLE_NAME as '表名',
|
||||
TABLE_COMMENT as '表注释',
|
||||
TABLE_ROWS as '预估行数',
|
||||
ROUND(DATA_LENGTH/1024/1024, 2) as '数据大小(MB)'
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE 'app_%'
|
||||
ORDER BY TABLE_NAME;
|
@ -1,142 +0,0 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
type company struct {
|
||||
ApiCode string
|
||||
Url string
|
||||
}
|
||||
|
||||
var Company = company{}
|
||||
|
||||
func (that *company) Init(apiCode string) {
|
||||
//"06c6a07e89dd45c88de040ee1489eef7"
|
||||
that.ApiCode = apiCode
|
||||
that.Url = "http://api.81api.com"
|
||||
}
|
||||
|
||||
// GetCompanyOtherAll 获取企业基础信息
|
||||
func (that *company) GetCompanyOtherAll(name string) Map {
|
||||
|
||||
res := Map{}
|
||||
data, e := that.GetCompanyPatentsInfo(name) //获取专利信息
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
} else {
|
||||
res["PatentsInfo"] = data.GetMap("data")
|
||||
}
|
||||
data, e = that.GetCompanyOtherCopyrightsInfo(name) //获取其他专利
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
} else {
|
||||
res["OtherCopyrightsInfo"] = data.GetMap("data")
|
||||
}
|
||||
data, e = that.GetCompanyTrademarksInfo(name) //获取商标
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
} else {
|
||||
res["TrademarksInfo"] = data.GetMap("data")
|
||||
}
|
||||
data, e = that.GetCompanySoftwareCopyrightsInfo(name) //获取软著
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
} else {
|
||||
res["SoftwareCopyrightsInfo"] = data.GetMap("data")
|
||||
}
|
||||
data, e = that.GetCompanyProfileTags(name) //获取大数据标签
|
||||
if e != nil {
|
||||
fmt.Println(e)
|
||||
} else {
|
||||
res["ProfileTags"] = data.GetSlice("data")
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// GetCompanyBaseInfo 获取企业基础信息
|
||||
func (that *company) GetCompanyList(name string) (Map, error) {
|
||||
url := "/fuzzyQueryCompanyInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyBaseInfo 获取企业基础信息
|
||||
func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
|
||||
url := "/getCompanyBaseInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyPatentsInfo 获取专利信息
|
||||
func (that *company) GetCompanyPatentsInfo(name string) (Map, error) {
|
||||
url := "/getCompanyPatentsInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyTrademarksInfo 获取商标信息
|
||||
func (that *company) GetCompanyTrademarksInfo(name string) (Map, error) {
|
||||
url := "/getCompanyTrademarksInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanySoftwareCopyrightsInfo 获取软著信息
|
||||
func (that *company) GetCompanySoftwareCopyrightsInfo(name string) (Map, error) {
|
||||
url := "/getCompanySoftwareCopyrightsInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyOtherCopyrightsInfo 获取其他著作信息
|
||||
func (that *company) GetCompanyOtherCopyrightsInfo(name string) (Map, error) {
|
||||
url := "/getCompanyOtherCopyrightsInfo/"
|
||||
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
|
||||
// GetCompanyProfileTags 获取大数据标签
|
||||
func (that *company) GetCompanyProfileTags(name string) (Map, error) {
|
||||
url := "/getCompanyProfileTags/"
|
||||
body, err := that.basePost(url, name)
|
||||
return ObjToMap(body), err
|
||||
}
|
||||
func (that *company) basePost(url string, name string) (string, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
reqest, err := http.NewRequest("GET", that.Url+url+name+"/?isRaiseErrorCode=1", nil)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Fatal error ", err.Error())
|
||||
return "", err
|
||||
}
|
||||
|
||||
reqest.Header.Add("Authorization", "APPCODE "+that.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
|
||||
}
|
142
dri/baidu/map.go
142
dri/baidu/map.go
@ -1,142 +0,0 @@
|
||||
package baidu
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type baiduMap struct {
|
||||
Ak string
|
||||
Url string
|
||||
}
|
||||
|
||||
var BaiDuMap = baiduMap{}
|
||||
|
||||
func (that *baiduMap) Init(Ak string) {
|
||||
//"ak=ZeT902EZvVgIoGVWEFK3osUm"
|
||||
that.Ak = Ak
|
||||
that.Url = "https://api.map.baidu.com/place/v2/suggestion?output=json" + "&ak=" + Ak
|
||||
//query
|
||||
}
|
||||
|
||||
// from 源坐标类型:
|
||||
// 1:GPS标准坐标;
|
||||
// 2:搜狗地图坐标;
|
||||
// 3:火星坐标(gcj02),即高德地图、腾讯地图和MapABC等地图使用的坐标;
|
||||
// 4:3中列举的地图坐标对应的墨卡托平面坐标;
|
||||
// 5:百度地图采用的经纬度坐标(bd09ll);
|
||||
// 6:百度地图采用的墨卡托平面坐标(bd09mc);
|
||||
// 7:图吧地图坐标;
|
||||
// 8:51地图坐标;
|
||||
// int 1 1 否
|
||||
// to
|
||||
// 目标坐标类型:
|
||||
// 3:火星坐标(gcj02),即高德地图、腾讯地图及MapABC等地图使用的坐标;
|
||||
// 5:百度地图采用的经纬度坐标(bd09ll);
|
||||
// 6:百度地图采用的墨卡托平面坐标(bd09mc);
|
||||
func (that *baiduMap) Geoconv(latlngs []Map, from, to int) (Slice, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
latlngsStr := ""
|
||||
for _, v := range latlngs {
|
||||
if latlngsStr != "" {
|
||||
latlngsStr = latlngsStr + ";" + v.GetString("lng") + "," + v.GetString("lat")
|
||||
} else {
|
||||
latlngsStr = v.GetString("lng") + "," + v.GetString("lat")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
url := "https://api.map.baidu.com/geoconv/v1/?from=" + ObjToStr(from) + "&to=" + ObjToStr(to) + "&ak=" + that.Ak + "&coords=" + latlngsStr
|
||||
reqest, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Fatal error ", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
response, err := client.Do(reqest)
|
||||
defer response.Body.Close()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Fatal error ", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//fmt.Println(string(body))
|
||||
data := ObjToMap(string(body))
|
||||
if data.GetCeilInt64("status") != 0 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data.GetSlice("result"), err
|
||||
}
|
||||
|
||||
func (that *baiduMap) GetAddress(lat string, lng string) (string, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
url := "https://api.map.baidu.com/reverse_geocoding/v3/?ak=" + that.Ak + "&output=json&location=" + lat + "," + lng
|
||||
reqest, err := http.NewRequest("GET", url, 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
|
||||
|
||||
}
|
||||
|
||||
// GetPosition 获取定位列表
|
||||
func (that *baiduMap) GetPosition(name string, region string) (string, error) {
|
||||
|
||||
client := &http.Client{}
|
||||
if region == "" {
|
||||
region = "全国"
|
||||
}
|
||||
reqest, err := http.NewRequest("GET", that.Url+"&query="+url.PathEscape(name)+"®ion="+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
|
||||
|
||||
}
|
@ -10,31 +10,29 @@ import (
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
type dingdongyun struct {
|
||||
type DDY struct {
|
||||
ApiKey string
|
||||
YzmUrl string
|
||||
TzUrl string
|
||||
}
|
||||
|
||||
var DDY = dingdongyun{}
|
||||
|
||||
func (that *dingdongyun) Init(apikey string) {
|
||||
that.ApiKey = apikey
|
||||
that.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
||||
that.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
||||
func (this *DDY) Init(apikey string) {
|
||||
this.ApiKey = apikey
|
||||
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
||||
this.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
||||
}
|
||||
|
||||
// SendYZM 发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
||||
func (that *dingdongyun) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
||||
//发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
||||
func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
|
||||
for k, v := range data {
|
||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||
}
|
||||
|
||||
return that.send(that.YzmUrl, umoblie, tpt)
|
||||
return this.send(this.YzmUrl, umoblie, tpt)
|
||||
}
|
||||
|
||||
// SendTz 发送通知
|
||||
func (that *dingdongyun) 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 {
|
||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||
}
|
||||
@ -46,14 +44,14 @@ func (that *dingdongyun) SendTz(umoblie []string, tpt string, data map[string]st
|
||||
}
|
||||
umobleStr += "," + v
|
||||
}
|
||||
return that.send(that.TzUrl, umobleStr, tpt)
|
||||
return this.send(this.TzUrl, umobleStr, tpt)
|
||||
}
|
||||
|
||||
//发送短信
|
||||
func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool, error) {
|
||||
func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error) {
|
||||
|
||||
data_send_sms_yzm := url.Values{"apikey": {that.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
||||
res, err := that.httpsPostForm(mUrl, data_send_sms_yzm)
|
||||
data_send_sms_yzm := url.Values{"apikey": {this.ApiKey}, "mobile": {umoblie}, "content": {content}}
|
||||
res, err := this.httpsPostForm(mUrl, data_send_sms_yzm)
|
||||
if err != nil && res == "" {
|
||||
return false, errors.New("连接错误")
|
||||
}
|
||||
@ -75,7 +73,7 @@ func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool
|
||||
}
|
||||
|
||||
//调用url发送短信的连接
|
||||
func (that *dingdongyun) httpsPostForm(url string, data url.Values) (string, error) {
|
||||
func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
|
||||
resp, err := http.PostForm(url, data)
|
||||
|
||||
if err != nil {
|
||||
@ -91,3 +89,9 @@ func (that *dingdongyun) httpsPostForm(url string, data url.Values) (string, err
|
||||
return string(body), nil
|
||||
|
||||
}
|
||||
|
||||
var DefaultDDY DDY
|
||||
|
||||
func init() {
|
||||
DefaultDDY = DDY{}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package download
|
||||
|
||||
import (
|
||||
. "../../common"
|
||||
"bytes"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Down 下载文件
|
||||
//下载文件
|
||||
func Down(url, path, name string, e ...*Error) bool {
|
||||
|
||||
os.MkdirAll(path, os.ModeDir)
|
||||
@ -18,13 +18,13 @@ func Down(url, path, name string, e ...*Error) bool {
|
||||
}
|
||||
out, err := os.Create(path + name)
|
||||
|
||||
if err != nil && len(e) != 0 {
|
||||
if err != nil && e[0] != nil {
|
||||
e[0].SetError(err)
|
||||
return false
|
||||
}
|
||||
defer out.Close()
|
||||
resp, err := http.Get(url)
|
||||
if err != nil && len(e) != 0 {
|
||||
if err != nil && e[0] != nil {
|
||||
e[0].SetError(err)
|
||||
return false
|
||||
}
|
||||
@ -32,7 +32,7 @@ func Down(url, path, name string, e ...*Error) bool {
|
||||
|
||||
pix, err := ioutil.ReadAll(resp.Body)
|
||||
_, err = io.Copy(out, bytes.NewReader(pix))
|
||||
if err != nil && len(e) != 0 {
|
||||
if err != nil && e[0] != nil {
|
||||
e[0].SetError(err)
|
||||
return false
|
||||
}
|
||||
|
@ -1,149 +0,0 @@
|
||||
package mongodb
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type MongoDb struct {
|
||||
Client *mongo.Client
|
||||
Ctx context.Context
|
||||
DataBase *mongo.Database
|
||||
Connect *mongo.Collection
|
||||
LastErr error
|
||||
}
|
||||
|
||||
func GetMongoDb(database, url string) (*MongoDb, error) {
|
||||
db := MongoDb{}
|
||||
clientOptions := options.Client().ApplyURI(url)
|
||||
|
||||
db.Ctx = context.TODO()
|
||||
// Connect to MongoDb
|
||||
var err error
|
||||
db.Client, err = mongo.Connect(db.Ctx, clientOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Check the connection
|
||||
err = db.Client.Ping(db.Ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println("Connected to MongoDb!")
|
||||
//databases, err := db.Client.ListDatabaseNames(db.Ctx, bson.M{})
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//fmt.Println(databases)
|
||||
db.DataBase = db.Client.Database(database)
|
||||
return &db, nil
|
||||
|
||||
}
|
||||
|
||||
func (that *MongoDb) Insert(table string, data interface{}) string {
|
||||
collection := that.DataBase.Collection(table)
|
||||
re, err := collection.InsertOne(that.Ctx, data)
|
||||
if err != nil {
|
||||
that.LastErr = err
|
||||
return ""
|
||||
}
|
||||
return ObjToStr(re.InsertedID)
|
||||
}
|
||||
|
||||
func (that *MongoDb) InsertMany(table string, data ...interface{}) Slice {
|
||||
collection := that.DataBase.Collection(table)
|
||||
re, err := collection.InsertMany(that.Ctx, data)
|
||||
if err != nil {
|
||||
that.LastErr = err
|
||||
return Slice{}
|
||||
}
|
||||
|
||||
return ObjToSlice(re.InsertedIDs)
|
||||
|
||||
}
|
||||
|
||||
func (that *MongoDb) Update(table string, data Map, where Map) int64 {
|
||||
collection := that.DataBase.Collection(table)
|
||||
re, err := collection.UpdateMany(that.Ctx, where, data)
|
||||
|
||||
if err != nil {
|
||||
that.LastErr = err
|
||||
return 0
|
||||
}
|
||||
|
||||
return re.ModifiedCount
|
||||
|
||||
}
|
||||
|
||||
func (that *MongoDb) Delete(table string, where Map) int64 {
|
||||
collection := that.DataBase.Collection(table)
|
||||
re, err := collection.DeleteMany(that.Ctx, where)
|
||||
|
||||
if err != nil {
|
||||
that.LastErr = err
|
||||
return 0
|
||||
}
|
||||
|
||||
return re.DeletedCount
|
||||
|
||||
}
|
||||
|
||||
func (that *MongoDb) Get(table string, where Map) Map {
|
||||
results := []Map{}
|
||||
var cursor *mongo.Cursor
|
||||
var err error
|
||||
collection := that.DataBase.Collection(table)
|
||||
if cursor, err = collection.Find(that.Ctx, where, options.Find().SetSkip(0), options.Find().SetLimit(2)); err != nil {
|
||||
that.LastErr = err
|
||||
return nil
|
||||
}
|
||||
//延迟关闭游标
|
||||
defer func() {
|
||||
if err := cursor.Close(that.Ctx); err != nil {
|
||||
that.LastErr = err
|
||||
|
||||
}
|
||||
}()
|
||||
//这里的结果遍历可以使用另外一种更方便的方式:
|
||||
if err = cursor.All(that.Ctx, &results); err != nil {
|
||||
that.LastErr = err
|
||||
return nil
|
||||
}
|
||||
if len(results) > 0 {
|
||||
|
||||
return results[0]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (that MongoDb) Select(table string, where Map, page, pageRow int64) []Map {
|
||||
page = (page - 1) * pageRow
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
results := []Map{}
|
||||
var cursor *mongo.Cursor
|
||||
var err error
|
||||
collection := that.DataBase.Collection(table)
|
||||
if cursor, err = collection.Find(that.Ctx, where, options.Find().SetSkip(page), options.Find().SetLimit(pageRow)); err != nil {
|
||||
that.LastErr = err
|
||||
return results
|
||||
}
|
||||
//延迟关闭游标
|
||||
defer func() {
|
||||
if err := cursor.Close(that.Ctx); err != nil {
|
||||
that.LastErr = err
|
||||
|
||||
}
|
||||
}()
|
||||
//这里的结果遍历可以使用另外一种更方便的方式:
|
||||
|
||||
if err = cursor.All(that.Ctx, &results); err != nil {
|
||||
that.LastErr = err
|
||||
return results
|
||||
}
|
||||
return results
|
||||
}
|
@ -23,7 +23,7 @@ func FileGet(path string) []byte {
|
||||
return buf
|
||||
}
|
||||
|
||||
// RSA_Encrypt RSA加密
|
||||
//RSA加密
|
||||
// plainText 要加密的数据
|
||||
// path 公钥匙文件地址
|
||||
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
||||
@ -46,7 +46,7 @@ func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
||||
return cipherText
|
||||
}
|
||||
|
||||
// RSA_Decrypt RSA解密
|
||||
//RSA解密
|
||||
// cipherText 需要解密的byte数据
|
||||
// path 私钥文件路径
|
||||
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
|
||||
@ -97,7 +97,7 @@ func Demo() {
|
||||
fmt.Println(string(decrypt))
|
||||
}
|
||||
|
||||
// GenerateRSAKey 生成RSA私钥和公钥,保存到文件中
|
||||
//生成RSA私钥和公钥,保存到文件中
|
||||
// bits 证书大小
|
||||
func GenerateRSAKey(bits int, path string) {
|
||||
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
|
||||
|
@ -1,119 +0,0 @@
|
||||
package tencent
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
gourl "net/url"
|
||||
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type company struct {
|
||||
secretId string
|
||||
secretKey string
|
||||
}
|
||||
|
||||
var Company = company{}
|
||||
|
||||
func (that *company) Init(secretId, secretKey string) {
|
||||
// 云市场分配的密钥Id
|
||||
//secretId := "xxxx"
|
||||
//// 云市场分配的密钥Key
|
||||
//secretKey := "xxxx"
|
||||
that.secretId = secretId
|
||||
that.secretKey = secretKey
|
||||
}
|
||||
|
||||
func (that *company) calcAuthorization(source 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(that.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\"",
|
||||
that.secretId, sign)
|
||||
|
||||
return auth, datetime, nil
|
||||
}
|
||||
|
||||
func (that *company) urlencode(params map[string]string) string {
|
||||
var p = gourl.Values{}
|
||||
for k, v := range params {
|
||||
p.Add(k, v)
|
||||
}
|
||||
return p.Encode()
|
||||
}
|
||||
|
||||
func (that *company) GetCompany(name string) Map {
|
||||
// 云市场分配的密钥Id
|
||||
//secretId := "xxxx"
|
||||
//// 云市场分配的密钥Key
|
||||
//secretKey := "xxxx"
|
||||
source := "market"
|
||||
|
||||
// 签名
|
||||
auth, datetime, _ := that.calcAuthorization(source)
|
||||
|
||||
// 请求方法
|
||||
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, that.urlencode(queryParams))
|
||||
}
|
||||
|
||||
bodyMethods := map[string]bool{"POST": true, "PUT": true, "PATCH": true}
|
||||
var body io.Reader = nil
|
||||
if bodyMethods[method] {
|
||||
body = strings.NewReader(that.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)
|
||||
}
|
@ -8,57 +8,16 @@ import (
|
||||
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
||||
)
|
||||
|
||||
type tencent struct {
|
||||
secretId string
|
||||
secretKey string
|
||||
credential *common.Credential
|
||||
}
|
||||
|
||||
var Tencent = tencent{}
|
||||
|
||||
func (that *tencent) Init(secretId, secretKey string) {
|
||||
// 云市场分配的密钥Id
|
||||
//secretId := "xxxx"
|
||||
//// 云市场分配的密钥Key
|
||||
//secretKey := "xxxx"
|
||||
that.secretId = secretId
|
||||
that.secretKey = secretKey
|
||||
that.credential = common.NewCredential(
|
||||
that.secretId,
|
||||
that.secretKey,
|
||||
var credential = common.NewCredential(
|
||||
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
|
||||
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
|
||||
)
|
||||
}
|
||||
|
||||
func (that *tencent) OCRCOMPANY(base64Str string) string {
|
||||
func OCR(base64Str string) string {
|
||||
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||
client, _ := ocr.NewClient(that.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 (that *tencent) OCR(base64Str string) string {
|
||||
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
||||
|
||||
request := ocr.NewGeneralAccurateOCRRequest()
|
||||
|
||||
@ -79,11 +38,11 @@ func (that *tencent) OCR(base64Str string) string {
|
||||
return response.ToJsonString()
|
||||
}
|
||||
|
||||
func (that *tencent) Qrcode(base64Str string) string {
|
||||
func Qrcode(base64Str string) string {
|
||||
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||
client, _ := ocr.NewClient(that.credential, "ap-guangzhou", cpf)
|
||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
||||
|
||||
request := ocr.NewQrcodeOCRRequest()
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "../../common"
|
||||
"errors"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
@ -15,7 +15,7 @@ type Upload struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func (that *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
||||
func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
|
||||
Request.ParseMultipartForm(32 << 20)
|
||||
var filePath string
|
||||
files := Request.MultipartForm.File
|
||||
@ -36,7 +36,7 @@ func (that *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
||||
data := time.Unix(int64(t), 0).Format("2006-01")
|
||||
path := ""
|
||||
if strings.EqualFold(savefilepath, "") {
|
||||
path = that.Path + data
|
||||
path = this.Path + data
|
||||
} else {
|
||||
path = savefilepath + data
|
||||
}
|
||||
@ -51,7 +51,7 @@ func (that *Upload) UpFile(Request *http.Request, fieldName, savefilepath, saveP
|
||||
}
|
||||
}
|
||||
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + ObjToStr(Rand(6))
|
||||
filePath = path + "/" + filename + that.Path
|
||||
filePath = path + "/" + filename + this.Path
|
||||
} else {
|
||||
filePath = savePath
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
package wechat
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/officialaccount"
|
||||
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/js"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/oauth"
|
||||
)
|
||||
|
||||
//基于此文档开发
|
||||
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
|
||||
type h5Program struct {
|
||||
Memory *cache.Memory
|
||||
Config *h5config.Config
|
||||
*officialaccount.OfficialAccount
|
||||
weixin *wechat.Wechat //微信登录实例
|
||||
}
|
||||
|
||||
var H5Program = h5Program{}
|
||||
|
||||
// Init 初始化
|
||||
func (that *h5Program) Init(appid string, appsecret string) {
|
||||
that.weixin = wechat.NewWechat()
|
||||
that.Memory = cache.NewMemory()
|
||||
that.Config = &h5config.Config{
|
||||
AppID: appid,
|
||||
AppSecret: appsecret,
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: that.Memory,
|
||||
}
|
||||
that.OfficialAccount = that.weixin.GetOfficialAccount(that.Config)
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
func (that *h5Program) GetUserInfo(code string) (appid string, resToken oauth.ResAccessToken, userInfo oauth.UserInfo, err error) {
|
||||
auth := that.GetOauth()
|
||||
//weixin.GetOpenPlatform()
|
||||
resToken, err = auth.GetUserAccessToken(code)
|
||||
if err != nil {
|
||||
|
||||
return auth.AppID, resToken, userInfo, err
|
||||
}
|
||||
|
||||
//getUserInfo
|
||||
userInfo, err = auth.GetUserInfo(resToken.AccessToken, resToken.OpenID, "")
|
||||
if err != nil {
|
||||
return auth.AppID, resToken, userInfo, err
|
||||
}
|
||||
|
||||
return auth.AppID, resToken, userInfo, err
|
||||
}
|
||||
|
||||
// GetSignUrl js url签名
|
||||
func (that *h5Program) GetSignUrl(signUrl string) (*js.Config, error) {
|
||||
|
||||
js := that.OfficialAccount.GetJs()
|
||||
cfg1, e := js.GetConfig(signUrl)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
return cfg1, nil
|
||||
}
|
||||
|
||||
// GetSignUrl js url签名
|
||||
//func (that *h5Program) GetJsPay(signUrl string) (*js.Config, error) {
|
||||
// //
|
||||
// //js := that.OfficialAccount().GetJs()
|
||||
// //
|
||||
// //cfg1, e := js.GetConfig(signUrl)
|
||||
// //if e != nil {
|
||||
// // return nil, e
|
||||
// //}
|
||||
//
|
||||
// return cfg1, nil
|
||||
//}
|
@ -1,66 +0,0 @@
|
||||
package wechat
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/silenceper/wechat/v2"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
|
||||
)
|
||||
|
||||
type miniProgram struct {
|
||||
Memory *cache.Memory
|
||||
Config *config.Config
|
||||
weixin *wechat.Wechat //微信登录实例
|
||||
*miniprogram.MiniProgram
|
||||
}
|
||||
|
||||
var MiniProgram = miniProgram{}
|
||||
|
||||
// Init 初始化
|
||||
func (that *miniProgram) Init(appid string, appsecret string) {
|
||||
|
||||
that.weixin = wechat.NewWechat()
|
||||
that.Memory = cache.NewMemory()
|
||||
that.Config = &config.Config{
|
||||
AppID: appid,
|
||||
AppSecret: appsecret,
|
||||
//Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
Cache: that.Memory,
|
||||
}
|
||||
that.MiniProgram = that.weixin.GetMiniProgram(that.Config)
|
||||
}
|
||||
|
||||
func (that *miniProgram) GetBaseUserInfo(code string) (appid string, re auth.ResCode2Session, err error) {
|
||||
appid = that.Config.AppID
|
||||
a := that.GetAuth()
|
||||
re, err = a.Code2Session(code)
|
||||
|
||||
if err != nil {
|
||||
return appid, re, err
|
||||
}
|
||||
|
||||
return appid, re, err
|
||||
}
|
||||
|
||||
func (that *miniProgram) GetPhoneNumber(sessionkey, encryptedData, iv string) (appid string, re *encryptor.PlainData, err error) {
|
||||
appid = that.Config.AppID
|
||||
|
||||
if sessionkey == "" || encryptedData == "" || iv == "" {
|
||||
return appid, re, errors.New("参数不足")
|
||||
}
|
||||
|
||||
eny := that.GetEncryptor()
|
||||
|
||||
re, err = eny.Decrypt(sessionkey, encryptedData, iv)
|
||||
|
||||
if err != nil {
|
||||
return appid, re, err
|
||||
}
|
||||
|
||||
return appid, re, err
|
||||
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
package wechat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-pay/gopay"
|
||||
"github.com/go-pay/gopay/wechat/v3"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
//基于此文档开发
|
||||
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
|
||||
type wxpay struct {
|
||||
client *wechat.ClientV3
|
||||
ctx context.Context
|
||||
apiV3Key string
|
||||
MchId string
|
||||
}
|
||||
|
||||
var WxPay = wxpay{}
|
||||
|
||||
// Init 初始化
|
||||
func (that *wxpay) Init(MchId, SerialNo, APIv3Key, PrivateKey string) {
|
||||
client, err := wechat.NewClientV3(MchId, SerialNo, APIv3Key, PrivateKey)
|
||||
if err != nil {
|
||||
//xlog.Error(err)
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
that.client = client
|
||||
that.apiV3Key = APIv3Key
|
||||
that.MchId = MchId
|
||||
// 设置微信平台API证书和序列号(如开启自动验签,请忽略此步骤)
|
||||
//client.SetPlatformCert([]byte(""), "")
|
||||
that.ctx = context.Background()
|
||||
// 启用自动同步返回验签,并定时更新微信平台API证书(开启自动验签时,无需单独设置微信平台API证书和序列号)
|
||||
err = client.AutoVerifySign()
|
||||
if err != nil {
|
||||
//xlog.Error(err)
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 打开Debug开关,输出日志,默认是关闭的
|
||||
client.DebugSwitch = gopay.DebugOn
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
func (that *wxpay) GetJsOrder(money int64, appid, openid, name, tradeNo, notifyUrl string) (jsApiParams *wechat.JSAPIPayParams, err error) {
|
||||
fmt.Println("dasdas", money, appid, name, tradeNo, notifyUrl)
|
||||
PrepayId, err := that.getPrepayId(money, appid, that.MchId, openid, name, tradeNo, notifyUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//小程序
|
||||
jsapi, err := that.client.PaySignOfJSAPI(appid, PrepayId)
|
||||
return jsapi, err
|
||||
}
|
||||
|
||||
func (that *wxpay) CallbackJsOrder(req *http.Request) (*wechat.V3DecryptResult, error) {
|
||||
|
||||
notifyReq, err := wechat.V3ParseNotify(req)
|
||||
if err != nil {
|
||||
//xlog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// wxPublicKey 通过 client.WxPublicKey() 获取
|
||||
err = notifyReq.VerifySignByPK(that.client.WxPublicKey())
|
||||
if err != nil {
|
||||
//xlog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// ========异步通知敏感信息解密========
|
||||
// 普通支付通知解密
|
||||
result, err := notifyReq.DecryptCipherText(that.apiV3Key)
|
||||
|
||||
//that.client.V3TransactionQueryOrder(that.ctx,result.BankType,result.OR)
|
||||
|
||||
return result, err
|
||||
|
||||
// 合单支付通知解密
|
||||
//result, err := notifyReq.DecryptCombineCipherText(apiV3Key)
|
||||
//// 退款通知解密
|
||||
//result, err := notifyReq.DecryptRefundCipherText(apiV3Key)
|
||||
|
||||
// ========异步通知应答========
|
||||
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功,否则会重试。
|
||||
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
|
||||
|
||||
// 此写法是 gin 框架返回微信的写法
|
||||
//c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||||
//
|
||||
//// 此写法是 echo 框架返回微信的写法
|
||||
//return c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
//func (that *wxpay) GetMiniOrder(money int64,appid,name,tradeNo,notifyUrl string) (jsApiParams *wechat.AppletParams,err error){
|
||||
//
|
||||
// PrepayId,err:=that.getPrepayId(money,name,tradeNo,notifyUrl)
|
||||
// if err!=nil{
|
||||
// return nil,err
|
||||
// }
|
||||
//
|
||||
// //小程序
|
||||
// applet, err := that.client.PaySignOfApplet(appid,PrepayId)
|
||||
//
|
||||
// return applet,err
|
||||
//}
|
||||
|
||||
func (that *wxpay) getPrepayId(money int64, appid, mchid, openid, name, tradeNo, notifyUrl string) (prepayid string, err error) {
|
||||
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
|
||||
// 初始化 BodyMap
|
||||
bm := make(gopay.BodyMap)
|
||||
bm.Set("appid", appid).
|
||||
Set("mchid", mchid).
|
||||
//Set("sub_mchid", "sub_mchid").
|
||||
Set("description", name).
|
||||
Set("out_trade_no", tradeNo).
|
||||
Set("time_expire", expire).
|
||||
Set("notify_url", notifyUrl).
|
||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
bm.Set("total", money).
|
||||
Set("currency", "CNY")
|
||||
}).
|
||||
SetBodyMap("payer", func(bm gopay.BodyMap) {
|
||||
bm.Set("openid", openid)
|
||||
})
|
||||
//ctx:=context.Context()
|
||||
|
||||
wxRsp, err := that.client.V3TransactionJsapi(that.ctx, bm)
|
||||
fmt.Println("获取PrepayId", wxRsp, err)
|
||||
if err != nil {
|
||||
//xlog.Error(err)
|
||||
return "", err
|
||||
}
|
||||
return wxRsp.Response.PrepayId, nil
|
||||
}
|
53
example/app/admin.go
Normal file
53
example/app/admin.go
Normal file
@ -0,0 +1,53 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
)
|
||||
|
||||
var adminCtr = Ctr{
|
||||
"token": func(this *Context) {
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"test": func(this *Context) {
|
||||
this.Session("id", this.SessionId)
|
||||
},
|
||||
//自带的登录
|
||||
"login": func(this *Context) {
|
||||
|
||||
name := this.Req.FormValue("name")
|
||||
pwd := this.Req.FormValue("password")
|
||||
if len(name) < 2 ||
|
||||
len(pwd) < 3 {
|
||||
this.Display(3, "数据校验不通过")
|
||||
}
|
||||
where := Map{"password": Md5(pwd)}
|
||||
if len(name) == 11 {
|
||||
where["phone"] = name
|
||||
} else {
|
||||
where["name"] = name
|
||||
}
|
||||
|
||||
admin := this.Db.Get("admin", "*", Map{"AND": where})
|
||||
if admin == nil {
|
||||
this.Display(4, "账户密码错误")
|
||||
return
|
||||
}
|
||||
|
||||
this.Session("id", admin.GetCeilInt("id"))
|
||||
admin["password"] = nil
|
||||
this.Display(0, admin)
|
||||
|
||||
},
|
||||
"info": func(this *Context) {
|
||||
admin := this.Db.Get("admin", "*", Map{"id": this.Session("id").ToInt()})
|
||||
|
||||
if admin == nil {
|
||||
this.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
admin["password"] = nil
|
||||
|
||||
this.Display(0, admin)
|
||||
},
|
||||
}
|
29
example/app/init.go
Normal file
29
example/app/init.go
Normal file
@ -0,0 +1,29 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
//"user": UserCtr,
|
||||
"product_spot_check": product_spot_checkCtr,
|
||||
"product": productCtr,
|
||||
"admin": adminCtr,
|
||||
"sms": Sms,
|
||||
"material": materialCtr,
|
||||
"material_inout": material_inoutCtr,
|
||||
"produce_product": produce_productCtr,
|
||||
"produce": produceCtr,
|
||||
"product_line": product_lineCtr,
|
||||
}
|
||||
|
||||
//生成随机码的4位随机数
|
||||
func getCode() string {
|
||||
//res := ""
|
||||
//for i := 0; i < 4; i++ {
|
||||
res := ObjToStr(RandX(1000, 9999))
|
||||
//}
|
||||
return res
|
||||
}
|
213
example/app/material.go
Normal file
213
example/app/material.go
Normal file
@ -0,0 +1,213 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var materialCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
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 {
|
||||
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) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
name := that.Req.FormValue("name")
|
||||
img := that.Req.FormValue("img")
|
||||
validity := ObjToInt(that.Req.FormValue("validity"))
|
||||
num := ObjToInt(that.Req.FormValue("num"))
|
||||
rule := that.Req.FormValue("rule")
|
||||
content := that.Req.FormValue("content")
|
||||
description := that.Req.FormValue("description")
|
||||
if name == "" || rule == "" {
|
||||
that.Display(3, "参数不足,请补充参数")
|
||||
return
|
||||
}
|
||||
|
||||
data := Map{
|
||||
"name": name,
|
||||
"img": img,
|
||||
"rule": rule,
|
||||
"admin_id": adminID,
|
||||
"count": 0,
|
||||
"used": 0,
|
||||
"saved": 0,
|
||||
"num": num,
|
||||
"validity": validity,
|
||||
"description": description,
|
||||
"content": content,
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
}
|
||||
|
||||
id := that.Db.Insert("material", data)
|
||||
if id == 0 {
|
||||
that.Display(4, "添加材料失败,请重新添加")
|
||||
return
|
||||
}
|
||||
|
||||
data["id"] = id
|
||||
|
||||
that.Display(0, data)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
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]})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "更新数据失败")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"inout": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
data := ObjToMap(that.Req.FormValue("data"))
|
||||
|
||||
texts := data.GetSlice("text")
|
||||
textData := []Map{}
|
||||
for k, _ := range texts {
|
||||
v := texts.GetString(k)
|
||||
if len(v) < 4 {
|
||||
continue
|
||||
}
|
||||
vs := that.Db.Select("material", "name,id,content,rule,num", Map{"content[~]": v[:len(v)/2]})
|
||||
for _, v1 := range vs {
|
||||
if len(textData) == 0 {
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
for _, vt := range textData {
|
||||
if v1.GetString("id") != vt.GetString("id") {
|
||||
|
||||
add := true
|
||||
for _, vt1 := range textData {
|
||||
if vt1.GetCeilInt("id") == v1.GetCeilInt("id") {
|
||||
add = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if add {
|
||||
v1["count"] = 1
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
} else {
|
||||
vt["count"] = vt.GetCeilInt("count") + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qrcode := data.GetSlice("qrcode")
|
||||
for k, _ := range qrcode {
|
||||
v := qrcode.GetString(k)
|
||||
if len(v) < 4 {
|
||||
continue
|
||||
}
|
||||
vs := that.Db.Select("material", "name,id,content,rule,num", Map{"content[~]": v[:len(v)/2]})
|
||||
for _, v1 := range vs {
|
||||
if len(textData) == 0 {
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
for _, vt := range textData {
|
||||
if v1.GetString("id") != vt.GetString("id") {
|
||||
v1["count"] = 1
|
||||
textData = append(textData, v1)
|
||||
} else {
|
||||
vt["count"] = vt.GetCeilInt("count") + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, textData)
|
||||
|
||||
},
|
||||
"search": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
leftJoin := Map{"[><]admin": "material.admin_id=admin.id"}
|
||||
columnStr := "material.id,material.name,material.img,material.count,material.used,material.saved,material.admin_id,admin.name AS admin_name,material.modify_time,material.state"
|
||||
where := Map{"ORDER": "modify_time DESC"}
|
||||
count := that.Db.Count("material", where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect("material", leftJoin, columnStr, where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
}
|
188
example/app/material_inout.go
Normal file
188
example/app/material_inout.go
Normal file
@ -0,0 +1,188 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var material_inoutCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
id := ObjToInt(that.Req.FormValue("id"))
|
||||
if id == 0 {
|
||||
that.Display(3, "请求参数不足,请检查参数")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Get("material_inout", "*", Map{"id": id})
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
img := that.Req.FormValue("img")
|
||||
rule := that.Req.FormValue("rule")
|
||||
materialId := ObjToInt(that.Req.FormValue("material_id"))
|
||||
produceId := ObjToInt(that.Req.FormValue("produce_id"))
|
||||
count := ObjToInt(that.Req.FormValue("num"))
|
||||
state := ObjToInt(that.Req.FormValue("state"))
|
||||
|
||||
content := that.Req.FormValue("content")
|
||||
description := that.Req.FormValue("description")
|
||||
|
||||
if rule == "" || materialId == 0 || count == 0 {
|
||||
that.Display(3, "参数不足,请补充参数")
|
||||
return
|
||||
}
|
||||
count1 := count
|
||||
if state > 0 {
|
||||
count = -count
|
||||
}
|
||||
|
||||
produce_material := that.Db.Get("produce_material", "id", Map{"AND": Map{"produce_id": produceId, "material_id": materialId}})
|
||||
if produce_material == nil {
|
||||
that.Db.Insert("produce_material", Map{"produce_id": produceId,
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"admin_id": adminID,
|
||||
"material_id": materialId})
|
||||
}
|
||||
if state == 0 {
|
||||
|
||||
that.Db.Update("material", Map{"count[#]": "count+" + ObjToStr(count), "saved[#]": "saved+" + ObjToStr(count)}, Map{"id": materialId})
|
||||
} else {
|
||||
that.Db.Update("material", Map{"count[#]": "count" + ObjToStr(count), "used[#]": "used+" + ObjToStr(-count)}, Map{"id": materialId})
|
||||
}
|
||||
|
||||
material := that.Db.Get("material", "*", Map{"id": materialId})
|
||||
data := Map{
|
||||
"img": img,
|
||||
"rule": rule,
|
||||
"admin_id": adminID,
|
||||
"material_id": materialId,
|
||||
"count": count1,
|
||||
"saved": material.GetCeilInt("count"),
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"produce_id": produceId,
|
||||
"description": description,
|
||||
"content": content,
|
||||
"state": state,
|
||||
}
|
||||
id := that.Db.Insert("material_inout", data)
|
||||
|
||||
if id == 0 {
|
||||
that.Display(4, "添加出入库记录失败,请重新添加")
|
||||
return
|
||||
}
|
||||
|
||||
data["id"] = id
|
||||
|
||||
that.Display(0, data)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
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]})
|
||||
|
||||
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) {
|
||||
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
materialId := ObjToInt(that.Req.FormValue("id"))
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
columnStr := "material_inout.id,material_inout.material_id,material.name,material_inout.img,material_inout.count,material_inout.saved,material_inout.admin_id,admin.name AS admin_name,material_inout.modify_time,material_inout.state"
|
||||
leftJoin := Map{"[><]material": "material_inout.material_id=material.id",
|
||||
"[><]admin": "material_inout.admin_id=admin.id",
|
||||
}
|
||||
where := Map{"ORDER": "modify_time DESC"}
|
||||
|
||||
if materialId != 0 {
|
||||
where["material_id"] = materialId
|
||||
}
|
||||
count := that.Db.Count("material_inout", where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect("material_inout", leftJoin, columnStr, where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
}
|
201
example/app/produce.go
Normal file
201
example/app/produce.go
Normal file
@ -0,0 +1,201 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var produceCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
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 {
|
||||
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.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]})
|
||||
|
||||
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, "删除成功")
|
||||
},
|
||||
"check": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
data := ObjToMap(that.Req.FormValue("data"))
|
||||
|
||||
texts := data.GetSlice("text")
|
||||
textData := []Map{}
|
||||
for k, _ := range texts {
|
||||
v := texts.GetString(k)
|
||||
if len(v) < 3 {
|
||||
continue
|
||||
}
|
||||
vs := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, "produce.name,produce.id,produce.product_id,product.name AS product_name,product.rule_check,product.rule_spot_check", Map{"produce.sn[~]": v[:len(v)/2+1]})
|
||||
for _, v1 := range vs {
|
||||
if len(textData) == 0 {
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
for _, vt := range textData {
|
||||
if v1.GetString("id") != vt.GetString("id") {
|
||||
|
||||
add := true
|
||||
for _, vt1 := range textData {
|
||||
if vt1.GetCeilInt("id") == v1.GetCeilInt("id") {
|
||||
add = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if add {
|
||||
v1["count"] = 1
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
} else {
|
||||
vt["count"] = vt.GetCeilInt("count") + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qrcode := data.GetSlice("qrcode")
|
||||
for k, _ := range qrcode {
|
||||
v := qrcode.GetString(k)
|
||||
if len(v) < 3 {
|
||||
continue
|
||||
}
|
||||
vs := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, "produce.name,produce.id,produce.product_id,product.name AS product_name,product.rule_check,product.rule_spot_check", Map{"produce.sn[~]": v[:len(v)/2+1]})
|
||||
for _, v1 := range vs {
|
||||
if len(textData) == 0 {
|
||||
textData = append(textData, v1)
|
||||
}
|
||||
for _, vt := range textData {
|
||||
if v1.GetString("id") != vt.GetString("id") {
|
||||
v1["count"] = 1
|
||||
textData = append(textData, v1)
|
||||
} else {
|
||||
vt["count"] = vt.GetCeilInt("count") + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, textData)
|
||||
|
||||
},
|
||||
"search": func(that *Context) {
|
||||
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
columnStr := "produce.id,produce.sn,produce.name,produce.state,produce.product_id,product.name AS product_name"
|
||||
where := Map{"produce.state[!]": 0, "ORDER": "produce.modify_time DESC"}
|
||||
|
||||
reData := that.Db.Select("produce", Map{"[>]product": "produce.product_id=product.id"}, columnStr, where)
|
||||
|
||||
that.Display(0, reData)
|
||||
},
|
||||
}
|
96
example/app/produce_product.go
Normal file
96
example/app/produce_product.go
Normal file
@ -0,0 +1,96 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var produce_productCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
id := ObjToInt(that.Req.FormValue("id"))
|
||||
sn := that.Req.FormValue("sn")
|
||||
if id == 0 && sn == "" {
|
||||
that.Display(3, "请求参数不足,请检查参数")
|
||||
return
|
||||
}
|
||||
|
||||
where := Map{}
|
||||
if id != 0 {
|
||||
where["produce_product.id"] = id
|
||||
} else {
|
||||
where["produce_product.sn"] = sn
|
||||
}
|
||||
|
||||
re := that.Db.Get("produce_product",
|
||||
|
||||
Map{"[><]product": "produce_product.product_id=product.id",
|
||||
"[><]produce": "produce_product.produce_id=produce.id",
|
||||
},
|
||||
"produce_product.id,produce_product.product_id,product.name AS product_name,"+
|
||||
"produce_product.modify_time,produce_product.state,product.rule_spot_check,produce_product.produce_id,produce.name AS produce_name", where)
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
sn := that.Req.FormValue("sn")
|
||||
product_id := ObjToInt(that.Req.FormValue("product_id"))
|
||||
produce_id := ObjToInt(that.Req.FormValue("produce_id"))
|
||||
product_line_id := ObjToInt(that.Req.FormValue("product_line_id"))
|
||||
//state := ObjToInt(that.Req.FormValue("state"))
|
||||
//rule_check := that.Req.FormValue("rule_check")
|
||||
//description := that.Req.FormValue("description")
|
||||
if sn == "" {
|
||||
that.Display(3, "参数不足,请补充参数")
|
||||
return
|
||||
}
|
||||
|
||||
data := Map{
|
||||
|
||||
"sn": sn,
|
||||
"product_id": product_id,
|
||||
"produce_id": produce_id,
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
}
|
||||
|
||||
data1 := ObjToMap(data.ToJsonString())
|
||||
data1["product_line_id"] = product_line_id
|
||||
id := that.Db.Insert("produce_product", data1)
|
||||
if id == 0 {
|
||||
that.Display(4, "添加新成品失败,请重新添加")
|
||||
return
|
||||
}
|
||||
|
||||
//data["id"] = id
|
||||
//data["rule"] = rule_check
|
||||
//data["produce_product_id"] = id
|
||||
//data["state"] = state
|
||||
//data["description"] = description
|
||||
//id = that.Db.Insert("product_check", data)
|
||||
//if id == 0 {
|
||||
// that.Display(4, "添加质检失败,请重新添加")
|
||||
// return
|
||||
//}
|
||||
that.Display(0, data)
|
||||
},
|
||||
}
|
138
example/app/product.go
Normal file
138
example/app/product.go
Normal file
@ -0,0 +1,138 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var productCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
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 {
|
||||
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) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
id := ObjToInt(that.Req.FormValue("id"))
|
||||
//抽检更新
|
||||
ruleSpotCheck := that.Req.FormValue("rule_spot_check")
|
||||
if ruleSpotCheck != "" {
|
||||
spotCheckPercentage := ObjToInt(that.Req.FormValue("spot_check_percentage"))
|
||||
if id == 0 || ruleSpotCheck == "" {
|
||||
that.Display(3, "请求参数不足,请检查参数")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Update("product", Map{"rule_spot_check": ruleSpotCheck, "spot_check_percentage": spotCheckPercentage, "modify_time": time.Now().Unix()}, Map{"id": id})
|
||||
if re == 0 {
|
||||
that.Display(4, "更新失败,无法更新抽检参数")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
//质检更新
|
||||
ruleCheck := that.Req.FormValue("rule_check")
|
||||
if id == 0 || ruleCheck == "" {
|
||||
that.Display(3, "请求参数不足,请检查参数")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Update("product", Map{"rule_check": ruleCheck, "modify_time": time.Now().Unix()}, Map{"id": id})
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "更新失败,无法更新质检参数")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
that.Display(0, "更新成功")
|
||||
},
|
||||
|
||||
"search": func(that *Context) {
|
||||
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
leftJoin := Map{"[><]admin": "product.admin_id=admin.id"}
|
||||
columnStr := "product.id,product.name,product.img,product.count,product.used,product.saved,product.spot_check_count,product.admin_id,admin.name AS admin_name,product.modify_time,product.state"
|
||||
where := Map{"ORDER": "modify_time DESC"}
|
||||
count := that.Db.Count("product", where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect("product", leftJoin, columnStr, where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
}
|
146
example/app/product_line.go
Normal file
146
example/app/product_line.go
Normal file
@ -0,0 +1,146 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var product_lineCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
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 {
|
||||
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.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]})
|
||||
|
||||
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) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
//page := ObjToInt(that.Req.FormValue("page"))
|
||||
//pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
//
|
||||
//if page < 1 {
|
||||
// page = 1
|
||||
//}
|
||||
//if pageSize <= 0 {
|
||||
// pageSize = 10
|
||||
//}
|
||||
|
||||
//leftJoin := Map{"[><]admin": "product.admin_id=admin.id"}
|
||||
|
||||
where := Map{"state": 0, "ORDER": "modify_time DESC"}
|
||||
//count := that.Db.Count("product", where)
|
||||
reData := that.Db.Select("product_line", "*", where)
|
||||
|
||||
that.Display(0, reData)
|
||||
|
||||
},
|
||||
}
|
138
example/app/product_spot_check.go
Normal file
138
example/app/product_spot_check.go
Normal file
@ -0,0 +1,138 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var product_spot_checkCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
id := ObjToInt(that.Req.FormValue("id"))
|
||||
if id == 0 {
|
||||
that.Display(3, "请求参数不足,请检查参数")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Get("product_spot_check",
|
||||
|
||||
Map{"[><]product": "product_spot_check.product_id=product.id",
|
||||
"[><]produce": "product_spot_check.produce_id=produce.id",
|
||||
},
|
||||
"id,img,product_id,product.name AS product_name,admin_id,"+
|
||||
"modify_time,state,rule,produce_id,produce.name AS produce_name", Map{"id": id})
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
|
||||
//img := that.Req.FormValue("img")
|
||||
sn := that.Req.FormValue("sn")
|
||||
rule := that.Req.FormValue("rule_spot_check")
|
||||
description := that.Req.FormValue("description")
|
||||
produceProductId := ObjToInt(that.Req.FormValue("produce_product_id"))
|
||||
|
||||
//count := ObjToInt(that.Req.FormValue("count"))
|
||||
state := ObjToInt(that.Req.FormValue("state"))
|
||||
if rule == "" || produceProductId == 0 {
|
||||
that.Display(3, "参数不足,请补充参数")
|
||||
return
|
||||
}
|
||||
|
||||
produceProduct := that.Db.Get("produce_product", "*", Map{"id": produceProductId})
|
||||
if produceProduct == nil {
|
||||
that.Display(4, "找不到成品记录,无法进行抽检")
|
||||
return
|
||||
}
|
||||
//判断是否已经抽检了
|
||||
alreadyCheck := that.Db.Get("product_spot_check", "id", Map{"produce_product_id": produceProductId})
|
||||
|
||||
if alreadyCheck == nil {
|
||||
|
||||
that.Db.Update("product", Map{"spot_check_count[#]": "spot_check_count+1"},
|
||||
Map{"id": produceProduct.GetCeilInt("product_id")})
|
||||
|
||||
that.Db.Update("produce", Map{"spot_check_count[#]": "spot_check_count+1"},
|
||||
Map{"id": produceProduct.GetCeilInt("produce_id")})
|
||||
}
|
||||
|
||||
data := Map{
|
||||
"sn": sn,
|
||||
"rule": rule,
|
||||
"admin_id": adminID,
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"product_id": produceProduct.GetCeilInt("product_id"),
|
||||
"produce_id": produceProduct.GetCeilInt("produce_id"),
|
||||
"produce_product_id": produceProductId,
|
||||
"description": description,
|
||||
"state": state,
|
||||
}
|
||||
|
||||
id := that.Db.Insert("product_spot_check", data)
|
||||
if id == 0 {
|
||||
that.Display(4, "添加抽检记录失败,请重新添加")
|
||||
return
|
||||
}
|
||||
|
||||
data["id"] = id
|
||||
|
||||
that.Display(0, data)
|
||||
},
|
||||
"search": func(that *Context) {
|
||||
|
||||
adminID := that.Session("id").ToInt()
|
||||
|
||||
if adminID == 0 {
|
||||
that.Display(2, "登录失效,请重新登录")
|
||||
return
|
||||
}
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
productId := ObjToInt(that.Req.FormValue("id"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
columnStr := "product_spot_check.id,product_spot_check.product_id,product_spot_check.sn,product.name,product_spot_check.img,product_spot_check.admin_id,admin.name AS admin_name,product_spot_check.modify_time,product_spot_check.state"
|
||||
leftJoin := Map{"[><]product": "product_spot_check.product_id=product.id",
|
||||
"[><]admin": "product_spot_check.admin_id=admin.id",
|
||||
}
|
||||
|
||||
where := Map{"ORDER": "id DESC"}
|
||||
|
||||
if productId != 0 {
|
||||
where["product_id"] = productId
|
||||
}
|
||||
|
||||
count := that.Db.Count("product_spot_check", where)
|
||||
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect("product_spot_check", leftJoin, columnStr, where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
}
|
33
example/app/sms.go
Normal file
33
example/app/sms.go
Normal file
@ -0,0 +1,33 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
"../../dri/ddsms"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
ddsms.DefaultDDY.SendYZM(phone, this.Config.GetString("smsLogin"), map[string]string{"code": code})
|
||||
|
||||
this.Display(0, "发送成功")
|
||||
},
|
||||
}
|
BIN
example/bzyy.exe
Normal file
BIN
example/bzyy.exe
Normal file
Binary file not shown.
@ -1,472 +0,0 @@
|
||||
{
|
||||
"flow": {
|
||||
"admin": {
|
||||
"sql": {
|
||||
"role_id": "role_id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "admin"
|
||||
},
|
||||
"article": {
|
||||
"sql": {
|
||||
"admin_id": "id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "article"
|
||||
},
|
||||
"ctg": {
|
||||
"sql": {
|
||||
"admin_id": "id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "ctg"
|
||||
},
|
||||
"ctg_article": {
|
||||
"sql": {
|
||||
"admin_id": "id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "ctg_article"
|
||||
},
|
||||
"ctg_copy": {
|
||||
"sql": {
|
||||
"admin_id": "id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "ctg_copy"
|
||||
},
|
||||
"logs": {
|
||||
"sql": {
|
||||
|
||||
},
|
||||
"stop": false,
|
||||
"table": "logs"
|
||||
},
|
||||
"org": {
|
||||
"sql": {
|
||||
"admin_id": "id"
|
||||
},
|
||||
"stop": false,
|
||||
"table": "org"
|
||||
},
|
||||
"role": {
|
||||
"sql": {
|
||||
"admin_id": "id",
|
||||
"id": "role_id"
|
||||
},
|
||||
"stop": true,
|
||||
"table": "role"
|
||||
}
|
||||
},
|
||||
"id": "74a8a59407fa7d6c7fcdc85742dbae57",
|
||||
"label": "HoTime管理平台",
|
||||
"labelConfig": {
|
||||
"add": "添加",
|
||||
"delete": "删除",
|
||||
"download": "下载清单",
|
||||
"edit": "编辑",
|
||||
"info": "查看详情",
|
||||
"show": "开启"
|
||||
},
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show"
|
||||
],
|
||||
"icon": "Setting",
|
||||
"label": "ebw_news",
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_news",
|
||||
"table": "ebw_news"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_news_addition_res",
|
||||
"table": "ebw_news_addition_res"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_annex",
|
||||
"table": "ebw_annex"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_customer",
|
||||
"table": "ebw_customer"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_items",
|
||||
"table": "ebw_items"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_res",
|
||||
"table": "ebw_res"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_vote",
|
||||
"table": "ebw_vote"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_vote_option",
|
||||
"table": "ebw_vote_option"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_user",
|
||||
"table": "ebw_user"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_attachment",
|
||||
"table": "ebw_attachment"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_jobs",
|
||||
"table": "ebw_jobs"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "ebw_vote_user",
|
||||
"table": "ebw_vote_user"
|
||||
}
|
||||
],
|
||||
"name": "sys:ebw"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show"
|
||||
],
|
||||
"icon": "Setting",
|
||||
"label": "系统管理",
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"download"
|
||||
],
|
||||
"label": "日志管理",
|
||||
"table": "logs"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "角色管理",
|
||||
"table": "role"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "组织管理",
|
||||
"table": "org"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "人员管理",
|
||||
"table": "admin"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "文章管理",
|
||||
"table": "article"
|
||||
}
|
||||
],
|
||||
"name": "sys"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show"
|
||||
],
|
||||
"icon": "Setting",
|
||||
"label": "外部系统",
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "外部系统",
|
||||
"table": "swiper_sys"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "顶部",
|
||||
"table": "swiper_top"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "飘窗",
|
||||
"table": "swiper_fly"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "底部",
|
||||
"table": "swiper_bottom"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "中间",
|
||||
"table": "swiper_center"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "关联专题",
|
||||
"table": "swiper_point"
|
||||
}
|
||||
],
|
||||
"name": "sys:swiper"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show"
|
||||
],
|
||||
"icon": "Setting",
|
||||
"label": "栏目管理",
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "栏目管理",
|
||||
"table": "ctg"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "关联栏目",
|
||||
"table": "ctg_article"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "栏目管理",
|
||||
"table": "ctg_copy"
|
||||
}
|
||||
],
|
||||
"name": "sys:ctg"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show"
|
||||
],
|
||||
"icon": "Setting",
|
||||
"label": "纪委信箱",
|
||||
"menus": [
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "纪委信箱",
|
||||
"table": "mail_discipline"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "总经理信箱",
|
||||
"table": "mail"
|
||||
},
|
||||
{
|
||||
"auth": [
|
||||
"show",
|
||||
"add",
|
||||
"delete",
|
||||
"edit",
|
||||
"info",
|
||||
"download"
|
||||
],
|
||||
"label": "党委书记信箱",
|
||||
"table": "mail_part"
|
||||
}
|
||||
],
|
||||
"name": "sys:mail"
|
||||
}
|
||||
],
|
||||
"name": "admin",
|
||||
"stop": [
|
||||
"role",
|
||||
"org"
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
3285
example/config/app.json
Normal file
3285
example/config/app.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,7 @@
|
||||
"cache": {
|
||||
"db": {
|
||||
"db": false,
|
||||
"session": true,
|
||||
"timeout": 7200
|
||||
"session": true
|
||||
},
|
||||
"memory": {
|
||||
"db": true,
|
||||
@ -11,22 +10,24 @@
|
||||
"timeout": 7200
|
||||
}
|
||||
},
|
||||
"codeConfig": [
|
||||
{
|
||||
"config": "config/admin.json",
|
||||
"configDB": "config/adminDB.json",
|
||||
"mode": 0,
|
||||
"name": "",
|
||||
"rule": "config/rule.json",
|
||||
"table": "admin"
|
||||
"codeConfig": {
|
||||
"admin": "config/app.json"
|
||||
},
|
||||
"codeConfig1": {
|
||||
"admin": {
|
||||
"config": "config/app.json",
|
||||
"package": "admin",
|
||||
"rule": "config/rule.json"
|
||||
}
|
||||
],
|
||||
},
|
||||
"crossDomain": "auto",
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.6.253",
|
||||
"name": "dgs-cms",
|
||||
"name": "myhs",
|
||||
"password": "dasda8454456",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
"user": "root"
|
||||
}
|
||||
},
|
||||
@ -41,8 +42,8 @@
|
||||
"4": "数据处理异常",
|
||||
"5": "数据结果异常"
|
||||
},
|
||||
"mode": 2,
|
||||
"port": "8081",
|
||||
"mode": 3,
|
||||
"port": "8080",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "tpt"
|
||||
}
|
@ -20,17 +20,10 @@
|
||||
},
|
||||
"注释": "可配置memory,db,redis,默认启用memory,默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致,缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用"
|
||||
},
|
||||
"codeConfig": [
|
||||
"注释:配置即启用,非必须,默认无",
|
||||
{
|
||||
"config": "默认config/app.json,必须,接口描述配置文件",
|
||||
"configDB": "默认无,非必须,有则每次将数据库数据生成到此目录用于配置读写,无则不生成",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"table": "默认admin,必须,根据数据库内当前表名做为用户生成数据"
|
||||
}
|
||||
],
|
||||
"codeConfig": {
|
||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||
"注释": "配置即启用,非必须,默认无"
|
||||
},
|
||||
"crossDomain": "默认空 非必须,空字符串为不开启,如果需要跨域设置,auto为智能开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域",
|
||||
"db": {
|
||||
"mysql": {
|
||||
|
Binary file not shown.
@ -1,422 +0,0 @@
|
||||
[
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "idcard",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "id",
|
||||
"strict": true,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "sn",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "parent_ids",
|
||||
"strict": true,
|
||||
"type": "index"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "index",
|
||||
"strict": true,
|
||||
"type": "index"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "parent_id",
|
||||
"true": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "amount",
|
||||
"strict": true,
|
||||
"type": "money"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "info",
|
||||
"strict": false,
|
||||
"type": "textArea"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "status",
|
||||
"strict": false,
|
||||
"type": "select"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "state",
|
||||
"strict": false,
|
||||
"type": "select"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "sex",
|
||||
"strict": false,
|
||||
"type": "select"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "delete",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "lat",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "lng",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "latitude",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "longitude",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "password",
|
||||
"strict": false,
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "pwd",
|
||||
"strict": false,
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": false,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "version",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "seq",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "sort",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "note",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "description",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "abstract",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "content",
|
||||
"strict": false,
|
||||
"type": "textArea"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "address",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "full_name",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "create_time",
|
||||
"strict": true,
|
||||
"type": "time"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "modify_time",
|
||||
"strict": true,
|
||||
"type": "time"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "image",
|
||||
"strict": false,
|
||||
"type": "image"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "img",
|
||||
"strict": false,
|
||||
"type": "image"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "avatar",
|
||||
"strict": false,
|
||||
"type": "image"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "icon",
|
||||
"strict": false,
|
||||
"type": "image"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "file",
|
||||
"strict": false,
|
||||
"type": "file"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "age",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "email",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "time",
|
||||
"strict": false,
|
||||
"type": "time"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "level",
|
||||
"strict": false,
|
||||
"type": ""
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "rule",
|
||||
"strict": false,
|
||||
"type": "form"
|
||||
},
|
||||
{
|
||||
"add": true,
|
||||
"edit": true,
|
||||
"info": true,
|
||||
"list": false,
|
||||
"must": false,
|
||||
"name": "auth",
|
||||
"strict": true,
|
||||
"type": "auth"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "table",
|
||||
"strict": false,
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"add": false,
|
||||
"edit": false,
|
||||
"info": true,
|
||||
"list": true,
|
||||
"must": false,
|
||||
"name": "table_id",
|
||||
"strict": false,
|
||||
"type": "table_id"
|
||||
}
|
||||
]
|
@ -1,17 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
"../../hotime"
|
||||
"../dri/ddsms"
|
||||
"./app"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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")
|
||||
//RESTfull接口适配
|
||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
||||
|
||||
appIns := Init("config/config.json")
|
||||
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
|
||||
|
||||
return isFinished
|
||||
return true
|
||||
})
|
||||
|
||||
appIns.Run(Router{})
|
||||
|
||||
//makeCode := code.MakeCode{}
|
||||
//fmt.Println(common.ObjToStr(makeCode.Db2JSON("admin","test",appIns.Db)))
|
||||
if ddsms.DefaultDDY.ApiKey == "" {
|
||||
ddsms.DefaultDDY.Init(appIns.Config.GetString("smsKey"))
|
||||
}
|
||||
|
||||
appIns.Run(hotime.Router{
|
||||
"app": app.Project,
|
||||
})
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.el-upload img[data-v-3b5105e6]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-3b5105e6]{font-size:40px;margin:30% 31%;display:block}.custom-tree-node[data-v-3b5105e6]{font-size:14px;padding-right:8px}.info-descriptions[data-v-4d4566fc] .el-descriptions__body .el-descriptions__label{min-width:90px;text-align:right;background:transparent;color:#606266;font-weight:400}.el-descriptions .is-bordered th[data-v-4d4566fc],.info-descriptions[data-v-4d4566fc] .el-descriptions .is-bordered td{border:transparent;max-width:25vw}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}.dialog-box .el-descriptions__header{margin:20px 0 5px}.dialog-box .el-descriptions__body{background:#fff}.textarea-box *{word-break:break-all;white-space:pre-wrap}.textarea-box table{width:100%!important}.textarea-box img{max-width:80%!important}.textarea-box::-webkit-scrollbar-thumb{height:5px;background-color:rgba(0,0,0,.2)!important}
|
@ -1 +0,0 @@
|
||||
body[data-v-c08f3364],dd[data-v-c08f3364],dl[data-v-c08f3364],form[data-v-c08f3364],h1[data-v-c08f3364],h2[data-v-c08f3364],h3[data-v-c08f3364],h4[data-v-c08f3364],h5[data-v-c08f3364],h6[data-v-c08f3364],html[data-v-c08f3364],ol[data-v-c08f3364],p[data-v-c08f3364],pre[data-v-c08f3364],tbody[data-v-c08f3364],textarea[data-v-c08f3364],tfoot[data-v-c08f3364],thead[data-v-c08f3364],ul[data-v-c08f3364]{margin:0;font-size:14px;font-family:Microsoft YaHei}dl[data-v-c08f3364],ol[data-v-c08f3364],ul[data-v-c08f3364]{padding:0}li[data-v-c08f3364]{list-style:none}input[data-v-c08f3364]{border:none;outline:none;font-family:Microsoft YaHei;background-color:#fff}a[data-v-c08f3364]{font-family:Microsoft YaHei;text-decoration:none}[data-v-c08f3364]{margin:0;padding:0}.login[data-v-c08f3364]{position:relative;width:100%;height:100%;background-color:#353d56;background-repeat:no-repeat;background-attachment:fixed;background-size:cover}.login-item[data-v-c08f3364]{position:absolute;top:calc(50% - 30vh);left:60%;min-width:388px;width:18vw;max-width:588px;padding:8vh 30px;box-sizing:border-box;background-size:468px 468px;background:hsla(0,0%,100%,.85);border-radius:10px}.login-item .right-content[data-v-c08f3364]{box-sizing:border-box;width:100%}.login-item .right-content .login-title[data-v-c08f3364]{font-size:26px;font-weight:700;color:#4f619b;text-align:center}.errorMsg[data-v-c08f3364]{width:100%;height:34px;line-height:34px;color:red;font-size:14px;overflow:hidden}.login-item .right-content .inputWrap[data-v-c08f3364]{width:90%;height:32px;line-height:32px;color:#646464;font-size:16px;border:1px solid #b4b4b4;margin:0 auto 5%;padding:2% 10px;border-radius:10px}.login-item .right-content .inputWrap.inputFocus[data-v-c08f3364]{border:1px solid #4f619b;box-shadow:0 0 0 3px rgba(91,113,185,.4)}.login-item .right-content .inputWrap input[data-v-c08f3364]{background-color:transparent;color:#646464;display:inline-block;height:100%;width:80%}.login-btn[data-v-c08f3364]{width:97%;height:52px;text-align:center;line-height:52px;font-size:17px;color:#fff;background-color:#4f619b;border-radius:10px;margin:0 auto;margin-top:50px;cursor:pointer;font-weight:800}
|
@ -1 +0,0 @@
|
||||
.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.el-upload img[data-v-51dbed3c]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-51dbed3c]{font-size:40px;margin:30% 31%;display:block}.custom-tree-node[data-v-51dbed3c]{font-size:14px;padding-right:8px}.info-descriptions[data-v-4d4566fc] .el-descriptions__body .el-descriptions__label{min-width:90px;text-align:right;background:transparent;color:#606266;font-weight:400}.el-descriptions .is-bordered th[data-v-4d4566fc],.info-descriptions[data-v-4d4566fc] .el-descriptions .is-bordered td{border:transparent;max-width:25vw}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}.dialog-box .el-descriptions__header{margin:20px 0 5px}.dialog-box .el-descriptions__body{background:#fff}.textarea-box *{word-break:break-all;white-space:pre-wrap}.textarea-box table{width:100%!important}.textarea-box img{max-width:80%!important}.textarea-box::-webkit-scrollbar-thumb{height:5px;background-color:rgba(0,0,0,.2)!important}
|
1
example/tpt/css/chunk-1afce11c.7ec257c2.css
Normal file
1
example/tpt/css/chunk-1afce11c.7ec257c2.css
Normal file
@ -0,0 +1 @@
|
||||
.left-nav-home-bar{background:#2c3759!important}.left-nav-home-bar,.left-nav-home-bar i{color:#fff!important}.el-submenu .el-menu-item{height:40px;line-height:40px}.el-menu .el-submenu__title{height:46px;line-height:46px}.left-nav-home-bar i{margin-bottom:6px!important}.el-menu-item-group__title{padding:0 0 0 20px}.head-left[data-v-297b6686],.head-right[data-v-297b6686]{display:flex;justify-content:center;flex-direction:column}.head-right[data-v-297b6686]{align-items:flex-end}.el-upload{height:100px;width:100px}.el-upload img[data-v-012633a9]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-012633a9]{font-size:40px;margin:30% 31%;display:block}.form-file-item .upload-file .el-upload{width:100px;height:auto;line-height:0;background-color:transparent}.form-file-item .el-button--small{height:32px}.el-input-number--mini{width:100px;margin-right:5px}.el-input-number--mini .el-input{width:100px!important}.basic-form{width:400px}.basic-form .el-input,.basic-form .el-select{width:84px;margin-right:5px}.form-file-item{margin-bottom:5px}.form-file-item .el-upload{width:60px;height:60px;line-height:60px}.form-file-item .file-item .name{width:100px}.form-file-item .name{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.form-list .form-common-item{display:flex;margin-bottom:5px}.form-common-item .name,.form-common-item .value{width:88px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list .select-list-item{display:flex;margin-bottom:5px}.select-list-item .name{width:76px}.select-list-item .name,.select-list-item .value{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list-item .value{width:77px}.select-wrap{text-align:left;margin-bottom:5px}.select-wrap .select-add-name{display:inline-block;width:87px;text-align:right}.select-wrap .el-input{width:84px}.el-input__inner{padding-left:10px;padding-right:5px}.el-upload{height:60px;width:60px;background:#eee;overflow:hidden}
|
1
example/tpt/css/chunk-1dd2a8d0.e4ca99de.css
Normal file
1
example/tpt/css/chunk-1dd2a8d0.e4ca99de.css
Normal file
@ -0,0 +1 @@
|
||||
.not-show-tab-label .el-tabs__header,.not-show-tab-search{display:none}
|
@ -1 +0,0 @@
|
||||
.full-screen-container[data-v-12e6b782]{z-index:10000}.file-upload .el-upload{background:transparent;width:100%;height:auto;text-align:left;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.file-upload .el-upload .el-button{margin-right:10px}.el-upload img[data-v-69e31561]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-69e31561]{font-size:40px;margin:30% 31%;display:block}.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}
|
@ -1 +0,0 @@
|
||||
.left-nav-home-bar{background:#2c3759!important;overflow:hidden;text-overflow:ellipsis}.left-nav-home-bar,.left-nav-home-bar i{color:#fff!important}.el-submenu .el-menu-item{height:40px;line-height:40px;width:auto;min-width:60px;padding:0 10px 0 25px!important;text-overflow:ellipsis;overflow:hidden}.el-menu .el-submenu__title{height:46px;line-height:46px;padding-left:10px!important;text-overflow:ellipsis;overflow:hidden}.left-nav-home-bar i{margin-bottom:6px!important}.el-menu-item-group__title{padding:0 0 0 10px}.el-menu--collapse .el-menu-item-group__title,.el-menu--collapse .el-submenu__title{padding-left:20px!important}.el-menu-item i,.el-submenu__title i{margin-top:-4px;vertical-align:middle;margin:-3px 5px 0 0;right:1px}.head-left[data-v-b2941c10],.head-right[data-v-b2941c10]{display:flex;justify-content:center;flex-direction:column}.head-right[data-v-b2941c10]{align-items:flex-end}.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.el-upload img[data-v-51dbed3c]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-51dbed3c]{font-size:40px;margin:30% 31%;display:block}.custom-tree-node[data-v-51dbed3c]{font-size:14px;padding-right:8px}.info-descriptions[data-v-4d4566fc] .el-descriptions__body .el-descriptions__label{min-width:90px;text-align:right;background:transparent;color:#606266;font-weight:400}.el-descriptions .is-bordered th[data-v-4d4566fc],.info-descriptions[data-v-4d4566fc] .el-descriptions .is-bordered td{border:transparent;max-width:25vw}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}.dialog-box .el-descriptions__header{margin:20px 0 5px}.dialog-box .el-descriptions__body{background:#fff}.textarea-box *{word-break:break-all;white-space:pre-wrap}.textarea-box table{width:100%!important}.textarea-box img{max-width:80%!important}.textarea-box::-webkit-scrollbar-thumb{height:5px;background-color:rgba(0,0,0,.2)!important}.el-dialog{margin:auto!important;top:50%;transform:translateY(-50%)}.el-dialog-div{height:75vh;overflow:auto}.el-dialog__body{padding-top:15px;padding-bottom:45px}.el-dialog-div .el-tabs__header{position:absolute;left:1px;top:69px;width:calc(90vw - 42px);margin:0 20px;z-index:1}.el-dialog-div .el-tabs__content{padding-top:50px}.el-dialog-div .el-affix--fixed{bottom:20vh}.el-dialog-div .el-affix--fixed .el-form-item{padding:0!important;background:transparent!important}
|
1
example/tpt/css/chunk-2f62f180.5c448e68.css
Normal file
1
example/tpt/css/chunk-2f62f180.5c448e68.css
Normal file
@ -0,0 +1 @@
|
||||
.el-upload{height:100px;width:100px}.el-upload img[data-v-012633a9]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-012633a9]{font-size:40px;margin:30% 31%;display:block}.form-file-item .upload-file .el-upload{width:100px;height:auto;line-height:0;background-color:transparent}.form-file-item .el-button--small{height:32px}.el-input-number--mini{width:100px;margin-right:5px}.el-input-number--mini .el-input{width:100px!important}.basic-form{width:400px}.basic-form .el-input,.basic-form .el-select{width:84px;margin-right:5px}.form-file-item{margin-bottom:5px}.form-file-item .el-upload{width:60px;height:60px;line-height:60px}.form-file-item .file-item .name{width:100px}.form-file-item .name{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.form-list .form-common-item{display:flex;margin-bottom:5px}.form-common-item .name,.form-common-item .value{width:88px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list .select-list-item{display:flex;margin-bottom:5px}.select-list-item .name{width:76px}.select-list-item .name,.select-list-item .value{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list-item .value{width:77px}.select-wrap{text-align:left;margin-bottom:5px}.select-wrap .select-add-name{display:inline-block;width:87px;text-align:right}.select-wrap .el-input{width:84px}.el-input__inner{padding-left:10px;padding-right:5px}.el-upload{height:60px;width:60px;background:#eee;overflow:hidden}
|
@ -1 +0,0 @@
|
||||
.full-screen-container[data-v-12e6b782]{z-index:10000}.file-upload .el-upload{background:transparent;width:100%;height:auto;text-align:left;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.file-upload .el-upload .el-button{margin-right:10px}.el-upload img[data-v-96cdfb38]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-96cdfb38]{font-size:40px;margin:30% 31%;display:block}.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}
|
@ -1 +0,0 @@
|
||||
.not-show-tab-label .el-tabs__header{display:none}.el-descriptions__body{background:#f0f0f0}.not-show-tab-search{display:none}.el-table__body-wrapper{margin-bottom:4px;padding-bottom:2px}.el-table__body-wrapper::-webkit-scrollbar{width:8px;height:8px}.el-table__body-wrapper::-webkit-scrollbar-track{border-radius:10px;-webkit-box-shadow:inset 0 0 6px hsla(0,0%,93.3%,.3);background-color:#eee}.el-table__body-wrapper::-webkit-scrollbar-thumb{border-radius:10px;-webkit-box-shadow:inset 0 0 6px rgba(145,143,143,.3);background-color:#918f8f}.input-with-select .el-input-group__prepend{background-color:#fff}.daterange-box .select .el-input__inner{border-top-right-radius:0;border-bottom-right-radius:0}.daterange-box .daterange.el-input__inner{border-top-left-radius:0;border-bottom-left-radius:0;vertical-align:bottom}[data-v-e9f58da4] .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content{background-color:#409eff!important;color:#fff}
|
@ -1 +0,0 @@
|
||||
.left-nav-home-bar{background:#2c3759!important;overflow:hidden;text-overflow:ellipsis}.left-nav-home-bar,.left-nav-home-bar i{color:#fff!important}.el-submenu .el-menu-item{height:40px;line-height:40px;width:auto;min-width:60px;padding:0 10px 0 25px!important;text-overflow:ellipsis;overflow:hidden}.el-menu .el-submenu__title{height:46px;line-height:46px;padding-left:10px!important;text-overflow:ellipsis;overflow:hidden}.left-nav-home-bar i{margin-bottom:6px!important}.el-menu-item-group__title{padding:0 0 0 10px}.el-menu--collapse .el-menu-item-group__title,.el-menu--collapse .el-submenu__title{padding-left:20px!important}.el-menu-item i,.el-submenu__title i{margin-top:-4px;vertical-align:middle;margin:-3px 5px 0 0;right:1px}.head-left[data-v-b2941c10],.head-right[data-v-b2941c10]{display:flex;justify-content:center;flex-direction:column}.head-right[data-v-b2941c10]{align-items:flex-end}.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.el-upload img[data-v-3b5105e6]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-3b5105e6]{font-size:40px;margin:30% 31%;display:block}.custom-tree-node[data-v-3b5105e6]{font-size:14px;padding-right:8px}.info-descriptions[data-v-4d4566fc] .el-descriptions__body .el-descriptions__label{min-width:90px;text-align:right;background:transparent;color:#606266;font-weight:400}.el-descriptions .is-bordered th[data-v-4d4566fc],.info-descriptions[data-v-4d4566fc] .el-descriptions .is-bordered td{border:transparent;max-width:25vw}.tree-line .el-tree-node{position:relative;padding-left:16px}.tree-line .el-tree-node__content{line-height:18px;font-size:14px}.tree-line .el-tree-node__children{padding-left:16px}.tree-line .el-tree-node:before{content:"";height:100%;width:1px;position:absolute;left:-3px;top:-26px;border-width:1px;border-left:1px dashed #52627c}.tree-line .el-tree-node:last-child:before{height:38px}.tree-line .el-tree-node:after{content:"";width:24px;height:20px;position:absolute;left:-3px;top:12px;border-width:1px;border-top:1px dashed #52627c}.tree-line>.el-tree-node:after{border-top:none}.tree-line>.el-tree-node:before{border-left:none}.tree-line .el-tree-node__expand-icon{font-size:18px;color:#000}.tree-line .el-tree-node__expand-icon.is-leaf{color:transparent}.dialog-box .el-descriptions__header{margin:20px 0 5px}.dialog-box .el-descriptions__body{background:#fff}.textarea-box *{word-break:break-all;white-space:pre-wrap}.textarea-box table{width:100%!important}.textarea-box img{max-width:80%!important}.textarea-box::-webkit-scrollbar-thumb{height:5px;background-color:rgba(0,0,0,.2)!important}.el-dialog{margin:auto!important;top:50%;transform:translateY(-50%)}.el-dialog-div{height:75vh;overflow:auto}.el-dialog__body{padding-top:15px;padding-bottom:45px}.el-dialog-div .el-tabs__header{position:absolute;left:1px;top:69px;width:calc(90vw - 42px);margin:0 20px;z-index:1}.el-dialog-div .el-tabs__content{padding-top:50px}.el-dialog-div .el-affix--fixed{bottom:20vh}.el-dialog-div .el-affix--fixed .el-form-item{padding:0!important;background:transparent!important}
|
File diff suppressed because one or more lines are too long
1
example/tpt/css/chunk-a74869b6.c460e209.css
Normal file
1
example/tpt/css/chunk-a74869b6.c460e209.css
Normal file
@ -0,0 +1 @@
|
||||
body[data-v-581864d3],dd[data-v-581864d3],dl[data-v-581864d3],form[data-v-581864d3],h1[data-v-581864d3],h2[data-v-581864d3],h3[data-v-581864d3],h4[data-v-581864d3],h5[data-v-581864d3],h6[data-v-581864d3],html[data-v-581864d3],ol[data-v-581864d3],p[data-v-581864d3],pre[data-v-581864d3],tbody[data-v-581864d3],textarea[data-v-581864d3],tfoot[data-v-581864d3],thead[data-v-581864d3],ul[data-v-581864d3]{margin:0;font-size:14px;font-family:Microsoft YaHei}dl[data-v-581864d3],ol[data-v-581864d3],ul[data-v-581864d3]{padding:0}li[data-v-581864d3]{list-style:none}input[data-v-581864d3]{border:none;outline:none;font-family:Microsoft YaHei;background-color:#fff}a[data-v-581864d3]{font-family:Microsoft YaHei;text-decoration:none}[data-v-581864d3]{margin:0;padding:0}.login[data-v-581864d3]{position:relative;width:100%;height:100%;background-color:#353d56}.login-item[data-v-581864d3]{position:absolute;top:calc(50% - 244px);left:calc(50% - 244px);width:488px;height:488px;padding:80px 0 152px 0;box-sizing:border-box;background-size:468px 468px}.login-item .left-title[data-v-581864d3]{display:inline-block;width:236px;height:100%;border-right:2px solid #88919e;text-align:center;padding-top:68px;box-sizing:border-box}.login-item .left-title p[data-v-581864d3]{font-size:30px;line-height:50px;color:#fff}.login-item .right-content[data-v-581864d3]{display:inline-block;vertical-align:top;padding-left:42px;box-sizing:border-box}.login-item .right-content .login-title[data-v-581864d3]{font-size:16px;color:#fff}.errorMsg[data-v-581864d3]{width:100%;height:34px;line-height:34px;color:red;font-size:14px;overflow:hidden}.login-item .right-content .inputWrap[data-v-581864d3]{width:204px;height:36px;line-height:36px;color:#99a3b2;font-size:14px;border-bottom:3px solid #98a2b1;margin-bottom:10px}.login-item .right-content .inputWrap input[data-v-581864d3]{background-color:transparent;color:#99a3b2}.login-btn[data-v-581864d3]{width:88px;height:36px;text-align:center;line-height:36px;font-size:14px;color:#fff;background-color:#4f619b;border-radius:18px;margin-top:60px;cursor:pointer}
|
1
example/tpt/css/chunk-b504df5c.61d7456c.css
Normal file
1
example/tpt/css/chunk-b504df5c.61d7456c.css
Normal file
@ -0,0 +1 @@
|
||||
.form-file-item .upload-file .el-upload{width:100px;height:auto;line-height:0;background-color:transparent}.form-file-item .el-button--small{height:32px}.el-input-number--mini{width:100px;margin-right:5px}.el-input-number--mini .el-input{width:100px!important}.basic-form{width:400px}.basic-form .el-input,.basic-form .el-select{width:84px;margin-right:5px}.form-file-item{margin-bottom:5px}.form-file-item .el-upload{width:60px;height:60px;line-height:60px}.form-file-item .file-item .name{width:100px}.form-file-item .name{width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.form-list .form-common-item{display:flex;margin-bottom:5px}.form-common-item .name,.form-common-item .value{width:88px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list .select-list-item{display:flex;margin-bottom:5px}.select-list-item .name{width:76px}.select-list-item .name,.select-list-item .value{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-list-item .value{width:77px}.select-wrap{text-align:left;margin-bottom:5px}.select-wrap .select-add-name{display:inline-block;width:87px;text-align:right}.select-wrap .el-input{width:84px}.el-input__inner{padding-left:10px;padding-right:5px}.el-upload,.el-upload-list--picture-card .el-upload-list__item{height:60px;width:60px}.el-upload-list__item.is-success.focusing .el-icon-close-tip{display:none!important}.el-upload{height:100px;width:100px;background:#eee;overflow:hidden}.file-upload .el-upload{background:transparent;width:100%;height:auto;text-align:left;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.file-upload .el-upload .el-button{margin-right:10px}.el-upload img[data-v-4b440c12]{height:100%;width:100%;-o-object-fit:cover;object-fit:cover;display:block}.el-upload i[data-v-4b440c12]{font-size:40px;margin:30% 31%;display:block}
|
1
example/tpt/css/chunk-d1a9ebe6.5cc24c46.css
Normal file
1
example/tpt/css/chunk-d1a9ebe6.5cc24c46.css
Normal file
@ -0,0 +1 @@
|
||||
h3[data-v-28af1b93]{margin:40px 0 0}ul[data-v-28af1b93]{list-style-type:none;padding:0}li[data-v-28af1b93]{display:inline-block;margin:0 10px}a[data-v-28af1b93]{color:#42b983}
|
@ -1 +0,0 @@
|
||||
.full-screen-container[data-v-12e6b782]{z-index:10000}.not-show-tab-label .el-tabs__header{display:none}.el-descriptions__body{background:#f0f0f0}.not-show-tab-search{display:none}.el-table__body-wrapper{margin-bottom:4px;padding-bottom:2px}.el-table__body-wrapper::-webkit-scrollbar{width:8px;height:8px}.el-table__body-wrapper::-webkit-scrollbar-track{border-radius:10px;-webkit-box-shadow:inset 0 0 6px hsla(0,0%,93.3%,.3);background-color:#eee}.el-table__body-wrapper::-webkit-scrollbar-thumb{border-radius:10px;-webkit-box-shadow:inset 0 0 6px rgba(145,143,143,.3);background-color:#918f8f}
|
BIN
example/tpt/file/2021/11/13/9111bcfcaf8b8240976dc08e97658605.png
Normal file
BIN
example/tpt/file/2021/11/13/9111bcfcaf8b8240976dc08e97658605.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 297 KiB |
BIN
example/tpt/file/2021/11/13/9129a3b12a8eb56a47da20135f8106bc.png
Normal file
BIN
example/tpt/file/2021/11/13/9129a3b12a8eb56a47da20135f8106bc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 120 KiB |
BIN
example/tpt/file/2021/12/27/a24a4bc4d8f4947de0eed6bcf9b7186c.jpg
Normal file
BIN
example/tpt/file/2021/12/27/a24a4bc4d8f4947de0eed6bcf9b7186c.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
<!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"><script src="js/manage.js"></script><script src="https://api.map.baidu.com/api?v=2.0&ak=bF4Y6tQg94hV2vesn2ZIaUIXO4aRxxRk"></script><title></title><style>body{
|
||||
<!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></title><style>body{
|
||||
margin: 0px;
|
||||
}</style><link href="css/chunk-0de923e9.c4e8272a.css" rel="prefetch"><link href="css/chunk-1a458102.466135f0.css" rel="prefetch"><link href="css/chunk-291edee4.508cb3c8.css" rel="prefetch"><link href="css/chunk-4aefa5ec.fcc75990.css" rel="prefetch"><link href="css/chunk-4f81d902.91f1ef17.css" rel="prefetch"><link href="css/chunk-856f3c38.9b9508b8.css" rel="prefetch"><link href="css/chunk-e3f8e5a6.7876554f.css" rel="prefetch"><link href="js/chunk-0de923e9.1f0fca7e.js" rel="prefetch"><link href="js/chunk-1a458102.9a54e9ae.js" rel="prefetch"><link href="js/chunk-25ddb50b.55ec750b.js" rel="prefetch"><link href="js/chunk-291edee4.e8dbe8c8.js" rel="prefetch"><link href="js/chunk-4aefa5ec.c237610d.js" rel="prefetch"><link href="js/chunk-4f81d902.c5fdb7dd.js" rel="prefetch"><link href="js/chunk-7ea17297.38d572ef.js" rel="prefetch"><link href="js/chunk-856f3c38.29c2fcc0.js" rel="prefetch"><link href="js/chunk-e3f8e5a6.ff58e6f8.js" rel="prefetch"><link href="js/chunk-e624c1ca.62513cbc.js" rel="prefetch"><link href="css/app.abfb5de2.css" rel="preload" as="style"><link href="js/app.25e49e88.js" rel="preload" as="script"><link href="css/app.abfb5de2.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.25e49e88.js"></script></body></html>
|
||||
}</style><link href="css/chunk-2b8aef56.7087d841.css" rel="prefetch"><link href="css/chunk-38db7d04.2b6ce0ac.css" rel="prefetch"><link href="css/chunk-5c99f384.31e35517.css" rel="prefetch"><link href="css/chunk-60f282ff.83752cba.css" rel="prefetch"><link href="css/chunk-a74869b6.c460e209.css" rel="prefetch"><link href="css/chunk-d1a9ebe6.5cc24c46.css" rel="prefetch"><link href="js/chunk-28c289a1.0ed6fefe.js" rel="prefetch"><link href="js/chunk-2b8aef56.8330998b.js" rel="prefetch"><link href="js/chunk-2c065dd6.d9c3e429.js" rel="prefetch"><link href="js/chunk-38db7d04.18ee879a.js" rel="prefetch"><link href="js/chunk-58db4e7f.c298e695.js" rel="prefetch"><link href="js/chunk-5c99f384.be52d852.js" rel="prefetch"><link href="js/chunk-60f282ff.cbb91cc0.js" rel="prefetch"><link href="js/chunk-78ba61e2.520b239c.js" rel="prefetch"><link href="js/chunk-a74869b6.01e5db7b.js" rel="prefetch"><link href="js/chunk-d1a9ebe6.fba0f501.js" rel="prefetch"><link href="css/app.5e2eb449.css" rel="preload" as="style"><link href="js/app.c87636c4.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.c87636c4.js"></script></body></html>
|
File diff suppressed because one or more lines are too long
42
example/tpt/js/app.3ff414bb.js
Normal file
42
example/tpt/js/app.3ff414bb.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-0de923e9"],{"578a":function(o,n,t){"use strict";t.r(n);t("b0c0");var i=t("f2bf"),s={class:"login-item"},r={class:"right-content"},u={class:"login-title"},l={style:{height:"60px"}},d=Object(i.r)(" 账号:"),b=Object(i.r)(" 密码:");var e=t("2934"),c={name:"Login",data:function(){return{showLog:!1,showLogInfo:"",label:"HoTime DashBoard",form:{name:"",password:""},backgroundImage:window.Hotime.data.name+"/hotime/wallpaper?random=1&type=1",focusName:!1,focusPassword:!1}},methods:{login:function(){var n=this;if(""==this.name||""==this.password)return this.showLogInfo="参数不足!",void(this.showLog=!0);Object(e.a)(window.Hotime.data.name+"/hotime/login",n.form).then(function(o){if(0!=o.status)return n.showLogInfo=o.error.msg,void(n.showLog=!0);location.hash="#/",location.reload()})},getBgImg:function(){var n=this;Object(e.e)(window.Hotime.data.name+"/hotime/wallpaper?random=1").then(function(o){0==o.status&&(n.backgroundImage=o.result.url)})},focusPrice:function(o){this["focus"+o]=!0},blurPrice:function(o){this["focus"+o]=!1}},mounted:function(){var n=this;this.label=window.Hotime.data.label,document.onkeydown=function(o){o=window.event||o;13==(o.keyCode||o.which||o.charCode)&&n.login()}}},a=(t("fad9"),t("6b0d")),t=t.n(a);n.default=t()(c,[["render",function(o,n,t,e,c,a){return Object(i.L)(),Object(i.n)("div",{class:"login",style:Object(i.C)({width:"100%",height:"100vh","background-image":"url("+c.backgroundImage+")"})},[Object(i.o)("div",s,[Object(i.o)("div",r,[Object(i.o)("p",u,Object(i.Y)(c.label),1),Object(i.o)("div",l,[Object(i.lb)(Object(i.o)("p",{class:"errorMsg"},Object(i.Y)(c.showLogInfo),513),[[i.hb,c.showLog]])]),Object(i.o)("p",{class:Object(i.B)(["inputWrap",{inputFocus:c.focusName}])},[d,Object(i.lb)(Object(i.o)("input",{type:"text","onUpdate:modelValue":n[0]||(n[0]=function(o){return c.form.name=o}),class:"accountVal",onKeyup:n[1]||(n[1]=Object(i.mb)(function(){return a.login&&a.login.apply(a,arguments)},["enter"])),onFocus:n[2]||(n[2]=function(o){return a.focusPrice("Name")}),onBlur:n[3]||(n[3]=function(o){return a.blurPrice("Name")})},null,544),[[i.gb,c.form.name]])],2),Object(i.o)("p",{class:Object(i.B)(["inputWrap",{inputFocus:c.focusPassword}])},[b,Object(i.lb)(Object(i.o)("input",{type:"password","onUpdate:modelValue":n[4]||(n[4]=function(o){return c.form.password=o}),class:"passwordVal",onKeyup:n[5]||(n[5]=Object(i.mb)(function(){return a.login&&a.login.apply(a,arguments)},["enter"])),onFocus:n[6]||(n[6]=function(o){return a.focusPrice("Password")}),onBlur:n[7]||(n[7]=function(o){return a.blurPrice("Password")})},null,544),[[i.gb,c.form.password]])],2),Object(i.o)("p",{class:"login-btn",onClick:n[8]||(n[8]=function(){return a.login&&a.login.apply(a,arguments)})},"登录")])])],4)}],["__scopeId","data-v-c08f3364"]])},dbeb:function(o,n,t){},fad9:function(o,n,t){"use strict";t("dbeb")}}]);
|
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-1afce11c.fbe5a1b4.js
Normal file
1
example/tpt/js/chunk-1afce11c.fbe5a1b4.js
Normal file
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-1dd2a8d0.c3cd4fb6.js
Normal file
1
example/tpt/js/chunk-1dd2a8d0.c3cd4fb6.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-25ddb50b"],{"107c":function(t,e,n){var r=n("d039"),c=n("da84").RegExp;t.exports=r(function(){var t=c("(?<a>b)","g");return"b"!==t.exec("b").groups.a||"bc"!=="b".replace(t,"$<a>c")})},"129f":function(t,e){t.exports=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}},"14c3":function(t,e,n){var r=n("c6b6"),c=n("9263");t.exports=function(t,e){var n=t.exec;if("function"==typeof n){n=n.call(t,e);if("object"!=typeof n)throw TypeError("RegExp exec method returned something other than an Object or null");return n}if("RegExp"!==r(t))throw TypeError("RegExp#exec called on incompatible receiver");return c.call(t,e)}},"159b":function(t,e,n){var r,c=n("da84"),i=n("fdbc"),o=n("17c2"),a=n("9112");for(r in i){var l=c[r],l=l&&l.prototype;if(l&&l.forEach!==o)try{a(l,"forEach",o)}catch(t){l.forEach=o}}},"17c2":function(t,e,n){"use strict";var r=n("b727").forEach,n=n("a640")("forEach");t.exports=n?[].forEach:function(t){return r(this,t,1<arguments.length?arguments[1]:void 0)}},"83c5":function(t,e,n){"use strict";n("159b");e.a={list:{},constructor:function(){this.list={}},$on:function(t,e){this.list[t]=this.list[t]||[],this.list[t].push(e)},$emit:function(t,e){this.list[t]&&this.list[t].forEach(function(t){t(e)})},$off:function(t){this.list[t]&&delete this.list[t]}}},"841c":function(t,e,n){"use strict";var r=n("d784"),o=n("825a"),a=n("1d80"),l=n("129f"),s=n("577e"),u=n("14c3");r("search",function(r,c,i){return[function(t){var e=a(this),n=null==t?void 0:t[r];return void 0!==n?n.call(t,e):new RegExp(t)[r](s(e))},function(t){var e=o(this),t=s(t),n=i(c,e,t);if(n.done)return n.value;n=e.lastIndex,l(n,0)||(e.lastIndex=0),t=u(e,t);return l(e.lastIndex,n)||(e.lastIndex=n),null===t?-1:t.index}]})},9263:function(t,e,n){"use strict";var r,p=n("577e"),h=n("ad6d"),c=n("9f7f"),i=n("5692"),g=n("7c73"),v=n("69f3").get,o=n("fce3"),n=n("107c"),E=RegExp.prototype.exec,b=i("native-string-replace",String.prototype.replace),I=E,R=(i=/a/,r=/b*/g,E.call(i,"a"),E.call(r,"a"),0!==i.lastIndex||0!==r.lastIndex),y=c.UNSUPPORTED_Y||c.BROKEN_CARET,w=void 0!==/()??/.exec("")[1];(R||w||y||o||n)&&(I=function(t){var e,n,r,c,i,o,a=this,l=v(a),t=p(t),s=l.raw;if(s)return s.lastIndex=a.lastIndex,f=I.call(s,t),a.lastIndex=s.lastIndex,f;var u=l.groups,s=y&&a.sticky,f=h.call(a),l=a.source,d=0,x=t;if(s&&(-1===(f=f.replace("y","")).indexOf("g")&&(f+="g"),x=t.slice(a.lastIndex),0<a.lastIndex&&(!a.multiline||a.multiline&&"\n"!==t.charAt(a.lastIndex-1))&&(l="(?: "+l+")",x=" "+x,d++),e=new RegExp("^(?:"+l+")",f)),w&&(e=new RegExp("^"+l+"$(?!\\s)",f)),R&&(n=a.lastIndex),r=E.call(s?e:a,x),s?r?(r.input=r.input.slice(d),r[0]=r[0].slice(d),r.index=a.lastIndex,a.lastIndex+=r[0].length):a.lastIndex=0:R&&r&&(a.lastIndex=a.global?r.index+r[0].length:n),w&&r&&1<r.length&&b.call(r[0],e,function(){for(c=1;c<arguments.length-2;c++)void 0===arguments[c]&&(r[c]=void 0)}),r&&u)for(r.groups=i=g(null),c=0;c<u.length;c++)i[(o=u[c])[0]]=r[o[1]];return r}),t.exports=I},"9f7f":function(t,e,n){var r=n("d039"),c=n("da84").RegExp;e.UNSUPPORTED_Y=r(function(){var t=c("a","y");return t.lastIndex=2,null!=t.exec("abcd")}),e.BROKEN_CARET=r(function(){var t=c("^r","gy");return t.lastIndex=2,null!=t.exec("str")})},ac1f:function(t,e,n){"use strict";var r=n("23e7"),n=n("9263");r({target:"RegExp",proto:!0,forced:/./.exec!==n},{exec:n})},ad6d:function(t,e,n){"use strict";var r=n("825a");t.exports=function(){var t=r(this),e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.sticky&&(e+="y"),e}},d784:function(t,e,n){"use strict";n("ac1f");var l=n("6eeb"),s=n("9263"),u=n("d039"),f=n("b622"),d=n("9112"),x=f("species"),p=RegExp.prototype;t.exports=function(n,t,e,r){var o,c=f(n),a=!u(function(){var t={};return t[c]=function(){return 7},7!=""[n](t)}),i=a&&!u(function(){var t=!1,e=/a/;return"split"===n&&((e={constructor:{}}).constructor[x]=function(){return e},e.flags="",e[c]=/./[c]),e.exec=function(){return t=!0,null},e[c](""),!t});a&&i&&!e||(o=/./[c],i=t(c,""[n],function(t,e,n,r,c){var i=e.exec;return i===s||i===p.exec?a&&!c?{done:!0,value:o.call(e,n,r)}:{done:!0,value:t.call(n,e,r)}:{done:!1}}),l(String.prototype,n,i[0]),l(p,c,i[1])),r&&d(p[c],"sham",!0)}},fce3:function(t,e,n){var r=n("d039"),c=n("da84").RegExp;t.exports=r(function(){var t=c(".","s");return!(t.dotAll&&t.exec("\n")&&"s"===t.flags)})}}]);
|
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-2c065dd6.99c035f4.js
Normal file
1
example/tpt/js/chunk-2c065dd6.99c035f4.js
Normal file
@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-2c065dd6"],{1:function(t,e){},2934:function(t,e,n){"use strict";n.d(e,"e",function(){return o}),n.d(e,"d",function(){return a}),n.d(e,"b",function(){return s}),n.d(e,"c",function(){return u}),n.d(e,"a",function(){return c}),n.d(e,"f",function(){return d});var e=n("b0c0"),r=n("b775"),e=n("4328"),i=n.n(e);function o(t,e){return Object(r.b)({url:t,method:"GET",params:e})}function a(t,e){return Object(r.b)({url:t,method:"GET",params:e})}function s(t,e){return Object(r.b)({url:t,method:"DELETE",data:i.a.stringify(e)})}function u(t,e){return Object(r.b)({url:t,method:"PUT",data:i.a.stringify(e)})}function c(t,e){return Object(r.b)({url:t,method:"POST",data:i.a.stringify(e)})}function d(t){var e=new FormData;return e.append("file",t,t.name),Object(r.b)({url:"file",headers:{"Content-Type":"multipart/form-data"},method:"POST",data:e})}},"83c5":function(t,e,n){"use strict";n("159b");e.a={list:{},constructor:function(){this.list={}},$on:function(t,e){this.list[t]=this.list[t]||[],this.list[t].push(e)},$emit:function(t,e){this.list[t]&&this.list[t].forEach(function(t){t(e)})},$off:function(t){this.list[t]&&delete this.list[t]}}},b775:function(t,e,n){"use strict";n.d(e,"a",function(){return u});var r=n("d3b7"),i=n("bc3a"),r=n.n(i),i=n("4328"),o=n.n(i),a=n("2bea"),s=n("56d7"),u="";r.a.defaults.withCredentials=!0,r.a.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8";r=r.a.create({baseURL:u,timeout:2e4});r.interceptors.request.use(function(t){return"get"===t.method&&(t.paramsSerializer=function(t){return o.a.stringify(t,{arrayFormat:"repeat"})}),t.withCredentials=!0,t},function(t){Promise.reject(t)}),r.interceptors.response.use(function(t){return 2!==t.data.statu?t.data:(a.b.Message({showClose:!0,message:"登录信息丢失,请重新登陆!",type:"error",duration:2e3,offset:100}),void s.app.$router.push({path:"/login"}))},function(t){var e="err:"+t,n={};return t.response?n=t.response.data:(-1!=e.indexOf("timeout")?(n.code=500,n.message="请求超时,请稍后再试"):-1!=e.indexOf("Network Error")?(n.code=500,n.message="网络错误,请稍后再试"):(n.code=500,n.message=""+t),n)}),e.b=r}}]);
|
1
example/tpt/js/chunk-2f62f180.820cf5fd.js
Normal file
1
example/tpt/js/chunk-2f62f180.820cf5fd.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-58db4e7f.c298e695.js
Normal file
1
example/tpt/js/chunk-58db4e7f.c298e695.js
Normal file
@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-58db4e7f"],{"159b":function(c,n,o){var r,t=o("da84"),a=o("fdbc"),f=o("17c2"),i=o("9112");for(r in a){var u=t[r],u=u&&u.prototype;if(u&&u.forEach!==f)try{i(u,"forEach",f)}catch(c){u.forEach=f}}},"17c2":function(c,n,o){"use strict";var r=o("b727").forEach,o=o("a640")("forEach");c.exports=o?[].forEach:function(c){return r(this,c,1<arguments.length?arguments[1]:void 0)}},a640:function(c,n,o){"use strict";var r=o("d039");c.exports=function(c,n){var o=[][c];return!!o&&r(function(){o.call(null,n||function(){throw 1},1)})}}}]);
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-78ba61e2.520b239c.js
Normal file
1
example/tpt/js/chunk-78ba61e2.520b239c.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
example/tpt/js/chunk-a74869b6.59e9b13d.js
Normal file
1
example/tpt/js/chunk-a74869b6.59e9b13d.js
Normal file
@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-a74869b6"],{1:function(t,e){},2934:function(t,e,n){"use strict";n.d(e,"e",function(){return a}),n.d(e,"d",function(){return s}),n.d(e,"b",function(){return i}),n.d(e,"c",function(){return c}),n.d(e,"a",function(){return u}),n.d(e,"f",function(){return d});var e=n("b0c0"),o=n("b775"),e=n("4328"),r=n.n(e);function a(t,e){return Object(o.b)({url:t,method:"GET",params:e})}function s(t,e){return Object(o.b)({url:t,method:"GET",params:e})}function i(t,e){return Object(o.b)({url:t,method:"DELETE",data:r.a.stringify(e)})}function c(t,e){return Object(o.b)({url:t,method:"PUT",data:r.a.stringify(e)})}function u(t,e){return Object(o.b)({url:t,method:"POST",data:r.a.stringify(e)})}function d(t){var e=new FormData;return e.append("file",t,t.name),Object(o.b)({url:"file",headers:{"Content-Type":"multipart/form-data"},method:"POST",data:e})}},"40a7":function(t,e,n){},"578a":function(t,e,n){"use strict";n.r(e);n("b0c0");var s=n("9f9f");Object(s.O)("data-v-581864d3");var i={class:"login",style:{width:"100%",height:"100vh"}},c={class:"login-item"},u={class:"left-title"},d={class:"right-content"},l=Object(s.o)("p",{class:"login-title"},"登录",-1),f={style:{height:"40px"}},b={class:"inputWrap"},p=Object(s.r)(" 账号:"),m={class:"inputWrap"},h=Object(s.r)(" 密码:");Object(s.M)();var o=n("2934"),r={name:"Login",data:function(){return{showLog:!1,showLogInfo:"",label:"HoTime DashBoard",form:{name:"",password:""}}},methods:{login:function(){var e=this;if(""==this.name||""==this.password)return this.showLogInfo="参数不足!",void(this.showLog=!0);Object(o.a)(window.Hotime.data.name+"/hotime/login",e.form).then(function(t){return 0!=t.status?(e.showLogInfo=t.error.msg,void(e.showLog=!0)):void e.$router.push({path:"/"})})}},mounted:function(){this.label=window.Hotime.data.label}};n("8d39");r.render=function(t,e,n,o,r,a){return Object(s.L)(),Object(s.n)("div",i,[Object(s.o)("div",c,[Object(s.o)("div",u,[Object(s.o)("p",null,Object(s.Y)(r.label),1)]),Object(s.o)("div",d,[l,Object(s.o)("div",f,[Object(s.kb)(Object(s.o)("p",{class:"errorMsg"},Object(s.Y)(r.showLogInfo),513),[[s.gb,r.showLog]])]),Object(s.o)("p",b,[p,Object(s.kb)(Object(s.o)("input",{type:"text","onUpdate:modelValue":e[0]||(e[0]=function(t){return r.form.name=t}),class:"accountVal"},null,512),[[s.fb,r.form.name]])]),Object(s.o)("p",m,[h,Object(s.kb)(Object(s.o)("input",{type:"password","onUpdate:modelValue":e[1]||(e[1]=function(t){return r.form.password=t}),class:"passwordVal"},null,512),[[s.fb,r.form.password]])]),Object(s.o)("p",{class:"login-btn",onClick:e[2]||(e[2]=function(){return a.login&&a.login.apply(a,arguments)})},"登录")])])])},r.__scopeId="data-v-581864d3";e.default=r},"8d39":function(t,e,n){"use strict";n("40a7")},b775:function(t,e,n){"use strict";n.d(e,"a",function(){return c});var o=n("d3b7"),r=n("bc3a"),o=n.n(r),r=n("4328"),a=n.n(r),s=n("2bea"),i=n("56d7"),c="";o.a.defaults.withCredentials=!0,o.a.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded;charset=UTF-8";o=o.a.create({baseURL:c,timeout:2e4});o.interceptors.request.use(function(t){return"get"===t.method&&(t.paramsSerializer=function(t){return a.a.stringify(t,{arrayFormat:"repeat"})}),t.withCredentials=!0,t},function(t){Promise.reject(t)}),o.interceptors.response.use(function(t){return 2!==t.data.statu?t.data:(s.b.Message({showClose:!0,message:"登录信息丢失,请重新登陆!",type:"error",duration:2e3,offset:100}),void i.app.$router.push({path:"/login"}))},function(t){var e="err:"+t,n={};return t.response?n=t.response.data:(-1!=e.indexOf("timeout")?(n.code=500,n.message="请求超时,请稍后再试"):-1!=e.indexOf("Network Error")?(n.code=500,n.message="网络错误,请稍后再试"):(n.code=500,n.message=""+t),n)}),e.b=o}}]);
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user