Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"app.go",
"appIndex.go",
"dao.go",
"info.go",
"pendant.go",
"recommend.go",
"status.go",
"uid2roomid.go",
],
importpath = "go-common/app/interface/live/app-interface/dao/room",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-interface/conf:go_default_library",
"//app/interface/live/app-interface/dao:go_default_library",
"//app/service/live/room/api/liverpc/v1:go_default_library",
"//app/service/live/room/api/liverpc/v2:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/rpc/liverpc/context:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,123 @@
package room
import (
"context"
"time"
"github.com/pkg/errors"
"go-common/app/interface/live/app-interface/conf"
cDao "go-common/app/interface/live/app-interface/dao"
roomV2 "go-common/app/service/live/room/api/liverpc/v2"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
// 根据moduleId查common房间列表
func (d *Dao) GetListByIds(ctx context.Context, moduleIds []int64) (respModuleList map[int64]*roomV2.AppIndexGetRoomListByIdsResp_RoomList, err error) {
getModuleListByIdsTimeOut := time.Duration(conf.GetTimeout("getModuleListByIds", 100)) * time.Millisecond
moduleList, err := cDao.RoomApi.V2AppIndex.GetRoomListByIds(rpcCtx.WithTimeout(ctx, getModuleListByIdsTimeOut), &roomV2.AppIndexGetRoomListByIdsReq{
Ids: moduleIds,
})
if err != nil {
log.Error("[GetListByIds]get all module ids rpc error, room.v1.AppIndex.GetModuleIds, error:%+v", err)
err = errors.New("GET Module List Rpc error")
return
}
if moduleList.Code != 0 || moduleList.Data == nil {
log.Error("[GetListByIds]get all module ids return data error, code, %d, msg: %s", moduleList.Code, moduleList.Msg)
err = errors.New("GET Module List return error")
return
}
if len(moduleList.Data) <= 0 {
log.Error("[GetListByIds]get all module ids empty error")
err = errors.New("GET Module List empty error")
return
}
respModuleList = moduleList.Data
return
}
// 获取所有模块基础信息
func (d *Dao) GetAllModuleInfo(ctx context.Context, moduleId int64) (moduleInfoList []*roomV2.AppIndexGetBaseMInfoListResp_ModuleInfo, err error) {
moduleInfoList = make([]*roomV2.AppIndexGetBaseMInfoListResp_ModuleInfo, 0)
param := &roomV2.AppIndexGetBaseMInfoListReq{}
if moduleId != 0 {
param.ModuleId = moduleId
}
moduleInfoListOut, err := cDao.RoomApi.V2AppIndex.GetBaseMInfoList(ctx, param)
if err != nil {
log.Error("[GetAllModuleInfo]RoomApi.V2AppIndex.GetBaseMInfoList rpc error, RoomApi.V2AppIndex.GetBaseMInfoList, error:%+v", err)
err = errors.New("RoomApi.V2AppIndex.GetBaseMInfoList rpc error")
return
}
if moduleInfoListOut.Code != 0 || moduleInfoListOut.Data == nil || len(moduleInfoListOut.Data) <= 0 {
log.Error("[GetAllModuleInfo]RoomApi.V2AppIndex.GetBaseMInfoList return data error, code, %d, msg: %s, error:%+v", moduleInfoListOut.Code, moduleInfoListOut.Msg, err)
err = errors.New("RoomApi.V2AppIndex.GetBaseMInfoList return data error")
return
}
moduleInfoList = moduleInfoListOut.Data
return
}
// 根据模块id获取分区入口信息
func (d *Dao) GetAreaEntrance(ctx context.Context, ids []int64) (result map[int64]*roomV2.AppIndexGetPicListByIdsResp_ItemList, err error) {
result = make(map[int64]*roomV2.AppIndexGetPicListByIdsResp_ItemList, 0)
areaEntranceOut, err := cDao.RoomApi.V2AppIndex.GetPicListByIds(ctx, &roomV2.AppIndexGetPicListByIdsReq{Ids: ids})
if err != nil {
log.Error("[GetAreaEntrance]RoomApi.V2AppIndex.GetPicListByIds rpc error:%+v", err)
err = errors.New("RoomApi.V2AppIndex.GetPicListByIds rpc error")
return
}
if areaEntranceOut.Code != 0 || areaEntranceOut.Data == nil {
log.Error("[GetAreaEntrance]RoomApi.V2AppIndex.GetPicListByIds return data error, code, %d, msg: %s, error:%+v", areaEntranceOut.Code, areaEntranceOut.Msg, err)
err = errors.New("RoomApi.V2AppIndex.GetPicListByIds return data error")
return
}
result = areaEntranceOut.Data
return
}
// 根据分区ids获取房间列表
func (d *Dao) GetMultiRoomList(ctx context.Context, areaIds string, platform string) (result map[int64][]*roomV2.AppIndexGetMultiRoomListResp_RoomList, err error) {
result = make(map[int64][]*roomV2.AppIndexGetMultiRoomListResp_RoomList)
multiRoomListOut, err := cDao.RoomApi.V2AppIndex.GetMultiRoomList(ctx, &roomV2.AppIndexGetMultiRoomListReq{
AreaIds: areaIds,
Platform: platform,
})
if err != nil {
log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList rpc error:%+v", err)
err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList rpc error")
return
}
if multiRoomListOut.Code != 0 || multiRoomListOut.Data == nil {
log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList return data error, code, %d, msg: %s", multiRoomListOut.Code, multiRoomListOut.Msg)
err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList return data error")
return
}
if len(multiRoomListOut.Data) <= 0 {
log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList empty error")
err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList empty error")
return
}
for _, item := range multiRoomListOut.Data {
if item != nil {
result[item.Id] = item.List
}
}
return
}

View File

@@ -0,0 +1,37 @@
package room
import (
"context"
"errors"
"time"
"go-common/app/interface/live/app-interface/conf"
cDao "go-common/app/interface/live/app-interface/dao"
roomV2 "go-common/app/service/live/room/api/liverpc/v2"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
func (d *Dao) GetActivityCard(ctx context.Context, ids []int64, logPrefix string) (err error, data map[int64]*roomV2.AppIndexGetActivityCardResp_ActivityCard) {
activityQueryTimeout := time.Duration(conf.GetTimeout("activityQuery", 100)) * time.Millisecond
cardInfo, roomError := cDao.RoomApi.V2AppIndex.GetActivityCard(rpcCtx.WithTimeout(ctx, activityQueryTimeout), &roomV2.AppIndexGetActivityCardReq{Ids: ids})
if roomError != nil {
log.Error("[%s] get activity card info rpc error, room.v2.AppIndex.GetActivityCard, error:%+v", logPrefix, roomError)
err = errors.New("get activity card info rpc error")
return
}
if cardInfo.Code != 0 {
log.Error("[%s] get activity card info response error, code, %d, msg: %s", logPrefix, cardInfo.Code, cardInfo.Msg)
err = errors.New("get activity card info response error")
return
}
if cardInfo.Data.ActivityCard == nil {
log.Error("[%s] get activity card info but on data", logPrefix)
err = errors.New("get activity card info but no data")
return
}
data = cardInfo.Data.ActivityCard
return
}

View File

@@ -0,0 +1,32 @@
package room
import (
"context"
"go-common/app/interface/live/app-interface/conf"
)
// Dao dao
type Dao struct {
c *conf.Config
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
}
return
}
// Close close the resource.
func (d *Dao) Close() {
return
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) error {
// TODO: if you need use mc,redis, please add
// check
return nil
}

View File

@@ -0,0 +1,52 @@
package room
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"go-common/app/interface/live/app-interface/conf"
cDao "go-common/app/interface/live/app-interface/dao"
roomV2 "go-common/app/service/live/room/api/liverpc/v2"
"go-common/library/ecode"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
// GetRoomInfoByIds
func (d *Dao) GetRoomInfoByIds(ctx context.Context, roomIds []int64, fields []string, from string) (multiRoomListResp map[int64]*roomV2.RoomGetByIdsResp_RoomInfo, err error) {
multiRoomListResp = make(map[int64]*roomV2.RoomGetByIdsResp_RoomInfo)
getByIdsTimeout := time.Duration(conf.GetTimeout("getByIds", 100)) * time.Millisecond
multiRoomList, getByIdsError := cDao.RoomApi.V2Room.GetByIds(rpcCtx.WithTimeout(ctx, getByIdsTimeout), &roomV2.RoomGetByIdsReq{
Ids: roomIds,
NeedBroadcastType: 1,
NeedUinfo: 1,
Fields: fields,
From: from,
})
if getByIdsError != nil {
log.Error("[GetRoomInfoByIds]room.v2.getByIds rpc error:%+v", getByIdsError)
// 这个是推荐房间列表的基础信息如果失败需要cancel不然返回值会很奇怪
err = errors.WithMessage(ecode.GetRoomError, fmt.Sprintf("room.v2.getByIds rpc error:%+v", getByIdsError))
return
}
if multiRoomList.Code != 0 {
log.Error("[GetRoomInfoByIds]room.v2.getByIds response error,code:%d,msg:%s", multiRoomList.Code, multiRoomList.Msg)
// 这个是推荐房间列表的基础信息如果失败需要cancel不然返回值会很奇怪
err = errors.WithMessage(ecode.GetRoomError, fmt.Sprintf("room.v2.getByIds response error,code:%d,msg:%s", multiRoomList.Code, multiRoomList.Msg))
return
}
if multiRoomList.Data == nil {
log.Error("[GetRoomInfoByIds]room.v2.getByIds empty error")
// 这个是推荐房间列表的基础信息如果失败需要cancel不然返回值会很奇怪
err = errors.WithMessage(ecode.GetRoomEmptyError, "room.v2.getByIds empty error")
return
}
multiRoomListResp = multiRoomList.Data
return
}

View File

@@ -0,0 +1,77 @@
package room
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"go-common/app/interface/live/app-interface/conf"
ServiceConf "go-common/app/interface/live/app-interface/conf"
cDao "go-common/app/interface/live/app-interface/dao"
roomV1 "go-common/app/service/live/room/api/liverpc/v1"
"go-common/library/ecode"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
// GetRoomPendant
func (d *Dao) GetRoomPendant(ctx context.Context, roomIds []int64, pendantType string, position int64) (pendantRoomListResp map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result, err error) {
pendantRoomListResp = make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
getPendantByIdsTimeout := time.Duration(conf.GetTimeout("getPendantByIds", 50)) * time.Millisecond
pendantRoomList, err := cDao.RoomApi.V1RoomPendant.GetPendantByIds(rpcCtx.WithTimeout(ctx, getPendantByIdsTimeout), &roomV1.RoomPendantGetPendantByIdsReq{
Ids: roomIds,
Type: pendantType,
Position: position, // 历史原因,取右上,但客户端展示在左上
})
if err != nil {
log.Error("[GetRoomPendant]room.v1.getPendantByIds rpc error:%+v", err)
err = errors.WithMessage(ecode.RoomPendantError, fmt.Sprintf("room.v1.getPendantByIds rpc error:%+v", err))
return
}
if pendantRoomList.Code != 0 {
log.Error("[GetRoomPendant]room.v1.getPendantByIds response code:%d,msg:%s", pendantRoomList.Code, pendantRoomList.Msg)
err = errors.WithMessage(ecode.RoomPendantReturnError, fmt.Sprintf("room.v1.getPendantByIds response error, code:%d, msg:%s", pendantRoomList.Code, pendantRoomList.Msg))
return
}
if pendantRoomList.Data == nil || pendantRoomList.Data.Result == nil {
log.Error("[GetRoomPendant]room.v1.getPendantByIds empty error")
err = errors.WithMessage(ecode.RoomPendantReturnError, "")
return
}
pendantRoomListResp = pendantRoomList.Data.Result
return
}
// GetRoomPendantInfo ...
// 获取角标信息
func (d *Dao) GetRoomPendantInfo(ctx context.Context, req *roomV1.RoomPendantGetPendantByIdsReq, params ServiceConf.ChunkCallInfo) (roomNewsResult *roomV1.RoomPendantGetPendantByIdsResp, err error) {
ret, err := cDao.RoomApi.V1RoomPendant.GetPendantByIds(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV1.RoomPendantGetPendantByIdsReq{Ids: req.Ids, Type: req.Type, Position: req.Position})
if err != nil {
return
}
erelongInfo, success := ServiceConf.CheckReturn(err, ret.Code, ret.Msg, ServiceConf.RoomPendent, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.PkIDRecordFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Ids)
} else {
err = errors.WithMessage(ecode.PkIDLiveRPCCodeError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Ids)
}
return nil, err
}
if ret.Data == nil {
erelongInfo.ErrType = ServiceConf.EmptyResultEn
erelongInfo.ErrDesc = ServiceConf.EmptyResult
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Ids)
return nil, err
}
roomNewsResult = ret
return
}

