xingzai il y a 1 an
Parent
commit
3b80097efb

+ 32 - 9
controllers/report.go

@@ -2918,7 +2918,8 @@ func (this *ReportController) SearchReportAndResource() {
 		return
 	}
 	//匹配报告标题、
-	condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
+	//condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
+	condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
 	sqlGroup = ` GROUP BY  a.article_id  ORDER BY a.publish_date DESC  `
 	if pageSize > 0 {
 		sqlGroup += ` LIMIT 5 `
@@ -2958,7 +2959,8 @@ func (this *ReportController) SearchReportAndResource() {
 		} else {
 			sqlGroupIk += ` LIMIT 20 `
 		}
-		conditionIk += ` AND ( a.title NOT LIKE '%` + keyWord + `%' AND  a.body NOT LIKE '%` + keyWord + `%' AND  a.annotation NOT LIKE '%` + keyWord + `%' AND  a.abstract NOT LIKE '%` + keyWord + `%') `
+		//conditionIk += ` AND ( a.title NOT LIKE '%` + keyWord + `%' AND  a.body NOT LIKE '%` + keyWord + `%' AND  a.annotation NOT LIKE '%` + keyWord + `%' AND  a.abstract NOT LIKE '%` + keyWord + `%') `
+		conditionIk += ` AND ( a.title NOT LIKE '%` + keyWord + `%'  AND  a.annotation NOT LIKE '%` + keyWord + `%' AND  a.abstract NOT LIKE '%` + keyWord + `%') `
 		//研选的联想词列表
 		ListYxReportIk, err := models.GetArticleCollectionList(` AND a.article_type_id IN (`+articleTypeIds+`) `+conditionIk+sqlGroupIk, user.UserId)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -2984,16 +2986,25 @@ func (this *ReportController) SearchReportAndResource() {
 			}
 		}
 	}
