|
@@ -1,50 +0,0 @@ |
|
|
package db |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/model" |
|
|
|
|
|
"xorm.io/xorm" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// 系统配置get |
|
|
|
|
|
func SysCfgGetAll(Db *xorm.Engine) (*[]model.SysCfg, error) { |
|
|
|
|
|
var cfgList []model.SysCfg |
|
|
|
|
|
if err := Db.Cols("k,v,memo").Find(&cfgList); err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
return &cfgList, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取一条记录 |
|
|
|
|
|
func SysCfgGetOne(Db *xorm.Engine, key string) (*model.SysCfg, error) { |
|
|
|
|
|
var cfgList model.SysCfg |
|
|
|
|
|
if has, err := Db.Where("`k`=?", key).Get(&cfgList); err != nil || has == false { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
return &cfgList, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 返回最后插入id |
|
|
|
|
|
func SysCfgInsert(Db *xorm.Engine, key, val, memo string) bool { |
|
|
|
|
|
cfg := model.SysCfg{K: key, V: val, Memo: memo} |
|
|
|
|
|
_, err := Db.InsertOne(&cfg) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SysCfgUpdate(Db *xorm.Engine, key, val, memo string) bool { |
|
|
|
|
|
cfg := model.SysCfg{K: key, V: val, Memo: memo} |
|
|
|
|
|
_, err := Db.Where("`key`=?", key).Cols("val,memo").Update(&cfg) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return false |
|
|
|
|
|
} |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
func SysCfgGetWithDb(eg *xorm.Engine, masterId string, HKey string) string { |
|
|
|
|
|
cfg, err := SysCfgGetOne(eg, HKey) |
|
|
|
|
|
if err != nil || cfg == nil { |
|
|
|
|
|
return "" |
|
|
|
|
|
} |
|
|
|
|
|
return cfg.V |
|
|
|
|
|
} |
|
|
|