diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index bd129b9..7e8976d 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -6,10 +6,9 @@ import ( "applet/app/enum" "applet/app/md" "applet/app/svc" + "applet/app/svc/sys_cfg" "applet/app/utils" "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "fmt" @@ -156,15 +155,7 @@ func GetOssUrl(c *gin.Context) { CommOss(c, args) } func CommOss(c *gin.Context, args ImgReqUploadReq) { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfgs, err := sysCfgDb.SysCfgGetAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) @@ -231,15 +222,7 @@ type GetSTSVoucherResp struct { // @Failure 400 {object} md.Response "具体错误" // @Router /api/getSTSVoucher [GET] func GetSTSVoucher(c *gin.Context) { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfgs, err := sysCfgDb.SysCfgGetAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) diff --git a/app/hdl/friend_circle/hdl_dynamic.go b/app/hdl/friend_circle/hdl_dynamic.go index 6ee8204..f4d3797 100644 --- a/app/hdl/friend_circle/hdl_dynamic.go +++ b/app/hdl/friend_circle/hdl_dynamic.go @@ -6,10 +6,8 @@ import ( md "applet/app/md/friend_circle" "applet/app/svc" "applet/app/utils" - "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - svc2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" "context" "encoding/json" @@ -134,8 +132,7 @@ func GetDynamic(c *gin.Context) { for _, user := range users { userMap[user.Id] = user.Nickname } - redisConn := cache.GetPool().Get() - scheme, domain := svc2.ImageBucket(db.Db, redisConn) + scheme, domain := svc.ImageBucket(db.Db) list := make([]md.DynamicRespNode, len(docs)) for _, doc := range docs { switch doc.Kind { @@ -144,8 +141,8 @@ func GetDynamic(c *gin.Context) { case 2: doc.Username = adminMap[doc.Uid] } - imageStr := svc2.ImageFormatWithBucketForDataInfo(scheme, domain, doc.Image) - videoStr := svc2.ImageFormatWithBucketForDataInfo(scheme, domain, doc.Video) + imageStr := svc.ImageFormatWithBucketForDataInfo(scheme, domain, doc.Image) + videoStr := svc.ImageFormatWithBucketForDataInfo(scheme, domain, doc.Video) images := strings.Split(imageStr, ";") videos := strings.Split(videoStr, ";") temp := md.DynamicRespNode{ @@ -289,8 +286,8 @@ func ReleaseDynamic(c *gin.Context) { if req.IsTopUp == 0 { req.IsTopUp = 2 } - redisConn := cache.GetPool().Get() - scheme, domain := svc2.ImageBucket(db.Db, redisConn) + + scheme, domain := svc.ImageBucket(db.Db) var imageStr string if len(req.Image) > 0 { imageStr = strings.Join(req.Image, ";") diff --git a/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go b/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go index 4682915..e3baded 100644 --- a/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go +++ b/app/hdl/institutional_management/egg_energy/hdl_platform_revenue.go @@ -4,9 +4,7 @@ import ( "applet/app/db" "applet/app/e" md "applet/app/md/institutional_management/egg_energy" - "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" + "applet/app/svc/sys_cfg" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" @@ -27,15 +25,7 @@ import ( // @Failure 400 {object} md.Response "具体错误" // @Router /api/institutionalManagement/eggEnergy/platformRevenue/getVideoReward [post] func GetVideoReward(c *gin.Context) { - conn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, conn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) - + cfgDb := sys_cfg.NewSysCfgDb(db.Db) unitPrice, err2 := cfgDb.SysCfgGetOneNoDataNoErr(enum2.VideoRewardUnitPrice) if err2 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err2.Error()) @@ -78,15 +68,7 @@ func SetVideoReward(c *gin.Context) { return } - conn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, conn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) - + cfgDb := sys_cfg.NewSysCfgDb(db.Db) if !cfgDb.SysCfgUpdate(enum2.VideoRewardUnitPrice, req.UnitPrice) { e.OutErr(c, e.ERR_DB_ORM, "更新:"+enum2.VideoReward.String(enum2.VideoRewardUnitPrice)+"失败!") return diff --git a/app/hdl/institutional_management/module_setting/hdl_basic.go b/app/hdl/institutional_management/module_setting/hdl_basic.go index 4ba0e31..648db45 100644 --- a/app/hdl/institutional_management/module_setting/hdl_basic.go +++ b/app/hdl/institutional_management/module_setting/hdl_basic.go @@ -5,11 +5,10 @@ import ( "applet/app/e" md2 "applet/app/md" "applet/app/md/institutional_management/module_setting" + svc2 "applet/app/svc" "applet/app/utils" - "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" "errors" "fmt" "github.com/gin-gonic/gin" @@ -70,9 +69,9 @@ func ModuleSettingGet(c *gin.Context) { return } } - redisConn := cache.GetPool().Get() - scheme, domain := svc.ImageBucket(db.Db, redisConn) - moduleStyleStr := svc.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data) + + scheme, domain := svc2.ImageBucket(db.Db) + moduleStyleStr := svc2.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data) utils.Unserialize([]byte(moduleStyleStr), &data) resp := md.ModuleSettingGetResp{ @@ -123,8 +122,7 @@ func ModuleSettingUpdate(c *gin.Context) { moduleStyle.Data = utils.SerializeStr(req.Data) // 替换所有 host - redisConn := cache.GetPool().Get() - scheme, domain := svc.ImageBucket(db.Db, redisConn) + scheme, domain := svc2.ImageBucket(db.Db) moduleStyle.Data = strings.ReplaceAll(moduleStyle.Data, fmt.Sprintf("%s://%s/", scheme, domain), "{{tempHost}}") affected, err := moduleStyleDb.ModuleStyleUpdate(moduleStyle.ModId, moduleStyle, forceColumns...) if err != nil { diff --git a/app/hdl/setCenter/oss/aliyun/hdl_basic.go b/app/hdl/setCenter/oss/aliyun/hdl_basic.go index b424e51..7afc741 100644 --- a/app/hdl/setCenter/oss/aliyun/hdl_basic.go +++ b/app/hdl/setCenter/oss/aliyun/hdl_basic.go @@ -4,10 +4,7 @@ import ( "applet/app/db" "applet/app/e" md "applet/app/md/setCenter/oss/aliyun" - "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "applet/app/svc/sys_cfg" enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "github.com/gin-gonic/gin" ) @@ -23,15 +20,7 @@ import ( // @Failure 400 {object} md.Response "具体错误" // @Router /api/settCenter/oss/aliYun/getBasic [get] func GetBasic(c *gin.Context) { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfg, err := sysCfgDb.SysCfgGetAll() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) @@ -122,14 +111,7 @@ func SetBasic(c *gin.Context) { return } - redisConn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, redisConn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) + cfgDb := sys_cfg.NewSysCfgDb(db.Db) if req.OssAccessKeyId != "" { cfgDb.SysCfgUpdate(enum2.AliyunOssAccessKeyID, req.OssAccessKeyId) diff --git a/app/hdl/website/hdl_website.go b/app/hdl/website/hdl_website.go index 823a523..a40a11e 100644 --- a/app/hdl/website/hdl_website.go +++ b/app/hdl/website/hdl_website.go @@ -6,9 +6,7 @@ import ( "applet/app/md" "applet/app/svc" "applet/app/utils" - "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" - svc2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" "github.com/gin-gonic/gin" ) @@ -69,9 +67,8 @@ func GetModuleSetting(c *gin.Context) { return } var dataMap interface{} - redisConn := cache.GetPool().Get() - scheme, domain := svc2.ImageBucket(db.Db, redisConn) - moduleStyle.Data = svc2.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data) + scheme, domain := svc.ImageBucket(db.Db) + moduleStyle.Data = svc.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data) utils.Unserialize([]byte(moduleStyle.Data), &dataMap) resp := md.GetModuleSettingResp{ ModName: moduleStyle.ModName, diff --git a/app/svc/cloud_bundle/svc_img_base.go b/app/svc/cloud_bundle/svc_img_base.go index acb559e..243dccb 100644 --- a/app/svc/cloud_bundle/svc_img_base.go +++ b/app/svc/cloud_bundle/svc_img_base.go @@ -5,11 +5,8 @@ import ( "applet/app/e" "applet/app/md" "applet/app/svc" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "encoding/json" "github.com/gin-gonic/gin" ) @@ -27,14 +24,7 @@ func ImgBaseSave(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - conn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, conn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) + cfgDb := sys_cfg.NewSysCfgDb(db.Db) cfgDb.SysCfgUpdate("app_cloud_bundle_data", utils.SerializeStr(req)) e.OutSuc(c, "success", nil) diff --git a/app/svc/cloud_bundle/svc_version_info.go b/app/svc/cloud_bundle/svc_version_info.go index 9afc65b..e0fa4ef 100644 --- a/app/svc/cloud_bundle/svc_version_info.go +++ b/app/svc/cloud_bundle/svc_version_info.go @@ -5,11 +5,8 @@ import ( "applet/app/e" "applet/app/md" "applet/app/svc" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "encoding/json" "github.com/gin-gonic/gin" ) @@ -50,15 +47,7 @@ func VersionBaseSave(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - conn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, conn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) - + cfgDb := sys_cfg.NewSysCfgDb(db.Db) cfgDb.SysCfgUpdate("app_version", utils.SerializeStr(req)) e.OutSuc(c, "success", nil) return diff --git a/app/svc/content_reward/svc_playlet.go b/app/svc/content_reward/svc_playlet.go index cf4a866..ba95432 100644 --- a/app/svc/content_reward/svc_playlet.go +++ b/app/svc/content_reward/svc_playlet.go @@ -5,9 +5,8 @@ import ( "applet/app/e" "applet/app/md" "applet/app/svc" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" ) @@ -33,8 +32,8 @@ func PlayletBaseSave(c *gin.Context) { e.OutErr(c, err1.Code, err1.Error()) return } - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) + + sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) sysCfgDb.SysCfgUpdate("playlet_base", utils.SerializeStr(req)) e.OutSuc(c, "success", nil) return diff --git a/app/svc/content_reward/svc_video.go b/app/svc/content_reward/svc_video.go index 04769e9..8a7cb5b 100644 --- a/app/svc/content_reward/svc_video.go +++ b/app/svc/content_reward/svc_video.go @@ -5,9 +5,8 @@ import ( "applet/app/e" "applet/app/md" "applet/app/svc" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" ) @@ -33,8 +32,7 @@ func VideoBaseSave(c *gin.Context) { e.OutErr(c, err1.Code, err1.Error()) return } - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) + sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) sysCfgDb.SysCfgUpdate("video_base", utils.SerializeStr(req)) e.OutSuc(c, "success", nil) return diff --git a/app/svc/notice/svc_aliyun_sms.go b/app/svc/notice/svc_aliyun_sms.go index a7fac16..524e176 100644 --- a/app/svc/notice/svc_aliyun_sms.go +++ b/app/svc/notice/svc_aliyun_sms.go @@ -4,10 +4,8 @@ import ( "applet/app/db" "applet/app/e" "applet/app/md" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "applet/app/utils/logx" - "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/model" "github.com/360EntSecGroup-Skylar/excelize" @@ -119,16 +117,7 @@ func AliyunSmsDel(c *gin.Context) { return } func AliyunSmsSaleBase(c *gin.Context) { - - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code") res := map[string]string{ "aliyun_sms_sale_code": aliyunSmsNotice, @@ -142,14 +131,7 @@ func AliyunSmsSaleSave(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"]) e.OutSuc(c, "success", nil) diff --git a/app/svc/svc_comm.go b/app/svc/svc_comm.go index c4fb09c..ec761d9 100644 --- a/app/svc/svc_comm.go +++ b/app/svc/svc_comm.go @@ -2,11 +2,8 @@ package svc import ( "applet/app/db" + "applet/app/svc/sys_cfg" "applet/app/utils" - "applet/app/utils/cache" - "applet/app/utils/logx" - "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/model" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client" @@ -19,14 +16,7 @@ import ( ) func GetOssUrl(img string) string { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") if strings.Contains(img, "http") == false && img != "" { http := sysCfg["oss_bucket_scheme"] @@ -35,41 +25,16 @@ func GetOssUrl(img string) string { return img } func GetOssDomain() string { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, 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) sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") http := sysCfg["oss_bucket_scheme"] return http + "://" + sysCfg["oss_domain"] + "/" } func GetSysCfgStr(key string) string { - redisConn := cache.GetPool().Get() - sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) - defer func(sysCfgDb dao.SysCfgDao) { - err := sysCfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(sysCfgDb) - - return sysCfgDb.SysCfgGetWithDb(key) + return sys_cfg.NewSysCfgDb(db.Db).SysCfgGetWithDb(key) } func SetSysCfgStr(key, val string) bool { - redisConn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, redisConn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) - + cfgDb := sys_cfg.NewSysCfgDb(db.Db) var bools bool if val != "" { data, _ := cfgDb.SysCfgGetOne(key) diff --git a/app/svc/svc_file_img_format.go b/app/svc/svc_file_img_format.go new file mode 100644 index 0000000..394979a --- /dev/null +++ b/app/svc/svc_file_img_format.go @@ -0,0 +1,41 @@ +package svc + +import ( + "applet/app/svc/sys_cfg" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" + "fmt" + "strings" + "xorm.io/xorm" +) + +// ImageBucket is 获取域名 +func ImageBucket(engine *xorm.Engine) (string, string) { + sysCfgDb := sys_cfg.NewSysCfgDb(engine) + res := sysCfgDb.SysCfgFindWithDb(enum.AliyunOssBucketScheme, enum.AliyunOssDomain) + return res[enum.AliyunOssBucketScheme], res[enum.AliyunOssDomain] +} + +// ImageFormatWithBucket is 格式化成oss 域名 +func ImageFormatWithBucket(scheme, domain, name string) string { + if strings.Contains(name, "http") || name == "" { + return name + } + return fmt.Sprintf("%s://%s/%s", scheme, domain, name) +} + +// ImageFormatWithBucketNew is 格式化成oss 域名 +func ImageFormatWithBucketNew(scheme, domain, name string) string { + if strings.Contains(name, "http") { + return name + } + + name = strings.ReplaceAll(name, "{{tempHost}}", "") + return fmt.Sprintf("%s://%s/%s", scheme, domain, name) +} + +// ImageFormatWithBucketForDataInfo is 格式化成oss 域名 (只格式化内容中的 url) +func ImageFormatWithBucketForDataInfo(scheme, domain, name string) string { + prefix := fmt.Sprintf("%s://%s/", scheme, domain) + name = strings.ReplaceAll(name, "{{tempHost}}", prefix) + return name +} diff --git a/app/svc/sys_cfg/sys_cfg_dao.go b/app/svc/sys_cfg/sys_cfg_dao.go new file mode 100644 index 0000000..9711b5f --- /dev/null +++ b/app/svc/sys_cfg/sys_cfg_dao.go @@ -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 +} diff --git a/app/svc/sys_cfg/sys_cfg_implement.go b/app/svc/sys_cfg/sys_cfg_implement.go new file mode 100644 index 0000000..153a319 --- /dev/null +++ b/app/svc/sys_cfg/sys_cfg_implement.go @@ -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 +} diff --git a/app/svc/user_real_name/svc_base.go b/app/svc/user_real_name/svc_base.go index b85cfd4..4ddfd1d 100644 --- a/app/svc/user_real_name/svc_base.go +++ b/app/svc/user_real_name/svc_base.go @@ -5,10 +5,7 @@ import ( "applet/app/e" "applet/app/md" "applet/app/svc" - "applet/app/utils/cache" - "applet/app/utils/logx" - "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "applet/app/svc/sys_cfg" "github.com/gin-gonic/gin" ) @@ -25,15 +22,8 @@ func BaseSave(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - conn := cache.GetPool().Get() - cfgDb := implement.NewSysCfgDb(db.Db, conn) - defer func(cfgDb dao.SysCfgDao) { - err := cfgDb.Close() - if err != nil { - logx.Error("redis close err:" + err.Error()) // 记录错误信息 - } - }(cfgDb) + cfgDb := sys_cfg.NewSysCfgDb(db.Db) cfgDb.SysCfgUpdate("user_real_name_money", req.UserRealNameMoney) cfgDb.SysCfgUpdate("user_real_name_rule", req.UserRealNameRule) e.OutSuc(c, "success", nil) diff --git a/app/task/init.go b/app/task/init.go index 43fbd50..faa44c1 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -87,14 +87,14 @@ func doTask(fnName string) func() { // 增加自动任务队列 func initTasks() { - jobs[taskMd.CronEggEnergyAutoRecordPrices] = taskEggEnergyAutoRecordPrices - jobs[taskMd.CronEggEnergyDealPlatformRevenueData] = taskEggEnergyDealPlatformRevenueData - jobs[taskMd.CronEggEnergyDealFundData] = taskEggEnergyDealFundData - jobs[taskMd.CronEggEnergyUserEggScore] = taskCronEggEnergyUserEggScore - jobs[taskMd.CornEggEnergyAutoReleaseTeamEggEnergy] = taskEggEnergyAutoReleaseTeamEggEnergy // 蛋蛋能量-自动释放团队蛋蛋能量到个人能量 - jobs[taskMd.CornSettlementStarLevelDividends] = taskEggEnergySettlementStarLevelDividends // 蛋蛋能量-结算星级分红 - jobs[taskMd.CornEggEnergyDealUserPublicPlatoonPunish] = taskEggEnergyDealUserPublicPlatoonPunish // 蛋蛋能量-公排处罚 - jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格 - jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红 + //jobs[taskMd.CronEggEnergyAutoRecordPrices] = taskEggEnergyAutoRecordPrices + //jobs[taskMd.CronEggEnergyDealPlatformRevenueData] = taskEggEnergyDealPlatformRevenueData + //jobs[taskMd.CronEggEnergyDealFundData] = taskEggEnergyDealFundData + //jobs[taskMd.CronEggEnergyUserEggScore] = taskCronEggEnergyUserEggScore + //jobs[taskMd.CornEggEnergyAutoReleaseTeamEggEnergy] = taskEggEnergyAutoReleaseTeamEggEnergy // 蛋蛋能量-自动释放团队蛋蛋能量到个人能量 + //jobs[taskMd.CornSettlementStarLevelDividends] = taskEggEnergySettlementStarLevelDividends // 蛋蛋能量-结算星级分红 + //jobs[taskMd.CornEggEnergyDealUserPublicPlatoonPunish] = taskEggEnergyDealUserPublicPlatoonPunish // 蛋蛋能量-公排处罚 + jobs[taskMd.CornEggEnergyAutoAdjustPrice] = taskEggEnergyAutoAdjustPrice // 蛋蛋能量-自动调整价格 + //jobs[taskMd.CornEggEnergyAutoCommunityDividends] = taskEggEnergyCommunityDividends // 蛋蛋能量-社区分红 } diff --git a/etc/cfg.yml b/etc/cfg.yml index 0aabe35..1ecd30e 100644 --- a/etc/cfg.yml +++ b/etc/cfg.yml @@ -20,6 +20,7 @@ db: max_idle_conns: 100 path: 'tmp/%s.log' + im_db: host: '119.23.182.117:3306' name: 'egg-im' diff --git a/go.mod b/go.mod index ac21c08..960ec56 100644 --- a/go.mod +++ b/go.mod @@ -33,8 +33,8 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211152610-0c5e1e903c99 - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241212114007-477fc46cda14 + 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_mq.git v0.0.5 github.com/360EntSecGroup-Skylar/excelize v1.4.1