diff --git a/proto/common.proto b/proto/common.proto index dbf797f..041e2b5 100644 --- a/proto/common.proto +++ b/proto/common.proto @@ -55,7 +55,8 @@ message Report message ReportResult { - ERROR_CODE Result = 1; + ERROR_CODE Result = 1; + repeated AudienceInfo Info = 2; } message GetRank @@ -65,8 +66,8 @@ message GetRank message GetRankResult { - ERROR_CODE Result = 1; - repeated ReportInfo Info = 2; + ERROR_CODE Result = 1; + repeated Audience Info = 2; } //新用户推送 @@ -77,7 +78,7 @@ message NotifyNewAudience //用户行为推送 message NotifyAudienceAction { - string OpenId = 1; + string OpenId = 1; //ID string Content = 2; //评论 int32 LikeNum = 3; //点赞数量 string GiftId = 4; //礼物ID @@ -86,27 +87,35 @@ message NotifyAudienceAction //============结构============ -//分数信息 +//上报分数信息 message ReportInfo { string OpenId = 1; int32 Score = 2; + bool IsWin = 3; } //观众信息 message Audience { - string OpenId = 1; - string NickName = 2; - string AvatarUrl = 3; - int32 Rank = 4; //排名 - int32 WinningStreak = 5; //连胜 + AudienceBasic AudienceBasic = 1; //观众基本信息 + AudienceInfo AudienceInfo = 2; //观众详细信息 +} + +//观众基本信息 +message AudienceBasic +{ + string OpenId = 1; //ID + string NickName = 2; //昵称 + string AvatarUrl = 3; //头像url } -//排名信息 -message RankInfo +//观众详细信息 +message AudienceInfo { - Audience Audience = 1; //观众信息 - int32 Rank = 2; //排名 - int32 Score = 3; //用户分数 + string OpenId = 1; //ID + int32 Score = 2; //总分 + int32 Rank = 3; //当前赛季排名 + int32 LastRank = 4; //上赛季排名 + int32 WinningStreak = 5; //连胜 } \ No newline at end of file diff --git a/proto/protoGen.bat b/proto/protoGen.bat index 040f931..d3cc98d 100644 --- a/proto/protoGen.bat +++ b/proto/protoGen.bat @@ -1,8 +1,8 @@ @ echo off cd ./protoc/bin set protoPath="../../" -set clientPath="D:/white_snake/douyin_prj/Assets/Script/GameLogic/Proto" -set serverPath="D:/dy_server/service/main/message" +set clientPath="/" +set serverPath="../../../service/main/message" protoc.exe -I=%protoPath% --csharp_out=%clientPath% --go_out=%serverPath% %protoPath%/*.proto clang-format.exe -i -style="{AlignConsecutiveAssignments: true,AlignConsecutiveDeclarations: true,AllowShortFunctionsOnASingleLine: None,BreakBeforeBraces: GNU,ColumnLimit: 0,IndentWidth: 4,Language: Proto}" %protoPath%/*.proto pause \ No newline at end of file diff --git a/service/main/game_mgr/handler_http.go b/service/main/game_mgr/handler_http.go index 671750a..c02c0c4 100644 --- a/service/main/game_mgr/handler_http.go +++ b/service/main/game_mgr/handler_http.go @@ -54,7 +54,7 @@ func OnDataPush(c *gin.Context) { return } - var audienceData []*pb.Audience + var audienceData []*pb.AudienceBasic var notifyData []*pb.NotifyAudienceAction switch msgType { @@ -73,7 +73,7 @@ func OnDataPush(c *gin.Context) { return } for _, data := range rawData { - audienceData = append(audienceData, &pb.Audience{ + audienceData = append(audienceData, &pb.AudienceBasic{ OpenId: data.SecOpenid, NickName: data.NickName, AvatarUrl: data.AvatarUrl, @@ -102,7 +102,7 @@ func OnDataPush(c *gin.Context) { return } for _, data := range rawData { - audienceData = append(audienceData, &pb.Audience{ + audienceData = append(audienceData, &pb.AudienceBasic{ OpenId: data.SecOpenid, NickName: data.NickName, AvatarUrl: data.AvatarUrl, @@ -127,7 +127,7 @@ func OnDataPush(c *gin.Context) { return } for _, data := range rawData { - audienceData = append(audienceData, &pb.Audience{ + audienceData = append(audienceData, &pb.AudienceBasic{ OpenId: data.SecOpenid, NickName: data.NickName, AvatarUrl: data.AvatarUrl, @@ -140,11 +140,10 @@ func OnDataPush(c *gin.Context) { } for _, audience := range audienceData { - redis.SetAudience(appId, audience) + redis.SetAudienceBasic(appId, audience) } for _, notify := range notifyData { redis.Publish(appId, roomId, notify) - fmt.Println("[Publish]", appId, roomId) } } diff --git a/service/main/message/pb/common.pb.go b/service/main/message/pb/common.pb.go index 0910fb4..5784724 100644 --- a/service/main/message/pb/common.pb.go +++ b/service/main/message/pb/common.pb.go @@ -624,7 +624,8 @@ type ReportResult struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Result ERROR_CODE `protobuf:"varint,1,opt,name=Result,json=result,proto3,enum=message.ERROR_CODE" json:"Result,omitempty"` + Result ERROR_CODE `protobuf:"varint,1,opt,name=Result,json=result,proto3,enum=message.ERROR_CODE" json:"Result,omitempty"` + Info []*AudienceInfo `protobuf:"bytes,2,rep,name=Info,json=info,proto3" json:"Info,omitempty"` } func (x *ReportResult) Reset() { @@ -674,11 +675,23 @@ func (x *ReportResult) GetResult() ERROR_CODE { return ERROR_CODE_SUCCESS } +func (x *ReportResult) GetInfo() []*AudienceInfo { + if x != nil { + return x.Info + } + return nil +} + func (x *ReportResult) SetResult(val ERROR_CODE) { if x != nil { x.Result = val } } +func (x *ReportResult) SetInfo(val []*AudienceInfo) { + if x != nil { + x.Info = val + } +} type GetRank struct { state protoimpl.MessageState @@ -746,8 +759,8 @@ type GetRankResult struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Result ERROR_CODE `protobuf:"varint,1,opt,name=Result,json=result,proto3,enum=message.ERROR_CODE" json:"Result,omitempty"` - Info []*ReportInfo `protobuf:"bytes,2,rep,name=Info,json=info,proto3" json:"Info,omitempty"` + Result ERROR_CODE `protobuf:"varint,1,opt,name=Result,json=result,proto3,enum=message.ERROR_CODE" json:"Result,omitempty"` + Info []*Audience `protobuf:"bytes,2,rep,name=Info,json=info,proto3" json:"Info,omitempty"` } func (x *GetRankResult) Reset() { @@ -797,7 +810,7 @@ func (x *GetRankResult) GetResult() ERROR_CODE { return ERROR_CODE_SUCCESS } -func (x *GetRankResult) GetInfo() []*ReportInfo { +func (x *GetRankResult) GetInfo() []*Audience { if x != nil { return x.Info } @@ -809,7 +822,7 @@ func (x *GetRankResult) SetResult(val ERROR_CODE) { x.Result = val } } -func (x *GetRankResult) SetInfo(val []*ReportInfo) { +func (x *GetRankResult) SetInfo(val []*Audience) { if x != nil { x.Info = val } @@ -883,7 +896,7 @@ type NotifyAudienceAction struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` + OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` //ID Content string `protobuf:"bytes,2,opt,name=Content,json=content,proto3" json:"Content,omitempty"` //评论 LikeNum int32 `protobuf:"varint,3,opt,name=LikeNum,json=likeNum,proto3" json:"LikeNum,omitempty"` //点赞数量 GiftId string `protobuf:"bytes,4,opt,name=GiftId,json=giftId,proto3" json:"GiftId,omitempty"` //礼物ID @@ -991,7 +1004,7 @@ func (x *NotifyAudienceAction) SetGiftNum(val int32) { } } -//分数信息 +//上报分数信息 type ReportInfo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -999,6 +1012,7 @@ type ReportInfo struct { OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` Score int32 `protobuf:"varint,2,opt,name=Score,json=score,proto3" json:"Score,omitempty"` + IsWin bool `protobuf:"varint,3,opt,name=IsWin,json=isWin,proto3" json:"IsWin,omitempty"` } func (x *ReportInfo) Reset() { @@ -1055,6 +1069,13 @@ func (x *ReportInfo) GetScore() int32 { return 0 } +func (x *ReportInfo) GetIsWin() bool { + if x != nil { + return x.IsWin + } + return false +} + func (x *ReportInfo) SetOpenId(val string) { if x != nil { x.OpenId = val @@ -1065,6 +1086,11 @@ func (x *ReportInfo) SetScore(val int32) { x.Score = val } } +func (x *ReportInfo) SetIsWin(val bool) { + if x != nil { + x.IsWin = val + } +} //观众信息 type Audience struct { @@ -1072,11 +1098,8 @@ type Audience struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` - NickName string `protobuf:"bytes,2,opt,name=NickName,json=nickName,proto3" json:"NickName,omitempty"` - AvatarUrl string `protobuf:"bytes,3,opt,name=AvatarUrl,json=avatarUrl,proto3" json:"AvatarUrl,omitempty"` - Rank int32 `protobuf:"varint,4,opt,name=Rank,json=rank,proto3" json:"Rank,omitempty"` //排名 - WinningStreak int32 `protobuf:"varint,5,opt,name=WinningStreak,json=winningStreak,proto3" json:"WinningStreak,omitempty"` //连胜 + AudienceBasic *AudienceBasic `protobuf:"bytes,1,opt,name=AudienceBasic,json=audienceBasic,proto3" json:"AudienceBasic,omitempty"` //观众基本信息 + AudienceInfo *AudienceInfo `protobuf:"bytes,2,opt,name=AudienceInfo,json=audienceInfo,proto3" json:"AudienceInfo,omitempty"` //观众详细信息 } func (x *Audience) Reset() { @@ -1119,103 +1142,157 @@ func (*Audience) Descriptor() ([]byte, []int) { return file_common_proto_rawDescGZIP(), []int{15} } -func (x *Audience) GetOpenId() string { +func (x *Audience) GetAudienceBasic() *AudienceBasic { if x != nil { - return x.OpenId + return x.AudienceBasic } - return "" + return nil } -func (x *Audience) GetNickName() string { +func (x *Audience) GetAudienceInfo() *AudienceInfo { if x != nil { - return x.NickName + return x.AudienceInfo } - return "" + return nil } -func (x *Audience) GetAvatarUrl() string { +func (x *Audience) SetAudienceBasic(val *AudienceBasic) { if x != nil { - return x.AvatarUrl + x.AudienceBasic = val } - return "" } - -func (x *Audience) GetRank() int32 { +func (x *Audience) SetAudienceInfo(val *AudienceInfo) { if x != nil { - return x.Rank + x.AudienceInfo = val } - return 0 } -func (x *Audience) GetWinningStreak() int32 { +//观众基本信息 +type AudienceBasic struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` //ID + NickName string `protobuf:"bytes,2,opt,name=NickName,json=nickName,proto3" json:"NickName,omitempty"` //昵称 + AvatarUrl string `protobuf:"bytes,3,opt,name=AvatarUrl,json=avatarUrl,proto3" json:"AvatarUrl,omitempty"` //头像url +} + +func (x *AudienceBasic) Reset() { + *x = AudienceBasic{} + if protoimpl.UnsafeEnabled { + mi := &file_common_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AudienceBasic) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (x *AudienceBasic) FromDB(data []byte) error { + return proto.Unmarshal(data, x) +} + +func (x *AudienceBasic) ToDB() ([]byte, error) { + return proto.Marshal(x) +} + +func (*AudienceBasic) ProtoMessage() {} + +func (x *AudienceBasic) ProtoReflect() protoreflect.Message { + mi := &file_common_proto_msgTypes[16] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AudienceBasic.ProtoReflect.Descriptor instead. +func (*AudienceBasic) Descriptor() ([]byte, []int) { + return file_common_proto_rawDescGZIP(), []int{16} +} + +func (x *AudienceBasic) GetOpenId() string { if x != nil { - return x.WinningStreak + return x.OpenId } - return 0 + return "" } -func (x *Audience) SetOpenId(val string) { +func (x *AudienceBasic) GetNickName() string { if x != nil { - x.OpenId = val + return x.NickName } + return "" } -func (x *Audience) SetNickName(val string) { + +func (x *AudienceBasic) GetAvatarUrl() string { if x != nil { - x.NickName = val + return x.AvatarUrl } + return "" } -func (x *Audience) SetAvatarUrl(val string) { + +func (x *AudienceBasic) SetOpenId(val string) { if x != nil { - x.AvatarUrl = val + x.OpenId = val } } -func (x *Audience) SetRank(val int32) { +func (x *AudienceBasic) SetNickName(val string) { if x != nil { - x.Rank = val + x.NickName = val } } -func (x *Audience) SetWinningStreak(val int32) { +func (x *AudienceBasic) SetAvatarUrl(val string) { if x != nil { - x.WinningStreak = val + x.AvatarUrl = val } } -//排名信息 -type RankInfo struct { +//观众详细信息 +type AudienceInfo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Audience *Audience `protobuf:"bytes,1,opt,name=Audience,json=audience,proto3" json:"Audience,omitempty"` //观众信息 - Rank int32 `protobuf:"varint,2,opt,name=Rank,json=rank,proto3" json:"Rank,omitempty"` //排名 - Score int32 `protobuf:"varint,3,opt,name=Score,json=score,proto3" json:"Score,omitempty"` //用户分数 + OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` //ID + Score int32 `protobuf:"varint,2,opt,name=Score,json=score,proto3" json:"Score,omitempty"` //总分 + Rank int32 `protobuf:"varint,3,opt,name=Rank,json=rank,proto3" json:"Rank,omitempty"` //当前赛季排名 + LastRank int32 `protobuf:"varint,4,opt,name=LastRank,json=lastRank,proto3" json:"LastRank,omitempty"` //上赛季排名 + WinningStreak int32 `protobuf:"varint,5,opt,name=WinningStreak,json=winningStreak,proto3" json:"WinningStreak,omitempty"` //连胜 } -func (x *RankInfo) Reset() { - *x = RankInfo{} +func (x *AudienceInfo) Reset() { + *x = AudienceInfo{} if protoimpl.UnsafeEnabled { - mi := &file_common_proto_msgTypes[16] + mi := &file_common_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *RankInfo) String() string { +func (x *AudienceInfo) String() string { return protoimpl.X.MessageStringOf(x) } -func (x *RankInfo) FromDB(data []byte) error { +func (x *AudienceInfo) FromDB(data []byte) error { return proto.Unmarshal(data, x) } -func (x *RankInfo) ToDB() ([]byte, error) { +func (x *AudienceInfo) ToDB() ([]byte, error) { return proto.Marshal(x) } -func (*RankInfo) ProtoMessage() {} +func (*AudienceInfo) ProtoMessage() {} -func (x *RankInfo) ProtoReflect() protoreflect.Message { - mi := &file_common_proto_msgTypes[16] +func (x *AudienceInfo) ProtoReflect() protoreflect.Message { + mi := &file_common_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1226,47 +1303,71 @@ func (x *RankInfo) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use RankInfo.ProtoReflect.Descriptor instead. -func (*RankInfo) Descriptor() ([]byte, []int) { - return file_common_proto_rawDescGZIP(), []int{16} +// Deprecated: Use AudienceInfo.ProtoReflect.Descriptor instead. +func (*AudienceInfo) Descriptor() ([]byte, []int) { + return file_common_proto_rawDescGZIP(), []int{17} } -func (x *RankInfo) GetAudience() *Audience { +func (x *AudienceInfo) GetOpenId() string { if x != nil { - return x.Audience + return x.OpenId } - return nil + return "" } -func (x *RankInfo) GetRank() int32 { +func (x *AudienceInfo) GetScore() int32 { + if x != nil { + return x.Score + } + return 0 +} + +func (x *AudienceInfo) GetRank() int32 { if x != nil { return x.Rank } return 0 } -func (x *RankInfo) GetScore() int32 { +func (x *AudienceInfo) GetLastRank() int32 { if x != nil { - return x.Score + return x.LastRank } return 0 } -func (x *RankInfo) SetAudience(val *Audience) { +func (x *AudienceInfo) GetWinningStreak() int32 { if x != nil { - x.Audience = val + return x.WinningStreak } + return 0 } -func (x *RankInfo) SetRank(val int32) { + +func (x *AudienceInfo) SetOpenId(val string) { if x != nil { - x.Rank = val + x.OpenId = val } } -func (x *RankInfo) SetScore(val int32) { +func (x *AudienceInfo) SetScore(val int32) { if x != nil { x.Score = val } } +func (x *AudienceInfo) SetRank(val int32) { + if x != nil { + x.Rank = val + } +} +func (x *AudienceInfo) SetLastRank(val int32) { + if x != nil { + x.LastRank = val + } +} +func (x *AudienceInfo) SetWinningStreak(val int32) { + if x != nil { + x.WinningStreak = val + } +} var File_common_proto protoreflect.FileDescriptor @@ -1306,53 +1407,65 @@ var file_common_proto_rawDesc = []byte{ 0x0a, 0x06, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, - 0x6f, 0x22, 0x3b, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, + 0x6f, 0x22, 0x66, 0x0a, 0x0c, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x2b, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x45, 0x52, 0x52, 0x4f, - 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x25, - 0x0a, 0x07, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x12, 0x1a, 0x0a, 0x08, 0x54, 0x6f, 0x70, - 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x6f, 0x70, - 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x65, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, - 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x2b, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x2e, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x52, 0x06, 0x72, 0x65, 0x73, - 0x75, 0x6c, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x70, 0x6f, - 0x72, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x42, 0x0a, 0x11, - 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, - 0x65, 0x12, 0x2d, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, - 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x61, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, - 0x22, 0x94, 0x01, 0x0a, 0x14, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x41, 0x75, 0x64, 0x69, 0x65, - 0x6e, 0x63, 0x65, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, + 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x29, + 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x25, 0x0a, 0x07, 0x47, 0x65, 0x74, + 0x52, 0x61, 0x6e, 0x6b, 0x12, 0x1a, 0x0a, 0x08, 0x54, 0x6f, 0x70, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x6f, 0x70, 0x43, 0x6f, 0x75, 0x6e, 0x74, + 0x22, 0x63, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x12, 0x2b, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x13, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x45, 0x52, 0x52, 0x4f, + 0x52, 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x25, + 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x52, + 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x42, 0x0a, 0x11, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x4e, + 0x65, 0x77, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x2d, 0x0a, 0x08, 0x41, 0x75, + 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x52, + 0x08, 0x61, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x94, 0x01, 0x0a, 0x14, 0x4e, 0x6f, + 0x74, 0x69, 0x66, 0x79, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x41, 0x63, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, + 0x74, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x4c, 0x69, 0x6b, 0x65, 0x4e, 0x75, 0x6d, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6c, 0x69, 0x6b, 0x65, 0x4e, 0x75, 0x6d, 0x12, 0x16, + 0x0a, 0x06, 0x47, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x47, 0x69, 0x66, 0x74, 0x4e, 0x75, + 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x75, 0x6d, + 0x22, 0x50, 0x0a, 0x0a, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, + 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x49, 0x73, 0x57, 0x69, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x69, 0x73, 0x57, + 0x69, 0x6e, 0x22, 0x83, 0x01, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, + 0x3c, 0x0a, 0x0d, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x42, 0x61, 0x73, 0x69, 0x63, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x42, 0x61, 0x73, 0x69, 0x63, 0x52, 0x0d, + 0x61, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x42, 0x61, 0x73, 0x69, 0x63, 0x12, 0x39, 0x0a, + 0x0c, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, + 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0c, 0x61, 0x75, 0x64, 0x69, + 0x65, 0x6e, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x61, 0x0a, 0x0d, 0x41, 0x75, 0x64, 0x69, + 0x65, 0x6e, 0x63, 0x65, 0x42, 0x61, 0x73, 0x69, 0x63, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, - 0x64, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x4c, - 0x69, 0x6b, 0x65, 0x4e, 0x75, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x6c, 0x69, - 0x6b, 0x65, 0x4e, 0x75, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x69, 0x66, 0x74, 0x49, 0x64, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x18, 0x0a, - 0x07, 0x47, 0x69, 0x66, 0x74, 0x4e, 0x75, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, - 0x67, 0x69, 0x66, 0x74, 0x4e, 0x75, 0x6d, 0x22, 0x3a, 0x0a, 0x0a, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x14, 0x0a, - 0x05, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, - 0x6f, 0x72, 0x65, 0x22, 0x96, 0x01, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, - 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, - 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, - 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, - 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, - 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0d, 0x57, 0x69, 0x6e, 0x6e, 0x69, 0x6e, - 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x77, - 0x69, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, 0x22, 0x63, 0x0a, 0x08, - 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2d, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, - 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x61, - 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a, 0x05, 0x53, - 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, - 0x65, 0x42, 0x05, 0x5a, 0x03, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, 0x6c, 0x22, 0x92, 0x01, 0x0a, 0x0c, + 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, + 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, + 0x65, 0x6e, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x61, + 0x6e, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x1a, + 0x0a, 0x08, 0x4c, 0x61, 0x73, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x08, 0x6c, 0x61, 0x73, 0x74, 0x52, 0x61, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0d, 0x57, 0x69, + 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x0d, 0x77, 0x69, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, + 0x42, 0x05, 0x5a, 0x03, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1367,7 +1480,7 @@ func file_common_proto_rawDescGZIP() []byte { return file_common_proto_rawDescData } -var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 17) +var file_common_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_common_proto_goTypes = []interface{}{ (*Ping)(nil), // 0: message.Ping (*Pong)(nil), // 1: message.Pong @@ -1385,24 +1498,27 @@ var file_common_proto_goTypes = []interface{}{ (*NotifyAudienceAction)(nil), // 13: message.NotifyAudienceAction (*ReportInfo)(nil), // 14: message.ReportInfo (*Audience)(nil), // 15: message.Audience - (*RankInfo)(nil), // 16: message.RankInfo - (ERROR_CODE)(0), // 17: message.ERROR_CODE + (*AudienceBasic)(nil), // 16: message.AudienceBasic + (*AudienceInfo)(nil), // 17: message.AudienceInfo + (ERROR_CODE)(0), // 18: message.ERROR_CODE } var file_common_proto_depIdxs = []int32{ - 17, // 0: message.LoginResult.Result:type_name -> message.ERROR_CODE - 17, // 1: message.PlayStartResult.Result:type_name -> message.ERROR_CODE - 17, // 2: message.PlayEndResult.Result:type_name -> message.ERROR_CODE + 18, // 0: message.LoginResult.Result:type_name -> message.ERROR_CODE + 18, // 1: message.PlayStartResult.Result:type_name -> message.ERROR_CODE + 18, // 2: message.PlayEndResult.Result:type_name -> message.ERROR_CODE 14, // 3: message.Report.Info:type_name -> message.ReportInfo - 17, // 4: message.ReportResult.Result:type_name -> message.ERROR_CODE - 17, // 5: message.GetRankResult.Result:type_name -> message.ERROR_CODE - 14, // 6: message.GetRankResult.Info:type_name -> message.ReportInfo - 15, // 7: message.NotifyNewAudience.Audience:type_name -> message.Audience - 15, // 8: message.RankInfo.Audience:type_name -> message.Audience - 9, // [9:9] is the sub-list for method output_type - 9, // [9:9] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 18, // 4: message.ReportResult.Result:type_name -> message.ERROR_CODE + 17, // 5: message.ReportResult.Info:type_name -> message.AudienceInfo + 18, // 6: message.GetRankResult.Result:type_name -> message.ERROR_CODE + 15, // 7: message.GetRankResult.Info:type_name -> message.Audience + 15, // 8: message.NotifyNewAudience.Audience:type_name -> message.Audience + 16, // 9: message.Audience.AudienceBasic:type_name -> message.AudienceBasic + 17, // 10: message.Audience.AudienceInfo:type_name -> message.AudienceInfo + 11, // [11:11] is the sub-list for method output_type + 11, // [11:11] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_common_proto_init() } @@ -1605,7 +1721,19 @@ func file_common_proto_init() { } } file_common_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RankInfo); i { + switch v := v.(*AudienceBasic); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AudienceInfo); i { case 0: return &v.state case 1: @@ -1623,7 +1751,7 @@ func file_common_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_common_proto_rawDesc, NumEnums: 0, - NumMessages: 17, + NumMessages: 18, NumExtensions: 0, NumServices: 0, }, diff --git a/service/main/redis/redis.go b/service/main/redis/redis.go index db1d2e8..3088bc2 100644 --- a/service/main/redis/redis.go +++ b/service/main/redis/redis.go @@ -4,16 +4,10 @@ import ( "app/service/main/message/pb" "context" "encoding/json" - "fmt" "github.com/redis/go-redis/v9" "os" ) -type RankInfo struct { - OpenId string - Score int32 -} - var client *redis.Client func init() { @@ -25,28 +19,30 @@ func init() { client = redis.NewClient(opts) } -func AddScore(appId string, scoreMap map[string]int32) error { +func UpdateReport(appId string, scoreMap map[string]int32) error { ctx := context.Background() pip := client.Pipeline() for openId, score := range scoreMap { - key := fmt.Sprintf("Score_%s", appId) + key := ThisWeekScoreKey(appId) pip.ZIncrBy(ctx, key, float64(score), openId) } _, err := pip.Exec(ctx) return err } -func GetRank(appId string, topCount int32) ([]*RankInfo, error) { +func GetRank(appId string, topCount int32) ([]*pb.Audience, error) { ctx := context.Background() - key := fmt.Sprintf("Score_%s", appId) + key := ThisWeekScoreKey(appId) cmd := client.ZRevRangeWithScores(ctx, key, 0, int64(topCount)) result, err := cmd.Result() if err != nil { return nil, err } - rankList := make([]*RankInfo, 0) + pip := client.Pipeline() for _, info := range result { - rankList = append(rankList, &RankInfo{ + key := ThisWeekScoreKey(appId) + + ret = append(ret, &RankInfo{ OpenId: info.Member.(string), Score: int32(info.Score), }) @@ -54,9 +50,9 @@ func GetRank(appId string, topCount int32) ([]*RankInfo, error) { return rankList, nil } -func SetAudience(appId string, data *pb.Audience) { +func SetAudienceBasic(appId string, data *pb.AudienceBasic) { ctx := context.Background() - key := fmt.Sprintf("UserData_%s_%s", appId, data.OpenId) + key := UserDataKey(appId, data.OpenId) exist, err := client.Exists(ctx, key).Result() if err != nil { return @@ -73,13 +69,20 @@ func SetAudience(appId string, data *pb.Audience) { } func GetAudience(appId string, openId string) *pb.Audience { + return &pb.Audience{ + AudienceBasic: GetAudienceBasic(appId, openId), + AudienceInfo: GetAudienceInfo(appId, openId), + } +} + +func GetAudienceBasic(appId string, openId string) *pb.AudienceBasic { ctx := context.Background() - key := fmt.Sprintf("UserData_%s_%s", appId, openId) + key := UserDataKey(appId, openId) result, err := client.Get(ctx, key).Result() if err != nil { return nil } - data := &pb.Audience{} + data := &pb.AudienceBasic{} err = json.Unmarshal([]byte(result), data) if err != nil { return nil @@ -87,12 +90,70 @@ func GetAudience(appId string, openId string) *pb.Audience { return data } +func GetAudienceInfo(appId string, openId string) *pb.AudienceInfo { + ctx := context.Background() + ret := &pb.AudienceInfo{ + OpenId: openId, + } + pip := client.Pipeline() + keyScore := ThisWeekScoreKey(appId) + keyScoreLast := LastWeekScoreKey(appId) + + var err error + cmdScore := pip.ZScore(ctx, keyScore, openId) + cmdRank := pip.ZRank(ctx, keyScore, openId) + cmdRankLast := pip.ZRank(ctx, keyScoreLast, openId) + result, err := pip.Exec(ctx) + if err != nil { + return ret + } + if len(result) != 3 { + return ret + } + if result, err := cmdScore.Result(); err == nil { + ret.Score = int32(result) + } + if result, err := cmdRank.Result(); err == nil { + ret.Rank = int32(result) + } + if result, err := cmdRankLast.Result(); err == nil { + ret.Score = int32(result) + } + return ret +} + +func GetAudienceBasicList(appId string, openIdList []string) (ret []*pb.AudienceBasic) { + ctx := context.Background() + pip := client.Pipeline() + var cmdList []*redis.StringCmd + for _, openId := range openIdList { + key := UserDataKey(appId, openId) + cmdList = append(cmdList, pip.Get(ctx, key)) + } + _, err := pip.Exec(ctx) + if err != nil { + return nil + } + for _, cmd := range cmdList { + data := &pb.AudienceBasic{} + if result, err := cmd.Result(); err == nil { + _ = json.Unmarshal([]byte(result), data) + } + ret = append(ret, data) + } + return +} + +func GetAudienceInfoList(appId string, openIdList []string) (ret []*pb.AudienceInfo) { + ctx := context.Background() + +} + func Subscribe(appId string, roomId string, pushFunc func(string), pushCloseChan chan struct{}) { ps := client.Subscribe(context.Background(), PublishKey(appId, roomId)) go func() { for { msg, err := ps.ReceiveMessage(context.Background()) - fmt.Println("ReceiveMessage", msg, err) if err != nil { return } @@ -112,7 +173,3 @@ func Publish(appId string, roomId string, data *pb.NotifyAudienceAction) { } client.Publish(context.Background(), PublishKey(appId, roomId), string(jsonData)) } - -func PublishKey(appId string, roomId string) string { - return fmt.Sprintf("DataPush_%s_%s", appId, roomId) -} diff --git a/service/main/redis/redis_keys.go b/service/main/redis/redis_keys.go new file mode 100644 index 0000000..8017b68 --- /dev/null +++ b/service/main/redis/redis_keys.go @@ -0,0 +1,30 @@ +package redis + +import ( + "fmt" + "time" +) + +func PublishKey(appId string, roomId string) string { + return fmt.Sprintf("DataPush_%s_%s", appId, roomId) +} + +func UserDataKey(appId string, openId string) string { + return fmt.Sprintf("UserData_%s_%s", appId, openId) +} + +func ThisWeekScoreKey(appId string) string { + weekStart := getWeekStart(time.Now()) + return fmt.Sprintf("Score_%s_%d", appId, weekStart) +} + +func LastWeekScoreKey(appId string) string { + weekStart := getWeekStart(time.Now().Add(-time.Hour * 24 * 7)) + return fmt.Sprintf("Score_%s_%d", appId, weekStart) +} + +func getWeekStart(now time.Time) int64 { + startOfWeek := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + startOfWeek = startOfWeek.AddDate(0, 0, int(-startOfWeek.Weekday())) + return startOfWeek.Unix() +} diff --git a/service/main/user/user.go b/service/main/user/user.go index 6de0648..049ed9c 100644 --- a/service/main/user/user.go +++ b/service/main/user/user.go @@ -86,7 +86,6 @@ func (s *User) OnRecv(msgId int32, data interface{}) { } func (s *User) OnRecvPush(data string) { - s.Log("OnRecvPush", data) msg := &pb.NotifyAudienceAction{} err := json.Unmarshal([]byte(data), msg) if err != nil { @@ -166,7 +165,7 @@ func (s *User) OnReport(msg *pb.Report) { for _, info := range msg.Info { scoreMap[info.OpenId] = info.Score } - err := redis.AddScore(s.appId, scoreMap) + err := redis.UpdateReport(s.appId, scoreMap) if err != nil { s.SendUserMsg(&pb.ReportResult{Result: pb.ERROR_CODE_FAIL}) return