View File

@@ -0,0 +1,43 @@
package room
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"go-common/app/interface/live/app-interface/conf"
cDao "go-common/app/interface/live/app-interface/dao"
roomV1 "go-common/app/service/live/room/api/liverpc/v1"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
)
// 获取首页推荐强推列表
func (d *Dao) GetStrongRecList(ctx context.Context, recPage int64) (strongRecRoomListResp *roomV1.RoomRecommendClientRecStrongResp, err error) {
strongRecRoomListResp = &roomV1.RoomRecommendClientRecStrongResp{}
clientRecStrongTimeout := time.Duration(conf.GetTimeout("clientRecStrong", 100)) * time.Millisecond
strongRecRoomList, err := cDao.RoomApi.V1RoomRecommend.ClientRecStrong(rpcCtx.WithTimeout(ctx, clientRecStrongTimeout), &roomV1.RoomRecommendClientRecStrongReq{
RecPage: recPage,
})
if err != nil {
log.Error("[GetStrongRecList]room.v1.clientStrongRec rpc error:%+v", err)
err = errors.New(fmt.Sprintf("room.v1.clientStrongRec rpc error:%+v", err))
return
}
if strongRecRoomList.Code != 0 {
log.Error("[GetStrongRecList]room.v1.getPendantByIds response code:%d,msg:%s", strongRecRoomList.Code, strongRecRoomList.Msg)
err = errors.New(fmt.Sprintf("room.v1.getPendantByIds response error, code:%d, msg:%s", strongRecRoomList.Code, strongRecRoomList.Msg))
return
}
if strongRecRoomList.Data == nil || strongRecRoomList.Data.Result == nil {
log.Error("[GetStrongRecList]room.v1.getPendantByIds empty")
err = errors.New("[getSkyHorseRoomList]room.v1.getPendantByIds empty")
return
}
strongRecRoomListResp = strongRecRoomList
return
}

