소스 검색

协议增加

xuzhiheng 4 년 전
부모
커밋
6e0bfad23b

+ 30 - 0
rpc/stdlib/internal/logic/docstatisticslogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
+	stdlibService "app.yhyue.com/moapp/jydocs/services/stdlib"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DocStatisticsLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDocStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocStatisticsLogic {
+	return &DocStatisticsLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DocStatisticsLogic) DocStatistics(in *stdlib.DocStatisticsReq) (*stdlib.DocChangeResp, error) {
+	// todo: add your logic here and delete this line
+	stdlibService.DocStatistics(in.DocId, int(in.DocStatisticsType))
+	return &stdlib.DocChangeResp{State: true}, nil
+}

+ 5 - 0
rpc/stdlib/internal/server/stdlibserver.go

@@ -35,3 +35,8 @@ func (s *StdlibServer) DocOff(ctx context.Context, in *stdlib.DocChangeReq) (*st
 	l := logic.NewDocOffLogic(ctx, s.svcCtx)
 	return l.DocOff(in)
 }
+
+func (s *StdlibServer) DocStatistics(ctx context.Context, in *stdlib.DocStatisticsReq) (*stdlib.DocChangeResp, error) {
+	l := logic.NewDocStatisticsLogic(ctx, s.svcCtx)
+	return l.DocStatistics(in)
+}

+ 16 - 1
rpc/stdlib/stdlib.proto

