|
@@ -3,11 +3,14 @@ package collection
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "hongze/hongze_yb/models/response"
|
|
|
"hongze/hongze_yb/models/tables/rddp/report"
|
|
|
"hongze/hongze_yb/models/tables/rddp/report_chapter"
|
|
|
"hongze/hongze_yb/models/tables/yb_community_video"
|
|
|
"hongze/hongze_yb/models/tables/yb_road_video"
|
|
|
"hongze/hongze_yb/models/tables/yb_user_collection"
|
|
|
+ "hongze/hongze_yb/utils"
|
|
|
+ "sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -62,7 +65,7 @@ func AddCollection(userId, collectionType, primaryId, extendId, sourceAgent int)
|
|
|
title = roadVideo.Title
|
|
|
publishTime = roadVideo.PublishTime
|
|
|
default:
|
|
|
- err = errors.New(fmt.Sprintf("收藏类型有误, 当前收藏类型"))
|
|
|
+ err = errors.New(fmt.Sprintf("收藏类型有误, 当前收藏类型%d", collectionType))
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -115,17 +118,17 @@ func CancelCollection(userId, collectionId int) (err error) {
|
|
|
}
|
|
|
|
|
|
// GetCollectionList 收藏列表
|
|
|
-// @Param from_type query int false "来源类型:0-全部; 1-研报; 2-线上路演; 3-视频社区"
|
|
|
-// @Param keywords query string false "搜索关键词"
|
|
|
-// @Param curr_page query int false "当前页码"
|
|
|
-// @Param page_size query int false "每页数量"
|
|
|
-func GetCollectionList(fromType, currPage, pageSize int, keywords string) (total int, err error) {
|
|
|
+func GetCollectionList(userId, fromType, currPage, pageSize int, keywords string) (total int, respList []*response.CollectionList, err error) {
|
|
|
+ respList = make([]*response.CollectionList, 0)
|
|
|
if fromType <= 0 {
|
|
|
fromType = 0
|
|
|
}
|
|
|
- // TODO:查询收藏列表
|
|
|
+
|
|
|
+ // 查询收藏列表
|
|
|
var cond string
|
|
|
var pars []interface{}
|
|
|
+ cond += `user_id = ?`
|
|
|
+ pars = append(pars, userId)
|
|
|
if fromType > 0 {
|
|
|
cond += ` AND collection_type = ?`
|
|
|
pars = append(pars, fromType)
|
|
@@ -140,7 +143,8 @@ func GetCollectionList(fromType, currPage, pageSize int, keywords string) (total
|
|
|
err = errors.New("获取收藏列表失败, Err: " + e.Error())
|
|
|
return
|
|
|
}
|
|
|
- // TODO:遍历收藏列表取出各类型的ID
|
|
|
+
|
|
|
+ // 遍历收藏列表取出各类型的ID
|
|
|
reportIdArr := make([]int, 0)
|
|
|
chapterIdArr := make([]int, 0)
|
|
|
videoIdArr := make([]int, 0)
|
|
@@ -159,9 +163,152 @@ func GetCollectionList(fromType, currPage, pageSize int, keywords string) (total
|
|
|
roadVideoIdArr = append(roadVideoIdArr, collections[i].PrimaryID)
|
|
|
}
|
|
|
}
|
|
|
- // TODO:各类型ID大于0则进行相应的查询
|
|
|
|
|
|
- // TODO:根据收藏类型组合list
|
|
|
+ // 查询相应收藏类型详情
|
|
|
+ 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()
|
|
|
+
|
|
|
+ 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)
|
|
|
+
|
|
|
+ // 报告
|
|
|
+ if len(reportIdArr) > 0 {
|
|
|
+ wg.Add(1)
|
|
|
+ go func() {
|
|
|
+ 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(videoIdArr) > 0 {
|
|
|
+ wg.Add(1)
|
|
|
+ go func() {
|
|
|
+ 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(roadVideoIdArr) > 0 {
|
|
|
+ wg.Add(1)
|
|
|
+ go func() {
|
|
|
+ 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]
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ }
|
|
|
+
|
|
|
+ wg.Wait()
|
|
|
+
|
|
|
+ if chapterErr != nil {
|
|
|
+ err = chapterErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if reportErr != nil {
|
|
|
+ err = reportErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if videoErr != nil {
|
|
|
+ err = videoErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if roadVideoErr != nil {
|
|
|
+ err = roadVideoErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("3", chapterMap)
|
|
|
+
|
|
|
+ // 响应列表
|
|
|
+ for i := range collections {
|
|
|
+ v := &response.CollectionList{
|
|
|
+ CollectionId: collections[i].CollectionID,
|
|
|
+ CollectionType: collections[i].CollectionType,
|
|
|
+ PrimaryId: collections[i].PrimaryID,
|
|
|
+ ExtendId: collections[i].ExtendID,
|
|
|
+ CreateTime: collections[i].CreateTime.Format(utils.FormatDate),
|
|
|
+ }
|
|
|
+ // 收藏类型:1-研报; 2-视频社区; 3-微路演视频
|
|
|
+ switch collections[i].CollectionType {
|
|
|
+ case CollectionTypeReport:
|
|
|
+ // 晨周报章节
|
|
|
+ if collections[i].ExtendID > 0 {
|
|
|
+ cp := chapterMap[collections[i].ExtendID]
|
|
|
+ if cp != nil {
|
|
|
+ v.PublishTime = cp.PublishTime.Format(utils.FormatDate)
|
|
|
+ v.ClassifyName = utils.REPORT_CHAPTER_TYPE_NAME_MAP[cp.ReportType]
|
|
|
+ v.Author = cp.Author
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ rp := reportMap[collections[i].PrimaryID]
|
|
|
+ if rp != nil {
|
|
|
+ v.PublishTime = rp.PublishTime.Format(utils.FormatDate)
|
|
|
+ v.ClassifyName = rp.ClassifyNameFirst
|
|
|
+ v.Author = rp.Author
|
|
|
+ }
|
|
|
+ case CollectionTypeVideo:
|
|
|
+ vd := videoMap[collections[i].PrimaryID]
|
|
|
+ if vd != nil {
|
|
|
+ v.PublishTime = vd.PublishTime.Format(utils.FormatDate)
|
|
|
+ v.ImgUrl = vd.CoverImgURL
|
|
|
+ }
|
|
|
+ case CollectionTypeRoadVideo:
|
|
|
+ rv := roadVideoMap[collections[i].PrimaryID]
|
|
|
+ if rv != nil {
|
|
|
+ v.PublishTime = rv.PublishTime.Format(utils.FormatDate)
|
|
|
+ v.ImgUrl = rv.CoverImgURL
|
|
|
+ v.Author = rv.AdminRealName
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ respList = append(respList, v)
|
|
|
+ }
|
|
|
|
|
|
return
|
|
|
}
|