From 05db9d108e855c5bb50a893883e61a5290739557 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 21 Aug 2024 17:33:07 +0800 Subject: [PATCH] cfg --- src/dao/sys_cfg_dao.go | 10 +++++ src/implement/sys_cfg_implement.go | 66 ++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/dao/sys_cfg_dao.go create mode 100644 src/implement/sys_cfg_implement.go 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 +}