123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package service
- import (
- "app.yhyue.com/moapp/jy_docs/rpc/partnerlib/entity"
- "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"
- "crypto/md5"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "strings"
- "time"
- )
- func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTotal int) {
- var docinInfos model.DocinInfoRes
- err = json.Unmarshal(b, &docinInfos)
- if err == nil {
- if expectTotal = len(docinInfos.Data); expectTotal > 0 {
- //剑鱼doc 一份 || 豆丁备份表一份
- var (
- docs []sm.Doc
- docsStatistics []sm.DocStatistics
- )
- for _, v := range docinInfos.Data {
- var (
- id = fmt.Sprintf("docin-%d", v.ProductId)
- md5Id = GetMD5(id, v.ProductName, v.Desc, v.FilePostfix) //判断数据是否已存在 md5
- price = v.Price //价格转换
- docTags, docClass = partner.SwitchDocClass(v.PcatName, v.CatName, 1) //标签和分类
- )
- if partner.CheckDocs(id, md5Id) {
- continue
- }
- lastId = v.ProductId
- docsStatistics = append(docsStatistics, sm.DocStatistics{
- AppId: entity.AppId,
- DocId: id,
- UpdateDate: time.Now(),
- DownTimes: v.DownloadCount,
- ViewTimes: v.VisitCount,
- })
- docs = append(docs, sm.Doc{
- Id: id,
- UserId: "docin",
- AppId: entity.AppId,
- DocName: v.ProductName,
- DocFileType: GetDocFileType(v.FilePostfix),
- DocFileSuffix: v.FilePostfix,
- DocFileSize: int(v.FileSize),
- DocPageSize: v.PageCount,
- DocTags: strings.Join(docTags, ","),
- DocClass: docClass,
- UploadDate: time.Now(),
- IsDelete: 0,
- OssDocId: "",
- OssDocUrl: "",
- Md5: md5Id, //
- OssPdfId: "",
- OssPdfUrl: "",
- OssTxtId: "",
- OssTxtUrl: "",
- Price: price,
- DownOrUp: 0,
- DocSummary: v.Desc,
- PreviewImgId: "",
- PreviewImgUrl: "",
- EncryptionLevel: 0,
- Source: 1,
- ProductType: v.Ifcharge,
- UpdateDate: time.Now(),
- })
- }
- if len(docs) > 0 {
- actualTotal = len(docs)
- //doc 文库文档数据信息
- partner.DocsInsert(docs, entity.InBatchesCount)
- //docsStatistics 文库文档浏览量及下载量信息
- partner.DocsStatistics(docsStatistics, entity.InBatchesCount)
- }
- }
- }
- return
- }
- func GetMD5(id, productName, desc, FilePostfix string) string {
- hash := md5.Sum([]byte(fmt.Sprintf("%s#%s#%#s#%s", id, productName, desc, FilePostfix)))
- return hex.EncodeToString(hash[:])
- }
- func GetDocFileType(fileSuffix string) (i int) {
- //1 doc 2 pdf 3 xls 4 ppt 5 txt 6 其他
- switch strings.ToLower(fileSuffix) {
- case "doc":
- i = 1
- case "pdf":
- i = 2
- case "xls", "xlsx":
- i = 3
- case "ppt":
- i = 4
- case "txt":
- i = 5
- default:
- i = 6
- }
- return
- }
|