LinskRuis.32 5 years ago
parent
commit
96ea50b343
  1. 1
      models/sys_file.go
  2. 14
      models/sys_param.go
  3. 70
      service/sysService/param.go
  4. 33
      webs/sys/main.go

1
models/sys_file.go

@ -11,7 +11,6 @@ type SysFile struct {
Uid string `xorm:"VARCHAR(64)"`
Toid string `xorm:"VARCHAR(64)"`
Extion string `xorm:"VARCHAR(50)"`
Name string `xorm:"not null pk VARCHAR(50)"`
Size int64 `xorm:"BIGINT(20)"`
Filename string `xorm:"VARCHAR(255)"`
Descpt string `xorm:"VARCHAR(500)"`

14
models/sys_param.go

@ -1,14 +0,0 @@
package models
import (
"time"
)
type SysParam struct {
Id int64 `xorm:"pk autoincr BIGINT(20)"`
Xid string `xorm:"not null pk VARCHAR(64)"`
Name string `xorm:"not null pk comment('key') VARCHAR(50)"`
Title string `xorm:"comment('名称') VARCHAR(100)"`
Value []byte `xorm:"BLOB"`
Times time.Time `xorm:"default CURRENT_TIMESTAMP TIMESTAMP"`
}

70
service/sysService/param.go

@ -1,70 +0,0 @@
package sysService
import (
"GoClouds/core/comm"
"GoClouds/models"
"encoding/json"
"gopkg.in/mgo.v2/bson"
"time"
)
func FindParam(key string) *models.SysParam {
e := new(models.SysParam)
ok, err := comm.DbSys.Where("name=?", key).Get(e)
if err != nil {
return nil
}
if ok {
return e
}
return nil
}
func GetParam(key string) map[string]interface{} {
e := new(models.SysParam)
ok, err := comm.DbSys.Where("name=?", key).Get(e)
if err != nil {
return nil
}
if !ok {
/*e.Xid=xid.NewV4().String()
e.Name=key
e.*/
return nil
}
rt := make(map[string]interface{})
err = json.Unmarshal(e.Value, &rt)
if err != nil {
return nil
}
return rt
}
func SetParam(key string, val *map[string]interface{}, tits ...string) bool {
e := new(models.SysParam)
ok, err := comm.DbSys.Where("name=?", key).Get(e)
if err != nil {
return false
}
bts, err := json.Marshal(val)
if err != nil {
return false
}
e.Value = bts
if len(tits) > 0 {
e.Title = tits[0]
}
if ok {
comm.DbSys.Where("xid=?", e.Xid).Update(e)
} else {
e.Xid = bson.NewObjectId().Hex()
e.Name = key
e.Times = time.Now()
comm.DbSys.Insert(e)
}
return true
}

33
webs/sys/main.go

@ -2,6 +2,7 @@ package main
import (
"GoClouds/core/comm"
"GoClouds/models"
"GoClouds/webs/sys/app"
"GoClouds/webs/sys/controller"
"github.com/mgr9525/go-cloud"
@ -25,6 +26,11 @@ func customFun() []template.FuncMap {
println("db err:" + err.Error())
os.Exit(1)
}
err = syncTable()
if err != nil {
println("db sync err:" + err.Error())
os.Exit(2)
}
gocloud.GetCustomConf("", app.Conf)
return []template.FuncMap{map[string]interface{}{
"AppName": func() string {
@ -39,3 +45,30 @@ func constomRoute() {
gocloud.RegController(new(controller.CommController))
gocloud.RegController(new(controller.UserController))
}
func syncTable() error {
if comm.DbSys == nil {
return nil
}
err := comm.DbSys.Sync(models.SysUser{})
if err != nil {
return err
}
err = comm.DbSys.Sync(models.SysFile{})
if err != nil {
return err
}
err = comm.DbSys.Sync(models.SysPermssion{})
if err != nil {
return err
}
err = comm.DbSys.Sync(models.SysRole{})
if err != nil {
return err
}
err = comm.DbSys.Sync(models.SysUserRole{})
if err != nil {
return err
}
return nil
}
Loading…
Cancel
Save