diff --git a/src/dao/sys_cfg_dao.go b/src/dao/sys_cfg_dao.go new file mode 100644 index 0000000..b7d5391 --- /dev/null +++ b/src/dao/sys_cfg_dao.go @@ -0,0 +1,10 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/model" + +type SysCfgDao interface { + GetSysCfg(keys string) (m *model.SysCfg, err error) + GetSysCfgStr(keys string) (str string) + FindSysCfg(keys ...string) (m *[]model.SysCfg, err error) + FindSysCfgStr(keys ...string) (str map[string]string) +} diff --git a/src/implement/sys_cfg_implement.go b/src/implement/sys_cfg_implement.go new file mode 100644 index 0000000..ac6e269 --- /dev/null +++ b/src/implement/sys_cfg_implement.go @@ -0,0 +1,66 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/dao" + "code.fnuoos.com/zhimeng/model.git/src/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewSysCfgDb(engine *xorm.Engine) dao.SysCfgDao { + return &SysCfgDb{Db: engine} +} + +type SysCfgDb struct { + Db *xorm.Engine +} + +func (s SysCfgDb) GetSysCfg(keys string) (sysCfg *model.SysCfg, err error) { + sysCfg = new(model.SysCfg) + has, err := s.Db.Where("`k` =?", keys).Get(sysCfg) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return sysCfg, nil +} +func (s SysCfgDb) GetSysCfgStr(keys string) (str string) { + sysCfg := new(model.SysCfg) + has, err := s.Db.Where("`k` =?", keys).Get(sysCfg) + if err != nil { + return "" + } + if has == false { + return "" + } + return sysCfg.V +} + +func (s SysCfgDb) FindSysCfg(keys ...string) (sysCfg *[]model.SysCfg, err error) { + sysCfg = new([]model.SysCfg) + has, err := s.Db.In("`k` ", keys).Get(sysCfg) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return sysCfg, nil +} +func (s SysCfgDb) FindSysCfgStr(keys ...string) (str map[string]string) { + str = make(map[string]string) + for _, v := range keys { + str[v] = "" + } + var sysCfg []model.SysCfg + err := s.Db.In("`k`", keys).Find(&sysCfg) + if err != nil { + return str + } + for _, v := range sysCfg { + str[v.K] = v.V + } + return str +}