Browse Source

专家背景修改,手动归类修改,下载报告链接过滤

xingzai 3 years ago
parent
commit
9b3d64bc1f
5 changed files with 221 additions and 29 deletions
  1. 9 2
      controllers/report.go
  2. 14 0
      models/article.go
  3. 29 14
      models/report_mapping.go
  4. 157 12
      services/tactics.go
  5. 12 1
      services/task.go

+ 9 - 2
controllers/report.go

@@ -43,7 +43,8 @@ func (this *ReportController) TradeList() {
 		br.Msg = "请输入分类ID"
 		return
 	}
-	list, err := models.GetTradeAll(uid, ChartPermissionId)
+	fmt.Println(uid)
+	list, err := models.GetTradeAll(ChartPermissionId)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -51,7 +52,13 @@ func (this *ReportController) TradeList() {
 	}
 	for k, v := range list {
 		list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
-		if v.Readnum == 0 {
+		count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+			return
+		}
+		if count == 0 {
 			list[k].IsRed = true
 		}
 	}

+ 14 - 0
models/article.go

@@ -28,6 +28,7 @@ type CygxArticle struct {
 	IsSummary        int    `description:"是否是纪要库,1是,0否"`
 	IsReport         int    `description:"是否属于报告,1是,0否"`
 	ReportType       int    `description:"报告类型,1行业报告,2产业报告,0无"`
+	FileLink         string `description:"下载预览链接"`
 }
 
 //新增文章
@@ -75,6 +76,7 @@ type ArticleDetail struct {
 	ArticleIdMd5         string `description:"纪要id"`
 	IsClass              int    `description:"是否归类,1是,0否"`
 	CategoryId           int    `description:"分类ID"`
+	FileLink             string `description:"下载预览链接"`
 	SellerList           []*SellerRep
 }
 
@@ -317,3 +319,15 @@ func GetUserIsReadThisNewCategoryArticleCount(categoryId, uid int) (count int, e
 	err = o.Raw(sqlCount, categoryId, uid).QueryRow(&count)
 	return
 }
+
+type ArticleId struct {
+	ArticleId int `description:"文章id"`
+}
+
+//获取自定义分类的文章ID
+func GetCustomArticleId() (item []*ArticleId, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT article_id  FROM cygx_article WHERE is_custom = 1 `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 29 - 14
models/report_mapping.go

@@ -67,22 +67,26 @@ ORDER BY
 }
 
 //行业列表
-func GetTradeAll(uid, ChartPermissionId int) (items []*TradeReportMapping, err error) {
+func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
 	o := orm.NewOrm()
-	//sql := `SELECT * FROM cygx_report_mapping WHERE chart_permission_id = ? AND report_type = 1;`
 	sql := `SELECT
-	art.article_id,art.publish_date as update_time ,re.category_id,re.sub_category_name,( SELECT COUNT( 1 ) FROM  cygx_article_history_record AS rec WHERE rec.user_id = ? AND rec.article_id = art.article_id ) AS readnum
-	FROM
-		cygx_report_mapping  as re
-        INNER JOIN cygx_article  as art ON re.category_id = art.category_id
-	WHERE
-	re.chart_permission_id = ?
-	AND re.report_type = 1
-	AND art.is_class = 1
-	AND re.chart_permission_id != 21
-	ORDER BY art.publish_date DESC
-	LIMIT 0,1`
-	_, err = o.Raw(sql, uid, ChartPermissionId).QueryRows(&items)
+		MAX( art.publish_date ) AS update_time,
+		re.category_id,
+		re.sub_category_name,
+		re.match_type_name 
+		FROM
+		cygx_report_mapping AS re
+		INNER JOIN cygx_article AS art ON re.category_id = art.category_id 
+		WHERE
+		re.chart_permission_id =? 
+		AND re.report_type = 1 
+		AND art.is_class = 1 
+		AND re.category_id NOT IN (67)
+		GROUP BY
+		art.category_id 
+		ORDER BY
+		update_time DESC`
+	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
 	return
 }
 
@@ -106,3 +110,14 @@ func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
 	err = o.Raw(sql, categoryId).QueryRow(&item)
 	return
 }