View File

@@ -0,0 +1,47 @@
package room
import (
"context"
"github.com/pkg/errors"
ServiceConf "go-common/app/interface/live/app-interface/conf"
"go-common/app/interface/live/app-interface/dao"
roomV1 "go-common/app/service/live/room/api/liverpc/v1"
"go-common/library/ecode"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
"time"
)
// GetRoomInfo ...
// 获取room信息
func (d *Dao) GetRoomInfo(ctx context.Context, req *roomV1.RoomGetStatusInfoByUidsReq, params ServiceConf.ChunkCallInfo) (resp *roomV1.RoomGetStatusInfoByUidsResp, err error) {
// ret, err := dao.FansMedalApi.V1FansMedal.TargetsWithMedal(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond),
resp = &roomV1.RoomGetStatusInfoByUidsResp{}
ret, err := dao.RoomApi.V1Room.GetStatusInfoByUids(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond),
&roomV1.RoomGetStatusInfoByUidsReq{Uids: req.Uids, FilterOffline: req.FilterOffline, NeedBroadcastType: req.NeedBroadcastType})
if err != nil {
return
}
erelongInfo, success := ServiceConf.CheckReturn(err, ret.Code, ret.Msg, ServiceConf.GetStatusInfoByUfos, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.RoomGetStatusInfoRPCError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Uids)
} else {
err = errors.WithMessage(ecode.RoomGetStatusInfoRPCError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Uids)
}
return
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = ServiceConf.EmptyResultEn
erelongInfo.ErrDesc = ServiceConf.EmptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Uids)
return
}
resp = ret
return
}

