wangchuanjin 4 年之前
父节点
当前提交
3bd7640c2d

+ 1 - 1
rpc/stdlib/etc/stdlib.yaml

@@ -1,5 +1,5 @@
 Name: jydocs.stdlib.rpc
-ListenOn: 192.168.20.36:8080
+ListenOn: :8080
 JyDocsMysqlDB:
   DriverName: "mysql"
   DataSourceName: "root:Topnet123@tcp(192.168.3.11:3366)/jydocs?charset=utf8mb4&parseTime=true&loc=Local"

+ 3 - 0
rpc/stdlib/internal/logic/docquerylogic.go

@@ -6,6 +6,7 @@ import (
 	"app.yhyue.com/moapp/jy_docs/rpc/stdlib/internal/svc"
 	"app.yhyue.com/moapp/jy_docs/rpc/stdlib/stdlib"
 	stdlibService "app.yhyue.com/moapp/jy_docs/services/stdlib"
+	"app.yhyue.com/moapp/jy_docs/services/util"
 	"app.yhyue.com/moapp/jybase/common"
 	"github.com/tal-tech/go-zero/core/logx"
 )
@@ -39,8 +40,10 @@ func (l *DocQueryLogic) DocQuery(in *stdlib.DocQueryRequest) (*stdlib.DocQueryRe
 				DocPageSize: common.Int64All(v["docPageSize"]),
 				DocFileSize: common.Int64All(v["docFileSize"]),
 				DownTimes:   common.Int64All(v["downTimes"]),
+				ViewTimes:   common.Int64All(v["viewTimes"]),
 				UploadDate:  common.ObjToString(v["uploadDate"]),
 				DocSummary:  common.ObjToString(v["docSummary"]),
+				DocFileType: util.DocFileType[common.IntAll(v["docFileType"])],
 			})
 		}
 	}

+ 4 - 2
rpc/stdlib/stdlib.proto

