fuwencai 4 年之前
父节点
当前提交
3ae9b350ff

+ 9 - 3
rpc/internal/logic/getunreadcountlogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"app.yhyue.com/moapp/MessageCenter/service"
 	"context"
 
 	"app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
@@ -24,8 +25,13 @@ func NewGetUnreadCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 }
 
 //   查询指定用户未读消息合计
-func (l *GetUnreadCountLogic) GetUnreadCount(in *message.DeleteMultipleMessageRequest) (*message.GetUnreadCountResponse, error) {
-	// todo: add your logic here and delete this line
+func (l *GetUnreadCountLogic) GetUnreadCount(in *message.GetUnreadCountRequest) (*message.GetUnreadCountResponse, error) {
 
-	return &message.GetUnreadCountResponse{}, nil
+	m := &service.MessageService{}
+	code, msg ,count:= m.CountUnread(in.UserId,in.Appid)
+	return &message.GetUnreadCountResponse{
+		Code:    code,
+		Message: msg,
+		Count: count,
+	}, nil
 }

+ 1 - 1
rpc/internal/server/messageserver.go

@@ -46,7 +46,7 @@ func (s *MessageServer) DeleteMultipleMessage(ctx context.Context, in *message.D
 }
 
 //   查询指定用户未读消息合计
-func (s *MessageServer) GetUnreadCount(ctx context.Context, in *message.DeleteMultipleMessageRequest) (*message.GetUnreadCountResponse, error) {
+func (s *MessageServer) GetUnreadCount(ctx context.Context, in *message.GetUnreadCountRequest) (*message.GetUnreadCountResponse, error) {
 	l := logic.NewGetUnreadCountLogic(ctx, s.svcCtx)
 	return l.GetUnreadCount(in)
 }

+ 1 - 1
rpc/message.proto

@@ -59,7 +59,7 @@ service Message {
   // 删除多条消息
   rpc DeleteMultipleMessage(DeleteMultipleMessageRequest) returns(Response);
   //  查询指定用户未读消息合计
-  rpc GetUnreadCount(DeleteMultipleMessageRequest) returns(GetUnreadCountResponse);
+  rpc GetUnreadCount(GetUnreadCountRequest) returns(GetUnreadCountResponse);
 
 
 }

+ 15 - 15
rpc/message/message.pb.go

@@ -548,7 +548,7 @@ var file_message_proto_rawDesc = []byte{
 	0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
 	0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12,
 	0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
-	0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x89, 0x03, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
+	0x63, 0x6f, 0x75, 0x6e, 0x74, 0x32, 0x82, 0x03, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
 	0x65, 0x12, 0x47, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53,
 	0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x20, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e,
 	0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x61, 0x64, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
@@ -567,13 +567,13 @@ var file_message_proto_rawDesc = []byte{
 	0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x75,
 	0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71,
 	0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x52,
-	0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x58, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x6e,
-	0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x6d, 0x65, 0x73, 0x73,
-	0x61, 0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70,
-	0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
-	0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x6e,
-	0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
-	0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x51, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x6e,
+	0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x6d, 0x65, 0x73, 0x73,
+	0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x6e, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75,
+	0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x73, 0x73,
+	0x61, 0x67, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x6e, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75,
+	0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x33,
 }
 
 var (
@@ -603,7 +603,7 @@ var file_message_proto_depIdxs = []int32{
 	0, // 1: message.Message.SendUserMsg:input_type -> message.SendMsgRequest
 	2, // 2: message.Message.DeleteSingleMessage:input_type -> message.DeleteSingleMessageRequest
 	3, // 3: message.Message.DeleteMultipleMessage:input_type -> message.DeleteMultipleMessageRequest
-	3, // 4: message.Message.GetUnreadCount:input_type -> message.DeleteMultipleMessageRequest
+	4, // 4: message.Message.GetUnreadCount:input_type -> message.GetUnreadCountRequest
 	5, // 5: message.Message.ChangeReadStatus:output_type -> message.Response
 	5, // 6: message.Message.SendUserMsg:output_type -> message.Response
 	5, // 7: message.Message.DeleteSingleMessage:output_type -> message.Response
@@ -748,7 +748,7 @@ type MessageClient interface {
 	// 删除多条消息
 	DeleteMultipleMessage(ctx context.Context, in *DeleteMultipleMessageRequest, opts ...grpc.CallOption) (*Response, error)
 	//  查询指定用户未读消息合计
-	GetUnreadCount(ctx context.Context, in *DeleteMultipleMessageRequest, opts ...grpc.CallOption) (*GetUnreadCountResponse, error)
+	GetUnreadCount(ctx context.Context, in *GetUnreadCountRequest, opts ...grpc.CallOption) (*GetUnreadCountResponse, error)
 }
 
 type messageClient struct {
@@ -795,7 +795,7 @@ func (c *messageClient) DeleteMultipleMessage(ctx context.Context, in *DeleteMul
 	return out, nil
 }
 
-func (c *messageClient) GetUnreadCount(ctx context.Context, in *DeleteMultipleMessageRequest, opts ...grpc.CallOption) (*GetUnreadCountResponse, error) {
+func (c *messageClient) GetUnreadCount(ctx context.Context, in *GetUnreadCountRequest, opts ...grpc.CallOption) (*GetUnreadCountResponse, error) {
 	out := new(GetUnreadCountResponse)
 	err := c.cc.Invoke(ctx, "/message.Message/GetUnreadCount", in, out, opts...)
 	if err != nil {
@@ -815,7 +815,7 @@ type MessageServer interface {
 	// 删除多条消息
 	DeleteMultipleMessage(context.Context, *DeleteMultipleMessageRequest) (*Response, error)
 	//  查询指定用户未读消息合计
-	GetUnreadCount(context.Context, *DeleteMultipleMessageRequest) (*GetUnreadCountResponse, error)
+	GetUnreadCount(context.Context, *GetUnreadCountRequest) (*GetUnreadCountResponse, error)
 }
 
 // UnimplementedMessageServer can be embedded to have forward compatible implementations.
@@ -834,7 +834,7 @@ func (*UnimplementedMessageServer) DeleteSingleMessage(context.Context, *DeleteS
 func (*UnimplementedMessageServer) DeleteMultipleMessage(context.Context, *DeleteMultipleMessageRequest) (*Response, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method DeleteMultipleMessage not implemented")
 }
-func (*UnimplementedMessageServer) GetUnreadCount(context.Context, *DeleteMultipleMessageRequest) (*GetUnreadCountResponse, error) {
+func (*UnimplementedMessageServer) GetUnreadCount(context.Context, *GetUnreadCountRequest) (*GetUnreadCountResponse, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method GetUnreadCount not implemented")
 }
 
@@ -915,7 +915,7 @@ func _Message_DeleteMultipleMessage_Handler(srv interface{}, ctx context.Context
 }
 
 func _Message_GetUnreadCount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-	in := new(DeleteMultipleMessageRequest)
+	in := new(GetUnreadCountRequest)
 	if err := dec(in); err != nil {
 		return nil, err
 	}
@@ -927,7 +927,7 @@ func _Message_GetUnreadCount_Handler(srv interface{}, ctx context.Context, dec f
 		FullMethod: "/message.Message/GetUnreadCount",
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
-		return srv.(MessageServer).GetUnreadCount(ctx, req.(*DeleteMultipleMessageRequest))
+		return srv.(MessageServer).GetUnreadCount(ctx, req.(*GetUnreadCountRequest))
 	}
 	return interceptor(ctx, in, info, handler)
 }

+ 2 - 2
rpc/messageclient/message.go

@@ -32,7 +32,7 @@ type (
 		//  删除多条消息
 		DeleteMultipleMessage(ctx context.Context, in *DeleteMultipleMessageRequest) (*Response, error)
 		//   查询指定用户未读消息合计
-		GetUnreadCount(ctx context.Context, in *DeleteMultipleMessageRequest) (*GetUnreadCountResponse, error)
+		GetUnreadCount(ctx context.Context, in *GetUnreadCountRequest) (*GetUnreadCountResponse, error)
 	}
 
 	defaultMessage struct {
@@ -71,7 +71,7 @@ func (m *defaultMessage) DeleteMultipleMessage(ctx context.Context, in *DeleteMu
 }
 
 //   查询指定用户未读消息合计
-func (m *defaultMessage) GetUnreadCount(ctx context.Context, in *DeleteMultipleMessageRequest) (*GetUnreadCountResponse, error) {
+func (m *defaultMessage) GetUnreadCount(ctx context.Context, in *GetUnreadCountRequest) (*GetUnreadCountResponse, error) {
 	client := message.NewMessageClient(m.cli.Conn())
 	return client.GetUnreadCount(ctx, in)
 }

+ 40 - 1
rpc/test/message_test.go

@@ -14,7 +14,7 @@ func  Test_ChangeReadStatus(t *testing.T)  {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}}))
 	//std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}}))
-	req := &messageclient.ChangeReadStatusRequest{Id: 1,ReadStatus: 1}
+	req := &messageclient.ChangeReadStatusRequest{Id: 1,ReadStatus: 1,Appid: "10000"}
 	res, err := std.ChangeReadStatus(ctx, req)
 	log.Println("err ", err,res)
 	//if res.State == true {
@@ -23,3 +23,42 @@ func  Test_ChangeReadStatus(t *testing.T)  {
 	//	log.Println("req false", res)
 	//}
 }
+func  Test_DeleteSingleMessage(t *testing.T)  {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}}))
+	//std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}}))
+	req := &messageclient.DeleteSingleMessageRequest{Id: 3,Appid: "10000"}
+	res, err := std.DeleteSingleMessage(ctx, req)
+	log.Println("err ", err,res)
+	//if res.State == true {
+	//	log.Println("req true")
+	//} else {
+	//	log.Println("req false", res)
+	//}
+}
+func  Test_DeleteMultipleMessage(t *testing.T)  {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}}))
+	//std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}}))
+	req := &messageclient.DeleteMultipleMessageRequest{Id: "4,5",Appid: "10000"}
+	res, err := std.DeleteMultipleMessage(ctx, req)
+	log.Println("err ", err,res)
+	//if res.State == true {
+	//	log.Println("req true")
+	//} else {
+	//	log.Println("req false", res)
+	//}
+}
+func  Test_CountUnreadMessage(t *testing.T)  {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := messageclient.NewMessage(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "message.rpc"}}))
+	//std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}}))
+	req := &messageclient.GetUnreadCountRequest{UserId: "6042120adca8410f1ef2ec84",Appid: "10000"}
+	res, err := std.GetUnreadCount(ctx, req)
+	log.Println("err ", err,res)
+	//if res.State == true {
+	//	log.Println("req true")
+	//} else {
+	//	log.Println("req false", res)
+	//}
+}

+ 2 - 2
service/messageService.go

@@ -57,12 +57,12 @@ func (service *MessageService) CountUnread(userId string,appId string) (int64, s
 	log.Println("123")
 	defer orm.Close()
 	m := entity.Message{}
-	m.Isdel=-1
 	count, err := orm.Where("receive_userid=? and isdel=1 and appid=?",userId,appId).Count(m)
-	if err != nil ||count==0{
+	if err != nil{
 		log.Println(err)
 		log.Println(count)
 		return 0, "查询未读消息失败",0
 	}
+	log.Println(count)
 	return 1, "查询未读消息成功",count
 }