|
@@ -301,7 +301,46 @@ func GetDocsData() (docClass []string, indexDocs [][]map[string]interface{}) {
|
|
|
//浏览量前十的一级分类
|
|
|
docClassNames := config.Sysconfig["indexDocClass"].([]interface{})
|
|
|
if docClassNames != nil && len(docClassNames) > 0 {
|
|
|
- docSql := `SELECT d.id,d.docName,d.docFileSuffix,d.docTags,d.previewImgId,d.productType,d.source FROM jydocs.doc d LEFT JOIN jydocs.doc_statistics ds ON d.id=ds.docId WHERE FIND_IN_SET(?,d.docTags) ORDER BY ds.viewTimes DESC LIMIT 10 `
|
|
|
+ indexDoc := []map[string]interface{}{}
|
|
|
+ //docSql := `SELECT d.id,d.docName,d.docFileSuffix,d.docTags,d.previewImgId,d.productType,d.source FROM jydocs.doc d LEFT JOIN jydocs.doc_statistics ds ON d.id=ds.docId WHERE FIND_IN_SET(?,d.docTags) ORDER BY ds.viewTimes DESC LIMIT 10 `
|
|
|
+ var docFormatFunc = func(docs *[]map[string]interface{}) {
|
|
|
+ for dock, docv := range *docs {
|
|
|
+ if dock > 7 {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ previewImg := fmt.Sprintf(ossUrl, common.InterfaceToStr(docv["previewImgId"]))
|
|
|
+ if common.IntAll(docv["source"]) == 2 {
|
|
|
+ previewImg = fmt.Sprintf(docinUrl, common.InterfaceToStr(docv["previewImgId"]))
|
|
|
+ }
|
|
|
+ fileSuffix := common.InterfaceToStr(docv["docFileSuffix"])
|
|
|
+ //文件类型,1 doc 2 pdf 3 xls 4 ppt 5 txt 6 其他
|
|
|
+ docFileType := common.IntAll(docv["docFileType"])
|
|
|
+ switch docFileType {
|
|
|
+ case 1:
|
|
|
+ fileSuffix = "doc"
|
|
|
+ case 2:
|
|
|
+ fileSuffix = "pdf"
|
|
|
+ case 3:
|
|
|
+ fileSuffix = "xls"
|
|
|
+ case 4:
|
|
|
+ fileSuffix = "ppt"
|
|
|
+ case 5:
|
|
|
+ fileSuffix = "txt"
|
|
|
+ default:
|
|
|
+ fileSuffix = "其他"
|
|
|
+ }
|
|
|
+ //if strings.HasPrefix(fileSuffix, ".") {
|
|
|
+ // fileSuffix = strings.ReplaceAll(fileSuffix, ".", "")
|
|
|
+ //}
|
|
|
+ indexDoc = append(indexDoc, map[string]interface{}{
|
|
|
+ "id": common.InterfaceToStr(docv["id"]),
|
|
|
+ "docName": common.InterfaceToStr(docv["docName"]),
|
|
|
+ "docFileSuffix": fileSuffix,
|
|
|
+ "previewImg": previewImg,
|
|
|
+ "productType": common.IntAll(docv["productType"]),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
for _, dv := range docClassNames {
|
|
|
tmpClass := common.ObjToMap(dv)
|
|
|
if tmpClass == nil {
|
|
@@ -309,33 +348,34 @@ func GetDocsData() (docClass []string, indexDocs [][]map[string]interface{}) {
|
|
|
}
|
|
|
name := common.InterfaceToStr((*tmpClass)["class"])
|
|
|
search := common.InterfaceToStr((*tmpClass)["search"])
|
|
|
- indexDoc := []map[string]interface{}{}
|
|
|
- docs := public.BaseMysql.SelectBySql(docSql, search)
|
|
|
- if docs != nil && len(*docs) > 0 {
|
|
|
- for dock, docv := range *docs {
|
|
|
- if dock > 7 {
|
|
|
- break
|
|
|
- }
|
|
|
- previewImg := fmt.Sprintf(ossUrl, common.InterfaceToStr(docv["previewImgId"]))
|
|
|
- if common.IntAll(docv["source"]) == 2 {
|
|
|
- previewImg = fmt.Sprintf(docinUrl, common.InterfaceToStr(docv["previewImgId"]))
|
|
|
- }
|
|
|
- fileSuffix := common.InterfaceToStr(docv["docFileSuffix"])
|
|
|
- if strings.HasPrefix(fileSuffix, ".") {
|
|
|
- fileSuffix = strings.ReplaceAll(fileSuffix, ".", "")
|
|
|
- }
|
|
|
- indexDoc = append(indexDoc, map[string]interface{}{
|
|
|
- "id": common.InterfaceToStr(docv["id"]),
|
|
|
- "docName": common.InterfaceToStr(docv["docName"]),
|
|
|
- "docFileSuffix": fileSuffix,
|
|
|
- "previewImg": previewImg,
|
|
|
- "productType": common.IntAll(docv["productType"]),
|
|
|
- })
|
|
|
+ code := common.InterfaceToStr((*tmpClass)["code"])
|
|
|
+ //2.0 推荐表数据
|
|
|
+ var docByTidb = func() {
|
|
|
+ docSql := fmt.Sprintf(`SELECT d.id, d.docName, d.docFileType, d.docFileSuffix, d.previewImgId, d.productType, d.source FROM doc d LEFT JOIN doc_recommend dr ON d.id = dr.doc_id WHERE dr.region_state = 1 AND dr.doc_class_code = '%s' ORDER BY dr.create_date DESC;`, code)
|
|
|
+ docs := public.BaseMysql.SelectBySql(docSql)
|
|
|
+ if docs != nil && len(*docs) > 0 {
|
|
|
+ docFormatFunc(docs)
|
|
|
}
|
|
|
}
|
|
|
- docClass = append(docClass, name)
|
|
|
- indexDocs = append(indexDocs, indexDoc)
|
|
|
-
|
|
|
+ docByTidb()
|
|
|
+ //1.0 查es
|
|
|
+ var docByEs = func() {
|
|
|
+ query := fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"docTags":"%s"}}]}},"size":10,"sort":[{"viewTimes":"desc"}]}`, search)
|
|
|
+ docs := public.Doc.Get("jydoc", "jydoc", query)
|
|
|
+ //docs := public.BaseMysql.SelectBySql(docSql, search)
|
|
|
+ if docs != nil && len(*docs) > 0 {
|
|
|
+ docFormatFunc(docs)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(indexDoc) == 0 {
|
|
|
+ docByEs()
|
|
|
+ }
|
|
|
+ if len(indexDoc) > 0 {
|
|
|
+ docClass = append(docClass, name)
|
|
|
+ indexDocs = append(indexDocs, indexDoc)
|
|
|
+ //
|
|
|
+ indexDoc = []map[string]interface{}{}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if len(indexDocs) > 0 {
|
|
@@ -352,7 +392,6 @@ func GetDocsData() (docClass []string, indexDocs [][]map[string]interface{}) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- fmt.Println(indexDocs)
|
|
|
return
|
|
|
}
|
|
|
|