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:
commit
1c6cfa8874
|
@ -55,3 +55,8 @@ const (
|
||||||
ZoneMomentPriorityInZone_Increment = 2000000000
|
ZoneMomentPriorityInZone_Increment = 2000000000
|
||||||
ZoneMomentPriorityInZone_Decrement = -2000000000
|
ZoneMomentPriorityInZone_Decrement = -2000000000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppConfigReflect_Current = 1 // 符合当前版本的version做映射
|
||||||
|
AppConfigReflect_LessThan = 2 // 小于当前版本的version做映射
|
||||||
|
)
|
||||||
|
|
|
@ -6,3 +6,9 @@ type Version struct {
|
||||||
DownloadUrl string `json:"download_url"`
|
DownloadUrl string `json:"download_url"`
|
||||||
Force bool `json:"force"`
|
Force bool `json:"force"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AppConfigReflect struct {
|
||||||
|
Type int64 `json:"type"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
ReflectedKey string `json:"reflected_key"`
|
||||||
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ import (
|
||||||
"service/library/contentaudit/textaudit"
|
"service/library/contentaudit/textaudit"
|
||||||
videomoderation "service/library/contentaudit/video_moderation"
|
videomoderation "service/library/contentaudit/video_moderation"
|
||||||
"service/library/logger"
|
"service/library/logger"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"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) {
|
func (s *Service) ApiGetAppConfigListByKey(ctx *gin.Context, req *appconfigproto.ApiListByKeyReq) (appconfig *dbstruct.AppConfig, ec errcode.ErrCode) {
|
||||||
ec = errcode.ErrCodeAppConfigSrvOk
|
ec = errcode.ErrCodeAppConfigSrvOk
|
||||||
|
|
||||||
//读取版本下是否有字段需要进行版本映射
|
configKey := req.ConfigKey
|
||||||
appConfigReflect, err := apollo.GetStringValue(consts.AppConfigReflectKey+"_"+req.BaseRequest.Version, apollo.ApolloOpts().SetNamespace("version"))
|
|
||||||
|
// 判断key是否需要映射,以及映射类型
|
||||||
|
cfg := apollostruct.AppConfigReflect{}
|
||||||
|
err := apollo.GetJson(consts.AppConfigReflectKey+"_"+req.ConfigKey, &cfg, apollo.ApolloOpts().SetNamespace("version"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Apollo read failed : %v", err)
|
|
||||||
ec = errcode.ErrCodeApolloReadFail
|
ec = errcode.ErrCodeApolloReadFail
|
||||||
|
logger.Error("Apollo read failed : %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if appConfigReflect != "" {
|
if cfg.Type == consts.AppConfigReflect_Current && req.BaseRequest.Version == cfg.Version {
|
||||||
appConfigReflectColumns := strings.Split(appConfigReflect, ";")
|
configKey = cfg.ReflectedKey
|
||||||
for _, column := range appConfigReflectColumns {
|
} else if cfg.Type == consts.AppConfigReflect_LessThan {
|
||||||
if req.ConfigKey == column {
|
isInNeedOfReflection, err := util.VerisonCompare(cfg.Version, req.BaseRequest.Version)
|
||||||
req.ConfigKey = req.ConfigKey + "_" + 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{
|
appconfig, err = _DefaultAppConfig.OpListByKey(ctx, &appconfigproto.OpListByKeyReq{
|
||||||
ConfigKey: req.ConfigKey,
|
ConfigKey: configKey,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("OpGetAppConfigListByKey fail, req: %v, err: %v", util.ToJson(req), err)
|
logger.Error("OpGetAppConfigListByKey fail, req: %v, err: %v", util.ToJson(req), err)
|
||||||
|
|
|
@ -163,3 +163,30 @@ func String2Int32(s string) int32 {
|
||||||
func String2Int64(s string) int64 {
|
func String2Int64(s string) int64 {
|
||||||
return int64(String2Int(s))
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue