diff --git a/api/consts/consts.go b/api/consts/consts.go index 7b005ce9..b68eaf69 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -21,6 +21,12 @@ const ( DevType_Ios = 1 ) +// 接口类型 +const ( + InterfaceType_Op = 0 + InterfaceType_Api = 1 +) + // apollo_config const ( MaxPswdWrongTimesKey = "max_pswd_wrong_times" diff --git a/api/proto/moment/proto/moment_api.go b/api/proto/moment/proto/moment_api.go index f6c60613..1f55899a 100644 --- a/api/proto/moment/proto/moment_api.go +++ b/api/proto/moment/proto/moment_api.go @@ -58,9 +58,9 @@ type ApiListByMidReq struct { } type ApiListByMidData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*ApiMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type ApiListByMidResp struct { @@ -79,9 +79,9 @@ type ApiListByMidsReq struct { } type ApiListByMidsData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*ApiMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type ApiListByMidsResp struct { @@ -99,9 +99,9 @@ type ApiListReq struct { } type ApiListData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*ApiMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type ApiListResp struct { diff --git a/api/proto/moment/proto/moment_api_vo_api.go b/api/proto/moment/proto/moment_api_vo_api.go new file mode 100644 index 00000000..5e36ad8a --- /dev/null +++ b/api/proto/moment/proto/moment_api_vo_api.go @@ -0,0 +1,23 @@ +package proto + +import ( + streamerproto "service/api/proto/streamer/proto" + "service/dbstruct" +) + +type ApiMomentVO struct { + *dbstruct.Moment + StreamerExt *streamerproto.ApiListExtVO `json:"streamer_ext"` +} + +func (vo *ApiMomentVO) CopyMoment(moment *dbstruct.Moment) { + vo.Moment = moment +} + +func (vo *ApiMomentVO) CopyStreamerExt(streamerExt streamerproto.StreamerExtVO) { + if streamerExt != nil { + if apiStreamerExt, ok := streamerExt.(*streamerproto.ApiListExtVO); ok { + vo.StreamerExt = apiStreamerExt + } + } +} diff --git a/api/proto/moment/proto/moment_api_vo_op.go b/api/proto/moment/proto/moment_api_vo_op.go new file mode 100644 index 00000000..da63129b --- /dev/null +++ b/api/proto/moment/proto/moment_api_vo_op.go @@ -0,0 +1,28 @@ +package proto + +import ( + streamerproto "service/api/proto/streamer/proto" + "service/dbstruct" +) + +type MomentVO interface { + CopyMoment(moment *dbstruct.Moment) + CopyStreamerExt(streamerExt streamerproto.StreamerExtVO) +} + +type OpMomentVO struct { + *dbstruct.Moment + StreamerExt *streamerproto.OpListExtVO `json:"streamer_ext"` +} + +func (vo *OpMomentVO) CopyMoment(moment *dbstruct.Moment) { + vo.Moment = moment +} + +func (vo *OpMomentVO) CopyStreamerExt(streamerExt streamerproto.StreamerExtVO) { + if streamerExt != nil { + if opStreamerExt, ok := streamerExt.(*streamerproto.OpListExtVO); ok { + vo.StreamerExt = opStreamerExt + } + } +} diff --git a/api/proto/moment/proto/moment_op.go b/api/proto/moment/proto/moment_op.go index 5e6fdb65..6df3fef1 100644 --- a/api/proto/moment/proto/moment_op.go +++ b/api/proto/moment/proto/moment_op.go @@ -57,9 +57,9 @@ type OpListReq struct { } type OpListData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*OpMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type OpListResp struct { @@ -78,9 +78,9 @@ type OpListByMidReq struct { } type OpListByMidData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*OpMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type OpListByMidResp struct { @@ -99,9 +99,9 @@ type OpListByMidsReq struct { } type OpListByMidsData struct { - List []*dbstruct.Moment `json:"list"` - Offset int `json:"offset"` - More int `json:"more"` + List []*OpMomentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` } type OpListByMidsResp struct { diff --git a/api/proto/streamer/proto/streamer_vo_api.go b/api/proto/streamer/proto/streamer_vo_api.go index 2b4c714f..1575f3a8 100644 --- a/api/proto/streamer/proto/streamer_vo_api.go +++ b/api/proto/streamer/proto/streamer_vo_api.go @@ -2,6 +2,7 @@ package proto import ( streamerlinkproto "service/api/proto/streamerlink/proto" + "service/bizcommon/util" "service/dbstruct" goproto "google.golang.org/protobuf/proto" @@ -42,6 +43,13 @@ type ApiListExtVO struct { WechatCoinPrice *int64 `json:"wechat_coin_price"` } +func (vo *ApiListExtVO) GetMid() int64 { + if vo != nil { + return util.DerefInt64(vo.Mid) + } + return 0 +} + func (vo *ApiListExtVO) CopyAccount(account *dbstruct.Account) { vo.Name = account.Name vo.UserId = account.UserId diff --git a/api/proto/streamer/proto/streamer_vo_op.go b/api/proto/streamer/proto/streamer_vo_op.go index 208286b5..5314881f 100644 --- a/api/proto/streamer/proto/streamer_vo_op.go +++ b/api/proto/streamer/proto/streamer_vo_op.go @@ -2,12 +2,14 @@ package proto import ( streamerlinkproto "service/api/proto/streamerlink/proto" + "service/bizcommon/util" "service/dbstruct" goproto "google.golang.org/protobuf/proto" ) type StreamerExtVO interface { + GetMid() int64 CopyAccount(account *dbstruct.Account) CopyStreamer(streamer *dbstruct.Streamer) CopyPlatforms(platforms *[]*streamerlinkproto.StreamerLinkVO) @@ -49,6 +51,13 @@ type OpListExtVO struct { WechatCoinPrice *int64 `json:"wechat_coin_price"` } +func (vo *OpListExtVO) GetMid() int64 { + if vo != nil { + return util.DerefInt64(vo.Mid) + } + return 0 +} + func (vo *OpListExtVO) CopyAccount(account *dbstruct.Account) { if account == nil { return diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 12ef0f3a..137abedb 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1610,7 +1610,7 @@ func (s *Service) ApiDeleteMoment(ctx *gin.Context, id int64) (ec errcode.ErrCod return } -func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq) (list []*dbstruct.Moment, ec errcode.ErrCode) { +func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk list, err := _DefaultMoment.OpList(ctx, &momentproto.OpListReq{ @@ -1624,10 +1624,24 @@ func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq ec = errcode.ErrCodeMomentSrvFail return } + + // 填充主播信息 + vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api) + if ec != errcode.ErrCodeMomentSrvOk { + logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMomentSrvFail + return + } + voList = make([]*momentproto.ApiMomentVO, 0) + for _, vo := range vos { + apiVO, _ := vo.(*momentproto.ApiMomentVO) + voList = append(voList, apiVO) + } + return } -func (s *Service) ApiGetMomentListByMid(ctx *gin.Context, req *momentproto.ApiListByMidReq) (list []*dbstruct.Moment, ec errcode.ErrCode) { +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 { @@ -1646,10 +1660,23 @@ func (s *Service) ApiGetMomentListByMid(ctx *gin.Context, req *momentproto.ApiLi ec = errcode.ErrCodeMomentSrvFail return } + + // 填充主播信息 + vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api) + if ec != errcode.ErrCodeMomentSrvOk { + logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMomentSrvFail + return + } + voList = make([]*momentproto.ApiMomentVO, 0) + for _, vo := range vos { + apiVO, _ := vo.(*momentproto.ApiMomentVO) + voList = append(voList, apiVO) + } return } -func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiListByMidsReq) (list []*dbstruct.Moment, ec errcode.ErrCode) { +func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiListByMidsReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk list, err := _DefaultMoment.OpListByMids(ctx, &momentproto.OpListByMidsReq{ @@ -1664,6 +1691,19 @@ func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiL ec = errcode.ErrCodeMomentSrvFail return } + + // 填充主播信息 + vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api) + if ec != errcode.ErrCodeMomentSrvOk { + logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMomentSrvFail + return + } + voList = make([]*momentproto.ApiMomentVO, 0) + for _, vo := range vos { + apiVO, _ := vo.(*momentproto.ApiMomentVO) + voList = append(voList, apiVO) + } return } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index ae31e441..b280c6a2 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -1022,7 +1022,7 @@ func (s *Service) OpDeleteMoment(ctx *gin.Context, id int64) (ec errcode.ErrCode return } -func (s *Service) OpGetMomentList(ctx *gin.Context, req *momentproto.OpListReq) (list []*dbstruct.Moment, ec errcode.ErrCode) { +func (s *Service) OpGetMomentList(ctx *gin.Context, req *momentproto.OpListReq) (voList []*momentproto.OpMomentVO, ec errcode.ErrCode) { ec = errcode.ErrCodeMomentSrvOk if ec = s.OpGetMomentListBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { @@ -1035,6 +1035,19 @@ func (s *Service) OpGetMomentList(ctx *gin.Context, req *momentproto.OpListReq) ec = errcode.ErrCodeMomentSrvFail return } + + // 填充主播信息 + vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Op) + if ec != errcode.ErrCodeMomentSrvOk { + logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeMomentSrvFail + return + } + voList = make([]*momentproto.OpMomentVO, 0) + for _, vo := range vos { + opVO, _ := vo.(*momentproto.OpMomentVO) + voList = append(voList, opVO) + } return } diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 32c93edb..e408bed8 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -227,6 +227,14 @@ func (s *Service) utilExtendAccountsIntoStreamerExts(ctx *gin.Context, accountLi return } +func (s *Service) utilGetStreamerExtMap(list []streamerproto.StreamerExtVO) map[int64]streamerproto.StreamerExtVO { + _map := make(map[int64]streamerproto.StreamerExtVO) + for _, vo := range list { + _map[vo.GetMid()] = vo + } + return _map +} + // 提供session_id,返回session_id -> Session的Map func (s *Service) utilGetContactCustomerServiceSessionMap(ctx *gin.Context, sessionIds []int64) (_map map[int64]*dbstruct.ContactCustomerServiceSession, err error) { list, err := _DefaultContactCustomerServiceSession.OpListBySessionIds(ctx, &contact_customer_service_sessionproto.OpListBySessionIdsReq{ @@ -316,3 +324,67 @@ func (s *Service) utilUnThumbsUpMoment(ctx *gin.Context, req *momentproto.OpThum } return } + +func (s *Service) utilFillMomentsStreamerInfo(ctx *gin.Context, moments []*dbstruct.Moment, option int) (vos []momentproto.MomentVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeMomentSrvOk + + // 组装midList + midSet := make(map[int64]*dbstruct.Moment) + for _, moment := range moments { + midSet[util.DerefInt64(moment.Mid)] = &dbstruct.Moment{} + } + midList := make([]int64, 0) + for k, _ := range midSet { + midList = append(midList, k) + } + + // 获取accountList + accountList, err := _DefaultAccount.OpListByMids(ctx, &accountproto.OpListByMidsReq{ + Mids: midList, + Sort: []string{"_id"}, + }) + if err != nil { + logger.Error("Account OpListByMids fail, err: %v", err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + // 将accountList扩张为streamerExtList + streamerExtList := make([]streamerproto.StreamerExtVO, 0) + if option == consts.InterfaceType_Api { + for range accountList { + streamerExtList = append(streamerExtList, &streamerproto.ApiListExtVO{}) + } + } else if option == consts.InterfaceType_Op { + for range accountList { + streamerExtList = append(streamerExtList, &streamerproto.OpListExtVO{}) + } + } + if ec = s.utilExtendAccountsIntoStreamerExts(ctx, accountList, streamerExtList); ec != errcode.ErrCodeStreamerSrvOk { + logger.Error("utilExtendAccountsIntoStreamerExts fail") + return + } + + // 转为streamerExtMap + streamerExtMap := s.utilGetStreamerExtMap(streamerExtList) + + // 填充momentVO + vos = make([]momentproto.MomentVO, 0) + 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) + } + } + + return +}