67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package friend
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelFriend struct {
|
|
modules.MCompModel
|
|
moduleFriend *Friend
|
|
}
|
|
|
|
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableFriend
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleFriend = module.(*Friend)
|
|
return
|
|
}
|
|
|
|
// Deprecated
|
|
func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DBUser {
|
|
var user *pb.DBUser
|
|
err := this.DB.FindOne(comm.TableUser, bson.M{
|
|
"name": nickName,
|
|
}).Decode(&user)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return user
|
|
}
|
|
|
|
//查询好友
|
|
func (this *ModelFriend) GetFriend(uid string) *pb.DBFriend {
|
|
friend := &pb.DBFriend{Uid: uid}
|
|
if this.moduleFriend.IsCross() {
|
|
err := this.Get(uid, friend)
|
|
if err != nil {
|
|
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
|
|
if err := this.Add(uid, friend); err != nil {
|
|
return nil
|
|
}
|
|
}
|
|
// log.Error("未获得好友数据", log.Fields{"uid": uid})
|
|
}
|
|
} else {
|
|
friend := &pb.DBFriend{}
|
|
if err := this.moduleFriend.service.AcrossClusterRpcCall(
|
|
context.Background(),
|
|
this.moduleFriend.GetCrossTag(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleFriendDB),
|
|
pb.RPCGeneralReqA1{Param1: uid},
|
|
friend); err != nil {
|
|
this.moduleFriend.Errorln(err)
|
|
}
|
|
}
|
|
|
|
return friend
|
|
}
|