Эх сурвалжийг харах

产业新和热的产业标签更新

xingzai 2 жил өмнө
parent
commit
8aa552c3de

+ 45 - 9
controllers/report.go

@@ -173,6 +173,24 @@ func (this *MobileReportController) IndustryList() {
 	if ChartPermissionId > 0 {
 		condition += ` AND man.chart_permission_id IN (` + strconv.Itoa(ChartPermissionId) + `)`
 	}
+
+	// 获取近一个月产业报告阅读次数最多的产业
+	var topCond string
+	var topPars []interface{}
+	topReadIndustryId := 0
+	if ChartPermissionId > 0 {
+		topCond += ` AND chart_permission_id = ?`
+		topPars = append(topPars, ChartPermissionId)
+	}
+	topReadIndustry, e := models.GetTopOneMonthArtReadNumIndustry(topCond, topPars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取近一个月报告阅读次数最多的产业失败, Err: " + e.Error()
+		return
+	}
+	if topReadIndustry != nil {
+		topReadIndustryId = topReadIndustry.IndustrialManagementId
+	}
 	// 深度覆盖
 	if deepCover == 1 {
 		// 查询深标签产业报告数
@@ -225,12 +243,12 @@ func (this *MobileReportController) IndustryList() {
 		ChartPermissionId = 20
 	}
 	//获取产业下阅读数量第三的产业详情
-	detailHot3, err := models.GetIndustrialManagementHot3(ChartPermissionId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取信息失败,Err:" + err.Error()
-		return
-	}
+	//detailHot3, err := models.GetIndustrialManagementHot3(ChartPermissionId)
+	//if err != nil && err.Error() != utils.ErrNoRow() {
+	//	br.Msg = "获取信息失败"
+	//	br.ErrMsg = "获取信息失败,Err:" + err.Error()
+	//	return
+	//}
 
 	list, err = models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
 	if err != nil {
@@ -240,9 +258,12 @@ func (this *MobileReportController) IndustryList() {
 	}
 
 	industrialIdArr := make([]int, 0)
-	for k, v := range list {
-		industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
-		if v.ArticleReadNum >= detailHot3.ArticleReadNum {
+	for k, _ := range list {
+		//industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
+		//if v.ArticleReadNum >= detailHot3.ArticleReadNum {
+		//	list[k].IsHot = true
+		//}
+		if topReadIndustryId > 0 && list[k].IndustrialManagementId == topReadIndustryId {
 			list[k].IsHot = true
 		}
 	}
@@ -272,6 +293,8 @@ func (this *MobileReportController) IndustryList() {
 			mapHistroyArticleId[v.ArticleId] = v.ArticleId
 		}
 	}
+	nowTime := time.Now().Local()
+	threeMonBefore := nowTime.AddDate(0, -3, 0)
 	for k, v := range list {
 		list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
 		if uid > 0 {
@@ -285,6 +308,19 @@ func (this *MobileReportController) IndustryList() {
 			}
 			list[k].IsFollow = false
 		}
+		// 关联报告发布时间均在3个月内则标记New
+		fmt.Println(v.MinReportTime)
+		if v.MinReportTime != "" {
+			t, e := time.Parse(utils.FormatDateTime, v.MinReportTime)
+			if e != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "报告最早发布时间有误, Err: " + e.Error()
+				return
+			}
+			if t.After(threeMonBefore) {
+				list[k].IsNew = true
+			}
+		}
 		//标的列表
 		industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
 		if err != nil {

+ 12 - 0
models/industrial_management.go

@@ -113,6 +113,7 @@ func GetIndustrialManagementAll(uid int, condition, orderSrt string, startSize,
 	sql := `SELECT
 			man.*,
             MAX( art.publish_date ) AS update_time ,
+			MIN(art.publish_date) AS min_report_time,
 		    (SELECT COUNT( 1 )  FROM cygx_industry_fllow AS f WHERE f.user_id = ` + strconv.Itoa(uid) + ` AND f.industrial_management_id = man.industrial_management_id AND f.type = 1) AS is_follow
 			FROM
 			cygx_industrial_management AS man
@@ -278,3 +279,14 @@ func GetIndustrialArticleGroupManagementByIndustrialManagementId(industrialManag
 	_, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&list)
 	return
 }
+
+// GetTopOneMonthArtReadNumIndustry 获取近一个月报告阅读数量最多的产业信息
+func GetTopOneMonthArtReadNumIndustry(condition string, pars []interface{}) (item *IndustrialManagement, err error) {
+	sql := `SELECT * FROM cygx_industrial_management WHERE 1 = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	sql += ` ORDER BY article_read_num DESC LIMIT 1`
+	err = orm.NewOrm().Raw(sql, pars).QueryRow(&item)
+	return
+}

+ 1 - 0
models/report.go

@@ -25,6 +25,7 @@ type IndustrialManagement struct {
 	ArticleId              int                  `description:"文章id"`
 	Source                 int                  `description:"来源 1:弘则资源包(报告)、2:研选主题(报告)"`
 	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
+	MinReportTime          string               `description:"报告最早发布时间"`
 }
 
 type TacticsListResp struct {

+ 8 - 2
services/elastic.go

@@ -254,14 +254,20 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 	shouldMapquery := make([]interface{}, 0)
 	// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
 	//keyWordWeight := GetWeight(keyWordLen)
+	var boost int
 	lenkeyWordArr := len(keyWordArr)
 	for k, v := range keyWordArr {
+		if k == 0 {
+			boost = 2 * 1000
+		} else {
+			boost = 1000
+		}
 		if v != "" {
 			shouldMapquery = append(shouldMapquery, map[string]interface{}{
 				"function_score": map[string]interface{}{
 					"query": map[string]interface{}{
 						"multi_match": map[string]interface{}{
-							"boost":  (lenkeyWordArr - k) * 100, //给查询的值赋予权重
+							"boost":  (lenkeyWordArr - k) * boost, //给查询的值赋予权重
 							"fields": []interface{}{"Title"},
 							"query":  v,
 						},
@@ -273,7 +279,7 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 				"function_score": map[string]interface{}{
 					"query": map[string]interface{}{
 						"multi_match": map[string]interface{}{
-							"boost":  (lenkeyWordArr-k)*100 - 1, //给查询的值赋予权重
+							"boost":  (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
 							"fields": []interface{}{"BodyText"},
 							"query":  v,
 						},