Browse Source

wip:同步索引库文档信息

wangshan 1 year ago
parent
commit
6c8d515d4d

+ 28 - 3
rpc/partnerlib/crontab/service/docinInfo.go

@@ -5,6 +5,7 @@ import (
 	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/model"
 	sm "app.yhyue.com/moapp/jy_docs/services/model"
 	"app.yhyue.com/moapp/jy_docs/services/partner"
+	"app.yhyue.com/moapp/jybase/date"
 	"crypto/md5"
 	"encoding/hex"
 	"encoding/json"
@@ -22,6 +23,7 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 			var (
 				docs           []sm.Doc
 				docsStatistics []sm.DocStatistics
+				docsES         []map[string]interface{}
 			)
 			for _, v := range docinInfos.Data {
 				var (
@@ -29,11 +31,13 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 					md5Id             = GetMD5(id, v.ProductName, v.Desc, v.FilePostfix) //判断数据是否已存在 md5
 					price             = v.Price                                          //价格转换
 					docTags, docClass = partner.SwitchDocClass(v.PcatName, v.CatName, 1) //标签和分类
+					fileType          = GetDocFileType(v.FilePostfix)
 				)
 				if partner.CheckDocs(id, md5Id) {
 					continue
 				}
 				lastId = v.ProductId
+				//tidb 分类
 				docsStatistics = append(docsStatistics, sm.DocStatistics{
 					AppId:      entity.AppId,
 					DocId:      id,
@@ -41,12 +45,13 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 					DownTimes:  v.DownloadCount,
 					ViewTimes:  v.VisitCount,
 				})
+				//tidb 文档
 				docs = append(docs, sm.Doc{
 					Id:              id,
 					UserId:          "docin",
 					AppId:           entity.AppId,
 					DocName:         v.ProductName,
-					DocFileType:     GetDocFileType(v.FilePostfix),
+					DocFileType:     fileType,
 					DocFileSuffix:   v.FilePostfix,
 					DocFileSize:     int(v.FileSize),
 					DocPageSize:     v.PageCount,
@@ -67,10 +72,28 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 					PreviewImgId:    "",
 					PreviewImgUrl:   "",
 					EncryptionLevel: 0,
-					Source:          1,
-					ProductType:     v.Ifcharge,
+					Source:          2,              //豆丁
+					ProductType:     v.Ifcharge + 1, //Ifcharge:是否付费,0:免费,1:收费;ProductType:商品类型:默认:0:全部;1:会员免费;2:精品(付费)
 					UpdateDate:      time.Now(),
 				})
+				//elastic
+				docsES = append(docsES, map[string]interface{}{
+					"id":           id,
+					"docClass":     docClass,
+					"docFileSize":  int(v.FileSize),
+					"docFileType":  fileType,
+					"docName":      v.ProductName,
+					"docPageSize":  v.PageCount,
+					"docSummary":   v.Desc,
+					"docTags":      strings.Join(docTags, ","),
+					"downTimes":    v.DownloadCount,
+					"previewImgId": v.ProductId,
+					"price":        v.Price,
+					"uploadDate":   date.NowFormat(date.Date_Full_Layout),
+					"viewTimes":    v.VisitCount,
+					"source":       2, //豆丁
+					"productType":  v.Ifcharge + 1,
+				})
 			}
 			if len(docs) > 0 {
 				actualTotal = len(docs)
@@ -78,6 +101,8 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 				partner.DocsInsert(docs, entity.InBatchesCount)
 				//docsStatistics 文库文档浏览量及下载量信息
 				partner.DocsStatistics(docsStatistics, entity.InBatchesCount)
+				//es sync data
+				partner.SyncDocsToES(docsES)
 			}
 		}
 	}

+ 1 - 0
rpc/partnerlib/entity/entity.go

@@ -5,6 +5,7 @@ const (
 	RedisCode      = "newother"
 	AppId          = "10000"
 	InBatchesCount = 20
+	ElasticJYDoc   = "jydoc"
 )
 
 var (

+ 9 - 1
services/partner/elastic.go

@@ -1,6 +1,14 @@
 package partner
 
+import (
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/entity"
+	"app.yhyue.com/moapp/jybase/es"
+)
+
 // 同步豆丁文档到es
-func SyncDocsToES() (err error) {
+func SyncDocsToES(docs []map[string]interface{}) {
+	if len(docs) > 0 {
+		es.BulkSave(entity.ElasticJYDoc, entity.ElasticJYDoc, &docs, false)
+	}
 	return
 }