+
+//判断该分类下最新的文章用户是否阅读
+func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) count
+			FROM cygx_article_history_record 
+			WHERE user_id = ? 
+			AND article_id = ( SELECT article_id FROM	cygx_article WHERE	category_id = ? 	AND is_class = 1 	AND is_report = 1 	AND is_filter = 0 ORDER BY publish_date DESC LIMIT 1)`
+	err = o.Raw(sql, uid, categoryId).QueryRow(&count)
+	return
+}

+ 157 - 12
services/tactics.go

@@ -291,22 +291,21 @@ func SyncTacticsListAddreport() (err error) {
 	}()
 	fmt.Println("同步数据")
 	//indexName := utils.IndexName
-	endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
-	list, err := models.GetTacticsList2(endDate)
-	//list, err := models.GetTacticsListAll2()
+	//endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
+	//list, err := models.GetTacticsList2(endDate)
+	list, err := models.GetTacticsListAll2()
+	if err != nil {
+		fmt.Println("GetTacticsList Err:", err.Error())
+		return
+	}
+	listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
 	if err != nil {
 		fmt.Println("GetTacticsList Err:", err.Error())
 		return
 	}
 	fmt.Println("list len:", len(list))
-
 	summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,95,96" //纪要库的文章类型categoty_id
 	listSummary := strings.Split(summaryCategoryIds, ",")
-	//listSummary, errsu := models.GetReportMappingCategoryID()
-	//if errsu != nil {
-	//	fmt.Println("GetTacticsList Err:", errsu.Error())
-	//	return
-	//}
 	noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
 	listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
 	listPermission, errper := models.GetPermissionMappingCategoryID()
@@ -345,7 +344,7 @@ func SyncTacticsListAddreport() (err error) {
 			}
 		}
 		v.Department = "弘则权益研究"
-		fmt.Println(k, v.ArticleId)
+		//fmt.Println(k, v.ArticleId)
 		hh, _ := time.ParseDuration("8h")
 		//pDate := publishDate.Add(hh)
 		v.PublishDate = v.PublishDate.Add(hh)
@@ -360,7 +359,15 @@ func SyncTacticsListAddreport() (err error) {
 			return err
 		}
 		v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
-		expertNumStr, expertContentStr, interviewDateStr := BodyAnalysis(v.Body)
+
+		expertNumStr, expertContentStr, interviewDateStr, fileLink := BodyAnalysis2(v.Body)
+
+		if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
+			v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
+			v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
+			v.Body = strings.Replace(v.Body, "):", "", -1)
+		}
+		//fmt.Println(fileLink)
 		var titleNew string
 		titleNew = v.Title
 		// 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
@@ -374,8 +381,11 @@ func SyncTacticsListAddreport() (err error) {
 		if v.CategoryId == 80 {
 			titleNew = v.Title + utils.WeekByDate(v.PublishDate)
 		}
+		//fmt.Println(k)
+		//fmt.Println(expertContentStr)
 		if count > 0 {
 			fmt.Println(k, v.ArticleId, "edit")
+			var isCustom bool
 			bodyText, _ := GetReportContentTextSub(v.Body)
 			updateParams := make(map[string]interface{})
 			//updateParams["Title"] = v.Title
@@ -389,7 +399,16 @@ func SyncTacticsListAddreport() (err error) {
 			updateParams["Abstract"] = html.EscapeString(v.Abstract)
 			updateParams["CategoryName"] = v.CategoryName
 			updateParams["SubCategoryName"] = v.SubCategoryName
-			updateParams["CategoryId"] = v.CategoryId
+			for _, vCustom := range listCustomArticle {
+				if v.ArticleId == vCustom.ArticleId {
+					fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
+					isCustom = true
+				}
+			}
+			if isCustom == false {
+				updateParams["CategoryId"] = v.CategoryId
+			}
+			//updateParams["CategoryId"] = v.CategoryId
 			updateParams["PublishStatus"] = v.PublishStatus
 			updateParams["ExpertBackground"] = expertContentStr
 			updateParams["ExpertNumber"] = expertNumStr
@@ -402,6 +421,7 @@ func SyncTacticsListAddreport() (err error) {
 				v.Department = "弘则权益研究"
 			}
 			updateParams["Department"] = v.Department
+			updateParams["FileLink"] = fileLink
 			whereParam := map[string]interface{}{"article_id": v.ArticleId}
 			err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
 			if err != nil {
@@ -433,6 +453,7 @@ func SyncTacticsListAddreport() (err error) {
 			item.IsSummary = v.IsSummary
 			item.IsReport = v.IsReport
 			item.ReportType = v.ReportType
+			item.FileLink = fileLink
 			_, err = models.AddCygxArticles(item)
 			if err != nil {
 				fmt.Println("AddCygxArticle Err:", err.Error())
@@ -511,3 +532,127 @@ func SyncTacticsListToEs() (err error) {
 	}
 	return
 }
+
+//body 解析
+func BodyAnalysis2(body string) (expertNumStr, expertContentStr, interviewDateStr, fileLink string) {
+	body = html.UnescapeString(body)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
+	if err != nil {
+		fmt.Println("create doc err:", err.Error())
+		return
+	}
+
+	var expertNumArr []string
+	var expertContentArr []string
+	var interviewDateArr []string
+	//var fileLink string
+
+	doc.Find("p").Each(func(i int, s *goquery.Selection) {
+		contentTxt := s.Text()
+		if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
+			interviewDate := s.Next().Text()
+			interviewDateArr = append(interviewDateArr, interviewDate)
+		}
+		if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
+			expertContent := s.Next().Text()
+			if expertContent == "" {
+				expertContent = contentTxt
+			}
+			if expertContent != "" {
+				rightIndex := strings.Index(expertContent, ")")
+				if rightIndex == 0 {
+					rightIndex = strings.Index(expertContent, ")")
+				}
+				if rightIndex > 0 {
+					expertNum := expertContent[:rightIndex]
+					expertNum = strings.Replace(expertNum, "(", "", -1)
+					expertNum = strings.Replace(expertNum, "(", "", -1)
+					expertNum = strings.Replace(expertNum, "专家评价", "", -1)
+					if expertNum != "" {
+						expertNumArr = append(expertNumArr, expertNum)
+						rightIndex = rightIndex
+						expertContentStr := expertContent[rightIndex:]
+						expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
+						expertContentStr = strings.TrimLeft(expertContentStr, ":")
+						expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
+						expertContentArr = append(expertContentArr, expertContentStr)
+					}
+				}
+			}
+		}
+	})
+	if len(expertContentArr) == 0 {
+		doc.Find("pre").Each(func(i int, s *goquery.Selection) {
+			contentTxt := s.Text()
+			if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
+				interviewDate := s.Next().Text()
+				if interviewDate != "" {
+					interviewDateArr = append(interviewDateArr, interviewDate)
+				}
+			}
+			if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
+				expertContent := s.Next().Text()
+				if expertContent == "" {
+					expertContent = contentTxt
+				}
+				if expertContent != "" {
+					rightIndex := strings.Index(expertContent, ")")
+					if rightIndex == 0 {
+						rightIndex = strings.Index(expertContent, ")")
+					}
+					expertNum := expertContent[:rightIndex]
+					expertNum = strings.Replace(expertNum, "(", "", -1)
+					expertNum = strings.Replace(expertNum, "(", "", -1)
+					expertNum = strings.Replace(expertNum, "专家评价", "", -1)
+					if expertNum != "" {
+						expertNumArr = append(expertNumArr, expertNum)
+						rightIndex = rightIndex
+						expertContentStr := expertContent[rightIndex:]
+						expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
+						expertContentStr = strings.TrimLeft(expertContentStr, ":")
+						expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
+						if expertContentStr != "" {
+							expertContentArr = append(expertContentArr, expertContentStr)
+						}
+					}
+				}
+			}
+		})
+	}
+
+	if len(expertNumArr) > 0 {
+		expertNumStr = expertNumArr[0]
+		if expertNumStr != "" {
+			expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
+			expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
+			expertNumStr = strings.Trim(expertNumStr, "")
+		}
+	}
+	if len(expertContentArr) > 0 {
+		expertContentStr = expertContentArr[0]
+	}
+
+	if len(expertContentStr) > 600 {
+		strnum := strings.Index(expertContentStr, "#专家评价:")
+		content := expertContentStr[strnum:len(expertContentStr)]
+		strnum2 := strings.Index(content, "(")
+		content = content[strnum2+9 : len(content)] //中文括号3位 专家编号6位
+		expertContentStr = content
+	}
+	if strings.Index(body, "报告全文(") > 0 && strings.Index(body, "PDF格式报告下载.pdf") > 0 {
+		numStar := strings.Index(body, "http")
+		numEnd := strings.Index(body, ".pdf")
+		fmt.Println("获取PDF链接")
+		fileLink = body[numStar : numEnd+4]
+	}
+
+	//body = strings.Replace(body, "报告全文(", "", -1)
+	//body = strings.Replace(body, "PDF格式报告下载.pdf", "", -1)
+	//body = strings.Replace(body, "):", "", -1)
+
+	if len(interviewDateArr) > 0 {
+		interviewDateStr = interviewDateArr[0]
+	}
+	//fmt.Println(expertContentStr)
+	return
+}

+ 12 - 1
services/task.go

@@ -23,7 +23,18 @@ func Task() {
 		toolbox.StartTask()
 	}
 
-	fmt.Println("end")
+	if utils.RunMode == "debug" {
+		//syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
+		//toolbox.AddTask("syncTacticsList", syncTacticsList)
+		//toolbox.StartTask()
+		syncTacticsListAddreport := toolbox.NewTask("syncTacticsListAddreport", "0 01 01 * * *", SyncTacticsListAddreport)
+		toolbox.AddTask("syncTacticsListAddreport", syncTacticsListAddreport)
+
+		//同步纪要库中的Es
+		syncTacticsListToEs := toolbox.NewTask("syncTacticsListToEs", "0 01 01 * * *", SyncTacticsListToEs)
+		toolbox.AddTask("syncTacticsListToEs", syncTacticsListToEs)
+		toolbox.StartTask()
+	}
 }
 
 func ElasticOption() {