@@ -28,8 +28,10 @@ message Doc {
   int64 docFileSize = 4;//文档大小
   int64 docPageSize = 5;//文档页码数
   int64 downTimes = 6;//下载次数
-  string uploadDate = 7;//上传时间
-  string docSummary = 8; //摘要
+  int64 viewTimes = 7;//浏览次数
+  string uploadDate = 8;//上传时间
+  string docSummary = 9; //摘要
+  string docFileType = 10;//文档类型
 }
 
 message DocChangeReq {

+ 27 - 7
rpc/stdlib/stdlib/stdlib.pb.go

@@ -222,8 +222,10 @@ type Doc struct {
 	DocFileSize int64  `protobuf:"varint,4,opt,name=docFileSize,proto3" json:"docFileSize,omitempty"` //文档大小
 	DocPageSize int64  `protobuf:"varint,5,opt,name=docPageSize,proto3" json:"docPageSize,omitempty"` //文档页码数
 	DownTimes   int64  `protobuf:"varint,6,opt,name=downTimes,proto3" json:"downTimes,omitempty"`     //下载次数
-	UploadDate  string `protobuf:"bytes,7,opt,name=uploadDate,proto3" json:"uploadDate,omitempty"`    //上传时间
-	DocSummary  string `protobuf:"bytes,8,opt,name=docSummary,proto3" json:"docSummary,omitempty"`    //摘要
+	ViewTimes   int64  `protobuf:"varint,7,opt,name=viewTimes,proto3" json:"viewTimes,omitempty"`     //浏览次数
+	UploadDate  string `protobuf:"bytes,8,opt,name=uploadDate,proto3" json:"uploadDate,omitempty"`    //上传时间
+	DocSummary  string `protobuf:"bytes,9,opt,name=docSummary,proto3" json:"docSummary,omitempty"`    //摘要
+	DocFileType string `protobuf:"bytes,10,opt,name=docFileType,proto3" json:"docFileType,omitempty"` //文档类型
 }
 
 func (x *Doc) Reset() {
@@ -300,6 +302,13 @@ func (x *Doc) GetDownTimes() int64 {
 	return 0
 }
 
+func (x *Doc) GetViewTimes() int64 {
+	if x != nil {
+		return x.ViewTimes
+	}
+	return 0
+}
+
 func (x *Doc) GetUploadDate() string {
 	if x != nil {
 		return x.UploadDate
@@ -314,6 +323,13 @@ func (x *Doc) GetDocSummary() string {
 	return ""
 }
 
+func (x *Doc) GetDocFileType() string {
+	if x != nil {
+		return x.DocFileType
+	}
+	return ""
+}
+
 type DocChangeReq struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -950,7 +966,7 @@ var file_stdlib_proto_rawDesc = []byte{
 	0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e,
 	0x44, 0x6f, 0x63, 0x52, 0x04, 0x64, 0x6f, 0x63, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74,
 	0x61, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x22,
-	0xed, 0x01, 0x0a, 0x03, 0x44, 0x6f, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64,
+	0xad, 0x02, 0x0a, 0x03, 0x44, 0x6f, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64,
 	0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x12, 0x18, 0x0a,
 	0x07, 0x64, 0x6f, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
 	0x64, 0x6f, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65,
@@ -961,10 +977,14 @@ var file_stdlib_proto_rawDesc = []byte{
 	0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x64, 0x6f, 0x63, 0x50, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a,
 	0x65, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x6f, 0x77, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x06,
 	0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x64, 0x6f, 0x77, 0x6e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x12,
-	0x1e, 0x0a, 0x0a, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x61, 0x74, 0x65, 0x18, 0x07, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x0a, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12,
-	0x1e, 0x0a, 0x0a, 0x64, 0x6f, 0x63, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x08, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x6f, 0x63, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x22,
+	0x1c, 0x0a, 0x09, 0x76, 0x69, 0x65, 0x77, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x07, 0x20, 0x01,
+	0x28, 0x03, 0x52, 0x09, 0x76, 0x69, 0x65, 0x77, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x12, 0x1e, 0x0a,
+	0x0a, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x61, 0x74, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28,
+	0x09, 0x52, 0x0a, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x44, 0x61, 0x74, 0x65, 0x12, 0x1e, 0x0a,
+	0x0a, 0x64, 0x6f, 0x63, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28,
+	0x09, 0x52, 0x0a, 0x64, 0x6f, 0x63, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x20, 0x0a,
+	0x0b, 0x64, 0x6f, 0x63, 0x46, 0x69, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0a, 0x20, 0x01,
+	0x28, 0x09, 0x52, 0x0b, 0x64, 0x6f, 0x63, 0x46, 0x69, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22,
 	0x36, 0x0a, 0x0c, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12,
 	0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
 	0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,

+ 8 - 8
rpc/stdlib/stdlibclient/stdlib.go

@@ -14,18 +14,18 @@ import (
 )
 
 type (
-	DocGetContentResp = stdlib.DocGetContentResp
-	DocActivityResp   = stdlib.DocActivityResp
-	DocQueryRequest   = stdlib.DocQueryRequest
-	DocQueryResponse  = stdlib.DocQueryResponse
 	DocChangeReq      = stdlib.DocChangeReq
-	DocStatisticsReq  = stdlib.DocStatisticsReq
-	DocGetCheckReq    = stdlib.DocGetCheckReq
-	DocGetCheckResp   = stdlib.DocGetCheckResp
-	Doc               = stdlib.Doc
 	DocChangeResp     = stdlib.DocChangeResp
 	DocActivityReq    = stdlib.DocActivityReq
 	DocActivity       = stdlib.DocActivity
+	DocQueryResponse  = stdlib.DocQueryResponse
+	Doc               = stdlib.Doc
+	DocStatisticsReq  = stdlib.DocStatisticsReq
+	DocGetCheckReq    = stdlib.DocGetCheckReq
+	DocGetCheckResp   = stdlib.DocGetCheckResp
+	DocGetContentResp = stdlib.DocGetContentResp
+	DocActivityResp   = stdlib.DocActivityResp
+	DocQueryRequest   = stdlib.DocQueryRequest
 
 	Stdlib interface {
 		DocQuery(ctx context.Context, in *DocQueryRequest) (*DocQueryResponse, error)

+ 2 - 1
rpc/stdlib/test/docquery_test.go

@@ -15,10 +15,11 @@ import (
 func Test_Docquery(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
 	std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"127.0.0.1:2379"}, Key: "jydocs.stdlib.rpc"}}))
-	res, err := std.DocQuery(ctx, &stdlib.DocQueryRequest{KeyWord: "委托书"})
+	res, err := std.DocQuery(ctx, &stdlib.DocQueryRequest{KeyWord: "软件", PageSize: 3})
 	if err != nil {
 		log.Println(err)
 	} else {
+		log.Println(res.Total, len(res.Docs))
 		log.Println(res)
 	}
 }

+ 3 - 3
services/stdlib/docService.go

@@ -14,7 +14,7 @@ import (
 const (
 	Es_Query_Boosting  = `{"query":{"boosting":{"positive":{"bool":{"must":[%s]}},"negative":{"bool":{"must":[%s]}},"negative_boost":2}}%s}`
 	Es_Query_Bool      = `{"query":{"bool":{"filter":[%s]}}%s}`
-	Es_Query_Append    = `,"_source":["title","publishtime"],"sort":{%s},"from":%d,"size":%d,"highlight":{"fields":{"docName":{},"docSummary":{}}}`
+	Es_Query_Append    = `,"_source":["_id","docName","price","downTimes","viewTimes","docSummary","uploadDate","docFileSize","docPageSize","docFileType"],"sort":{%s},"from":%d,"size":%d,"highlight":{"fields":{"docName":{},"docSummary":{}}}`
 	Multi_Match        = `{"multi_match":{"query":"%s","fields":["docName","docSummary"]}}`
 	Multi_Match_Phrase = `{"multi_match":{"query":"%s","fields":["docName.docName_c","docSummary.docSummary_c"],"type":"phrase"}}`
 	Terms              = `{"trems":{"%s":[%s]}}`
@@ -73,9 +73,9 @@ func FindDocumentsByKeyWords(keyWord string, docClass, docTag []string, publishT
 	}
 	query := ""
 	if keyWord != "" {
-		fmt.Sprintf(Es_Query_Boosting, strings.Join(musts, ","), strings.Join(negative_musts, ","), fmt.Sprintf(Es_Query_Append, strings.Join(sorts, ","), (pageNum-1)*pageSize, pageSize))
+		query = fmt.Sprintf(Es_Query_Boosting, strings.Join(musts, ","), strings.Join(negative_musts, ","), fmt.Sprintf(Es_Query_Append, strings.Join(sorts, ","), (pageNum-1)*pageSize, pageSize))
 	} else {
-		fmt.Sprintf(Es_Query_Bool, strings.Join(musts, ","), fmt.Sprintf(Es_Query_Append, strings.Join(sorts, ","), (pageNum-1)*pageSize, pageSize))
+		query = fmt.Sprintf(Es_Query_Bool, strings.Join(musts, ","), fmt.Sprintf(Es_Query_Append, strings.Join(sorts, ","), (pageNum-1)*pageSize, pageSize))
 	}
 	log.Println("query:", query)
 	return elastic.DfsGet(jyDocsRpcUtil.Es_JyDoc, "", query)