+
+	var articleIdsArr []int
+	var articleIdsSpecialArr []int // 研选专栏ID
 	for k, v := range ListHzReport {
 		ListHzReport[k].Source = 1
-		if v.MyCollectNum > 0 {
-			ListHzReport[k].IsCollect = true
-		}
+		//if v.MyCollectNum > 0 {
+		//	ListHzReport[k].IsCollect = true
+		//}
+		articleIdsArr = append(articleIdsArr, v.ArticleId)
 	}
 	for k, v := range ListYxReport {
 		ListYxReport[k].Source = 2
-		if v.MyCollectNum > 0 {
-			ListYxReport[k].IsCollect = true
+		//if v.MyCollectNum > 0 {
+		//	ListYxReport[k].IsCollect = true
+		//}
+		if v.ArticleTypeId == -1 {
+			articleIdsSpecialArr = append(articleIdsSpecialArr, v.ArticleId)
+		} else {
+			articleIdsArr = append(articleIdsArr, v.ArticleId)
 		}
 	}
 
@@ -3001,13 +3012,22 @@ func (this *ReportController) SearchReportAndResource() {
 	for _, v := range ListHzReport {
 		articleIds += strconv.Itoa(v.ArticleId) + ","
 	}
+
+	articleMapPv := services.GetArticleHistoryByArticleId(articleIdsArr)                       //文章Pv
+	articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)                     //用户收藏的文章
+	articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIdsArr) //文章收藏的数量
+	articleCollectYanxuanSpecialMap, _ := services.GetYanxuanSpecialCollectMap(user.UserId)    //用户收藏的研选专栏
+
 	for i, v := range ListYxReport {
 		articleIds += strconv.Itoa(v.ArticleId) + ","
-
 		if v.ArticleTypeId == -1 {
-			ListYxReport[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
+			v.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
+			v.IsCollect = articleCollectYanxuanSpecialMap[v.ArticleId]
 		} else if v.ArticleTypeId > 0 {
 			ListYxReport[i].ArticleTypeName = utils.CYGX_YANXUAN_ARTICLE
+			ListYxReport[i].Pv = articleMapPv[v.ArticleId]
+			ListYxReport[i].CollectNum = articleCollectNumMap[v.ArticleId]
+			ListYxReport[i].IsCollect = articleCollectMap[v.ArticleId]
 		}
 		if v.SpecialType == 1 {
 			ListYxReport[i].Title = "【笔记】" + ListYxReport[i].Title
@@ -3056,6 +3076,9 @@ func (this *ReportController) SearchReportAndResource() {
 		} else {
 			ListHzReport[k].List = make([]*models.IndustrialManagementResp, 0)
 		}
+		v.Pv = articleMapPv[v.ArticleId]
+		v.CollectNum = articleCollectNumMap[v.ArticleId]
+		v.IsCollect = articleCollectMap[v.ArticleId]
 	}
 	for k, v := range ListYxReport {
 		if len(industrialMap[v.ArticleId]) > 0 {

+ 8 - 0
models/cygx_yanxuan_special_collect.go

@@ -48,3 +48,11 @@ func GetCygxYanxuanSpecialCollectCount(condition string, pars []interface{}) (co
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// GetCygxYanxuanSpecialCollectByUser 根据用户ID获取所有文章收藏
+func GetCygxYanxuanSpecialCollectByUser(userId int) (items []*CygxYanxuanSpecialCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_yanxuan_special_collect  WHERE 1 =1  AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}

+ 29 - 0
models/industrial_management.go

@@ -845,3 +845,32 @@ func UpdateIndustrialManagementArticleNewPublishData(items map[int]string) (err
 	}
 	return
 }
+
+// UpdateIndustrialManagementInit 初始化每月产业用户关注数量
+func UpdateIndustrialManagementInit() (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_industrial_management SET one_month_follow_num = 0 `
+	_, err = o.Raw(sql).Exec()
+	return
+}
+
+// UpdateIndustrialManagementOneMonthFollowNumMulti  批量修改每月产业用户关注数量
+func UpdateIndustrialManagementOneMonthFollowNumMulti(items []*CygxIndustryFllowNumResp) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw(` UPDATE cygx_industrial_management SET one_month_follow_num = ? WHERE industrial_management_id = ?  `).Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(
+			v.Total,
+			v.IndustrialManagementId)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 27 - 0
models/industry_fllow.go

@@ -1,7 +1,9 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"time"
 )
 
@@ -213,3 +215,28 @@ func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSi
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+type CygxIndustryFllowNumResp struct {
+	IndustrialManagementId int `description:"产业D"`
+	Total                  int `description:"关注数量"`
+}
+
+// 获取用户关注的产业列表
+func GetIndustrialManagementOneMonthFollowNum() (items []*CygxIndustryFllowNumResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS total,
+			industrial_management_id 
+		FROM
+			cygx_industry_fllow AS idf 
+		WHERE
+			1 = 1 
+			AND create_time > '%s' 
+			AND create_time < '%s' 
+			AND source != 3
+		GROUP BY
+			industrial_management_id `
+	sql = fmt.Sprintf(sql, time.Now().AddDate(0, -1, 0).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 154 - 26
models/report.go

@@ -587,6 +587,63 @@ func GetArticleCollectionList(condition string, userId int) (items []*ArticleCol
 	return
 } //end
 
+// 资源包研选跟研选专栏的搜索
+//func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int) (items []*ArticleCollectionResp, err error) {
+//	o := orm.NewOrm()
+//	sql := `SELECT
+//			a.article_id,
+//			a.title,
+//			date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
+//			d.nick_name,
+//			d.department_id,
+//			a.article_type_id,
+//			0 AS is_special,
+//			"" AS special_tags,
+//			"" AS company_tags,
+//			"" AS industry_tags,
+//			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
+//			'' AS special_type,
+//			'' AS user_id,
+//			'' AS create_time
+//		FROM
+//			cygx_article AS a
+//			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+//			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+//			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
+//		WHERE
+//			1 = 1
+//			AND a.publish_status = 1 ` + condition + `  GROUP BY article_id
+//			UNION ALL
+//		SELECT
+//			a.id AS article_id,
+//			a.title AS title,
+//			date_format( a.publish_time, '%Y-%m-%d' ) AS publish_date,
+//			"" AS nick_name,
+//			0 AS department_id,
+//			- 1 AS article_type_id,
+//			1 AS is_special,
+//			a.tags AS special_tags,
+//			a.company_tags,
+//			a.industry_tags,
+//			( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
+//			( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
+//			( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
+//			a.type AS special_type,
+//			a.user_id AS user_id,
+//			a.create_time AS create_time
+//		FROM
+//			cygx_yanxuan_special AS a
+//			JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
+//		WHERE
+//			1 = 1
+//			AND a.STATUS = 3 ` + conditionSpecial + ` ORDER BY publish_date DESC  LIMIT 30`
+//
+//	_, err = o.Raw(sql, userId, userId).QueryRows(&items)
+//	return
+//} //end
+
 // 资源包研选跟研选专栏的搜索
 func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int) (items []*ArticleCollectionResp, err error) {
 	o := orm.NewOrm()
@@ -598,19 +655,16 @@ func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int)
 			d.department_id,
 			a.article_type_id,
 			0 AS is_special,
+			0 AS pv,
+			0 AS collect_num,
 			"" AS special_tags,
 			"" AS company_tags,
 			"" AS industry_tags,
-			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id AND user_id = ? ) AS my_collect_num,
 			'' AS special_type,
 			'' AS user_id,
 			'' AS create_time 
 		FROM
 			cygx_article AS a
-			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
-			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
 			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id 
 		WHERE
 			1 = 1 
@@ -624,12 +678,11 @@ func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int)
 			0 AS department_id,
 			- 1 AS article_type_id,
 			1 AS is_special,
+			a.pv,
+			a.article_collect_num as collect_num,
 			a.tags AS special_tags,
 			a.company_tags,
 			a.industry_tags,
-			( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
-			( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
-			( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num,
 			a.type AS special_type,
 			a.user_id AS user_id,
 			a.create_time AS create_time 
@@ -640,7 +693,7 @@ func GetArticleAndYxSpecialList(condition, conditionSpecial string, userId int)
 			1 = 1 
 			AND a.STATUS = 3 ` + conditionSpecial + ` ORDER BY publish_date DESC  LIMIT 30`
 
-	_, err = o.Raw(sql, userId, userId).QueryRows(&items)
+	_, err = o.Raw(sql).QueryRows(&items)
 	return
 } //end
 
@@ -686,6 +739,69 @@ func GetArticleResearchCount(condition string, pars []interface{}, needYanxuanSp
 	return
 }
 
+//func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleCollectionResp, err error) {
+//	o := orm.NewOrm()
+//	sql := `SELECT
+//			a.article_id,
+//			a.title,
+//			a.publish_date AS publish_time,
+//			a.article_type_id,
+//			d.nick_name,
+//			d.department_id,
+//			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac    WHERE ac.article_id = a.article_id  ) AS collect_num,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collect_num_order,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ? ) AS my_collect_num,
+//			0 AS is_special,
+//			0 AS special_type,
+//			0 AS user_id,
+//			'' AS company_tags,
+//			'' AS industry_tags
+//		FROM
+//			cygx_article AS a
+//			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+//			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+//			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id
+//		WHERE
+//			1 = 1  AND a.publish_status = 1
+//		  `
+//	if condition != "" {
+//		sql += condition
+//	}
+//	sql += ` GROUP BY a.article_id  `
+//	if needYanxuanSpecial {
+//		sql += `UNION ALL
+//	SELECT
+//		a.id AS article_id,
+//		a.title AS title,
+//		a.publish_time AS publish_time,
+//		-1 AS article_type_id,
+//		b.nick_name AS nick_name,
+//		a.user_id AS department_id,
+//		( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
+//		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac  WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
+//		0 AS collect_num_order,
+//		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num,
+//		1 AS is_special,
+//		a.type AS special_type,
+//		a.user_id AS user_id,
+//		a.company_tags AS company_tags,
+//		a.industry_tags AS industry_tags
+//	FROM
+//	cygx_yanxuan_special AS a
+//	JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
+//	WHERE
+//	1 = 1  AND a.status = 3 `
+//		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
+//		_, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
+//	} else {
+//		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
+//		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
+//	}
+//
+//	return
+//}
+
 func GetArticleResearchList(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleCollectionResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -695,10 +811,6 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 			a.article_type_id,
 			d.nick_name,
 			d.department_id,
-			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac    WHERE ac.article_id = a.article_id  ) AS collect_num, 
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collect_num_order, 
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ? ) AS my_collect_num,
 			0 AS is_special,
 			0 AS special_type,
 			0 AS user_id,
@@ -706,8 +818,6 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 			'' AS industry_tags
 		FROM
 			cygx_article AS a
-			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
-			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
 			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id 
 		WHERE
 			1 = 1  AND a.publish_status = 1
@@ -725,10 +835,6 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 		-1 AS article_type_id,
 		b.nick_name AS nick_name,
 		a.user_id AS department_id,
-		( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
-		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac  WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
-		0 AS collect_num_order,
-		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num,
 		1 AS is_special,
 		a.type AS special_type,
 		a.user_id AS user_id,
@@ -740,10 +846,10 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 	WHERE
 	1 = 1  AND a.status = 3 `
 		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
-		_, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	} else {
 		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
-		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	}
 
 	return
@@ -1055,6 +1161,31 @@ type ReoprtSearchResp struct {
 	ListHz []*ArticleCollectionResp `description:"弘则报告"`
 }
 
+//// 列表
+//func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
+//	o := orm.NewOrm()
+//	sql := `SELECT
+//			a.article_id,
+//			a.title,
+//			date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
+//			m.industry_name,
+//			m.industrial_management_id,
+//			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
+//			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ?) AS my_collect_num
+//		FROM
+//			cygx_article AS a
+//			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+//			LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+//		WHERE
+//			1 = 1 `
+//	if condition != "" {
+//		sql += condition
+//	}
+//	_, err = o.Raw(sql, userId).QueryRows(&items)
+//	return
+//} //end
+
 // 列表
 func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
 	o := orm.NewOrm()
@@ -1063,10 +1194,7 @@ func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollecti
 			a.title,
 			date_format( a.publish_date, '%Y-%m-%d' ) AS publish_date,
 			m.industry_name,
-			m.industrial_management_id,
-			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id ) AS collect_num,
-			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ?) AS my_collect_num
+			m.industrial_management_id
 		FROM
 			cygx_article AS a
 			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
@@ -1076,7 +1204,7 @@ func GetReoprtSearchList(condition string, userId int) (items []*ArticleCollecti
 	if condition != "" {
 		sql += condition
 	}
-	_, err = o.Raw(sql, userId).QueryRows(&items)
+	_, err = o.Raw(sql).QueryRows(&items)
 	return
 } //end
 

+ 22 - 0
services/cygx_yanxuan_special.go

@@ -447,3 +447,25 @@ func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
 	}
 	return
 }
+
+// GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏
+func GetYanxuanSpecialCollectMap(userId int) (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏失败 ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	list, e := models.GetCygxYanxuanSpecialCollectByUser(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("根据用户ID获取所有文章收藏,GetCygxYanxuanSpecialCollectByUser " + e.Error())
+		return
+	}
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.YanxuanSpecialId] = true
+		}
+	}
+	return
+}

