Merge pull request 'by Robin at 20240514' (#429) from feat-IRONFANS-121-Robin into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/429
This commit is contained in:
chenhao 2024-05-14 17:23:12 +08:00
commit 1c6cfa8874
4 changed files with 56 additions and 11 deletions

View File

@ -55,3 +55,8 @@ const (
ZoneMomentPriorityInZone_Increment = 2000000000
ZoneMomentPriorityInZone_Decrement = -2000000000
)
const (
AppConfigReflect_Current = 1 // 符合当前版本的version做映射
AppConfigReflect_LessThan = 2 // 小于当前版本的version做映射
)

View File

@ -6,3 +6,9 @@ type Version struct {
DownloadUrl string `json:"download_url"`
Force bool `json:"force"`
}
type AppConfigReflect struct {
Type int64 `json:"type"`
Version string `json:"version"`
ReflectedKey string `json:"reflected_key"`
}

View File

@ -40,7 +40,6 @@ import (
"service/library/contentaudit/textaudit"
videomoderation "service/library/contentaudit/video_moderation"
"service/library/logger"
"strings"
"time"
"go.mongodb.org/mongo-driver/mongo"
@ -2032,24 +2031,32 @@ func (s *Service) ApiGetThumbsUpList(ctx *gin.Context, req *thumbsupproto.ApiLis
func (s *Service) ApiGetAppConfigListByKey(ctx *gin.Context, req *appconfigproto.ApiListByKeyReq) (appconfig *dbstruct.AppConfig, ec errcode.ErrCode) {
ec = errcode.ErrCodeAppConfigSrvOk
//读取版本下是否有字段需要进行版本映射
appConfigReflect, err := apollo.GetStringValue(consts.AppConfigReflectKey+"_"+req.BaseRequest.Version, apollo.ApolloOpts().SetNamespace("version"))
configKey := req.ConfigKey
// 判断key是否需要映射以及映射类型
cfg := apollostruct.AppConfigReflect{}
err := apollo.GetJson(consts.AppConfigReflectKey+"_"+req.ConfigKey, &cfg, apollo.ApolloOpts().SetNamespace("version"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
logger.Error("Apollo read failed : %v", err)
return
}
if appConfigReflect != "" {
appConfigReflectColumns := strings.Split(appConfigReflect, ";")
for _, column := range appConfigReflectColumns {
if req.ConfigKey == column {
req.ConfigKey = req.ConfigKey + "_" + req.BaseRequest.Version
}
if cfg.Type == consts.AppConfigReflect_Current && req.BaseRequest.Version == cfg.Version {
configKey = cfg.ReflectedKey
} else if cfg.Type == consts.AppConfigReflect_LessThan {
isInNeedOfReflection, err := util.VerisonCompare(cfg.Version, req.BaseRequest.Version)
if err != nil {
ec = errcode.ErrCodeApolloVersionFormatError
logger.Error("VerisonCompare failed : %v", err)
return
}
if isInNeedOfReflection {
configKey = cfg.ReflectedKey
}
}
appconfig, err = _DefaultAppConfig.OpListByKey(ctx, &appconfigproto.OpListByKeyReq{
ConfigKey: req.ConfigKey,
ConfigKey: configKey,
})
if err != nil {
logger.Error("OpGetAppConfigListByKey fail, req: %v, err: %v", util.ToJson(req), err)

View File

@ -163,3 +163,30 @@ func String2Int32(s string) int32 {
func String2Int64(s string) int64 {
return int64(String2Int(s))
}
func VerisonCompare(ver1 string, ver2 string) (bool, error) {
ver1SeqNos := strings.Split(ver1, ".")
ver2SeqNos := strings.Split(ver2, ".")
if len(ver1SeqNos) != len(ver2SeqNos) {
logger.Error("version format error")
return false, fmt.Errorf("version format error")
}
for i := range ver1SeqNos {
ver1SeqNo, err := strconv.Atoi(ver1SeqNos[i])
if err != nil {
logger.Error("ver1 version format error:%v", err)
return false, err
}
ver2SeqNo, err := strconv.Atoi(ver2SeqNos[i])
if err != nil {
logger.Error("ver2 version format error:%v", err)
return false, err
}
if ver1SeqNo > ver2SeqNo {
return true, nil
} else if ver1SeqNo < ver2SeqNo {
return false, nil
}
}
return false, nil
}