|
@@ -0,0 +1,56 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_clpt/models"
|
|
|
+ "hongze/hongze_clpt/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
|
|
|
+}
|
|
|
+
|
|
|
+// GetCygxArticleCollectNumMapByArtcileIds 根据文章ID获取对应文章被收藏的数量
|
|
|
+func GetCygxArticleCollectNumMapByArtcileIds(articleIds []int) (mapResp map[int]int, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("根据文章ID获取对应文章被收藏的数量 GetCygxArticleCollectNumMapByArtcileIds ErrMsg:"+err.Error()+fmt.Sprint(articleIds), 2)
|
|
|
+
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ list, e := models.GetArticleCollectListNum(articleIds)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetArticleCollectListNum " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mapResp = make(map[int]int, 0)
|
|
|
+ if len(list) > 0 {
|
|
|
+ for _, v := range list {
|
|
|
+ mapResp[v.ArticleId] = v.CollectNum
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|