xingzai 2 år sedan
förälder
incheckning
92bdc86993

+ 2 - 9
controllers/article.go

@@ -86,6 +86,8 @@ func (this *ArticleController) Detail() {
 	if _, ok := lyjhTypeMap[detail.CategoryId]; ok {
 		detail.IsRoadShow = true
 	}
+	articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
+	detail.IsCollect = articleCollectMap[detail.ArticleId]
 	if isSendWx == 1 {
 		var condition string
 		var pars []interface{}
@@ -290,15 +292,6 @@ func (this *ArticleController) Detail() {
 			}
 		}
 
-		collectCount, err := models.GetArticleCollectCount(uid, articleId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
-			return
-		}
-		if collectCount > 0 {
-			detail.IsCollect = true
-		}
 		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取信息失败"

+ 4 - 3
controllers/user.go

@@ -1616,9 +1616,9 @@ func (this *UserController) CommnetList() {
 		br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
 		return
 	}
-
+	articleLyjhMap, _ := services.GetLyjhArticleMap()
+	articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
 	resp := new(models.CygxCommentListResp)
-
 	for _, comment := range commentlist {
 		item := models.CygxArticleCommentResp{
 			Id:          comment.Id,
@@ -1641,9 +1641,10 @@ func (this *UserController) CommnetList() {
 		} else if comment.ActivityId > 0 {
 			item.RedirectType = 2
 		}
+		item.IsCollect = articleCollectMap[comment.ArticleId]
+		item.IsRoadShow = articleLyjhMap[comment.ArticleId]
 		resp.List = append(resp.List, &item)
 	}
-
 	br.Msg = "获取成功!"
 	br.Ret = 200
 	br.Success = true

+ 12 - 4
models/article_collect.go

@@ -21,7 +21,7 @@ type CygxArticleCollect struct {
 	RealName        string `description:"用户实际名称"`
 }
 
-//添加收藏信息
+// 添加收藏信息
 func AddCygxArticleCollect(item *CygxArticleCollect) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
@@ -79,7 +79,15 @@ func GetCygxArticleCollectList(condition string) (items []*CygxArticleCollect, e
 	return
 }
 
-//修改用户收藏文章的相关信息
+// GetCygxArticleCollectByUser 根据用户ID获取所有文章收藏
+func GetCygxArticleCollectByUser(userId int) (items []*CygxArticleCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_collect  WHERE 1 =1  AND article_id > 0 AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}
+
+// 修改用户收藏文章的相关信息
 func UpdateCygxArticleCollect(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
 	var sql string
@@ -98,7 +106,7 @@ type CygxArticleCollectCountRep struct {
 	Num       int `description:"数量"`
 }
 
-//获取文章被收藏的数量
+// 获取文章被收藏的数量
 func GetUserArticleCollectList() (items []*CygxArticleCollectCountRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -119,7 +127,7 @@ func GetUserArticleCollectList() (items []*CygxArticleCollectCountRep, err error
 	return
 }
 
-//修改文章收藏的数量
+// 修改文章收藏的数量
 func UpdateArticleCollectCountNum(num, articleId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE cygx_article SET user_collection_num = ? WHERE article_id = ?`

+ 4 - 2
models/article_comment.go

@@ -23,7 +23,7 @@ type CygxArticleComment struct {
 	Title           string    `description:"标题"`
 }
 
-//添加留言
+// 添加留言
 func AddArticleComment(item *CygxArticleComment) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
@@ -35,7 +35,7 @@ type AddCygxArticleCommentReq struct {
 	Content   string `description:"内容"`
 }
 
-//我的留言列表
+// 我的留言列表
 func GetCommentList(userId int) (items []*CygxArticleComment, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -63,6 +63,8 @@ type CygxArticleCommentResp struct {
 	Content      string    `description:"内容"`
 	Title        string    `description:"标题"`
 	RedirectType int       `description:"跳转类型 1文章 2活动 3产业资源包"`
+	IsCollect    bool      `description:"是否收藏:true,已收藏,false:未收藏"`
+	IsRoadShow   bool      `description:"是否是路演精华"`
 }
 
 type CygxCommentListResp struct {

+ 33 - 0
services/articlt_collect.go

@@ -0,0 +1,33 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+)
+
+//func init() {
+//	GetCygxArticleCollectMap(90)
+//}
+
+// GetCygxArticleCollectMap 根据用户ID获取所有文章收藏
+func GetCygxArticleCollectMap(userId int) (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("根据用户ID获取所有文章收藏失败 ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	list, e := models.GetCygxArticleCollectByUser(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("根据用户ID获取所有文章收藏,GetCygxArticleCollectByUser " + e.Error())
+		return
+	}
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.ArticleId] = true
+		}
+	}
+	return
+}

+ 38 - 0
services/industrial_management.go

@@ -694,3 +694,41 @@ func GetLyjhTypeMap() (mapResp map[int]int, err error) {
 	}
 	return
 }
+
+// GetLyjhArticleMap 获取路演精华对应文章ID
+func GetLyjhArticleMap() (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("获取路演精华对应文章ID失败 ErrMsg:"+err.Error(), 2)
+		}
+	}()
+	condition := " AND match_type_name = '路演精华'  "
+	var pars []interface{}
+	list, e := models.GetReportMappingList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("报告最早发布时间有误,GetindustryVideo " + e.Error())
+		return
+	}
+	var categoryId []int
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			categoryId = append(categoryId, v.CategoryId)
+		}
+	}
+	lencategoryId := len(categoryId)
+	if lencategoryId > 0 {
+		pars = make([]interface{}, 0)
+		condition = ` AND a.category_id IN (` + utils.GetOrmInReplace(lencategoryId) + `)`
+		pars = append(pars, categoryId)
+		listArticle, e := models.GetHomeList(condition, pars, 0, 1000)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetResourceDataList, Err: " + e.Error())
+			return
+		}
+		for _, v := range listArticle {
+			mapResp[v.ArticleId] = true
+		}
+	}
+	return
+}