Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 136232dd57 | |||
| 008f19355c | |||
| 1fc0a5bbbc | |||
| ce099b8fc8 | |||
| 9c00ac6ba1 | |||
| a5c002bbce | |||
| cf50a699a6 | |||
| 662003c0ca | |||
| f24de2562a | |||
| b84bd7e16f | |||
| 2fb6abf53a | |||
| 2eab29f428 | |||
| 84ee0d259f | |||
| eccab42fc8 | |||
| 1465ba36d3 | |||
| 8380b097b2 | |||
| 6b8f901163 | |||
| bb16f0a75b | |||
| 84dbc5d71e | |||
| 166eeee64c | |||
| 7a649fd652 | |||
| 94ae568526 | |||
| 9ec597f26c | |||
| 388bc5006d | |||
| 0e33c2ad9d | |||
| af726fbcfb | |||
| 1e82a5964d | |||
| d62ba8b0cd | |||
| 320ebe25ec | |||
| 68257d1742 | |||
| 80d167cb1b | |||
| cd911e8fa4 | |||
| faa6fcb00c | |||
| 836c1f461f | |||
| 97b2f54383 | |||
| 9d5f8438c5 | |||
| 3f7963e7cf | |||
| 269df85d27 | |||
| d28c6863e4 | |||
| bba4990ccc | |||
| c57afd6a5d | |||
| 25f355c8d0 | |||
| b1b0673e69 | |||
| 72c086d726 | |||
| 3810ba6c0b | |||
| 5c775b4539 | |||
| deb3e54cc3 | |||
| d1a8f6c668 | |||
| 2291ba7402 | |||
| 20390091f2 | |||
| 123d819b0f | |||
| 30e275a27d | |||
| 1a53f587e8 |
+244
-36
@@ -8,6 +8,7 @@ import (
|
||||
. "./log"
|
||||
"database/sql"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -15,10 +16,12 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
*code.MakeCode
|
||||
MakeCodeRouter Router
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
@@ -63,15 +66,21 @@ func (that *Application) Run(router Router) {
|
||||
//
|
||||
//}
|
||||
|
||||
that.Router = router
|
||||
//that.Router = router
|
||||
if that.Router == nil {
|
||||
that.Router = Router{}
|
||||
}
|
||||
for k, v := range router {
|
||||
that.Router[k] = v
|
||||
}
|
||||
//重新设置MethodRouter//直达路由
|
||||
that.MethodRouter = MethodRouter{}
|
||||
modeRouterStrict := true
|
||||
if that.Config.GetBool("modeRouterStrict") == false {
|
||||
modeRouterStrict = false
|
||||
}
|
||||
if router != nil {
|
||||
for pk, pv := range router {
|
||||
if that.Router != nil {
|
||||
for pk, pv := range that.Router {
|
||||
if !modeRouterStrict {
|
||||
pk = strings.ToLower(pk)
|
||||
}
|
||||
@@ -281,6 +290,7 @@ func (that *Application) urlSer(url string) (string, []string) {
|
||||
//访问
|
||||
|
||||
func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
nowUnixTime := time.Now()
|
||||
|
||||
_, s := that.urlSer(req.RequestURI)
|
||||
//获取cookie
|
||||
@@ -292,21 +302,22 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
// 没有保存就生成随机的session
|
||||
cookie, err := req.Cookie(that.Config.GetString("sessionName"))
|
||||
sessionId := Md5(strconv.Itoa(Rand(10)))
|
||||
token := req.FormValue("token")
|
||||
needSetCookie := ""
|
||||
token := req.Header.Get("Authorization")
|
||||
if len(token) != 32 {
|
||||
|
||||
if err != nil || (len(token) == 32 && cookie.Value != token) {
|
||||
if len(token) == 32 {
|
||||
sessionId = token
|
||||
}
|
||||
//没有跨域设置
|
||||
if that.Config.GetString("crossDomain") == "" {
|
||||
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
} else {
|
||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; SameSite=None; Secure")
|
||||
}
|
||||
} else {
|
||||
token = req.FormValue("token")
|
||||
}
|
||||
//没有cookie或者cookie不等于token
|
||||
//有token优先token
|
||||
if len(token) == 32 {
|
||||
sessionId = token
|
||||
//没有token,则查阅session
|
||||
} else if err == nil && cookie.Value != "" {
|
||||
sessionId = cookie.Value
|
||||
//session也没有则判断是否创建cookie
|
||||
} else {
|
||||
needSetCookie = sessionId
|
||||
}
|
||||
|
||||
unescapeUrl, err := url.QueryUnescape(req.RequestURI)
|
||||
@@ -325,11 +336,26 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
context.HandlerStr, context.RouterString = that.urlSer(context.HandlerStr)
|
||||
|
||||
//跨域设置
|
||||
that.crossDomain(&context)
|
||||
//是否展示日志
|
||||
if that.WebConnectLog != nil {
|
||||
that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")), context.Req.Method, context.HandlerStr)
|
||||
}
|
||||
that.crossDomain(&context, needSetCookie)
|
||||
|
||||
defer func() {
|
||||
//是否展示日志
|
||||
if that.WebConnectLog != nil {
|
||||
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
//负载均衡优化
|
||||
if ipStr == "127.0.0.1" {
|
||||
if req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = req.Header.Get("X-Forwarded-For")
|
||||
} else if req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = req.Header.Get("X-Real-IP")
|
||||
}
|
||||
}
|
||||
|
||||
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||
"time cost:", ObjToFloat64(time.Now().UnixNano()-nowUnixTime.UnixNano())/1000000.00, "ms",
|
||||
"data length:", ObjToFloat64(context.DataSize)/1000.00, "KB", context.HandlerStr)
|
||||
}
|
||||
}()
|
||||
|
||||
//访问拦截true继续false暂停
|
||||
connectListenerLen := len(that.connectListener)
|
||||
@@ -403,35 +429,66 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func (that *Application) crossDomain(context *Context) {
|
||||
func (that *Application) crossDomain(context *Context, sessionId string) {
|
||||
|
||||
//没有跨域设置
|
||||
if context.Config.GetString("crossDomain") == "" {
|
||||
if sessionId != "" {
|
||||
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
header := context.Resp.Header()
|
||||
//header.Set("Access-Control-Allow-Origin", "*")
|
||||
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
||||
header.Set("Access-Control-Allow-Credentials", "true")
|
||||
header.Set("Access-Control-Expose-Headers", "*")
|
||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||
|
||||
//不跨域,则不设置
|
||||
remoteHost := context.Req.Host
|
||||
if context.Config.GetString("port") == "80" || context.Config.GetString("port") == "443" {
|
||||
remoteHost = remoteHost + ":" + context.Config.GetString("port")
|
||||
}
|
||||
if context.Config.GetString("crossDomain") != "auto" {
|
||||
//不跨域,则不设置
|
||||
if strings.Contains(context.Config.GetString("crossDomain"), remoteHost) {
|
||||
|
||||
if sessionId != "" {
|
||||
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
}
|
||||
return
|
||||
}
|
||||
header.Set("Access-Control-Allow-Origin", that.Config.GetString("crossDomain"))
|
||||
// 后端设置,2592000单位秒,这里是30天
|
||||
header.Set("Access-Control-Max-Age", "2592000")
|
||||
|
||||
//header.Set("Access-Control-Allow-Origin", "*")
|
||||
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
||||
header.Set("Access-Control-Allow-Credentials", "true")
|
||||
header.Set("Access-Control-Expose-Headers", "*")
|
||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||
|
||||
if sessionId != "" {
|
||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
origin := context.Req.Header.Get("Origin")
|
||||
if origin != "" {
|
||||
header.Set("Access-Control-Allow-Origin", origin)
|
||||
|
||||
refer := context.Req.Header.Get("Referer")
|
||||
if (origin != "" && strings.Contains(origin, remoteHost)) || strings.Contains(refer, remoteHost) {
|
||||
|
||||
if sessionId != "" {
|
||||
http.SetCookie(context.Resp, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
refer := context.Req.Header.Get("Referer")
|
||||
if refer != "" {
|
||||
if origin != "" {
|
||||
header.Set("Access-Control-Allow-Origin", origin)
|
||||
//return
|
||||
} else if refer != "" {
|
||||
tempInt := 0
|
||||
lastInt := strings.IndexFunc(refer, func(r rune) bool {
|
||||
if r == '/' && tempInt > 8 {
|
||||
@@ -446,7 +503,20 @@ func (that *Application) crossDomain(context *Context) {
|
||||
}
|
||||
refer = Substr(refer, 0, lastInt)
|
||||
header.Set("Access-Control-Allow-Origin", refer)
|
||||
//header.Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
}
|
||||
|
||||
header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE")
|
||||
header.Set("Access-Control-Allow-Credentials", "true")
|
||||
header.Set("Access-Control-Expose-Headers", "*")
|
||||
header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token")
|
||||
|
||||
if sessionId != "" {
|
||||
//跨域允许需要设置cookie的允许跨域https才有效果
|
||||
context.Resp.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Init 初始化application
|
||||
@@ -459,13 +529,26 @@ func Init(config string) Application {
|
||||
appIns.SetCache()
|
||||
appIns.MakeCode = &code.MakeCode{}
|
||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
||||
if codeConfig != nil {
|
||||
if codeConfig != nil {
|
||||
for k, _ := range codeConfig {
|
||||
if appIns.Config.GetInt("mode") == 2{
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db)
|
||||
}else{
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil)
|
||||
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)
|
||||
}
|
||||
//接入动态代码层
|
||||
if appIns.Router == nil {
|
||||
appIns.Router = Router{}
|
||||
}
|
||||
appIns.Router[k] = TptProject
|
||||
for k1, _ := range appIns.MakeCode.TableColumns {
|
||||
appIns.Router[k][k1] = appIns.Router[k]["hotimeCommon"]
|
||||
}
|
||||
|
||||
setMakeCodeLintener(k, &appIns)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -529,3 +612,128 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
return master, slave
|
||||
})
|
||||
}
|
||||
|
||||
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 true
|
||||
}
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
|
||||
return true
|
||||
}
|
||||
|
||||
if context.Session(name+"_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
//文件上传接口
|
||||
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
|
||||
if context.Session(name+"_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return false
|
||||
}
|
||||
//读取网络文件
|
||||
fi, fheader, err := context.Req.FormFile("file")
|
||||
if err != nil {
|
||||
context.Display(3, err)
|
||||
return false
|
||||
|
||||
}
|
||||
filePath := context.Config.GetString("filePath")
|
||||
if filePath == "" {
|
||||
filePath = "file/2006/01/02/"
|
||||
}
|
||||
|
||||
path := time.Now().Format(filePath)
|
||||
e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
||||
newFile, e := os.Create(context.Config.GetString("tpt") + "/" + filePath)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
|
||||
_, e = io.Copy(newFile, fi)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
|
||||
context.Display(0, filePath)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
||||
!(context.Router[context.RouterString[0]] != nil &&
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
||||
return true
|
||||
}
|
||||
//排除无效操作
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method != "GET" &&
|
||||
context.Req.Method != "POST" {
|
||||
return true
|
||||
}
|
||||
//列表检索
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "GET" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
||||
}
|
||||
//新建
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "POST" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
||||
}
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "POST" {
|
||||
return true
|
||||
}
|
||||
//查询单条
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
||||
}
|
||||
//更新
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "PUT" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
||||
}
|
||||
//移除
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "DELETE" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
||||
}
|
||||
context.View()
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
Vendored
+17
-17
@@ -21,7 +21,7 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
//内存缓存有
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
return reData
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
@@ -40,12 +40,12 @@ func (that *HoTimeCache) Session(key string, data ...interface{}) *Obj {
|
||||
//db缓存有
|
||||
if that.dbCache != nil && that.dbCache.SessionSet {
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.SessionSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
if that.redisCache != nil && that.redisCache.SessionSet {
|
||||
that.redisCache.Cache(key, reData)
|
||||
that.redisCache.Cache(key, reData.Data)
|
||||
}
|
||||
|
||||
return reData
|
||||
@@ -76,7 +76,7 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
//内存缓存有
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
reData = that.memoryCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
return reData
|
||||
}
|
||||
}
|
||||
@@ -84,9 +84,9 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
//redis缓存有
|
||||
if that.redisCache != nil && that.redisCache.DbSet {
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
@@ -95,13 +95,13 @@ func (that *HoTimeCache) Db(key string, data ...interface{}) *Obj {
|
||||
//redis缓存有
|
||||
if that.dbCache != nil && that.dbCache.DbSet {
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
if that.memoryCache != nil && that.memoryCache.DbSet {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
|
||||
if that.redisCache != nil && that.redisCache.DbSet {
|
||||
that.redisCache.Cache(key, reData)
|
||||
that.redisCache.Cache(key, reData.Data)
|
||||
}
|
||||
|
||||
return reData
|
||||
@@ -140,10 +140,10 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
//redis缓存有
|
||||
if that.redisCache != nil {
|
||||
reData = that.redisCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
|
||||
if that.memoryCache != nil {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
@@ -152,12 +152,12 @@ func (that *HoTimeCache) Cache(key string, data ...interface{}) *Obj {
|
||||
//redis缓存有
|
||||
if that.dbCache != nil {
|
||||
reData = that.dbCache.Cache(key, data...)
|
||||
if reData != nil {
|
||||
if reData.Data != nil {
|
||||
if that.memoryCache != nil {
|
||||
that.memoryCache.Cache(key, reData)
|
||||
that.memoryCache.Cache(key, reData.Data)
|
||||
}
|
||||
if that.redisCache != nil {
|
||||
that.redisCache.Cache(key, reData)
|
||||
that.redisCache.Cache(key, reData.Data)
|
||||
}
|
||||
return reData
|
||||
}
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
. "../hotime/common"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Project 管理端项目
|
||||
var TptProject = Proj{
|
||||
//"user": UserCtr,
|
||||
"hotimeCommon": Ctr{
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(that.RouterString[1], str, where)
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
|
||||
re := that.Db.Insert(that.RouterString[1], inData)
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "无法插入对应数据")
|
||||
return
|
||||
}
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
|
||||
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
|
||||
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
|
||||
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||
} else if inData.GetString("index") != "" {
|
||||
inData["index"] = "," + ObjToStr(re) + ","
|
||||
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
}
|
||||
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.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) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
|
||||
|
||||
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||
|
||||
for _, v := range reData {
|
||||
for k, _ := range v {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
|
||||
if parentC != nil {
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
},
|
||||
"hotime": Ctr{
|
||||
"login": func(this *Context) {
|
||||
hotimeName := this.RouterString[0]
|
||||
name := this.Req.FormValue("name")
|
||||
password := this.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
this.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := this.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
if user == nil {
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
this.Session(hotimeName+"_id", user.GetCeilInt("id"))
|
||||
this.Session(hotimeName+"_name", name)
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"logout": func(this *Context) {
|
||||
hotimeName := this.RouterString[0]
|
||||
this.Session(hotimeName+"_id", nil)
|
||||
this.Session(hotimeName+"_name", nil)
|
||||
this.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info(hotimeName, data, that.Db)
|
||||
where := Map{"id": that.Session(hotimeName + "_id").ToCeilInt()}
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
} else if len(inData) > 1 {
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
re := that.Db.Get(hotimeName, str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns[hotimeName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), "id,"+column.GetString("value"), Map{"id": v})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
},
|
||||
}
|
||||
+9
-5
@@ -8,6 +8,7 @@ var Config = Map{
|
||||
"name": "HoTimeDashBoard",
|
||||
"id": "2f92h3herh23rh2y8",
|
||||
"label": "HoTime管理平台",
|
||||
|
||||
"menus": []Map{
|
||||
{"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"},
|
||||
//{"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"},
|
||||
@@ -56,9 +57,10 @@ 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", false, 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},
|
||||
|
||||
@@ -67,7 +69,7 @@ var ColumnNameType = []ColumnShow{
|
||||
{"latitude", false, true, true, false, "", false},
|
||||
{"longitude", false, true, true, false, "", false},
|
||||
|
||||
{"index", false, false, false, false, "", false},
|
||||
{"index", false, false, false, false, "index", false},
|
||||
{"password", false, true, false, false, "password", false},
|
||||
{"pwd", false, true, false, false, "password", false},
|
||||
{"info", false, true, true, false, "", false},
|
||||
@@ -80,14 +82,16 @@ var ColumnNameType = []ColumnShow{
|
||||
{"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, "", false},
|
||||
{"modify_time", false, false, 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, false, true, false, "", false},
|
||||
{"time", true, true, true, true, "time", false},
|
||||
{"level", false, false, true, false, "", false},
|
||||
{"rule", true, true, true, false, "form", false},
|
||||
}
|
||||
|
||||
+245
-93
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MakeCode struct {
|
||||
@@ -21,7 +22,7 @@ type MakeCode struct {
|
||||
Error
|
||||
}
|
||||
|
||||
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCode bool) {
|
||||
isMake := false
|
||||
idSlice := Slice{}
|
||||
|
||||
@@ -112,7 +113,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
|
||||
}
|
||||
|
||||
if db==nil{
|
||||
if db == nil {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -143,27 +144,14 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
"auth": []string{"add", "delete", "edit", "info"},
|
||||
"columns": []Map{},
|
||||
"search": []Map{
|
||||
//{"type": "tree", "name": "oid", "label": "组织", "table": "organization", "showName": "label", "children": "children"},
|
||||
|
||||
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
||||
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||
//{"type": "select", "name": "state", "label": "状态", "value": nil,
|
||||
// "options": []Map{
|
||||
// {"name": "正常", "value": 0},
|
||||
// {"name": "异常", "value": 1},
|
||||
// {"name": "全部", "value": nil},
|
||||
// },
|
||||
//},
|
||||
},
|
||||
}
|
||||
}
|
||||
//else {
|
||||
// if !(that.TableConfig.GetMap(v.GetString("name")).GetString("label") != "备注" &&
|
||||
// v.GetString("label") == "备注") {
|
||||
// that.TableConfig.GetMap(v.GetString("name"))["label"] = v.GetString("label")
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
//初始化
|
||||
if that.TableColumns[v.GetString("name")] == nil {
|
||||
that.TableColumns[v.GetString("name")] = make(map[string]Map)
|
||||
@@ -184,6 +172,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
|
||||
idSlice = append(idSlice, tableInfo)
|
||||
for _, info := range tableInfo {
|
||||
|
||||
if info.GetString("label") == "" {
|
||||
info["label"] = info.GetString("name")
|
||||
}
|
||||
@@ -191,10 +180,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
|
||||
if coloum == nil {
|
||||
//根据类型判断真实类型
|
||||
for k, v := range ColumnDataType {
|
||||
if strings.Contains(info.GetString("type"), k) || strings.Contains(info.GetString("name"), k) {
|
||||
info["type"] = v
|
||||
break
|
||||
for k, v1 := range ColumnDataType {
|
||||
if strings.Contains(info.GetString("name"), k) || strings.Contains(info.GetString("type"), k) {
|
||||
info["type"] = v1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,30 +199,41 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
coloum["label"] = info.GetString("label")[:indexNum]
|
||||
}
|
||||
|
||||
for _, v := range ColumnNameType {
|
||||
if (v.Strict && coloum.GetString("name") == v.Name) || (!v.Strict && strings.Contains(coloum.GetString("name"), v.Name)) {
|
||||
for _, ColumnName := range ColumnNameType {
|
||||
if (ColumnName.Strict && coloum.GetString("name") == ColumnName.Name) ||
|
||||
(!ColumnName.Strict && strings.Contains(coloum.GetString("name"), ColumnName.Name)) {
|
||||
//全部都不需要则不加入
|
||||
if v.Edit == false && v.List == false && v.Info == false {
|
||||
if ColumnName.Edit == false && ColumnName.List == false && ColumnName.Info == false {
|
||||
coloum["notUse"] = true
|
||||
//continue
|
||||
}
|
||||
coloum["info"] = ColumnName.Info
|
||||
coloum["edit"] = ColumnName.Edit
|
||||
coloum["add"] = ColumnName.Edit
|
||||
coloum["list"] = ColumnName.List
|
||||
coloum["must"] = ColumnName.Must
|
||||
|
||||
if ColumnName.Info {
|
||||
delete(coloum, "info")
|
||||
}
|
||||
if ColumnName.Edit {
|
||||
delete(coloum, "edit")
|
||||
delete(coloum, "add")
|
||||
}
|
||||
if ColumnName.List {
|
||||
delete(coloum, "list")
|
||||
}
|
||||
if ColumnName.Must {
|
||||
delete(coloum, "must")
|
||||
}
|
||||
|
||||
if ColumnName.Type != "" {
|
||||
coloum["type"] = ColumnName.Type
|
||||
}
|
||||
if ColumnName.Strict && coloum.GetString("name") == ColumnName.Name {
|
||||
break
|
||||
}
|
||||
if v.Info == false {
|
||||
coloum["info"] = v.Info
|
||||
}
|
||||
if v.Edit == false {
|
||||
coloum["edit"] = v.Edit
|
||||
coloum["add"] = v.Edit
|
||||
}
|
||||
if v.List == false {
|
||||
coloum["list"] = v.List
|
||||
}
|
||||
if v.Must == true {
|
||||
coloum["must"] = v.Must
|
||||
}
|
||||
if v.Type != "" {
|
||||
coloum["type"] = v.Type
|
||||
}
|
||||
break
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,9 +242,9 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
coloum["sortable"] = true
|
||||
}
|
||||
|
||||
if !coloum.GetBool("notUse") {
|
||||
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
|
||||
}
|
||||
//if !coloum.GetBool("notUse") {
|
||||
that.TableConfig.GetMap(v.GetString("name"))["columns"] = append(that.TableConfig.GetMap(v.GetString("name")).GetSlice("columns"), coloum)
|
||||
//}
|
||||
//如果是select类型需要设置options
|
||||
//if coloum.GetString("type") == "select" {
|
||||
|
||||
@@ -286,22 +285,25 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
|
||||
}
|
||||
|
||||
//创建模块文件
|
||||
//判断文件是否存在
|
||||
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
|
||||
_, err := os.Stat(name + "/" + v.GetString("name") + ".go")
|
||||
if err != nil { //文件不存在,则根据模板创建
|
||||
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1)
|
||||
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
|
||||
_ = os.MkdirAll(name, os.ModeDir)
|
||||
err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
if makeCode {
|
||||
//创建模块文件
|
||||
//判断文件是否存在
|
||||
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
|
||||
_, err := os.Stat(name + "/" + v.GetString("name") + ".go")
|
||||
if err != nil { //文件不存在,则根据模板创建
|
||||
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1)
|
||||
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
|
||||
_ = os.MkdirAll(name, os.ModeDir)
|
||||
err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
isMake = true
|
||||
}
|
||||
isMake = true
|
||||
}
|
||||
|
||||
ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n "
|
||||
ctrList = ctrList + `"` + v.GetString("name") + `":` + v.GetString("name") + "Ctr,\r\n "
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -324,6 +326,10 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
isMenusGet := false //判断是否被目录收录
|
||||
for indexKey, _ := range that.IndexMenus {
|
||||
indexCode := strings.Index(indexKey, fk)
|
||||
if indexCode == 0 {
|
||||
isMenusGet = false
|
||||
continue
|
||||
}
|
||||
//如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||
if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||
isMenusGet = true
|
||||
@@ -340,16 +346,21 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
//并且代表有前缀,根据数据表分库设定使用
|
||||
if tablePrefixCode != -1 {
|
||||
prefixName = fk[:tablePrefixCode]
|
||||
} else {
|
||||
prefixName = fk
|
||||
}
|
||||
if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if strings.Index(ck, prefixName) == 0 && ck != prefixName && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
//if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if strings.Index(ck, prefixName) == 0 && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
@@ -395,23 +406,29 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
if oldTableName == "parent" {
|
||||
oldTableName = fk
|
||||
}
|
||||
//如果本身匹配则不再继续精简匹配
|
||||
if that.TableConfig[oldTableName] == nil {
|
||||
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||
}
|
||||
|
||||
//字段有动词前缀,自动进行解析
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
//字段有动词前缀,自动进行解析
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
|
||||
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||
|
||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = oldTableName[prefixColumn+1:]
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = oldTableName[prefixColumn+1:]
|
||||
}
|
||||
if prefixColumn >= len(oldTableName) {
|
||||
prefixColumn = -1
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||
}
|
||||
}
|
||||
|
||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||
@@ -476,13 +493,16 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
|
||||
fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
that.Config["id"] = id
|
||||
//init文件初始化
|
||||
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
||||
_ = os.MkdirAll(name, os.ModeDir)
|
||||
err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
|
||||
if makeCode {
|
||||
//init文件初始化
|
||||
myInit = strings.Replace(myInit, "{{id}}", id, -1)
|
||||
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
|
||||
_ = os.MkdirAll(name, os.ModeDir)
|
||||
err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
}
|
||||
//写入配置文件
|
||||
//var configByte bytes.Buffer
|
||||
@@ -495,14 +515,49 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB) {
|
||||
}
|
||||
fmt.Println("有新的代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
|
||||
}
|
||||
|
||||
func (that *MakeCode) Info(table string) string {
|
||||
func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string, Map) {
|
||||
reStr := ""
|
||||
data := Map{}
|
||||
var ruleData Map
|
||||
for _, v := range that.TableColumns[table] {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
//准备加入索引权限
|
||||
if v.GetString("link") != "" &&
|
||||
userData != nil &&
|
||||
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
//初始化ruleData
|
||||
if ruleData == nil {
|
||||
ruleData = Map{}
|
||||
for _, v := range that.TableColumns["admin"] {
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" &&
|
||||
userData.Get(v.GetString("name")) != nil {
|
||||
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
|
||||
}
|
||||
}
|
||||
}
|
||||
if ruleData[v.GetString("link")] != nil {
|
||||
|
||||
if v.GetString("name") == "parent_id" {
|
||||
data["index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
|
||||
} else {
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||
for _, v := range idMap {
|
||||
ids = append(ids, v.GetCeilInt("id"))
|
||||
}
|
||||
data[v.GetString("name")] = ids
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if v.Get("info") == nil || v.GetBool("info") {
|
||||
reStr += "`" + v.GetString("name") + "`,"
|
||||
}
|
||||
@@ -510,19 +565,28 @@ func (that *MakeCode) Info(table string) string {
|
||||
if len(reStr) != 0 {
|
||||
reStr = reStr[:len(reStr)-1]
|
||||
}
|
||||
return reStr
|
||||
return reStr, data
|
||||
}
|
||||
func (that *MakeCode) Add(table string, req *http.Request) Map {
|
||||
data := Map{}
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
data[v.GetString("name")] = ","
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
if v.Get("add") == nil || v.GetBool("add") {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 0 {
|
||||
return nil
|
||||
if v.GetBool("must") {
|
||||
return nil
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
|
||||
@@ -535,7 +599,15 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if v.GetString("name") == "create_time" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
continue
|
||||
}
|
||||
|
||||
if v.GetString("name") == "modify_time" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
}
|
||||
if len(data) == 0 {
|
||||
@@ -549,8 +621,12 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
data[v.GetString("name")] = ","
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if v.Get("edit") == nil || v.GetBool("edit") {
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue == "" || reqValue == "null" {
|
||||
@@ -562,6 +638,9 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
data[v.GetString("name")] = reqValue
|
||||
}
|
||||
}
|
||||
if v.GetString("name") == "modify_time" {
|
||||
data[v.GetString("name")] = time.Now().Unix()
|
||||
}
|
||||
}
|
||||
|
||||
if len(data) == 0 {
|
||||
@@ -570,19 +649,36 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
|
||||
return data
|
||||
}
|
||||
func (that *MakeCode) Delete(table string, req *http.Request) Map {
|
||||
data := Map{}
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
data[v.GetString("name")] = ","
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
|
||||
reStr := ""
|
||||
leftJoin := Map{}
|
||||
data := Map{}
|
||||
keyword := Map{}
|
||||
daterange := Map{}
|
||||
sort := Map{}
|
||||
var ruleData Map
|
||||
hasUser := false
|
||||
|
||||
keywordStr := req.FormValue("keyword")
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
|
||||
continue
|
||||
}
|
||||
if v["list"] != false {
|
||||
@@ -590,17 +686,59 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
|
||||
reStr += v.GetString("link") + "." +
|
||||
v.GetString("value") + " AS " +
|
||||
reStr += table + "." + v.GetString("name") + "," +
|
||||
v.GetString("link") + "." + v.GetString("value") + " AS " +
|
||||
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
|
||||
|
||||
leftJoin["[>]"+v.GetString("link")] =
|
||||
table + "." + v.GetString("name") + "=" +
|
||||
v.GetString("link") + ".id"
|
||||
if v.GetString("link") == "admin" {
|
||||
hasUser = true
|
||||
}
|
||||
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue != "" {
|
||||
data[table+"."+v.GetString("name")] = reqValue
|
||||
}
|
||||
|
||||
} else {
|
||||
reStr += table + "." + v.GetString("name") + ","
|
||||
}
|
||||
|
||||
//准备加入索引权限
|
||||
if v.GetString("link") != "" &&
|
||||
userData != nil &&
|
||||
that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
//初始化ruleData
|
||||
if ruleData == nil {
|
||||
ruleData = Map{}
|
||||
for _, v := range that.TableColumns["admin"] {
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" &&
|
||||
userData.Get(v.GetString("name")) != nil {
|
||||
ruleData[v.GetString("link")] = userData.Get(v.GetString("name"))
|
||||
}
|
||||
}
|
||||
}
|
||||
if ruleData[v.GetString("link")] != nil {
|
||||
|
||||
if v.GetString("name") == "parent_id" {
|
||||
data[table+".index[~]"] = "," + ruleData.GetString(v.GetString("link")) + ","
|
||||
|
||||
} else {
|
||||
idMap := db.Select(v.GetString("link"), "id", Map{"index[~]": "," + ruleData.GetString(v.GetString("link")) + ","})
|
||||
ids := Slice{ruleData.GetCeilInt(v.GetString("link"))}
|
||||
for _, v := range idMap {
|
||||
ids = append(ids, v.GetCeilInt("id"))
|
||||
}
|
||||
data[table+"."+v.GetString("name")] = ids
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if keywordStr != "" {
|
||||
if v.GetString("type") == "text" {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
@@ -647,7 +785,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
}
|
||||
//日期类型
|
||||
if searchItemName == "daterange" && v.GetString("type") == "time" {
|
||||
fmt.Println(req.Form["daterange"])
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
}
|
||||
}
|
||||
@@ -662,7 +800,8 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
if searchItemName == "parent_id" {
|
||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||
if parentID == 0 {
|
||||
data["OR"] = Map{table + ".parent_id[#]": 0, table + ".parent_id": nil}
|
||||
parentID = userData.GetCeilInt(table + "_id")
|
||||
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
||||
} else {
|
||||
data[table+".parent_id"] = parentID
|
||||
}
|
||||
@@ -672,6 +811,9 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
if sort["ORDER"] == nil {
|
||||
sort["ORDER"] = table + ".id DESC"
|
||||
}
|
||||
|
||||
where := Map{}
|
||||
|
||||
@@ -709,6 +851,12 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
where = data
|
||||
}
|
||||
|
||||
if len(where) == 0 && hasUser {
|
||||
|
||||
//where["admin.id"] = userData["id"]
|
||||
|
||||
}
|
||||
|
||||
if len(sort) != 0 {
|
||||
for k, v := range sort {
|
||||
where[k] = v
|
||||
@@ -717,3 +865,7 @@ func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (
|
||||
|
||||
return reStr, leftJoin, where
|
||||
}
|
||||
|
||||
func setListener() {
|
||||
|
||||
}
|
||||
|
||||
+120
-40
@@ -15,26 +15,55 @@ var Project = Proj{
|
||||
{{tablesCtr}}
|
||||
"hotime":Ctr{
|
||||
"login": func(this *Context) {
|
||||
name:=this.Req.FormValue("name")
|
||||
password:=this.Req.FormValue("password")
|
||||
if name==""||password==""{
|
||||
this.Display(3,"参数不足")
|
||||
name := this.Req.FormValue("name")
|
||||
password := this.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
this.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user:=this.Db.Get("{{name}}","*",Map{"AND":Map{"name":name,"password":Md5(password)}})
|
||||
if user==nil{
|
||||
this.Display(5,"登录失败")
|
||||
user := this.Db.Get("admin", "*", Map{"AND": Map{"OR":Map{"name": name,"phone":name}, "password": Md5(password)}})
|
||||
if user == nil {
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
this.Session("id",user.GetCeilInt("id"))
|
||||
this.Session("name",name)
|
||||
this.Display(0,"登录成功")
|
||||
this.Session("admin_id", user.GetCeilInt("id"))
|
||||
this.Session("admin_name", name)
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"logout": func(this *Context) {
|
||||
this.Session("id",nil)
|
||||
this.Session("name",nil)
|
||||
this.Display(0,"退出登录成功")
|
||||
this.Session("admin_id", nil)
|
||||
this.Session("admin_name", nil)
|
||||
this.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info("admin", data, that.Db)
|
||||
where := Map{"id": that.Session("admin_id").ToCeilInt()}
|
||||
if len(inData) ==1 {
|
||||
inData["id"] =where["id"]
|
||||
where = Map{"AND": inData}
|
||||
}else if len(inData) >1 {
|
||||
where["OR"]=inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
re := that.Db.Get("admin", str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns["admin"][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"),"id," +column.GetString("value"), Map{"id": v})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
},
|
||||
}
|
||||
`
|
||||
var CtrTpt = `package {{name}}
|
||||
@@ -42,11 +71,24 @@ var CtrTpt = `package {{name}}
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var {{table}}Ctr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]})
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) ==1 {
|
||||
inData["id"] =where["id"]
|
||||
where = Map{"AND": inData}
|
||||
}else if len(inData) >1 {
|
||||
where["OR"]=inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
re := that.Db.Get(that.RouterString[1], str, where)
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
@@ -54,13 +96,12 @@ var {{table}}Ctr = Ctr{
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
|
||||
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column==nil{
|
||||
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"), column.GetString("value"), Map{"id": v})
|
||||
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})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,12 +113,23 @@ var {{table}}Ctr = Ctr{
|
||||
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)
|
||||
},
|
||||
@@ -87,6 +139,22 @@ var {{table}}Ctr = Ctr{
|
||||
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 {
|
||||
@@ -97,54 +165,66 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
re :=int64(0)
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
|
||||
re=that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
}else {
|
||||
re=that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
|
||||
}
|
||||
|
||||
if re == 0 {
|
||||
that.Display(4, "删除数据失败")
|
||||
return
|
||||
}
|
||||
that.Display(0, re)
|
||||
that.Display(0, "删除成功")
|
||||
},
|
||||
|
||||
"search": func(that *Context) {
|
||||
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
|
||||
columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db)
|
||||
page:=ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize:=ObjToInt(that.Req.FormValue("pageSize"))
|
||||
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
|
||||
if page<1{
|
||||
page=1
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
if pageSize<=0{
|
||||
pageSize=20
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
count:=that.Db.Count(that.RouterString[1],leftJoin,where)
|
||||
count := that.Db.Count(that.RouterString[1], leftJoin, where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect(that.RouterString[1],leftJoin,columnStr, where)
|
||||
|
||||
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||
|
||||
for _, v := range reData {
|
||||
for k, _ := range v {
|
||||
column:=that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column==nil{
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if column["list"]!=false&&column["name"]=="parent_id"&&column.GetString("link")!=""{
|
||||
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||
parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)})
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=""
|
||||
if parentC!=nil{
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")]=parentC.GetString(column.GetString("value"))
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
|
||||
if parentC != nil {
|
||||
v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, Map{"count":count,"data":reData})
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
},
|
||||
}
|
||||
`
|
||||
|
||||
@@ -36,6 +36,42 @@ func StrFirstToUpper(str string) string {
|
||||
return strings.ToUpper(first) + other
|
||||
}
|
||||
|
||||
//相似度计算 ld compares two strings and returns the levenshtein distance between them.
|
||||
func StrLd(s, t string, ignoreCase bool) int {
|
||||
if ignoreCase {
|
||||
s = strings.ToLower(s)
|
||||
t = strings.ToLower(t)
|
||||
}
|
||||
d := make([][]int, len(s)+1)
|
||||
for i := range d {
|
||||
d[i] = make([]int, len(t)+1)
|
||||
}
|
||||
for i := range d {
|
||||
d[i][0] = i
|
||||
}
|
||||
for j := range d[0] {
|
||||
d[0][j] = j
|
||||
}
|
||||
for j := 1; j <= len(t); j++ {
|
||||
for i := 1; i <= len(s); i++ {
|
||||
if s[i-1] == t[j-1] {
|
||||
d[i][j] = d[i-1][j-1]
|
||||
} else {
|
||||
min := d[i-1][j]
|
||||
if d[i][j-1] < min {
|
||||
min = d[i][j-1]
|
||||
}
|
||||
if d[i-1][j-1] < min {
|
||||
min = d[i-1][j-1]
|
||||
}
|
||||
d[i][j] = min + 1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return d[len(s)][len(t)]
|
||||
}
|
||||
|
||||
// Substr 字符串截取
|
||||
func Substr(str string, start int, length int) string {
|
||||
rs := []rune(str)
|
||||
|
||||
@@ -18,6 +18,7 @@ type Context struct {
|
||||
RespData Map
|
||||
CacheIns
|
||||
SessionIns
|
||||
DataSize int
|
||||
HandlerStr string //复写请求url
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ func (that *Context) Display(statu int, data interface{}) {
|
||||
}
|
||||
|
||||
func (that *Context) View() {
|
||||
|
||||
if that.RespData == nil {
|
||||
return
|
||||
}
|
||||
@@ -63,6 +65,8 @@ func (that *Context) View() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
that.DataSize = len(d)
|
||||
that.RespData = nil
|
||||
that.Resp.Write(d)
|
||||
return
|
||||
}
|
||||
|
||||
+4
-5
@@ -652,8 +652,10 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
where := ""
|
||||
res := make([]interface{}, 0)
|
||||
length := len(k)
|
||||
|
||||
if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
|
||||
if k == "[#]" {
|
||||
k = strings.Replace(k, "[#]", "", -1)
|
||||
where += " " + ObjToStr(v) + " "
|
||||
} else if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' {
|
||||
def := false
|
||||
|
||||
switch Substr(k, length-3, 3) {
|
||||
@@ -791,9 +793,6 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
} else if k == "[#]" {
|
||||
k = strings.Replace(k, "[#]", "", -1)
|
||||
where += " " + ObjToStr(v) + " "
|
||||
} else {
|
||||
//fmt.Println(reflect.ValueOf(v).Type().String())
|
||||
if !strings.Contains(k, ".") {
|
||||
|
||||
+9
-3
@@ -18,8 +18,8 @@ type DDY struct {
|
||||
|
||||
func (this *DDY) Init(apikey string) {
|
||||
this.ApiKey = apikey
|
||||
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/single_send"
|
||||
this.TzUrl = "https://api.dingdongcloud.com/v1/sms/notice/multi_send"
|
||||
this.YzmUrl = "https://api.dingdongcloud.com/v2/sms/captcha/send.json"
|
||||
this.TzUrl = "https://api.dingdongcloud.com/v2/sms/notice/send.json"
|
||||
}
|
||||
|
||||
//发送短信验证码 code验证码如:123456 返回true表示发送成功flase表示发送失败
|
||||
@@ -34,7 +34,7 @@ func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bo
|
||||
//发送通知
|
||||
func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
|
||||
for k, v := range data {
|
||||
tpt = strings.Replace(tpt, "["+k+"]", v, -1)
|
||||
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
|
||||
}
|
||||
umobleStr := ""
|
||||
for i, v := range umoblie {
|
||||
@@ -89,3 +89,9 @@ func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
|
||||
return string(body), nil
|
||||
|
||||
}
|
||||
|
||||
var DefaultDDY DDY
|
||||
|
||||
func init() {
|
||||
DefaultDDY = DDY{}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package rsa
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/asn1"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func FileGet(path string) []byte {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
//读取文件的内容
|
||||
info, _ := file.Stat()
|
||||
buf := make([]byte, info.Size())
|
||||
file.Read(buf)
|
||||
return buf
|
||||
}
|
||||
|
||||
//RSA加密
|
||||
// plainText 要加密的数据
|
||||
// path 公钥匙文件地址
|
||||
func RSA_Encrypt(plainText []byte, buf []byte) []byte {
|
||||
//pem解码
|
||||
block, _ := pem.Decode(buf)
|
||||
//x509解码
|
||||
|
||||
publicKeyInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//类型断言
|
||||
publicKey := publicKeyInterface.(*rsa.PublicKey)
|
||||
//对明文进行加密
|
||||
cipherText, err := rsa.EncryptPKCS1v15(rand.Reader, publicKey, plainText)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//返回密文
|
||||
return cipherText
|
||||
}
|
||||
|
||||
//RSA解密
|
||||
// cipherText 需要解密的byte数据
|
||||
// path 私钥文件路径
|
||||
func RSA_Decrypt(cipherText []byte, buf []byte) []byte {
|
||||
|
||||
//pem解码
|
||||
block, _ := pem.Decode(buf)
|
||||
//X509解码
|
||||
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//对密文进行解密
|
||||
//plainText,_:=rsa.DecryptPKCS1v15(rand.Reader,privateKey,cipherText)
|
||||
|
||||
v, err := rsa.DecryptPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), cipherText)
|
||||
//返回明文
|
||||
return v
|
||||
}
|
||||
func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte {
|
||||
info := struct {
|
||||
Version int
|
||||
PrivateKeyAlgorithm []asn1.ObjectIdentifier
|
||||
PrivateKey []byte
|
||||
}{}
|
||||
info.Version = 0
|
||||
info.PrivateKeyAlgorithm = make([]asn1.ObjectIdentifier, 1)
|
||||
info.PrivateKeyAlgorithm[0] = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 1}
|
||||
info.PrivateKey = x509.MarshalPKCS1PrivateKey(key)
|
||||
|
||||
k, err := asn1.Marshal(info)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
func Demo() {
|
||||
//生成密钥对,保存到文件
|
||||
GenerateRSAKey(2048, "./")
|
||||
//加密
|
||||
data := []byte("hello world")
|
||||
encrypt := RSA_Encrypt(data, FileGet("public.pem"))
|
||||
fmt.Println(string(encrypt))
|
||||
|
||||
// 解密
|
||||
decrypt := RSA_Decrypt(encrypt, FileGet("private.pem"))
|
||||
fmt.Println(string(decrypt))
|
||||
}
|
||||
|
||||
//生成RSA私钥和公钥,保存到文件中
|
||||
// bits 证书大小
|
||||
func GenerateRSAKey(bits int, path string) {
|
||||
//GenerateKey函数使用随机数据生成器random生成一对具有指定字位数的RSA密钥
|
||||
//Reader是一个全局、共享的密码用强随机数生成器
|
||||
privateKey, err := rsa.GenerateKey(rand.Reader, bits)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//保存私钥
|
||||
//通过x509标准将得到的ras私钥序列化为ASN.1 的 DER编码字符串
|
||||
X509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey)
|
||||
//使用pem格式对x509输出的内容进行编码
|
||||
//创建文件保存私钥
|
||||
privateFile, err := os.Create(path + "private.pem")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer privateFile.Close()
|
||||
//构建一个pem.Block结构体对象
|
||||
privateBlock := pem.Block{Type: "RSA Private Key", Bytes: X509PrivateKey}
|
||||
//将数据保存到文件
|
||||
pem.Encode(privateFile, &privateBlock)
|
||||
|
||||
//保存公钥
|
||||
//获取公钥的数据
|
||||
publicKey := privateKey.PublicKey
|
||||
//X509对公钥编码
|
||||
X509PublicKey, err := x509.MarshalPKIXPublicKey(&publicKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//pem格式编码
|
||||
//创建用于保存公钥的文件
|
||||
publicFile, err := os.Create(path + "public.pem")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer publicFile.Close()
|
||||
//创建一个pem.Block结构体对象
|
||||
publicBlock := pem.Block{Type: "RSA Public Key", Bytes: X509PublicKey}
|
||||
//保存到文件
|
||||
pem.Encode(publicFile, &publicBlock)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package tencent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119"
|
||||
)
|
||||
|
||||
var credential = common.NewCredential(
|
||||
"AKIDOgT8cKCQksnY7yKATaYO7j9ORJzSYohP",
|
||||
"GNXgjdN4czA9ya0FNMApVJzTmsmU0KSN",
|
||||
)
|
||||
|
||||
func OCR(base64Str string) string {
|
||||
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
||||
|
||||
request := ocr.NewGeneralAccurateOCRRequest()
|
||||
|
||||
//request.ImageUrl = common.StringPtr("https://img0.baidu.com/it/u=2041013181,3227632688&fm=26&fmt=auto")
|
||||
request.ImageBase64 = common.StringPtr(base64Str)
|
||||
|
||||
response, err := client.GeneralAccurateOCR(request)
|
||||
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
fmt.Println("An API error has returned: %s", err)
|
||||
return ""
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("An API error has returned: %s", err)
|
||||
return ""
|
||||
}
|
||||
//fmt.Printf("%s", response.ToJsonString())
|
||||
|
||||
return response.ToJsonString()
|
||||
}
|
||||
|
||||
func Qrcode(base64Str string) string {
|
||||
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com"
|
||||
client, _ := ocr.NewClient(credential, "ap-guangzhou", cpf)
|
||||
|
||||
request := ocr.NewQrcodeOCRRequest()
|
||||
|
||||
request.ImageBase64 = common.StringPtr(base64Str)
|
||||
|
||||
response, err := client.QrcodeOCR(request)
|
||||
if _, ok := err.(*errors.TencentCloudSDKError); ok {
|
||||
fmt.Println("An API error has returned: %s", err)
|
||||
return ""
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println("An API error has returned: %s", err)
|
||||
return ""
|
||||
}
|
||||
//fmt.Printf("%s", response.ToJsonString())
|
||||
|
||||
return response.ToJsonString()
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
)
|
||||
|
||||
var ID = "3c5fc9732b8ddcb0a91b428976f2ce86"
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
//"user": UserCtr,
|
||||
"admin": adminCtr,
|
||||
"category": categoryCtr,
|
||||
"ctg_order_date": ctg_order_dateCtr,
|
||||
"order": orderCtr,
|
||||
"org": orgCtr,
|
||||
"role": roleCtr,
|
||||
"user": userCtr,
|
||||
"hotime": Ctr{
|
||||
"login": func(this *Context) {
|
||||
name := this.Req.FormValue("name")
|
||||
password := this.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
this.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := this.Db.Get("admin", "*", Map{"AND": Map{"name": name, "password": Md5(password)}})
|
||||
if user == nil {
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
this.Session("admin_id", user.GetCeilInt("id"))
|
||||
this.Session("admin_name", name)
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"logout": func(this *Context) {
|
||||
this.Session("admin_id", nil)
|
||||
this.Session("admin_name", nil)
|
||||
this.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
re := that.Db.Get("admin", that.MakeCode.Info("admin"), Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
|
||||
column := that.MakeCode.TableColumns["admin"][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" {
|
||||
re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v})
|
||||
}
|
||||
}
|
||||
|
||||
that.Display(0, re)
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
)
|
||||
|
||||
var categoryCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
parentId := ObjToInt(that.Req.FormValue("id"))
|
||||
//parentId := ObjToInt(that.RouterString[2])
|
||||
childData:=[]Map{}
|
||||
if parentId == 0 {
|
||||
childData1 := that.Db.Select("category", "*", Map{"parent_id": nil})
|
||||
|
||||
for _, v := range childData1 {
|
||||
data := that.Db.Get("category", "*", Map{"parent_id": v.GetCeilInt("id")})
|
||||
childData=append(childData,data)
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
childData = that.Db.Select("category", "*", Map{"parent_id": parentId})
|
||||
}
|
||||
|
||||
|
||||
|
||||
for _, v := range childData {
|
||||
v["child"] = that.Db.Select("category", "*", Map{"parent_id": v.GetCeilInt("id")})
|
||||
}
|
||||
|
||||
that.Display(0, childData)
|
||||
},
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ctg_order_dateCtr = Ctr{
|
||||
|
||||
"info": func(that *Context) {
|
||||
|
||||
//today:=time.Now().Weekday()
|
||||
id := ObjToInt(that.Req.FormValue("id"))
|
||||
category := that.Db.Get("category", "*", Map{"id": id})
|
||||
if category == nil {
|
||||
that.Display(4, "找不到该类别!")
|
||||
return
|
||||
}
|
||||
|
||||
todayPMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
||||
todayAMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02"+" 09:00"))
|
||||
|
||||
weekDay := 1
|
||||
|
||||
switch time.Now().Weekday().String() {
|
||||
case "Monday":
|
||||
weekDay = 1
|
||||
case "Tuesday":
|
||||
weekDay = 2
|
||||
case "Wednesday":
|
||||
weekDay = 3
|
||||
case "Thursday":
|
||||
weekDay = 4
|
||||
case "Friday":
|
||||
weekDay = 5
|
||||
case "Saturday":
|
||||
weekDay = 6
|
||||
case "Sunday":
|
||||
weekDay = 7
|
||||
|
||||
}
|
||||
|
||||
////future:=that.Db.Select("ctg_order_date","*",Map{"category_id":that.RouterString[2],"date[>]":time})
|
||||
date := Slice{}
|
||||
for i := 0; i < 7; i++ {
|
||||
day := weekDay + i + 1
|
||||
|
||||
if day > 7 {
|
||||
day = day - 7
|
||||
}
|
||||
if day == 6 || day == 7 {
|
||||
continue
|
||||
}
|
||||
//fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1)))
|
||||
dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"),
|
||||
"date": todayAMTime.Unix() + int64(24*60*60*(i+1))}})
|
||||
if dayAM == nil {
|
||||
dayAM = Map{"name": "9:00-12:00",
|
||||
"date": todayAMTime.Unix() + int64(24*60*60*(i+1)),
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"start_sn": category.GetCeilInt("start_sn"),
|
||||
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("am"+ObjToStr(day)),
|
||||
"now_sn": category.GetCeilInt("start_sn"),
|
||||
"category_id": category.GetCeilInt("id"),
|
||||
}
|
||||
dayAM["id"] = that.Db.Insert("ctg_order_date", dayAM)
|
||||
if dayAM.GetCeilInt64("id") == 0 {
|
||||
that.Display(4, "内部错误!")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"), "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}})
|
||||
fmt.Println(that.Db.LastQuery, that.Db.LastData, dayPM, that.Db.LastErr)
|
||||
if dayPM == nil {
|
||||
fmt.Println("dasdasdasda")
|
||||
dayPM = Map{"name": "14:00-16:00",
|
||||
"date": todayPMTime.Unix() + int64(24*60*60*(i+1)),
|
||||
"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"start_sn": category.GetCeilInt("start_sn"),
|
||||
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("pm"+ObjToStr(day)),
|
||||
"now_sn": category.GetCeilInt("start_sn"),
|
||||
"category_id": category.GetCeilInt("id"),
|
||||
}
|
||||
dayPM["id"] = that.Db.Insert("ctg_order_date", dayPM)
|
||||
if dayPM.GetCeilInt64("id") == 0 {
|
||||
that.Display(4, "内部错误!")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
date = append(date, Map{"name": "星期" + ObjToStr(day) + "(" + time.Unix(todayPMTime.Unix()+int64(24*60*60*(i+1)), 0).Format("01-02") + ")",
|
||||
"am": dayAM,
|
||||
"pm": dayPM,
|
||||
})
|
||||
}
|
||||
|
||||
that.Display(0, date)
|
||||
},
|
||||
}
|
||||
+9
-66
@@ -3,25 +3,20 @@ package app
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ID = "aad1472b19e575a71ee8f75629e27867"
|
||||
|
||||
// Project 管理端项目
|
||||
var Project = Proj{
|
||||
//"user": UserCtr,
|
||||
"category": categoryCtr,
|
||||
"ctg_order_date": ctg_order_dateCtr,
|
||||
"order": orderCtr,
|
||||
"user": userCtr,
|
||||
"sms": Sms,
|
||||
"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位随机数
|
||||
@@ -32,55 +27,3 @@ func getCode() string {
|
||||
//}
|
||||
return res
|
||||
}
|
||||
|
||||
func tencentSendYzm(umobile, code string) error {
|
||||
|
||||
random := RandX(999999, 9999999)
|
||||
url := "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=1400235813&random=" + ObjToStr(random)
|
||||
fmt.Println("URL:>", url)
|
||||
|
||||
h := sha256.New()
|
||||
h.Write([]byte(`appkey=d511de15e5ccb43fc171772dbb8b599f&random=` + ObjToStr(random) + `&time=` + ObjToStr(time.Now().Unix()) + `&mobile=` + umobile))
|
||||
bs := h.Sum(nil)
|
||||
s256 := hex.EncodeToString(bs)
|
||||
|
||||
//json序列化
|
||||
post := `{
|
||||
"ext": "",
|
||||
"extend": "",
|
||||
"params": [
|
||||
"` + code + `"
|
||||
],
|
||||
"sig": "` + s256 + `",
|
||||
"sign": "乐呵呵旅游网",
|
||||
"tel": {
|
||||
"mobile": "` + umobile + `",
|
||||
"nationcode": "86"
|
||||
},
|
||||
"time": ` + ObjToStr(time.Now().Unix()) + `,
|
||||
"tpl_id": 378916
|
||||
}`
|
||||
|
||||
fmt.Println(url, "post", post)
|
||||
|
||||
var jsonStr = []byte(post)
|
||||
fmt.Println("jsonStr", jsonStr)
|
||||
fmt.Println("new_str", bytes.NewBuffer(jsonStr))
|
||||
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
|
||||
// req.Header.Set("X-Custom-Header", "myvalue")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("response Status:", resp.Status)
|
||||
fmt.Println("response Headers:", resp.Header)
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Println("response Body:", string(body))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -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})
|
||||
},
|
||||
}
|
||||
@@ -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})
|
||||
},
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var orderCtr = Ctr{
|
||||
"count": func(this *Context) {
|
||||
if this.Session("id").ToCeilInt() == 0 {
|
||||
this.Display(2, "没有登录!")
|
||||
return
|
||||
}
|
||||
re := Map{}
|
||||
re["total"] = this.Db.Count("order", Map{"user_id": this.Session("id").ToCeilInt()})
|
||||
re["finish"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 2}})
|
||||
re["late"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 3}})
|
||||
|
||||
this.Display(0, re)
|
||||
},
|
||||
"add": func(this *Context) {
|
||||
if this.Session("id").ToCeilInt() == 0 {
|
||||
this.Display(2, "没有登录!")
|
||||
return
|
||||
}
|
||||
ctgOrderDateId := ObjToInt(this.Req.FormValue("ctg_order_date_id"))
|
||||
//ctgId:=ObjToInt(this.Req.FormValue("category_id"))
|
||||
ctgOrderDate := this.Db.Get("ctg_order_date", "*", Map{"id": ctgOrderDateId})
|
||||
|
||||
if ctgOrderDate.GetCeilInt64("now_sn")+1 > ctgOrderDate.GetCeilInt64("max_sn") {
|
||||
this.Display(5, "当前排号已经用完")
|
||||
return
|
||||
}
|
||||
|
||||
data := Map{"create_time": time.Now().Unix(),
|
||||
"modify_time": time.Now().Unix(),
|
||||
"user_id": this.Session("id").ToCeilInt(),
|
||||
"date": ctgOrderDate.GetString("date"),
|
||||
"sn": ctgOrderDate.GetCeilInt64("now_sn") + 1,
|
||||
"category_id": ctgOrderDate.GetCeilInt("category_id"),
|
||||
"admin_id": 1,
|
||||
"status": 1,
|
||||
"name": time.Unix(ctgOrderDate.GetCeilInt64("date"), 0).Format("2006-01-02 ") + ctgOrderDate.GetString("name"),
|
||||
}
|
||||
|
||||
data["id"] = this.Db.Insert("order", data)
|
||||
|
||||
if data.GetCeilInt("id") == 0 {
|
||||
this.Display(5, "预约失败")
|
||||
return
|
||||
}
|
||||
|
||||
this.Db.Update("ctg_order_date", Map{"now_sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, "modify_time": time.Now().Unix()}, Map{"id": ctgOrderDate.GetCeilInt("id")})
|
||||
this.Display(0, data)
|
||||
},
|
||||
"search": func(that *Context) {
|
||||
if that.Session("id").ToCeilInt() == 0 {
|
||||
that.Display(2, "没有登录!")
|
||||
return
|
||||
}
|
||||
|
||||
data := that.Db.Select("order", "*", Map{"user_id": that.Session("id").ToCeilInt()})
|
||||
for _, v := range data {
|
||||
v["category"] = that.Db.Get("category", "*", Map{"id": v.GetCeilInt("category_id")})
|
||||
v["parent_category"] = that.Db.Get("category", "id,name", Map{"id": v.GetMap("category").GetCeilInt("parent_id")})
|
||||
}
|
||||
that.Display(0, data)
|
||||
},
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
@@ -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)
|
||||
},
|
||||
}
|
||||
@@ -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})
|
||||
},
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
},
|
||||
}
|
||||
@@ -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})
|
||||
},
|
||||
}
|
||||
+2
-1
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
"../../dri/ddsms"
|
||||
)
|
||||
|
||||
var Sms = Ctr{
|
||||
@@ -25,7 +26,7 @@ var Sms = Ctr{
|
||||
this.Session("phone", phone)
|
||||
this.Session("code", code)
|
||||
|
||||
tencentSendYzm(phone, code)
|
||||
ddsms.DefaultDDY.SendYZM(phone, this.Config.GetString("smsLogin"), map[string]string{"code": code})
|
||||
|
||||
this.Display(0, "发送成功")
|
||||
},
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var userCtr = Ctr{
|
||||
"token": func(this *Context) {
|
||||
this.Display(0, this.SessionId)
|
||||
},
|
||||
"test": func(this *Context) {
|
||||
this.Session("id", 1)
|
||||
},
|
||||
"add": func(this *Context) {
|
||||
if this.Req.FormValue("code") != this.Session("code").ToStr() ||
|
||||
this.Req.FormValue("phone") != this.Session("phone").ToStr() {
|
||||
this.Display(3, "短信验证不通过")
|
||||
return
|
||||
}
|
||||
|
||||
phone := this.Req.FormValue("phone")
|
||||
idcard := this.Req.FormValue("idcard")
|
||||
name := this.Req.FormValue("name")
|
||||
|
||||
user := this.Db.Get("user", "*", Map{"phone": phone})
|
||||
|
||||
if user == nil {
|
||||
user = Map{"phone": phone, "idcard": idcard, "name": name, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()}
|
||||
user["id"] = this.Db.Insert("user", user)
|
||||
|
||||
} else {
|
||||
user["phone"] = phone
|
||||
user["idcard"] = idcard
|
||||
user["name"] = name
|
||||
user["modify_time"] = time.Now().Unix()
|
||||
re := this.Db.Update("user", user, Map{"id": user.GetCeilInt64("id")})
|
||||
if re == 0 {
|
||||
this.Display(4, "系统错误")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if user.GetCeilInt64("id") == 0 {
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
|
||||
this.Session("id", user.GetCeilInt("id"))
|
||||
this.Display(0, "登录成功")
|
||||
|
||||
},
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,7 @@
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.6.253",
|
||||
"name": "bzyy",
|
||||
"name": "myhs",
|
||||
"password": "dasda8454456",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
@@ -42,8 +42,8 @@
|
||||
"4": "数据处理异常",
|
||||
"5": "数据结果异常"
|
||||
},
|
||||
"mode": 0,
|
||||
"port": "80",
|
||||
"mode": 3,
|
||||
"port": "8080",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "tpt"
|
||||
}
|
||||
@@ -59,7 +59,7 @@
|
||||
},
|
||||
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"logLevel": "默认0,必须,0关闭,1打印,日志等级",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2,开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存",
|
||||
"modeRouterStrict": "默认false,必须,路由严格模式false,为大小写忽略必须匹配,true必须大小写匹配",
|
||||
"port": "默认80,必须,web服务开启Http端口,0为不启用http服务,默认80",
|
||||
"sessionName": "默认HOTIME,必须,设置session的cookie名",
|
||||
|
||||
+9
-171
@@ -2,192 +2,30 @@ package main
|
||||
|
||||
import (
|
||||
"../../hotime"
|
||||
"../../hotime/common"
|
||||
"./admin"
|
||||
"../dri/ddsms"
|
||||
"./app"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(time.Now().Weekday().String())
|
||||
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
||||
fmt.Println(date, date.Unix())
|
||||
//fmt.Println("0123456"[1:7])
|
||||
appIns := hotime.Init("config/config.json")
|
||||
//RESTfull接口适配
|
||||
appIns.SetConnectListener(func(context *hotime.Context) bool {
|
||||
|
||||
if len(context.RouterString)>1&& context.RouterString[0] == "admin" {
|
||||
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
|
||||
return true
|
||||
}
|
||||
|
||||
if context.Session("admin_id").Data == nil {
|
||||
context.Display(2, "你还没有登录")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
//文件上传接口
|
||||
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
|
||||
|
||||
//读取网络文件
|
||||
fi, fheader, err := context.Req.FormFile("file")
|
||||
if err != nil {
|
||||
context.Display(3, err)
|
||||
return false
|
||||
|
||||
}
|
||||
filePath := context.Config.GetString("filePath")
|
||||
if filePath == "" {
|
||||
filePath = "file/2006/01/02/"
|
||||
}
|
||||
|
||||
path := time.Now().Format(filePath)
|
||||
e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
filePath = path + common.Md5(common.ObjToStr(common.RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
|
||||
newFile, e := os.Create(context.Config.GetString("tpt") + "/" + filePath)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
|
||||
_, e = io.Copy(newFile, fi)
|
||||
|
||||
if e != nil {
|
||||
context.Display(3, e)
|
||||
return false
|
||||
}
|
||||
|
||||
context.Display(0, filePath)
|
||||
return false
|
||||
}
|
||||
|
||||
if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
|
||||
!(context.Router[context.RouterString[0]] != nil &&
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
|
||||
return true
|
||||
}
|
||||
//排除无效操作
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method != "GET" &&
|
||||
context.Req.Method != "POST" {
|
||||
return true
|
||||
}
|
||||
//列表检索
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "GET" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
|
||||
}
|
||||
//新建
|
||||
if len(context.RouterString) == 2 &&
|
||||
context.Req.Method == "POST" {
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["add"] == nil {
|
||||
return true
|
||||
}
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context)
|
||||
}
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "POST" {
|
||||
return true
|
||||
}
|
||||
//查询单条
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "GET" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
|
||||
}
|
||||
//更新
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "PUT" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["update"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["update"](context)
|
||||
}
|
||||
//移除
|
||||
if len(context.RouterString) == 3 &&
|
||||
context.Req.Method == "DELETE" {
|
||||
|
||||
if context.Router[context.RouterString[0]][context.RouterString[1]]["remove"] == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
|
||||
}
|
||||
context.View()
|
||||
return false
|
||||
return true
|
||||
})
|
||||
|
||||
//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{
|
||||
"admin": admin.Project,
|
||||
"app": app.Project,
|
||||
//"app": hotime.Proj{
|
||||
// "index": hotime.Ctr{
|
||||
// "test": func(this *hotime.Context) {
|
||||
//
|
||||
// data := this.Db.Get("cached", "*")
|
||||
// fmt.Println(data)
|
||||
// fmt.Println(this.Session("test").ToCeilInt())
|
||||
// this.Session("test1", 98984984)
|
||||
// fmt.Println(this.Session("test1").Data)
|
||||
// this.Error.SetError(errors.New("dasdasdas"))
|
||||
// //fmt.Println(this.Db.GetTag())
|
||||
// //this.Application.Log.Error("dasdasdas")
|
||||
// //this.Log.Error("dadasdasd")
|
||||
// //x:=this.Db.Action(func(db hotime.HoTimeDB) bool {
|
||||
// //
|
||||
// // db.Insert("user",hotime.Map{"unickname":"dasdas"})
|
||||
// //
|
||||
// // return true
|
||||
// //})
|
||||
// //hotime.LogError("dasdasdasdasdas")
|
||||
// this.Display(5, "dsadas")
|
||||
// },
|
||||
// "websocket": func(this *hotime.Context) {
|
||||
// hdler := websocket.Handler(func(ws *websocket.Conn) {
|
||||
// for true {
|
||||
// msg := make([]byte, 5120)
|
||||
// n, err := ws.Read(msg)
|
||||
// go func() {
|
||||
// time.Sleep(time.Second * 5)
|
||||
// ws.Write([]byte("dsadasdasgregergrerge"))
|
||||
//
|
||||
// }()
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("Receive: %s\n", msg[:n])
|
||||
//
|
||||
// send_msg := "[" + string(msg[:n]) + "]"
|
||||
// m, err := ws.Write([]byte(send_msg))
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// fmt.Printf("Send: %s\n", msg[:m])
|
||||
// }
|
||||
// })
|
||||
// hdler.ServeHTTP(this.Resp, this.Req)
|
||||
// },
|
||||
// },
|
||||
//},
|
||||
"app": app.Project,
|
||||
})
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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 +0,0 @@
|
||||
h3[data-v-b9167eee]{margin:40px 0 0}ul[data-v-b9167eee]{list-style-type:none;padding:0}li[data-v-b9167eee]{display:inline-block;margin:0 10px}a[data-v-b9167eee]{color:#42b983}
|
||||
@@ -0,0 +1 @@
|
||||
.not-show-tab-label .el-tabs__header,.not-show-tab-search{display:none}
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
@@ -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}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 297 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
@@ -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"><title>hotime</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-038340db.e4ca99de.css" rel="prefetch"><link href="css/chunk-0524801b.1e910850.css" rel="prefetch"><link href="css/chunk-1c438cad.2fd7d31d.css" rel="prefetch"><link href="css/chunk-1d1a12b6.8c684de3.css" rel="prefetch"><link href="css/chunk-2c1d9b2f.78c69bda.css" rel="prefetch"><link href="css/chunk-5ccac4d0.5f1c91ca.css" rel="prefetch"><link href="css/chunk-c569a38e.01bc1b83.css" rel="prefetch"><link href="css/chunk-c7a51d14.4a0871eb.css" rel="prefetch"><link href="js/chunk-038340db.3c8b0cb6.js" rel="prefetch"><link href="js/chunk-0524801b.de9b433f.js" rel="prefetch"><link href="js/chunk-14f17cfa.c5104e8c.js" rel="prefetch"><link href="js/chunk-1c438cad.72a22c19.js" rel="prefetch"><link href="js/chunk-1d1a12b6.6900cc01.js" rel="prefetch"><link href="js/chunk-2c1d9b2f.39065c9e.js" rel="prefetch"><link href="js/chunk-5b2ead63.af868ff8.js" rel="prefetch"><link href="js/chunk-5ccac4d0.98ff45de.js" rel="prefetch"><link href="js/chunk-68815fbc.04152d5f.js" rel="prefetch"><link href="js/chunk-c569a38e.16d55c64.js" rel="prefetch"><link href="js/chunk-c7a51d14.3cd28dc4.js" rel="prefetch"><link href="css/app.5e2eb449.css" rel="preload" as="style"><link href="js/app.f5f26baa.js" rel="preload" as="script"><link href="css/app.5e2eb449.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but hotime doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/app.f5f26baa.js"></script></body></html>
|
||||
}</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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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}}]);
|
||||
File diff suppressed because one or more lines are too long
@@ -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
@@ -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}}]);
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
(window.webpackJsonp=window.webpackJsonp||[]).push([["chunk-d1a9ebe6"],{"587e":function(a,e,t){"use strict";t.r(e);var n=t("9f9f");Object(n.O)("data-v-28af1b93");var v={class:"hello"},b=Object(n.q)('<p data-v-28af1b93> For a guide and recipes on how to configure / customize this project,<br data-v-28af1b93> check out the <a href="https://cli.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>vue-cli documentation</a>. </p><h3 data-v-28af1b93>Installed CLI Plugins</h3><ul data-v-28af1b93><li data-v-28af1b93><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener" data-v-28af1b93>babel</a></li><li data-v-28af1b93><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener" data-v-28af1b93>eslint</a></li></ul><h3 data-v-28af1b93>Essential Links</h3><ul data-v-28af1b93><li data-v-28af1b93><a href="https://vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>Core Docs</a></li><li data-v-28af1b93><a href="https://forum.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>Forum</a></li><li data-v-28af1b93><a href="https://chat.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>Community Chat</a></li><li data-v-28af1b93><a href="https://twitter.com/vuejs" target="_blank" rel="noopener" data-v-28af1b93>Twitter</a></li><li data-v-28af1b93><a href="https://news.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>News</a></li></ul><h3 data-v-28af1b93>Ecosystem</h3><ul data-v-28af1b93><li data-v-28af1b93><a href="https://router.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>vue-router</a></li><li data-v-28af1b93><a href="https://vuex.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>vuex</a></li><li data-v-28af1b93><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener" data-v-28af1b93>vue-devtools</a></li><li data-v-28af1b93><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener" data-v-28af1b93>vue-loader</a></li><li data-v-28af1b93><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener" data-v-28af1b93>awesome-vue</a></li></ul>',7);Object(n.M)();var r={name:"HelloWorld",props:{msg:String}};t("6fe9");r.render=function(a,e,t,r,l,o){return Object(n.L)(),Object(n.n)("div",v,[Object(n.o)("h1",null,Object(n.Y)(t.msg),1),b])},r.__scopeId="data-v-28af1b93";e.default=r},"6fe9":function(a,e,t){"use strict";t("e8a7")},e8a7:function(a,e,t){}}]);
|
||||
@@ -10,7 +10,7 @@ var App = map[string]*Application{} //整个项目
|
||||
//var Db = HoTimeDB{} //数据库实例
|
||||
|
||||
var Config = Map{
|
||||
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式
|
||||
"mode": 3, //模式 0生产模式,1,测试模式,2,开发模式,3,内嵌代码模式
|
||||
"codeConfig": Map{
|
||||
"admin": "config/app.json",
|
||||
},
|
||||
@@ -51,7 +51,7 @@ var ConfigNote = Map{
|
||||
"logFile": "无默认,非必须,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
|
||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2,开发模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
||||
"codeConfig": Map{
|
||||
"注释": "配置即启用,非必须,默认无",
|
||||
//"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
||||
|
||||
Reference in New Issue
Block a user