框架优化
This commit is contained in:
parent
ebea14c74f
commit
b7c243823a
@ -20,8 +20,7 @@ import (
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
*code.MakeCode
|
||||
MakeCodeRouter Router
|
||||
MakeCodeRouter map[string]*code.MakeCode
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
@ -533,32 +532,41 @@ func Init(config string) Application {
|
||||
|
||||
SetDB(&appIns)
|
||||
appIns.SetCache()
|
||||
appIns.MakeCode = &code.MakeCode{}
|
||||
codeConfig := appIns.Config.GetMap("codeConfig")
|
||||
appIns.MakeCodeRouter = Router{}
|
||||
|
||||
if codeConfig != nil {
|
||||
|
||||
for k, _ := range codeConfig {
|
||||
if appIns.Config.GetInt("mode") == 2 {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, true)
|
||||
appIns.MakeCodeRouter[k] = Proj{}
|
||||
} else if appIns.Config.GetInt("mode") == 3 {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, false)
|
||||
appIns.MakeCodeRouter[k] = Proj{}
|
||||
codeMake := codeConfig.GetMap(k)
|
||||
if codeMake == nil {
|
||||
continue
|
||||
}
|
||||
codeMake["table"] = k
|
||||
if appIns.MakeCodeRouter == nil {
|
||||
appIns.MakeCodeRouter = map[string]*code.MakeCode{}
|
||||
}
|
||||
if appIns.Config.GetInt("mode") > 0 {
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
} else {
|
||||
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil, false)
|
||||
appIns.MakeCodeRouter[k] = Proj{}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
|
||||
}
|
||||
//接入动态代码层
|
||||
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"]
|
||||
|
||||
if codeMake.GetString("name") == "" {
|
||||
codeMake["name"] = k
|
||||
}
|
||||
|
||||
setMakeCodeLintener(k, &appIns)
|
||||
appIns.Router[codeMake.GetString("name")] = TptProject
|
||||
for k1, _ := range appIns.MakeCodeRouter[codeMake.GetString("name")].TableColumns {
|
||||
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
|
||||
}
|
||||
|
||||
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
|
||||
|
||||
}
|
||||
|
||||
|
52
code.go
52
code.go
@ -12,7 +12,7 @@ var TptProject = Proj{
|
||||
"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)
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) == 1 {
|
||||
@ -31,7 +31,7 @@ var TptProject = Proj{
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@ -43,7 +43,8 @@ var TptProject = Proj{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -68,7 +69,8 @@ var TptProject = Proj{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
@ -103,7 +105,8 @@ var TptProject = Proj{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -127,7 +130,7 @@ var TptProject = Proj{
|
||||
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)
|
||||
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
@ -145,10 +148,11 @@ var TptProject = Proj{
|
||||
PageSelect(that.RouterString[1], leftJoin, columnStr, where)
|
||||
|
||||
for _, v := range reData {
|
||||
for k, _ := range v {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
v.RangeSort(func(k string, v1 interface{}) (isEnd bool) {
|
||||
//for k, _ := range v {
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
return true
|
||||
}
|
||||
|
||||
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" {
|
||||
@ -159,7 +163,9 @@ var TptProject = Proj{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//}
|
||||
return isEnd
|
||||
})
|
||||
}
|
||||
|
||||
that.Display(0, Map{"count": count, "data": reData})
|
||||
@ -168,33 +174,39 @@ var TptProject = Proj{
|
||||
"hotime": Ctr{
|
||||
"login": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
|
||||
name := that.Req.FormValue("name")
|
||||
password := that.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
that.Display(3, "参数不足")
|
||||
return
|
||||
}
|
||||
user := that.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
|
||||
|
||||
if user == nil {
|
||||
that.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
that.Session(hotimeName+"_id", user.GetCeilInt("id"))
|
||||
that.Session(hotimeName+"_name", name)
|
||||
that.Session(fileConfig.GetString("table")+"_id", user.GetCeilInt("id"))
|
||||
that.Session(fileConfig.GetString("table")+"_name", name)
|
||||
delete(user, "password")
|
||||
that.Display(0, user)
|
||||
},
|
||||
"logout": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
that.Session(hotimeName+"_id", nil)
|
||||
that.Session(hotimeName+"_name", nil)
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
that.Session(fileConfig.GetString("table")+"_id", nil)
|
||||
that.Session(fileConfig.GetString("table")+"_name", nil)
|
||||
that.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()}
|
||||
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
|
||||
|
||||
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(fileConfig.GetString("table"), data, that.Db)
|
||||
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
|
||||
if len(inData) == 1 {
|
||||
inData["id"] = where["id"]
|
||||
where = Map{"AND": inData}
|
||||
@ -202,13 +214,13 @@ var TptProject = Proj{
|
||||
where["OR"] = inData
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
re := that.Db.Get(hotimeName, str, where)
|
||||
re := that.Db.Get(fileConfig.GetString("table"), str, where)
|
||||
if re == nil {
|
||||
that.Display(4, "找不到对应信息")
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns[hotimeName][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[hotimeName][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -61,8 +61,6 @@ type ColumnShow struct {
|
||||
|
||||
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},
|
||||
|
136
code/makecode.go
136
code/makecode.go
@ -9,23 +9,26 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MakeCode struct {
|
||||
FileConfig Map
|
||||
IndexMenus Map
|
||||
TableConfig Map
|
||||
TableColumns map[string]map[string]Map
|
||||
SearchColumns map[string]map[string]Map
|
||||
Config Map
|
||||
RuleConfig []Map
|
||||
Error
|
||||
}
|
||||
|
||||
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCode bool) {
|
||||
func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
isMake := false
|
||||
idSlice := Slice{}
|
||||
|
||||
that.FileConfig = config
|
||||
if that.TableColumns == nil {
|
||||
that.TableColumns = make(map[string]map[string]Map)
|
||||
}
|
||||
@ -34,20 +37,40 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
|
||||
}
|
||||
|
||||
//加载配置文件
|
||||
btes, err := ioutil.ReadFile(path)
|
||||
Config["name"] = name
|
||||
btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||
|
||||
that.Config = DeepCopyMap(Config).(Map)
|
||||
|
||||
that.Config["name"] = config.GetString("table")
|
||||
if err == nil {
|
||||
cmap := Map{}
|
||||
//文件是否损坏
|
||||
cmap.JsonToMap(string(btes), &that.Error)
|
||||
for k, v := range cmap {
|
||||
that.Config[k] = v //程序配置
|
||||
Config[k] = v //系统配置
|
||||
//Config[k] = v //系统配置
|
||||
}
|
||||
} else {
|
||||
that.Error.SetError(errors.New("配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
}
|
||||
//加载规则文件
|
||||
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||
that.RuleConfig = []Map{}
|
||||
if errRule == nil {
|
||||
//cmap := Map{}
|
||||
//文件是否损坏
|
||||
ruleLis := ObjToSlice(string(btesRule), &that.Error)
|
||||
//cmap.JSON()
|
||||
for k, _ := range ruleLis {
|
||||
that.RuleConfig = append(that.RuleConfig, ruleLis.GetMap(k))
|
||||
}
|
||||
} else {
|
||||
for _, v := range ColumnNameType {
|
||||
that.RuleConfig = append(that.RuleConfig, Map{"name": v.Name, "list": v.List, "edit": v.Edit, "info": v.Info, "must": v.Must, "strict": v.Strict, "type": v.Type})
|
||||
}
|
||||
that.Error.SetError(errors.New("rule配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
}
|
||||
|
||||
that.IndexMenus = Map{}
|
||||
menusConfig := that.Config.GetSlice("menus")
|
||||
//将配置写入到内存中仅作为判断用
|
||||
@ -119,7 +142,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
|
||||
}
|
||||
|
||||
//数据库反哺
|
||||
myInit := strings.Replace(InitTpt, "{{name}}", name, -1)
|
||||
myInit := strings.Replace(InitTpt, "{{name}}", config.GetString("table"), -1)
|
||||
ctrList := ""
|
||||
|
||||
nowTables := make([]Map, 0)
|
||||
@ -205,38 +228,38 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
|
||||
coloum["label"] = coloum.GetString("label")[:indexNum]
|
||||
}
|
||||
|
||||
for _, ColumnName := range ColumnNameType {
|
||||
if (ColumnName.Strict && coloum.GetString("name") == ColumnName.Name) ||
|
||||
(!ColumnName.Strict && strings.Contains(coloum.GetString("name"), ColumnName.Name)) {
|
||||
for _, ColumnName := range that.RuleConfig {
|
||||
if (ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name")) ||
|
||||
(!ColumnName.GetBool("strict") && strings.Contains(coloum.GetString("name"), ColumnName.GetString("name"))) {
|
||||
//全部都不需要则不加入
|
||||
if ColumnName.Edit == false && ColumnName.List == false && ColumnName.Info == false {
|
||||
if ColumnName.GetBool("edit") == false && ColumnName.GetBool("list") == false && ColumnName.GetBool("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
|
||||
coloum["info"] = ColumnName.GetBool("info")
|
||||
coloum["edit"] = ColumnName.GetBool("edit")
|
||||
coloum["add"] = ColumnName.GetBool("edit")
|
||||
coloum["list"] = ColumnName.GetBool("list")
|
||||
coloum["must"] = ColumnName.GetBool("must")
|
||||
|
||||
if ColumnName.Info {
|
||||
if ColumnName.GetBool("info") {
|
||||
delete(coloum, "info")
|
||||
}
|
||||
if ColumnName.Edit {
|
||||
if ColumnName.GetBool("edit") {
|
||||
delete(coloum, "edit")
|
||||
delete(coloum, "add")
|
||||
}
|
||||
if ColumnName.List {
|
||||
if ColumnName.GetBool("list") {
|
||||
delete(coloum, "list")
|
||||
}
|
||||
if ColumnName.Must {
|
||||
if ColumnName.GetBool("must") {
|
||||
delete(coloum, "must")
|
||||
}
|
||||
|
||||
if ColumnName.Type != "" {
|
||||
coloum["type"] = ColumnName.Type
|
||||
if ColumnName.GetString("type") != "" {
|
||||
coloum["type"] = ColumnName.GetString("type")
|
||||
}
|
||||
if ColumnName.Strict && coloum.GetString("name") == ColumnName.Name {
|
||||
if ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name") {
|
||||
break
|
||||
}
|
||||
|
||||
@ -291,16 +314,16 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
|
||||
|
||||
}
|
||||
|
||||
if makeCode {
|
||||
if config.GetInt("mode") != 0 {
|
||||
//创建模块文件
|
||||
//判断文件是否存在
|
||||
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
|
||||
_, err := os.Stat(name + "/" + v.GetString("name") + ".go")
|
||||
_, err := os.Stat(config.GetString("name") + "/" + v.GetString("name") + ".go")
|
||||
if err != nil { //文件不存在,则根据模板创建
|
||||
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1)
|
||||
myCtr := strings.Replace(CtrTpt, "{{name}}", config.GetString("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)
|
||||
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("name")+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
@ -506,25 +529,31 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
|
||||
fmt.Println(id, "---", that.Config.GetString("id"))
|
||||
that.Config["id"] = id
|
||||
|
||||
if makeCode {
|
||||
if config.GetInt("mode") != 0 {
|
||||
//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)
|
||||
_ = os.MkdirAll(config.GetString("name"), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("name")+"/init.go", []byte(myInit), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
}
|
||||
//写入配置文件
|
||||
//var configByte bytes.Buffer
|
||||
|
||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
_ = os.MkdirAll(filepath.Dir(path), os.ModeDir)
|
||||
err = ioutil.WriteFile(path, []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("rule")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("rule"), []byte(ObjToStr(that.RuleConfig)), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
|
||||
//写入配置文件
|
||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
|
||||
fmt.Println("有新的代码生成,请重新运行")
|
||||
os.Exit(-1)
|
||||
|
||||
@ -534,7 +563,16 @@ func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string,
|
||||
reStr := ""
|
||||
data := Map{}
|
||||
var ruleData Map
|
||||
for _, v := range that.TableColumns[table] {
|
||||
testQu := []string{}
|
||||
testQuData := that.TableColumns[table]
|
||||
for key, _ := range testQuData {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
@ -682,12 +720,22 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
data := Map{}
|
||||
keyword := Map{}
|
||||
daterange := Map{}
|
||||
sort := Map{}
|
||||
sortMap := Map{}
|
||||
var ruleData Map
|
||||
hasUser := false
|
||||
|
||||
keywordStr := req.FormValue("keyword")
|
||||
for _, v := range that.TableColumns[table] {
|
||||
|
||||
testQu := []string{}
|
||||
testQuData := that.TableColumns[table]
|
||||
for key, _ := range testQuData {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
|
||||
@ -803,7 +851,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
if searchItem.GetString("name") == "sort" {
|
||||
sort["ORDER"] = table + "." + reqValue
|
||||
sortMap["ORDER"] = table + "." + reqValue
|
||||
}
|
||||
|
||||
continue
|
||||
@ -823,8 +871,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
if sort["ORDER"] == nil {
|
||||
sort["ORDER"] = table + ".id DESC"
|
||||
if sortMap["ORDER"] == nil {
|
||||
sortMap["ORDER"] = table + ".id DESC"
|
||||
}
|
||||
|
||||
where := Map{}
|
||||
@ -869,8 +917,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
}
|
||||
|
||||
if len(sort) != 0 {
|
||||
for k, v := range sort {
|
||||
if len(sortMap) != 0 {
|
||||
for k, v := range sortMap {
|
||||
where[k] = v
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ var Project = Proj{
|
||||
{{tablesCtr}}
|
||||
"hotime":Ctr{
|
||||
"login": func(that *Context) {
|
||||
|
||||
name := that.Req.FormValue("name")
|
||||
password := that.Req.FormValue("password")
|
||||
if name == "" || password == "" {
|
||||
@ -36,8 +37,9 @@ var Project = Proj{
|
||||
that.Display(0, "退出登录成功")
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info("admin", data, that.Db)
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info("admin", data, that.Db)
|
||||
where := Map{"id": that.Session("admin_id").ToCeilInt()}
|
||||
if len(inData) ==1 {
|
||||
inData["id"] =where["id"]
|
||||
@ -52,7 +54,7 @@ var Project = Proj{
|
||||
return
|
||||
}
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns["admin"][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns["admin"][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@ -76,8 +78,9 @@ import (
|
||||
|
||||
var {{table}}Ctr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
|
||||
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
|
||||
where := Map{"id": that.RouterString[2]}
|
||||
|
||||
if len(inData) ==1 {
|
||||
@ -96,7 +99,7 @@ var {{table}}Ctr = Ctr{
|
||||
}
|
||||
|
||||
for k, v := range re {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
@ -108,7 +111,8 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"add": func(that *Context) {
|
||||
inData := that.MakeCode.Add(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -134,7 +138,8 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"update": func(that *Context) {
|
||||
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
@ -165,7 +170,8 @@ var {{table}}Ctr = Ctr{
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
@ -186,10 +192,10 @@ var {{table}}Ctr = Ctr{
|
||||
},
|
||||
|
||||
"search": func(that *Context) {
|
||||
|
||||
hotimeName := that.RouterString[0]
|
||||
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
|
||||
|
||||
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
|
||||
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
@ -208,7 +214,7 @@ var {{table}}Ctr = Ctr{
|
||||
|
||||
for _, v := range reData {
|
||||
for k, _ := range v {
|
||||
column := that.MakeCode.TableColumns[that.RouterString[1]][k]
|
||||
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
|
||||
if column == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
//hotime的常用map
|
||||
@ -98,6 +99,22 @@ func (that Map) GetBool(key string, err ...*Error) bool {
|
||||
|
||||
return v
|
||||
|
||||
}
|
||||
func (that Map) RangeSort(callback func(k string, v interface{}) (isEnd bool)) {
|
||||
testQu := []string{}
|
||||
//testQuData:= qu[0].(Map)
|
||||
for key, _ := range that {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
for _, k := range testQu {
|
||||
re := callback(k, that[k])
|
||||
if re {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (that Map) GetMap(key string, err ...*Error) Map {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -447,7 +448,16 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
}
|
||||
|
||||
if join {
|
||||
for k, v := range qu[0].(Map) {
|
||||
var testQu = []string{}
|
||||
testQuData := qu[0].(Map)
|
||||
for key, _ := range testQuData {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
switch Substr(k, 0, 3) {
|
||||
case "[>]":
|
||||
query += " LEFT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string)
|
||||
@ -560,7 +570,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
|
||||
res := make([]interface{}, 0)
|
||||
//AND OR判断
|
||||
for k, v := range data {
|
||||
testQu := []string{}
|
||||
//testQuData:= qu[0].(Map)
|
||||
for key, _ := range data {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
for _, k := range testQu {
|
||||
v := data[k]
|
||||
x := 0
|
||||
for i := 0; i < len(condition); i++ {
|
||||
|
||||
@ -607,7 +625,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
|
||||
|
||||
//特殊字符
|
||||
for j := 0; j < len(vcond); j++ {
|
||||
for k, v := range data {
|
||||
testQu := []string{}
|
||||
//testQuData:= qu[0].(Map)
|
||||
for key, _ := range data {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
for _, k := range testQu {
|
||||
v := data[k]
|
||||
if vcond[j] == k {
|
||||
if k == "ORDER" {
|
||||
where += " " + k + " BY "
|
||||
@ -881,7 +907,15 @@ func (that *HoTimeDB) cond(tag string, data Map) (string, []interface{}) {
|
||||
res := make([]interface{}, 0)
|
||||
lens := len(data)
|
||||
//fmt.Println(lens)
|
||||
for k, v := range data {
|
||||
testQu := []string{}
|
||||
//testQuData:= qu[0].(Map)
|
||||
for key, _ := range data {
|
||||
//fmt.Println(key, ":", value)
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
for _, k := range testQu {
|
||||
v := data[k]
|
||||
x := 0
|
||||
for i := 0; i < len(condition); i++ {
|
||||
|
||||
|
@ -12,12 +12,9 @@
|
||||
}
|
||||
},
|
||||
"codeConfig": {
|
||||
"admin": "config/app.json"
|
||||
},
|
||||
"codeConfig1": {
|
||||
"admin": {
|
||||
"config": "config/app.json",
|
||||
"package": "admin",
|
||||
"name": "admin",
|
||||
"rule": "config/rule.json"
|
||||
}
|
||||
},
|
||||
@ -44,7 +41,7 @@
|
||||
"5": "数据结果异常"
|
||||
},
|
||||
"imgPath": "img/2006/01/02/",
|
||||
"mode": 3,
|
||||
"mode": 0,
|
||||
"port": "8081",
|
||||
"sessionName": "HOTIME",
|
||||
"smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa",
|
||||
|
@ -21,7 +21,13 @@
|
||||
"注释": "可配置memory,db,redis,默认启用memory,默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致,缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用"
|
||||
},
|
||||
"codeConfig": {
|
||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||
"admin": {
|
||||
"config": "默认config/app.json,必须,接口描述配置文件",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"注释": "默认admin,非必须,有则根据数据库内当前表名做为用户生成数据"
|
||||
},
|
||||
"注释": "配置即启用,非必须,默认无"
|
||||
},
|
||||
"crossDomain": "默认空 非必须,空字符串为不开启,如果需要跨域设置,auto为智能开启所有网站允许跨域,http://www.baidu.com为指定域允许跨域",
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"code.hoteas.com/golang/hotime"
|
||||
//. "code.hoteas.com/golang/hotime/common"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@ -11,5 +12,7 @@ func main() {
|
||||
fmt.Println(date, date.Unix())
|
||||
//fmt.Println("0123456"[1:7])
|
||||
appIns := hotime.Init("config/config.json")
|
||||
//a:=Map{}
|
||||
//a.GetBool()
|
||||
appIns.Run(hotime.Router{})
|
||||
}
|
||||
|
32
var.go
32
var.go
@ -10,15 +10,17 @@ var App = map[string]*Application{} //整个项目
|
||||
//var Db = HoTimeDB{} //数据库实例
|
||||
|
||||
var Config = Map{
|
||||
"mode": 3, //模式 0生产模式,1,测试模式,2,开发模式,3,内嵌代码模式
|
||||
"mode": 2, //模式 0生产模式,1,测试模式,2,开发模式
|
||||
//"codeConfig": Map{
|
||||
// "admin": "config/app.json",
|
||||
//},
|
||||
"codeConfig": Map{
|
||||
"admin": "config/app.json",
|
||||
},
|
||||
"codeConfig1": Map{
|
||||
"admin": Map{ //默认无,必须,接口类别名称
|
||||
"package": "admin", //默认admin,非必须,有则生成代码到此目录,无则采用缺省模式不生成代码只生成接口
|
||||
"admin": Map{
|
||||
//"table":"admin",//默认admin,必须,有则根据数据库内当前表名做为用户生成数据
|
||||
"name": "", //默认admin,非必须,有则生成代码到此目录,无则采用缺省模式使用表名
|
||||
"config": "config/app.json", //默认config/app.json,必须,接口描述配置文件
|
||||
"rule": "config/rule.json", //默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成
|
||||
"mode": 0, //默认0,非必须,0为内嵌代码模式,1为生成代码模式
|
||||
},
|
||||
},
|
||||
"db": Map{
|
||||
@ -52,12 +54,22 @@ var ConfigNote = Map{
|
||||
"webConnectLogShow": "默认true,非必须,访问日志如果需要web访问链接、访问ip、访问时间打印,false为关闭true开启此功能",
|
||||
"webConnectLogFile": "无默认,非必须,webConnectLogShow开启之后才能使用,如果需要存储日志文件时使用,保存格式为:a/b/c/20060102150405.txt,将生成:a/b/c/年月日时分秒.txt,按需设置",
|
||||
"mode": "默认0,非必须,0生产模式,1,测试模式,2开发模式,3内嵌代码模式,在开发模式下会显示更多的数据用于开发测试,并能够辅助研发,自动生成配置文件、代码等功能,web无缓存,数据库不启用缓存", //debug 0关闭1开启
|
||||
//"codeConfig": Map{
|
||||
// "注释": "配置即启用,非必须,默认无",
|
||||
// //"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
||||
// //"path":""
|
||||
//
|
||||
// "packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||
//},
|
||||
"codeConfig": Map{
|
||||
"注释": "配置即启用,非必须,默认无",
|
||||
//"package":"默认admin,必须,mode模式为2时会自动生成包文件夹和代码文件",
|
||||
//"path":""
|
||||
|
||||
"packageName": "默认无,必须,包名称以及应用名,生成代码的配置文件地址,比如config/app.json,数据库有更新时自动更新配置文件以及对应的生成文件",
|
||||
"admin": Map{ //默认无,必须,接口类别名称
|
||||
"注释": "默认admin,非必须,有则根据数据库内当前表名做为用户生成数据", //
|
||||
"name": "默认无,非必须,有则生成代码到此目录,无则采用缺省模式使用表名,如设置为:admin,将在admin目录生成包名为admin的代码",
|
||||
"config": "默认config/app.json,必须,接口描述配置文件", //
|
||||
"rule": "默认config/rule.json,非必须,有则按改规则生成接口,无则按系统内嵌方式生成",
|
||||
"mode": "默认0,非必须,0为内嵌代码模式,1为生成代码模式",
|
||||
},
|
||||
},
|
||||
"db": Map{
|
||||
"注释": "配置即启用,非必须,默认使用sqlite数据库",
|
||||
|
Loading…
Reference in New Issue
Block a user