Browse Source

更新域名获取

master
dengbiao 4 months ago
parent
commit
c581cd4925
5 changed files with 27 additions and 56 deletions
  1. +1
    -1
      app/db/dao/sys_cfg_dao.go
  2. +5
    -5
      app/db/implement/sys_cfg_implement.go
  3. +0
    -7
      app/db/model/sys_cfg.go
  4. +4
    -4
      app/svc/svc_master.go
  5. +17
    -39
      app/svc/svc_sys_cfg_get.go

+ 1
- 1
app/db/dao/sys_cfg_dao.go View File

@@ -1,6 +1,6 @@
package dao

import "applet/app/db/model"
import "code.fnuoos.com/zhimeng/model.git/src/model"

type SysCfgDao interface {
SysCfgGetAll() (*[]model.SysCfg, error)


+ 5
- 5
app/db/implement/sys_cfg_implement.go View File

@@ -2,10 +2,10 @@

import (
"applet/app/db/dao"
"applet/app/db/model"
"applet/app/md"
"applet/app/utils/cache"
"applet/app/utils/logx"
"code.fnuoos.com/zhimeng/model.git/src/model"
"fmt"
"xorm.io/xorm"
)
@@ -51,7 +51,7 @@ func (s SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) {
}

func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool {
cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
cfg := model.SysCfg{K: key, V: val, Memo: memo}
_, err := s.Db.InsertOne(&cfg)
if err != nil {
logx.Error(err)
@@ -61,7 +61,7 @@ func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool {
}

func (s SysCfgDb) SysCfgUpdate(key, val string) bool {
cfg := model.SysCfg{Key: key, Val: val}
cfg := model.SysCfg{K: key, V: val}
_, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg)
if err != nil {
logx.Error(err)
@@ -88,7 +88,7 @@ func (s SysCfgDb) SysCfgGetWithDb(HKey string) string {
}

// 设置缓存
_, err = cache.HSet(cacheKey, HKey, cfg.Val)
_, err = cache.HSet(cacheKey, HKey, cfg.V)
if err != nil {
_ = logx.Error(err)
return ""
@@ -100,7 +100,7 @@ func (s SysCfgDb) SysCfgGetWithDb(HKey string) string {
return ""
}
}
return cfg.Val
return cfg.V
}
return get
}


+ 0
- 7
app/db/model/sys_cfg.go View File

@@ -1,7 +0,0 @@
package model

type SysCfg struct {
Key string `json:"key" xorm:"not null pk comment('键') VARCHAR(127)"`
Val string `json:"val" xorm:"comment('值') TEXT"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"`
}

+ 4
- 4
app/svc/svc_master.go View File

@@ -20,17 +20,17 @@ func GetMasterId(c *gin.Context) (masterId string) {
if masterId == "" {
//TODO::通过域名查找masterId
host := c.Request.Host
mediumAppDomainDb := implement.NewMediumAppDomainDb(db.Db)
mediumAppDomain, err := mediumAppDomainDb.GetMediumAppDomainByHost(host)
userAppDomainDb := implement.NewUserAppDomainDb(db.Db)
userAppDomain, err := userAppDomainDb.GetMediumAppDomainByHost(host)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err)
return
}
if mediumAppDomain == nil {
if userAppDomain == nil {
e.OutErr(c, e.ERR_NOT_FAN, "域名不存在")
return
}
masterId = utils.IntToStr(mediumAppDomain.Uuid)
masterId = utils.IntToStr(userAppDomain.Uuid)
c.Set("master_id", masterId)
}
fmt.Println("master_id:::::::", masterId)


+ 17
- 39
app/svc/svc_sys_cfg_get.go View File

@@ -1,6 +1,7 @@
package svc

import (
"applet/app/db/implement"
db "code.fnuoos.com/zhimeng/model.git/src"
"github.com/gin-gonic/gin"
"xorm.io/xorm"
@@ -11,9 +12,10 @@ import (

// 单挑记录获取
func SysCfgGet(c *gin.Context, key string) string {
mid := c.GetString("mid")
eg := db.DBs[mid]
return db.SysCfgGetWithDb(eg, mid, key)
masterId := GetMasterId(c)
eg := db.DBs[masterId]
sysCfgDb := implement.NewSysCfgDb(eg, masterId)
return sysCfgDb.SysCfgGetWithDb(key)
}

// 多条记录获取
@@ -22,7 +24,7 @@ func SysCfgFind(c *gin.Context, keys ...string) map[string]string {
if c == nil {
masterId = ""
} else {
masterId = c.GetString("mid")
masterId = GetMasterId(c)
}
tmp := SysCfgFindComm(masterId, keys...)
return tmp
@@ -36,51 +38,23 @@ func SysCfgFindComm(masterId string, keys ...string) map[string]string {
}
res := map[string]string{}
//TODO::判断keys长度(大于10个直接查数据库)
sysCfgDb := implement.NewSysCfgDb(eg, masterId)
if len(keys) > 10 {
cfgList, _ := db.SysCfgGetAll(eg)
cfgList, _ := sysCfgDb.SysCfgGetAll()
if cfgList == nil {
return nil
}
for _, v := range *cfgList {
res[v.Key] = v.Val
res[v.K] = v.V
}
} else {
for _, key := range keys {
res[key] = db.SysCfgGetWithDb(eg, masterId, key)
res[key] = sysCfgDb.SysCfgGetWithDb(key)
}
}
return res
}

// 多条记录获取
func EgSysCfgFind(keys ...string) map[string]string {
var e *xorm.Engine
res := map[string]string{}
if len(res) == 0 {
cfgList, _ := db.SysCfgGetAll(e)
if cfgList == nil {
return nil
}
for _, v := range *cfgList {
res[v.Key] = v.Val
}
// 先不设置缓存
// cache.SetJson(md.KEY_SYS_CFG_CACHE, res, 60)
}
if len(keys) == 0 {
return res
}
tmp := map[string]string{}
for _, v := range keys {
if val, ok := res[v]; ok {
tmp[v] = val
} else {
tmp[v] = ""
}
}
return tmp
}

// 清理系统配置信息
func SysCfgCleanCache() {
cache.Del(md.KEY_SYS_CFG_CACHE)
@@ -88,13 +62,17 @@ func SysCfgCleanCache() {

// 写入系统设置
func SysCfgSet(c *gin.Context, key, val, memo string) bool {
cfg, err := db.SysCfgGetOne(db.DBs[c.GetString("mid")], key)
masterId := GetMasterId(c)
eg := db.DBs[masterId]
sysCfgDb := implement.NewSysCfgDb(eg, masterId)

cfg, err := sysCfgDb.SysCfgGetOne(key)
if err != nil || cfg == nil {
return db.SysCfgInsert(db.DBs[c.GetString("mid")], key, val, memo)
return sysCfgDb.SysCfgInsert(key, val, memo)
}
if memo != "" && cfg.Memo != memo {
cfg.Memo = memo
}
SysCfgCleanCache()
return db.SysCfgUpdate(db.DBs[c.GetString("mid")], key, val, cfg.Memo)
return sysCfgDb.SysCfgUpdate(key, val)
}

Loading…
Cancel
Save