Merge pull request 'By Robin at 20240119; fix' (#60) from feat-20230112-001-Robin into test

Reviewed-on: #60
This commit is contained in:
chenhao 2024-01-19 00:31:56 +08:00
commit b38f89228d
10 changed files with 169 additions and 56 deletions

View File

@ -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 //是
)

View File

@ -0,0 +1,6 @@
package interfaces
type IsFollowedFillable interface {
GetMid() int64
SetIsFollowed(is_followed int64)
}

View File

@ -0,0 +1,6 @@
package interfaces
type IsThumbedUpFillable interface {
GetMomentId() int64
SetIsThumbedUp(is_followed int64)
}

View File

@ -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
}

View File

@ -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

View File

@ -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"`
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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"
@ -362,6 +364,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
}
@ -373,14 +376,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)
}
@ -388,3 +395,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
}