forked from mgr/GoClouds
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.2 KiB
70 lines
1.2 KiB
package sysService
|
|
|
|
import (
|
|
"GoClouds/core/comm"
|
|
"GoClouds/models"
|
|
"encoding/json"
|
|
uuid "github.com/satori/go.uuid"
|
|
"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.Uuid=uuid.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("uuid=?", e.Uuid).Update(e)
|
|
} else {
|
|
e.Uuid = uuid.NewV4().String()
|
|
e.Name = key
|
|
e.Times = time.Now()
|
|
comm.DbSys.Insert(e)
|
|
}
|
|
|
|
return true
|
|
}
|