From 3ccfbf0e7644010606cf191c9f5c0794ffbc7a89 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sat, 27 Apr 2024 17:23:04 +0800 Subject: [PATCH] by Robin at 20240427 --- api/consts/consts.go | 1 + apollostruct/restricted_visitor.go | 5 +++++ app/mix/service/apiservice.go | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/api/consts/consts.go b/api/consts/consts.go index 38ae7b2a..8ebf7a24 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -51,6 +51,7 @@ const ( DefaultMomentTextKey = "default_moment_text" MaxDailyZoneMomentCreateTimesKey = "max_daily_zone_moment_create_times" ReferentialZoneMomentKey = "referential_zone_moment" + RestrictedVisitorMomentKey = "restricted_visitor_moment" ) // del_flag diff --git a/apollostruct/restricted_visitor.go b/apollostruct/restricted_visitor.go index 1c0a25f1..16585ff7 100644 --- a/apollostruct/restricted_visitor.go +++ b/apollostruct/restricted_visitor.go @@ -5,3 +5,8 @@ type RestrictedVisitorCfg struct { RestrictedVisitorMids []int64 `json:"restricted_visitor_mids"` // 限制可见范围的访客mids RestrictedVisitorVisibleMids []int64 `json:"restricted_visitor_visible_mids"` // 限制访客可见的mids } + +type RestrictedVisitorMomentCfg struct { + RestrictedVisitorMids []int64 `json:"restricted_visitor_mids"` // 限制可见范围的访客mids + RestrictedVisitorVisibleMomentIds []int64 `json:"restricted_visitor_visible_moment_ids"` // 限制访客可见的动态ids +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index cd5702d6..289318a1 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2052,6 +2052,33 @@ func (s *Service) ApiGetMomentRecommList(ctx *gin.Context, req *momentproto.ApiR ids = append(ids, recommIds...) } + // 取apollo配置 + cfg := &apollostruct.RestrictedVisitorMomentCfg{} + err = apollo.GetJson(consts.RestrictedVisitorMomentKey, &cfg, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + return nil, errcode.ErrCodeApolloReadFail + } + + // 查询是否限制访客 + visitorMid := req.BaseRequest.Mid + for _, restricted_visitor_mid := range cfg.RestrictedVisitorMids { + if restricted_visitor_mid == visitorMid { // 是限制访问的访客 + recommMap := make(map[int64]int64) + for _, momentId := range ids { + recommMap[momentId] = 1 + } + restrictedRecommList := make([]int64, 0) + for _, restrictedVisitorVisibleMomentId := range cfg.RestrictedVisitorVisibleMomentIds { + if recommMap[restrictedVisitorVisibleMomentId] == 1 { + restrictedRecommList = append(restrictedRecommList, restrictedVisitorVisibleMomentId) + } + } + ids = restrictedRecommList + break + } + } + // 4.查询动态内容 recommMomentList, err = s.utilGetApiMomentVOListByIds(ctx, req.Mid, ids) if err != nil {