hsun 2 жил өмнө
parent
commit
cb33e781ab

+ 8 - 0
models/tables/yb_user_collection/model.go

@@ -23,6 +23,14 @@ func GetPageListByCondition(condition string, pars []interface{}, pageIndex, pag
 	return
 }
 
+// GetPageListTotalByCondition 获取收藏列表总数-分页
+func GetPageListTotalByCondition(condition string, pars []interface{}) (total int64, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
+		Where(condition, pars...).
+		Count(&total).Error
+	return
+}
+
 // GetItemById 主键获取收藏
 func GetItemById(collectionId int) (item *YbUserCollection, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).

+ 69 - 62
services/collection/collection.go

@@ -138,6 +138,12 @@ func GetCollectionList(userId, fromType, currPage, pageSize int, keywords string
 		cond += ` AND title LIKE ?`
 		pars = append(pars, keywords)
 	}
+	collectionTotal, e := yb_user_collection.GetPageListTotalByCondition(cond, pars)
+	if e != nil {
+		err = errors.New("获取收藏列表总数失败, Err: " + e.Error())
+		return
+	}
+	total = int(collectionTotal)
 	collections, e := yb_user_collection.GetPageListByCondition(cond, pars, currPage, pageSize)
 	if e != nil {
 		err = errors.New("获取收藏列表失败, Err: " + e.Error())
@@ -165,83 +171,85 @@ func GetCollectionList(userId, fromType, currPage, pageSize int, keywords string
 	}
 
 	// 查询相应收藏类型详情
-	wg := sync.WaitGroup{}
-
-	// 章节
 	var chapterErr, reportErr, videoErr, roadVideoErr error
 	chapterMap := make(map[int]*report_chapter.ReportChapter, 0)
 	reportMap := make(map[int]*report.Report, 0)
 	videoMap := make(map[int]*yb_community_video.YbCommunityVideo, 0)
 	roadVideoMap := make(map[int]*yb_road_video.YbRoadVideo, 0)
 
-	if len(chapterIdArr) > 0 {
-		wg.Add(1)
-		go func() {
-			wg.Done()
+	wg := sync.WaitGroup{}
 
-			chapters, e := report_chapter.GetListByChapterIds(chapterIdArr)
-			if e != nil {
-				chapterErr = errors.New("获取章节失败, Err: " + e.Error())
-				return
-			}
-			for i := range chapters {
-				chapterMap[chapters[i].ReportChapterId] = chapters[i]
-				fmt.Println("1", chapterMap)
-			}
-		}()
-	}
-	fmt.Println("2", chapterMap)
+	// 章节
+	wg.Add(1)
+	go func() {
+		defer wg.Done()
+
+		if len(chapterIdArr) == 0 {
+			return
+		}
+		chapters, e := report_chapter.GetListByChapterIds(chapterIdArr)
+		if e != nil {
+			chapterErr = errors.New("获取章节失败, Err: " + e.Error())
+			return
+		}
+		for i := range chapters {
+			chapterMap[chapters[i].ReportChapterId] = chapters[i]
+		}
+	}()
 
 	// 报告
-	if len(reportIdArr) > 0 {
-		wg.Add(1)
-		go func() {
-			wg.Done()
+	wg.Add(1)
+	go func() {
+		defer wg.Done()
 
-			reports, e := report.GetListByReportIds(reportIdArr)
-			if e != nil {
-				reportErr = errors.New("获取报告失败, Err: " + e.Error())
-				return
-			}
-			for i := range reports {
-				reportMap[reports[i].Id] = reports[i]
-			}
-		}()
-	}
+		if len(reportIdArr) == 0 {
+			return
+		}
+		reports, e := report.GetListByReportIds(reportIdArr)
+		if e != nil {
+			reportErr = errors.New("获取报告失败, Err: " + e.Error())
+			return
+		}
+		for i := range reports {
+			reportMap[reports[i].Id] = reports[i]
+		}
+	}()
 
 	// 视频
-	if len(videoIdArr) > 0 {
-		wg.Add(1)
-		go func() {
-			wg.Done()
+	wg.Add(1)
+	go func() {
+		defer wg.Done()
 
-			videos, e := yb_community_video.GetListByVideoIds(videoIdArr)
-			if e != nil {
-				videoErr = errors.New("获取视频失败, Err: " + e.Error())
-				return
-			}
-			for i := range videos {
-				videoMap[videos[i].CommunityVideoID] = videos[i]
-			}
-		}()
-	}
+		if len(videoIdArr) == 0 {
+			return
+		}
+		videos, e := yb_community_video.GetListByVideoIds(videoIdArr)
+		if e != nil {
+			videoErr = errors.New("获取视频失败, Err: " + e.Error())
+			return
+		}
+		for i := range videos {
+			videoMap[videos[i].CommunityVideoID] = videos[i]
+		}
+	}()
 
 	// 路演视频
-	if len(roadVideoIdArr) > 0 {
-		wg.Add(1)
-		go func() {
-			wg.Done()
+	wg.Add(1)
+	go func() {
+		defer wg.Done()
 
-			roadVideos, e := yb_road_video.GetListByVideoIds(roadVideoIdArr)
-			if e != nil {
-				roadVideoErr = errors.New("获取视频失败, Err: " + e.Error())
-				return
-			}
-			for i := range roadVideos {
-				roadVideoMap[roadVideos[i].RoadVideoID] = roadVideos[i]
-			}
-		}()
-	}
+		if len(roadVideoIdArr) == 0 {
+			return
+		}
+		roadVideos, e := yb_road_video.GetListByVideoIds(roadVideoIdArr)
+		if e != nil {
+			roadVideoErr = errors.New("获取视频失败, Err: " + e.Error())
+			return
+		}
+		for i := range roadVideos {
+			roadVideoMap[roadVideos[i].RoadVideoID] = roadVideos[i]
+		}
+	}()
 
 	wg.Wait()
 
@@ -261,7 +269,6 @@ func GetCollectionList(userId, fromType, currPage, pageSize int, keywords string
 		err = roadVideoErr
 		return
 	}
-	fmt.Println("3", chapterMap)
 
 	// 响应列表
 	for i := range collections {