@@ -5,8 +5,14 @@ package stdlib;
 
 
 message DocQueryRequest {
-  string keyWords = 1; //检索词
+  string keyWords = 1; //检索词  文档名检索  模糊
+                       // 分类 []string
+                    	// 标签 []string
+						// 发布时间排序
+						// 下载次数排序
+						// 浏览量排序
   int32 pageNum = 2; //页码
+  int32 pageSize = 3; //每页数量
 }
 
 message DocQueryResponse {
@@ -26,6 +32,7 @@ message Doc {
   int32 pageSize = 5;//文档页码数
   string tags = 6;//文档标签
   string userId = 7;//上传人id
+                         //摘要
 }
 
 message DocChangeReq {
@@ -37,8 +44,16 @@ message DocChangeResp {
   bool state = 1; //是否成功
 }
 
+message DocStatisticsReq {
+  string docId = 1; //文档id
+  int32 DocStatisticsType = 2; //文档统计类型 1增加下载次数 2增加浏览次数 3评分
+}
+
+
+
 service Stdlib {
   rpc DocQuery(DocQueryRequest) returns(DocQueryResponse); //文档检索
   rpc DocOn(DocChangeReq) returns(DocChangeResp); //文档上架
   rpc DocOff(DocChangeReq) returns(DocChangeResp); //文档下架
+  rpc DocStatistics(DocStatisticsReq) returns(DocChangeResp); //文档浏览次数下载次数处理
 }

+ 138 - 22
rpc/stdlib/stdlib/stdlib.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.25.0
-// 	protoc        v3.15.1
+// 	protoc-gen-go v1.23.0
+// 	protoc        v3.11.4
 // source: stdlib.proto
 
 package stdlib
@@ -352,6 +352,61 @@ func (x *DocChangeResp) GetState() bool {
 	return false
 }
 
+type DocStatisticsReq struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	DocId             string `protobuf:"bytes,1,opt,name=docId,proto3" json:"docId,omitempty"`                          //文档id
+	DocStatisticsType int32  `protobuf:"varint,2,opt,name=DocStatisticsType,proto3" json:"DocStatisticsType,omitempty"` //文档统计类型 1增加下载次数 2增加浏览次数 3评分
+}
+
+func (x *DocStatisticsReq) Reset() {
+	*x = DocStatisticsReq{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_stdlib_proto_msgTypes[5]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *DocStatisticsReq) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*DocStatisticsReq) ProtoMessage() {}
+
+func (x *DocStatisticsReq) ProtoReflect() protoreflect.Message {
+	mi := &file_stdlib_proto_msgTypes[5]
+	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 DocStatisticsReq.ProtoReflect.Descriptor instead.
+func (*DocStatisticsReq) Descriptor() ([]byte, []int) {
+	return file_stdlib_proto_rawDescGZIP(), []int{5}
+}
+
+func (x *DocStatisticsReq) GetDocId() string {
+	if x != nil {
+		return x.DocId
+	}
+	return ""
+}
+
+func (x *DocStatisticsReq) GetDocStatisticsType() int32 {
+	if x != nil {
+		return x.DocStatisticsType
+	}
+	return 0
+}
+
 var File_stdlib_proto protoreflect.FileDescriptor
 
 var file_stdlib_proto_rawDesc = []byte{
@@ -384,19 +439,29 @@ var file_stdlib_proto_rawDesc = []byte{
 	0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x65,
 	0x61, 0x73, 0x6f, 0x6e, 0x22, 0x25, 0x0a, 0x0d, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67,
 	0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01,
-	0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x32, 0xb4, 0x01, 0x0a, 0x06,
-	0x53, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x12, 0x3d, 0x0a, 0x08, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65,
-	0x72, 0x79, 0x12, 0x17, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51,
-	0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x74,
-	0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73,
-	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a, 0x05, 0x44, 0x6f, 0x63, 0x4f, 0x6e, 0x12, 0x14,
-	0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67,
-	0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f,
-	0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x35, 0x0a, 0x06, 0x44,
-	0x6f, 0x63, 0x4f, 0x66, 0x66, 0x12, 0x14, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44,
-	0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74,
-	0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65,
-	0x73, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x56, 0x0a, 0x10, 0x44,
+	0x6f, 0x63, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 0x12,
+	0x14, 0x0a, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
+	0x64, 0x6f, 0x63, 0x49, 0x64, 0x12, 0x2c, 0x0a, 0x11, 0x44, 0x6f, 0x63, 0x53, 0x74, 0x61, 0x74,
+	0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
+	0x52, 0x11, 0x44, 0x6f, 0x63, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x54,
+	0x79, 0x70, 0x65, 0x32, 0xf6, 0x01, 0x0a, 0x06, 0x53, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x12, 0x3d,
+	0x0a, 0x08, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x17, 0x2e, 0x73, 0x74, 0x64,
+	0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
+	0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63,
+	0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a,
+	0x05, 0x44, 0x6f, 0x63, 0x4f, 0x6e, 0x12, 0x14, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e,
+	0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73,
+	0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52,
+	0x65, 0x73, 0x70, 0x12, 0x35, 0x0a, 0x06, 0x44, 0x6f, 0x63, 0x4f, 0x66, 0x66, 0x12, 0x14, 0x2e,
+	0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65,
+	0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63,
+	0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x40, 0x0a, 0x0d, 0x44, 0x6f,
+	0x63, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x12, 0x18, 0x2e, 0x73, 0x74,
+	0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69,
+	0x63, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44,
+	0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x62, 0x06, 0x70, 0x72,
+	0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -411,24 +476,27 @@ func file_stdlib_proto_rawDescGZIP() []byte {
 	return file_stdlib_proto_rawDescData
 }
 
-var file_stdlib_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
+var file_stdlib_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
 var file_stdlib_proto_goTypes = []interface{}{
 	(*DocQueryRequest)(nil),  // 0: stdlib.DocQueryRequest
 	(*DocQueryResponse)(nil), // 1: stdlib.DocQueryResponse
 	(*Doc)(nil),              // 2: stdlib.Doc
 	(*DocChangeReq)(nil),     // 3: stdlib.DocChangeReq
 	(*DocChangeResp)(nil),    // 4: stdlib.DocChangeResp
+	(*DocStatisticsReq)(nil), // 5: stdlib.DocStatisticsReq
 }
 var file_stdlib_proto_depIdxs = []int32{
 	2, // 0: stdlib.DocQueryResponse.docs:type_name -> stdlib.Doc
 	0, // 1: stdlib.Stdlib.DocQuery:input_type -> stdlib.DocQueryRequest
 	3, // 2: stdlib.Stdlib.DocOn:input_type -> stdlib.DocChangeReq
 	3, // 3: stdlib.Stdlib.DocOff:input_type -> stdlib.DocChangeReq
-	1, // 4: stdlib.Stdlib.DocQuery:output_type -> stdlib.DocQueryResponse
-	4, // 5: stdlib.Stdlib.DocOn:output_type -> stdlib.DocChangeResp
-	4, // 6: stdlib.Stdlib.DocOff:output_type -> stdlib.DocChangeResp
-	4, // [4:7] is the sub-list for method output_type
-	1, // [1:4] is the sub-list for method input_type
+	5, // 4: stdlib.Stdlib.DocStatistics:input_type -> stdlib.DocStatisticsReq
+	1, // 5: stdlib.Stdlib.DocQuery:output_type -> stdlib.DocQueryResponse
+	4, // 6: stdlib.Stdlib.DocOn:output_type -> stdlib.DocChangeResp
+	4, // 7: stdlib.Stdlib.DocOff:output_type -> stdlib.DocChangeResp
+	4, // 8: stdlib.Stdlib.DocStatistics:output_type -> stdlib.DocChangeResp
+	5, // [5:9] is the sub-list for method output_type
+	1, // [1:5] is the sub-list for method input_type
 	1, // [1:1] is the sub-list for extension type_name
 	1, // [1:1] is the sub-list for extension extendee
 	0, // [0:1] is the sub-list for field type_name
@@ -500,6 +568,18 @@ func file_stdlib_proto_init() {
 				return nil
 			}
 		}
+		file_stdlib_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*DocStatisticsReq); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
 	}
 	type x struct{}
 	out := protoimpl.TypeBuilder{
@@ -507,7 +587,7 @@ func file_stdlib_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_stdlib_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   5,
+			NumMessages:   6,
 			NumExtensions: 0,
 			NumServices:   1,
 		},
@@ -536,6 +616,7 @@ type StdlibClient interface {
 	DocQuery(ctx context.Context, in *DocQueryRequest, opts ...grpc.CallOption) (*DocQueryResponse, error)
 	DocOn(ctx context.Context, in *DocChangeReq, opts ...grpc.CallOption) (*DocChangeResp, error)
 	DocOff(ctx context.Context, in *DocChangeReq, opts ...grpc.CallOption) (*DocChangeResp, error)
+	DocStatistics(ctx context.Context, in *DocStatisticsReq, opts ...grpc.CallOption) (*DocChangeResp, error)
 }
 
 type stdlibClient struct {
@@ -573,11 +654,21 @@ func (c *stdlibClient) DocOff(ctx context.Context, in *DocChangeReq, opts ...grp
 	return out, nil
 }
 
+func (c *stdlibClient) DocStatistics(ctx context.Context, in *DocStatisticsReq, opts ...grpc.CallOption) (*DocChangeResp, error) {
+	out := new(DocChangeResp)
+	err := c.cc.Invoke(ctx, "/stdlib.Stdlib/DocStatistics", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // StdlibServer is the server API for Stdlib service.
 type StdlibServer interface {
 	DocQuery(context.Context, *DocQueryRequest) (*DocQueryResponse, error)
 	DocOn(context.Context, *DocChangeReq) (*DocChangeResp, error)
 	DocOff(context.Context, *DocChangeReq) (*DocChangeResp, error)
+	DocStatistics(context.Context, *DocStatisticsReq) (*DocChangeResp, error)
 }
 
 // UnimplementedStdlibServer can be embedded to have forward compatible implementations.
@@ -593,6 +684,9 @@ func (*UnimplementedStdlibServer) DocOn(context.Context, *DocChangeReq) (*DocCha
 func (*UnimplementedStdlibServer) DocOff(context.Context, *DocChangeReq) (*DocChangeResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method DocOff not implemented")
 }
+func (*UnimplementedStdlibServer) DocStatistics(context.Context, *DocStatisticsReq) (*DocChangeResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method DocStatistics not implemented")
+}
 
 func RegisterStdlibServer(s *grpc.Server, srv StdlibServer) {
 	s.RegisterService(&_Stdlib_serviceDesc, srv)
@@ -652,6 +746,24 @@ func _Stdlib_DocOff_Handler(srv interface{}, ctx context.Context, dec func(inter
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Stdlib_DocStatistics_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(DocStatisticsReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(StdlibServer).DocStatistics(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/stdlib.Stdlib/DocStatistics",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(StdlibServer).DocStatistics(ctx, req.(*DocStatisticsReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 var _Stdlib_serviceDesc = grpc.ServiceDesc{
 	ServiceName: "stdlib.Stdlib",
 	HandlerType: (*StdlibServer)(nil),
@@ -668,6 +780,10 @@ var _Stdlib_serviceDesc = grpc.ServiceDesc{
 			MethodName: "DocOff",
 			Handler:    _Stdlib_DocOff_Handler,
 		},
+		{
+			MethodName: "DocStatistics",
+			Handler:    _Stdlib_DocStatistics_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "stdlib.proto",

+ 7 - 0
rpc/stdlib/stdlibclient/stdlib.go

@@ -19,11 +19,13 @@ type (
 	Doc              = stdlib.Doc
 	DocChangeReq     = stdlib.DocChangeReq
 	DocChangeResp    = stdlib.DocChangeResp
+	DocStatisticsReq = stdlib.DocStatisticsReq
 
 	Stdlib interface {
 		DocQuery(ctx context.Context, in *DocQueryRequest) (*DocQueryResponse, error)
 		DocOn(ctx context.Context, in *DocChangeReq) (*DocChangeResp, error)
 		DocOff(ctx context.Context, in *DocChangeReq) (*DocChangeResp, error)
+		DocStatistics(ctx context.Context, in *DocStatisticsReq) (*DocChangeResp, error)
 	}
 
 	defaultStdlib struct {
@@ -51,3 +53,8 @@ func (m *defaultStdlib) DocOff(ctx context.Context, in *DocChangeReq) (*DocChang
 	client := stdlib.NewStdlibClient(m.cli.Conn())
 	return client.DocOff(ctx, in)
 }
+
+func (m *defaultStdlib) DocStatistics(ctx context.Context, in *DocStatisticsReq) (*DocChangeResp, error) {
+	client := stdlib.NewStdlibClient(m.cli.Conn())
+	return client.DocStatistics(ctx, in)
+}

+ 3 - 2
services/stdlib/docChangeService.go

@@ -1,10 +1,11 @@
 package stdlib
 
 import (
-	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
 	"errors"
-	"gorm.io/gorm"
 	"time"
+
+	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
+	"gorm.io/gorm"
 )
 
 const DocOn = 1

+ 9 - 0
services/stdlib/docStatistics.go

@@ -0,0 +1,9 @@
+package stdlib
+
+import (
+	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
+)
+
+func DocStatistics(docId string, dtype int) {
+	jyDocsRpcUtil.GetJyDocsDB()
+}

+ 2 - 1
services/util/baseInit.go

@@ -1,10 +1,11 @@
 package util
 
 import (
+	"log"
+
 	elastic "app.yhyue.com/moapp/jybase/esv7"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"gorm.io/gorm"
-	"log"
 )
 
 type MysqlDBConfig struct {