View File

@@ -0,0 +1,39 @@
package room
import (
"context"
"github.com/pkg/errors"
ServiceConf "go-common/app/interface/live/app-interface/conf"
"go-common/app/interface/live/app-interface/dao"
roomV2 "go-common/app/service/live/room/api/liverpc/v2"
"go-common/library/ecode"
"go-common/library/log"
rpcCtx "go-common/library/net/rpc/liverpc/context"
"time"
)
// UIDs2roomIDs ...
// uid转换roomID,每批最大400
func (d *Dao) UIDs2roomIDs(ctx context.Context, req *roomV2.RoomRoomIdByUidMultiReq, params ServiceConf.ChunkCallInfo) (ret *roomV2.RoomRoomIdByUidMultiResp, err error) {
ret, err = dao.RoomApi.V2Room.RoomIdByUidMulti(rpcCtx.WithTimeout(ctx, time.Duration(params.RPCTimeout)*time.Millisecond), &roomV2.RoomRoomIdByUidMultiReq{Uids: req.Uids})
if err != nil {
return
}
erelongInfo, success := ServiceConf.CheckReturn(err, ret.Code, ret.Msg, ServiceConf.GetRoomID, params.RPCTimeout, params.ChunkSize, params.ChunkNum)
if !success {
if err != nil {
err = errors.WithMessage(ecode.FansMedalFrameWorkCallError, "GET SEA PATROL FAIL")
log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|error:%+v"+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
err, erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Uids)
}
return
}
if ret.Data == nil || len(ret.Data) <= 0 {
erelongInfo.ErrType = ServiceConf.EmptyResultEn
erelongInfo.ErrDesc = ServiceConf.EmptyResult
// log.Error(erelongInfo.ErrType+"|"+erelongInfo.URLName+"|Code:%d"+"|Msg:%s"+"|RPCTimeout:%d"+"|ChunkSize:%d"+"|ChunkNum:%d"+"|ParamsName:%s"+"|Params:%v",
// erelongInfo.Code, erelongInfo.Msg, erelongInfo.RPCTimeout, erelongInfo.ChunkSize, erelongInfo.ChunkNum, params.ParamsName, req.Uids)
return
}
return
}