From 876ec6513f480b020d3515751e3b441c8d2bad6a Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 19 Jan 2024 00:31:03 +0800 Subject: [PATCH] By Robin at 20240119; fix --- api/consts/status.go | 12 +++++ api/interfaces/is_followed_fillable.go | 6 +++ api/interfaces/is_thumbed_up_fillable.go | 6 +++ api/proto/moment/proto/moment_api_vo_api.go | 22 ++++++++ api/proto/moment/proto/not_null_def_api.go | 6 +-- api/proto/thumbsup/proto/thumbsup_op.go | 18 +++++++ app/mix/service/apiservice.go | 48 +++++++++++++---- .../service/apiservice_business_validation.go | 44 --------------- app/mix/service/logic/thumbsup.go | 9 ++++ app/mix/service/utilservice.go | 54 +++++++++++++++++++ 10 files changed, 169 insertions(+), 56 deletions(-) create mode 100644 api/interfaces/is_followed_fillable.go create mode 100644 api/interfaces/is_thumbed_up_fillable.go diff --git a/api/consts/status.go b/api/consts/status.go index 409cf0c3..cee0e91f 100644 --- a/api/consts/status.go +++ b/api/consts/status.go @@ -74,3 +74,15 @@ const ( Feedback_Invalid = 3 //无效 Feedback_RelatedToIteration = 4 //迭代相关 ) + +// 是否被关注 +const ( + IsFollowed_No = 0 //否 + IsFollowed_Yes = 1 //是 +) + +// 是否被点赞 +const ( + IsThumbedUp_No = 0 //否 + IsThumbedUp_Yes = 1 //是 +) diff --git a/api/interfaces/is_followed_fillable.go b/api/interfaces/is_followed_fillable.go new file mode 100644 index 00000000..4cddab31 --- /dev/null +++ b/api/interfaces/is_followed_fillable.go @@ -0,0 +1,6 @@ +package interfaces + +type IsFollowedFillable interface { + GetMid() int64 + SetIsFollowed(is_followed int64) +} diff --git a/api/interfaces/is_thumbed_up_fillable.go b/api/interfaces/is_thumbed_up_fillable.go new file mode 100644 index 00000000..8b847325 --- /dev/null +++ b/api/interfaces/is_thumbed_up_fillable.go @@ -0,0 +1,6 @@ +package interfaces + +type IsThumbedUpFillable interface { + GetMomentId() int64 + SetIsThumbedUp(is_followed int64) +} diff --git a/api/proto/moment/proto/moment_api_vo_api.go b/api/proto/moment/proto/moment_api_vo_api.go index 5e36ad8a..1511c715 100644 --- a/api/proto/moment/proto/moment_api_vo_api.go +++ b/api/proto/moment/proto/moment_api_vo_api.go @@ -2,12 +2,15 @@ package proto import ( streamerproto "service/api/proto/streamer/proto" + "service/bizcommon/util" "service/dbstruct" ) type ApiMomentVO struct { *dbstruct.Moment StreamerExt *streamerproto.ApiListExtVO `json:"streamer_ext"` + IsFollowed int64 `json:"is_followed"` + IsThumbedUp int64 `json:"is_thumbed_up"` } func (vo *ApiMomentVO) CopyMoment(moment *dbstruct.Moment) { @@ -21,3 +24,22 @@ func (vo *ApiMomentVO) CopyStreamerExt(streamerExt streamerproto.StreamerExtVO) } } } + +func (vo *ApiMomentVO) GetMid() int64 { + return vo.StreamerExt.GetMid() +} + +func (vo *ApiMomentVO) GetMomentId() int64 { + if vo.Moment != nil && vo.Moment.Id != nil { + return util.DerefInt64(vo.Moment.Id) + } + return -1 +} + +func (vo *ApiMomentVO) SetIsFollowed(is_followed int64) { + vo.IsFollowed = is_followed +} + +func (vo *ApiMomentVO) SetIsThumbedUp(is_thumbed_up int64) { + vo.IsThumbedUp = is_thumbed_up +} diff --git a/api/proto/moment/proto/not_null_def_api.go b/api/proto/moment/proto/not_null_def_api.go index 678a42e4..709451b4 100644 --- a/api/proto/moment/proto/not_null_def_api.go +++ b/api/proto/moment/proto/not_null_def_api.go @@ -5,7 +5,7 @@ import "service/library/validator" func (p *ApiCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = make([]*validator.JsonParam, 0) - params = append(params, validator.NewInt64PtrParam("请确认创建动态的用户id!", p.Moment.Mid)) + //params = append(params, validator.NewInt64PtrParam("请确认创建动态的用户id!", p.Moment.Mid)) params = append(params, validator.NewInt64PtrParam("请确认创建动态的可见范围!", p.Moment.Status)) params = append(params, validator.NewStructPtrParam("动态内容不能为空!", p.Moment)) @@ -31,7 +31,7 @@ func (p *ApiUpdateReq) ProvideNotNullValue() (params []*validator.JsonParam) { func (p *ApiListByMidReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = make([]*validator.JsonParam, 0) - params = append(params, validator.NewInt64PtrParam("请输入待查询动态的用户id!", p.Mid)) + //params = append(params, validator.NewInt64PtrParam("请输入待查询动态的用户id!", p.Mid)) return } @@ -48,7 +48,7 @@ func (p *ApiThumbsUpReq) ProvideNotNullValue() (params []*validator.JsonParam) { params = make([]*validator.JsonParam, 0) params = append(params, validator.NewInt64PtrParam("请输入待点赞动态的id!", p.MomentId)) - params = append(params, validator.NewInt64PtrParam("请输入点赞动态的用户id!", p.Mid)) + //params = append(params, validator.NewInt64PtrParam("请输入点赞动态的用户id!", p.Mid)) params = append(params, validator.NewInt64PtrParam("请输入点赞动态的次数!", p.Times)) return diff --git a/api/proto/thumbsup/proto/thumbsup_op.go b/api/proto/thumbsup/proto/thumbsup_op.go index 73044f0d..a76b30a5 100644 --- a/api/proto/thumbsup/proto/thumbsup_op.go +++ b/api/proto/thumbsup/proto/thumbsup_op.go @@ -66,3 +66,21 @@ type OpListResp struct { base.BaseResponse Data *OpListData `json:"data"` } + +// op 列表-按句柄 +type OpListBySentenceReq struct { + base.BaseRequest + MomentId *int64 `json:"moment_id"` + Mid *int64 `json:"mid"` +} + +type OpListBySentenceData struct { + List []*dbstruct.ThumbsUp `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListBySentenceResp struct { + base.BaseResponse + Data *OpListBySentenceData `json:"data"` +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 924088ba..003ad747 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1556,9 +1556,7 @@ func (s *Service) ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context, func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk - if ec = s.ApiCreateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { - return - } + req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid) err := _DefaultMoment.OpCreate(ctx, &momentproto.OpCreateReq{ Moment: req.Moment, @@ -1574,9 +1572,7 @@ func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateRe func (s *Service) ApiUpdateMoment(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk - if ec = s.ApiUpdateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { - return - } + req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid) err := _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{ Moment: &dbstruct.Moment{ @@ -1625,6 +1621,15 @@ func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq return } + // 获取访问者的关注列表 + visitorMid := req.GetBaseRequest().Mid + followMap, err := s.utilGetFollowMap(ctx, visitorMid) + if err != nil { + logger.Error("utilGetFollowMap fail") + ec = errcode.ErrCodeAccountRelationSrvFail + return + } + // 填充主播信息 vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api) if ec != errcode.ErrCodeMomentSrvOk { @@ -1635,6 +1640,14 @@ func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq voList = make([]*momentproto.ApiMomentVO, 0) for _, vo := range vos { apiVO, _ := vo.(*momentproto.ApiMomentVO) + // 填充是否关注 + s.utilFillIsFollowedFillable(ctx, followMap, apiVO) + // 填充是否点赞 + if err := s.utilFillIsThumbedUpFillable(ctx, visitorMid, apiVO); err != nil { + logger.Error("utilFillIsThumbedUpFillable fail") + ec = errcode.ErrCodeThumbsUpSrvFail + return + } voList = append(voList, apiVO) } @@ -1644,9 +1657,7 @@ func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq func (s *Service) ApiGetMomentListByMid(ctx *gin.Context, req *momentproto.ApiListByMidReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk - if ec = s.ApiGetMomentListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { - return - } + req.Mid = goproto.Int64(req.BaseRequest.Mid) list, err := _DefaultMoment.OpListByMid(ctx, &momentproto.OpListByMidReq{ Mid: req.Mid, @@ -1692,6 +1703,15 @@ func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiL return } + // 获取访问者的关注列表 + visitorMid := req.GetBaseRequest().Mid + followMap, err := s.utilGetFollowMap(ctx, visitorMid) + if err != nil { + logger.Error("utilGetFollowMap fail") + ec = errcode.ErrCodeAccountRelationSrvFail + return + } + // 填充主播信息 vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api) if ec != errcode.ErrCodeMomentSrvOk { @@ -1702,6 +1722,14 @@ func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiL voList = make([]*momentproto.ApiMomentVO, 0) for _, vo := range vos { apiVO, _ := vo.(*momentproto.ApiMomentVO) + // 填充是否关注 + s.utilFillIsFollowedFillable(ctx, followMap, apiVO) + // 填充是否点赞 + if err := s.utilFillIsThumbedUpFillable(ctx, visitorMid, apiVO); err != nil { + logger.Error("utilFillIsThumbedUpFillable fail") + ec = errcode.ErrCodeThumbsUpSrvFail + return + } voList = append(voList, apiVO) } return @@ -1710,6 +1738,8 @@ func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiL func (s *Service) ApiThumbsUpMoment(ctx *gin.Context, req *momentproto.ApiThumbsUpReq) (ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk + req.Mid = goproto.Int64(req.BaseRequest.Mid) + times := util.DerefInt64(req.Times) if times != 1 && times == -1 { ec = errcode.ErrCodeMomentSrvFail diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index 17e48ef3..940495d2 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -6,7 +6,6 @@ import ( accountproto "service/api/proto/account/proto" accountrelationproto "service/api/proto/accountrelation/proto" loginproto "service/api/proto/login/proto" - momentproto "service/api/proto/moment/proto" streamerproto "service/api/proto/streamer/proto" streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto" vericodeproto "service/api/proto/vericode/proto" @@ -523,46 +522,3 @@ func (s *Service) ApiGetStreamerWxIdBusinessValidate(ctx *gin.Context, req *stre return } - -// 点赞 -func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode) { - ec = errcode.ErrCodeMomentSrvOk - // 1.业务校验 - result := businessvalidator.NewAuthBusinessValidator(ctx, req). - EnsureIsOperatingHisOwn(util.DerefInt64(req.Moment.Mid)). - Validate(). - Collect() - if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { - logger.Error("ApiCreateMoment business validation failed") - return - } - return -} - -func (s *Service) ApiUpdateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) { - ec = errcode.ErrCodeMomentSrvOk - // 1.业务校验 - result := businessvalidator.NewAuthBusinessValidator(ctx, req). - EnsureIsOperatingHisOwn(util.DerefInt64(req.Moment.Mid)). - Validate(). - Collect() - if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { - logger.Error("ApiUpdateMoment business validation failed") - return - } - return -} - -func (s *Service) ApiGetMomentListByMidBusinessValidate(ctx *gin.Context, req *momentproto.ApiListByMidReq) (ec errcode.ErrCode) { - ec = errcode.ErrCodeMomentSrvOk - // 1.业务校验 - result := businessvalidator.NewAuthBusinessValidator(ctx, req). - EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)). - Validate(). - Collect() - if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { - logger.Error("OpGetMomentList business validation failed") - return - } - return -} diff --git a/app/mix/service/logic/thumbsup.go b/app/mix/service/logic/thumbsup.go index f38b04ed..32e86ec4 100644 --- a/app/mix/service/logic/thumbsup.go +++ b/app/mix/service/logic/thumbsup.go @@ -77,3 +77,12 @@ func (p *ThumbsUp) OpList(ctx *gin.Context, req *thumbsupproto.OpListReq) ([]*db } return list, nil } + +func (p *ThumbsUp) OpListBySentence(ctx *gin.Context, req *thumbsupproto.OpListBySentenceReq) (*dbstruct.ThumbsUp, error) { + thumbsup, err := p.store.GetUniqueThumbsUpList(ctx, util.DerefInt64(req.MomentId), util.DerefInt64(req.Mid)) + if err != nil { + logger.Error("GetUniqueThumbsUpList fail, err: %v", err) + return nil, err + } + return thumbsup, nil +} diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 4bf4caf3..6872a378 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -4,7 +4,9 @@ import ( "fmt" "service/api/consts" "service/api/errcode" + "service/api/interfaces" accountproto "service/api/proto/account/proto" + accountrelationproto "service/api/proto/accountrelation/proto" contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto" loginproto "service/api/proto/login/proto" momentproto "service/api/proto/moment/proto" @@ -344,6 +346,7 @@ func (s *Service) utilFillMomentsStreamerInfo(ctx *gin.Context, moments []*dbstr } if ec = s.utilExtendAccountsIntoStreamerExts(ctx, accountList, streamerExtList); ec != errcode.ErrCodeStreamerSrvOk { logger.Error("utilExtendAccountsIntoStreamerExts fail") + ec = errcode.ErrCodeStreamerSrvFail return } @@ -355,14 +358,18 @@ func (s *Service) utilFillMomentsStreamerInfo(ctx *gin.Context, moments []*dbstr if option == consts.InterfaceType_Api { for _, moment := range moments { vo := &momentproto.ApiMomentVO{} + // 填充动态信息 vo.CopyMoment(moment) + // 填充主播信息 vo.CopyStreamerExt(streamerExtMap[util.DerefInt64(moment.Mid)]) vos = append(vos, vo) } } else if option == consts.InterfaceType_Op { for _, moment := range moments { vo := &momentproto.OpMomentVO{} + // 填充动态信息 vo.CopyMoment(moment) + // 填充主播信息 vo.CopyStreamerExt(streamerExtMap[util.DerefInt64(moment.Mid)]) vos = append(vos, vo) } @@ -370,3 +377,50 @@ func (s *Service) utilFillMomentsStreamerInfo(ctx *gin.Context, moments []*dbstr return } + +func (s *Service) utilGetFollowMap(ctx *gin.Context, visitorMid int64) (_map map[int64]*dbstruct.AccountRelation, err error) { + // 查找访问人的关注列表 + accountrelations, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{ + SubMid: goproto.Int64(visitorMid), + Predicate: goproto.Int64(consts.Follow), + }) + if err != nil { + logger.Error("_DefaultAccountRelation OpListBySubMidAndPredicate fail, err: %v", err) + return nil, err + } + + // 取出关注列表中的obj_mid + _map = make(map[int64]*dbstruct.AccountRelation) + for _, accountrelation := range accountrelations { + _map[util.DerefInt64(accountrelation.ObjMid)] = accountrelation + } + + return +} + +func (s *Service) utilFillIsFollowedFillable(ctx *gin.Context, visitorFollowMap map[int64]*dbstruct.AccountRelation, isFollowedFillable interfaces.IsFollowedFillable) { + if visitorFollowMap[isFollowedFillable.GetMid()] != nil { + isFollowedFillable.SetIsFollowed(consts.IsFollowed_Yes) + } else { + isFollowedFillable.SetIsFollowed(consts.IsFollowed_No) + } + + return +} + +func (s *Service) utilFillIsThumbedUpFillable(ctx *gin.Context, visitorMid int64, isThumbedUp interfaces.IsThumbedUpFillable) error { + thumbsup, err := _DefaultThumbsUp.OpListBySentence(ctx, &thumbsupproto.OpListBySentenceReq{ + MomentId: goproto.Int64(isThumbedUp.GetMomentId()), + Mid: goproto.Int64(visitorMid), + }) + if err != nil { + logger.Error("_DefaultThumbsUp OpListBySentence fail, err: %v", err) + return err + } + if thumbsup != nil { + isThumbedUp.SetIsThumbedUp(consts.IsThumbedUp_Yes) + } else { + isThumbedUp.SetIsThumbedUp(consts.IsThumbedUp_No) + } + return nil +}