+ 3 - 3
services/elasticsearch.go

@@ -151,7 +151,7 @@ func SaveData() {
 
 type tracelog struct{}
 
-//实现输出
+// 实现输出
 func (tracelog) Printf(format string, v ...interface{}) {
 	fmt.Printf(format, v...)
 }
@@ -397,7 +397,7 @@ func RemoveDuplicatesAndEmpty(a []string) (ret []string) {
 	return
 }
 
-//KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
+// KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
 func KeyWordArrSqlRegexp(a []string) (ret string) {
 	a_len := len(a)
 	for i := 0; i < a_len; i++ {
@@ -410,7 +410,7 @@ func KeyWordArrSqlRegexp(a []string) (ret string) {
 	return
 }
 
-//KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
+// KeyWordArrSqlRegexp 预处理ik联想词的模糊查询语句
 func KeyWordArrSqlRegexpAll(a []string) (ret string) {
 	a_len := len(a)
 	for i := 0; i < a_len; i++ {

+ 49 - 0
services/industrial_management.go

@@ -801,3 +801,52 @@ func GetCygxIndustrialSubjectMap() (itemMap map[int]string, err error) {
 	}
 	return
 }
+
+//func init() {
+//	UpdateIndustrialManagementOneMonthFollowNum()
+//}
+
+// UpdateIndustrialManagementOneMonthFollowNum 更新产业近一个月被关注的数量
+func UpdateIndustrialManagementOneMonthFollowNum(cont context.Context) (err error) {
+	//var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("UpdateIndustrialManagementOneMonthFollowNum ErrMsg:"+err.Error(), 2)
+		}
+	}()
+	listNum, e := models.GetIndustrialManagementOneMonthFollowNum()
+	if e != nil {
+		err = errors.New("GetIndustrialManagementOneMonthFollowNum, Err: " + e.Error())
+		return
+	}
+
+	e = models.UpdateIndustrialManagementInit() //初始化每月产业用户关注数量
+	if e != nil {
+		err = errors.New("UpdateIndustrialManagementInit, Err: " + e.Error())
+		return
+	}
+	var items []*models.CygxIndustryFllowNumResp
+	for _, v := range listNum {
+		item := new(models.CygxIndustryFllowNumResp)
+		item.IndustrialManagementId = v.IndustrialManagementId
+		item.Total = v.Total
+		items = append(items, item)
+		//一次最多插入五百条
+		if len(items)%500 == 0 {
+			e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
+			if e != nil {
+				err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
+				return
+			}
+		}
+	}
+	if len(items) > 0 {
+		e = models.UpdateIndustrialManagementOneMonthFollowNumMulti(items)
+		if e != nil {
+			err = errors.New("UpdateIndustrialManagementOneMonthFollowNumMulti, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}

+ 4 - 0
services/task.go

@@ -122,6 +122,10 @@ func Task() {
 
 		getStocksFromVmp := task.NewTask("getStocksFromVmp", "0 40 3 * * *", GetStocksFromVmp)
 		task.AddTask("getStocksFromVmp", getStocksFromVmp) //定时任务更新上市公司表
+
+		updateIndustrialManagementOneMonthFollowNum := task.NewTask("updateIndustrialManagementOneMonthFollowNum", "0 10 1 * * *", UpdateIndustrialManagementOneMonthFollowNum)
+		task.AddTask("updateIndustrialManagementOneMonthFollowNum", updateIndustrialManagementOneMonthFollowNum) //更新产业近一个月被关注的数量
+
 	}
 	if utils.RunMode != "release" {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章