@@ -0,0 +1,14 @@ | |||||
package sys_cfg | |||||
import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
type SysCfgDao interface { | |||||
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,0 +1,118 @@ | |||||
package sys_cfg | |||||
import ( | |||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/md" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | |||||
"fmt" | |||||
"xorm.io/xorm" | |||||
) | |||||
func NewSysCfgDb(engine *xorm.Engine) SysCfgDao { | |||||
return &SysCfgDb{ | |||||
Db: engine, | |||||
} | |||||
} | |||||
type SysCfgDb struct { | |||||
Db *xorm.Engine | |||||
} | |||||
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 | |||||
} |
@@ -3,14 +3,12 @@ package consume | |||||
import ( | import ( | ||||
"applet/app/cfg" | "applet/app/cfg" | ||||
"applet/app/db" | "applet/app/db" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | |||||
"applet/app/svc/sys_cfg" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | "code.fnuoos.com/EggPlanet/egg_system_rules.git" | ||||
utils2 "applet/app/utils" | utils2 "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"applet/consume/md" | "applet/consume/md" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" | ||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | ||||
@@ -76,14 +74,7 @@ func handleAliyunSmsRecordConsume(msgData []byte) error { | |||||
return err | return err | ||||
} | } | ||||
engine := db.Db | engine := db.Db | ||||
redisConn := cache.GetPool().Get() | |||||
sysCfgDb := implement.NewSysCfgDb(engine, redisConn) | |||||
defer func(sysCfgDb dao.SysCfgDao) { | |||||
err := sysCfgDb.Close() | |||||
if err != nil { | |||||
logx.Error("redis close err:" + err.Error()) // 记录错误信息 | |||||
} | |||||
}(sysCfgDb) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(engine) | |||||
aliyunSmsId := sysCfgDb.SysCfgGetWithDb("aliyun_sms_id") | aliyunSmsId := sysCfgDb.SysCfgGetWithDb("aliyun_sms_id") | ||||
aliyunSmsSecret := sysCfgDb.SysCfgGetWithDb("aliyun_sms_secret") | aliyunSmsSecret := sysCfgDb.SysCfgGetWithDb("aliyun_sms_secret") | ||||
aliyunSmsSignName := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sign_name") | aliyunSmsSignName := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sign_name") | ||||
@@ -4,15 +4,14 @@ import ( | |||||
"applet/app/cfg" | "applet/app/cfg" | ||||
"applet/app/db" | "applet/app/db" | ||||
utils2 "applet/app/utils" | utils2 "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"applet/consume/md" | "applet/consume/md" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | "code.fnuoos.com/EggPlanet/egg_system_rules.git" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc/sys_cfg" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | ||||
"context" | "context" | ||||
"encoding/json" | "encoding/json" | ||||
@@ -158,13 +157,7 @@ type InitAlipayStruct struct { | |||||
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。 | // isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。 | ||||
func InitAlipay(initData *InitAlipayStruct) (client *alipay.Client, err error) { | func InitAlipay(initData *InitAlipayStruct) (client *alipay.Client, err error) { | ||||
if initData == nil { | if initData == nil { | ||||
sysCfgDb := implement.NewSysCfgDb(db.Db, cache.GetPool().Get()) | |||||
defer func(sysCfgDb dao.SysCfgDao) { | |||||
err := sysCfgDb.Close() | |||||
if err != nil { | |||||
logx.Error("redis close err:" + err.Error()) // 记录错误信息 | |||||
} | |||||
}(sysCfgDb) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfgMap := sysCfgDb.SysCfgFindWithDb(enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | sysCfgMap := sysCfgDb.SysCfgFindWithDb(enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | ||||
initData = &InitAlipayStruct{ | initData = &InitAlipayStruct{ | ||||
IsProd: true, | IsProd: true, | ||||
@@ -3,13 +3,10 @@ package consume | |||||
import ( | import ( | ||||
"applet/app/cfg" | "applet/app/cfg" | ||||
"applet/app/db" | "applet/app/db" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | |||||
"applet/app/svc/sys_cfg" | |||||
utils2 "applet/app/utils" | utils2 "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"applet/consume/md" | "applet/consume/md" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | "code.fnuoos.com/EggPlanet/egg_system_rules.git" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/jPush" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/jPush" | ||||
@@ -77,14 +74,7 @@ func handleJpushRecordConsume(msgData []byte) error { | |||||
return err | return err | ||||
} | } | ||||
engine := db.Db | engine := db.Db | ||||
redisConn := cache.GetPool().Get() | |||||
sysCfgDb := implement.NewSysCfgDb(engine, redisConn) | |||||
defer func(sysCfgDb dao.SysCfgDao) { | |||||
err := sysCfgDb.Close() | |||||
if err != nil { | |||||
logx.Error("redis close err:" + err.Error()) // 记录错误信息 | |||||
} | |||||
}(sysCfgDb) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(engine) | |||||
jpushKey := sysCfgDb.SysCfgGetWithDb("jpush_key") | jpushKey := sysCfgDb.SysCfgGetWithDb("jpush_key") | ||||
jpushSecret := sysCfgDb.SysCfgGetWithDb("jpush_secret") | jpushSecret := sysCfgDb.SysCfgGetWithDb("jpush_secret") | ||||
if msg.Target == "0" { //广播全部 | if msg.Target == "0" { //广播全部 | ||||
@@ -4,8 +4,8 @@ import ( | |||||
"applet/app/cfg" | "applet/app/cfg" | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/svc/sys_cfg" | |||||
utils2 "applet/app/utils" | utils2 "applet/app/utils" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | "code.fnuoos.com/EggPlanet/egg_system_rules.git" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | ||||
@@ -88,14 +88,7 @@ func handlePlayletRewardConsume(ch *rabbit.Channel, msgData []byte) error { | |||||
defer cb() // 释放锁 | defer cb() // 释放锁 | ||||
} | } | ||||
eg := db.Db | eg := db.Db | ||||
redisConn := cache.GetPool().Get() | |||||
sysCfgDb := implement.NewSysCfgDb(eg, redisConn) | |||||
defer func(sysCfgDb dao.SysCfgDao) { | |||||
err := sysCfgDb.Close() | |||||
if err != nil { | |||||
logx.Error("redis close err:" + err.Error()) // 记录错误信息 | |||||
} | |||||
}(sysCfgDb) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(eg) | |||||
playletBase := sysCfgDb.SysCfgGetWithDb("playlet_base") | playletBase := sysCfgDb.SysCfgGetWithDb("playlet_base") | ||||
sess := eg.NewSession() | sess := eg.NewSession() | ||||
defer sess.Close() | defer sess.Close() | ||||
@@ -8,13 +8,13 @@ import ( | |||||
"applet/app/utils/cache" | "applet/app/utils/cache" | ||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"applet/consume/md" | "applet/consume/md" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | "code.fnuoos.com/EggPlanet/egg_system_rules.git" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc/sys_cfg" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | ||||
"encoding/json" | "encoding/json" | ||||
"errors" | "errors" | ||||
@@ -87,14 +87,7 @@ func handleVideoRewardConsume(ch *rabbit.Channel, msgData []byte) error { | |||||
defer cb() // 释放锁 | defer cb() // 释放锁 | ||||
} | } | ||||
eg := db.Db | eg := db.Db | ||||
redisConn := cache.GetPool().Get() | |||||
sysCfgDb := implement.NewSysCfgDb(eg, redisConn) | |||||
defer func(sysCfgDb dao.SysCfgDao) { | |||||
err := sysCfgDb.Close() | |||||
if err != nil { | |||||
logx.Error("redis close err:" + err.Error()) // 记录错误信息 | |||||
} | |||||
}(sysCfgDb) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
videoBase := sysCfgDb.SysCfgGetWithDb("video_base") | videoBase := sysCfgDb.SysCfgGetWithDb("video_base") | ||||
sess := eg.NewSession() | sess := eg.NewSession() | ||||
defer sess.Close() | defer sess.Close() | ||||
@@ -7,8 +7,8 @@ go 1.19 | |||||
//replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules | //replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules | ||||
require ( | require ( | ||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2 | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241212093609-6ece027b8e1d | |||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14 | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241212122404-22c05dd7f73c | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||
github.com/boombuler/barcode v1.0.1 | github.com/boombuler/barcode v1.0.1 | ||||