4 changed files with 33 additions and 85 deletions
@ -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"` |
|||
} |
@ -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 |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue