Procházet zdrojové kódy

delete sys_cfg

master
dengbiao před 3 týdny
rodič
revize
b030746d56
2 změnil soubory, kde provedl 0 přidání a 147 odebrání
  1. +0
    -15
      src/dao/sys_cfg_dao.go
  2. +0
    -132
      src/implement/sys_cfg_implement.go

+ 0
- 15
src/dao/sys_cfg_dao.go Zobrazit soubor

@@ -1,15 +0,0 @@
package dao

import "code.fnuoos.com/EggPlanet/egg_models.git/src/model"

type SysCfgDao interface {
Close() error
SysCfgGetAll() (*[]model.SysCfg, error)
SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error)
SysCfgGetOne(key string) (*model.SysCfg, error)
SysCfgInsert(key, val, memo string) bool
SysCfgUpdate(key, val string) bool
SysCfgGetWithDb(HKey string) string
SysCfgDel(HKey string) error
SysCfgFindWithDb(keys ...string) map[string]string
}

+ 0
- 132
src/implement/sys_cfg_implement.go Zobrazit soubor

@@ -1,132 +0,0 @@
package implement

import (
"code.fnuoos.com/EggPlanet/egg_models.git/md"
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"code.fnuoos.com/EggPlanet/egg_models.git/utils/cache"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"fmt"
"github.com/gomodule/redigo/redis"
"xorm.io/xorm"
)

func NewSysCfgDb(engine *xorm.Engine, conn redis.Conn) dao.SysCfgDao {
if conn != nil {
cache.NewRedisConn(conn)
}
return &SysCfgDb{
Db: engine,
RedisAddr: conn,
}
}

type SysCfgDb struct {
Db *xorm.Engine
RedisAddr redis.Conn
}

func (s SysCfgDb) Close() error { //TODO::使用时,强制defer调用此析构函数
if s.RedisAddr != nil {
return s.RedisAddr.Close()
}
return nil
}

func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) {
var cfgList []model.SysCfg
if err := s.Db.Cols("key,val,memo").Find(&cfgList); err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error) {
var cfgList model.SysCfg
_, err := s.Db.Where("`key`=?", key).Get(&cfgList)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) {
var cfgList model.SysCfg
if has, err := s.Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool {
cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
_, err := s.Db.InsertOne(&cfg)
if err != nil {
zhios_order_relate_logx.Error(err)
return false
}
return true
}

func (s SysCfgDb) SysCfgUpdate(key, val string) bool {
cfg := model.SysCfg{Key: key, Val: val}
_, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg)
if err != nil {
zhios_order_relate_logx.Error(err)
return false
}
s.SysCfgDel(key)
return true
}

func (s SysCfgDb) SysCfgGetWithDb(HKey string) string {
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1])
get, err := cache.HGetString(cacheKey, HKey)
if err != nil || get == "" {
cfg, err := s.SysCfgGetOne(HKey)
if err != nil || cfg == nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}

// key是否存在
cacheKeyExist := false
if cache.Exists(cacheKey) {
cacheKeyExist = true
}

// 设置缓存
_, err = cache.HSet(cacheKey, HKey, cfg.Val)
if err != nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}
if !cacheKeyExist { // 如果是首次设置 设置过期时间
_, err := cache.Expire(cacheKey, md.CfgCacheTime)
if err != nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}
}
return cfg.Val
}
return get
}

func (s SysCfgDb) SysCfgDel(HKey string) error {
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1])
_, err := cache.HDel(cacheKey, HKey)
if err != nil {
return err
}
return nil
}

func (s SysCfgDb) SysCfgFindWithDb(keys ...string) map[string]string {
res := map[string]string{}
for _, v := range keys {
val := s.SysCfgGetWithDb(v)
res[v] = val
}
return res
}

Načítá se…
Zrušit
Uložit