Merge pull request 'by Robin at 20240117; fix' (#59) from feat-20230112-001-Robin into test

Reviewed-on: #59
This commit is contained in:
chenhao 2024-01-17 19:19:01 +08:00
commit 9d30b82e70
10 changed files with 221 additions and 22 deletions

View File

@ -21,6 +21,12 @@ const (
DevType_Ios = 1
)
// 接口类型
const (
InterfaceType_Op = 0
InterfaceType_Api = 1
)
// apollo_config
const (
MaxPswdWrongTimesKey = "max_pswd_wrong_times"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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