Преглед изворни кода

路演视频列表评论/点赞/吐槽

hsun пре 2 година
родитељ
комит
607d3b950e

+ 0 - 3
controller/community/video.go

@@ -1,7 +1,6 @@
 package community
 
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/models/request"
@@ -43,7 +42,6 @@ func VideoList(c *gin.Context) {
 	// 点赞/吐槽数据
 	err = community.HandleLikeOrTeaseByCommunityVideoItemList(userInfo.UserID, list)
 	if err != nil {
-		fmt.Println(err.Error())
 		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
 		return
 	}
@@ -51,7 +49,6 @@ func VideoList(c *gin.Context) {
 	// 评论数据
 	err = community.HandleCommentByCommunityVideoItemList(list)
 	if err != nil {
-		fmt.Println(err.Error())
 		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
 		return
 	}

+ 16 - 2
controller/road/video.go

@@ -42,10 +42,24 @@ func VideoList(c *gin.Context) {
 		response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
 		return
 	}
+
+	// 点赞/吐槽数据
+	err = community.HandleLikeOrTeaseByRoadVideoItemList(userinfo.UserID, list.List)
+	if err != nil {
+		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
+		return
+	}
+
+	// 评论数据
+	err = community.HandleCommentByRoadVideoItemList(list.List)
+	if err != nil {
+		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
+		return
+	}
+
 	response.OkData("获取成功", list, c)
 }
 
-
 // VideoPlayLog 记录视频播放日志
 // @Tags 视频社区模块
 // @Description 记录视频播放日志
@@ -75,4 +89,4 @@ func VideoPlayLog(c *gin.Context) {
 		return
 	}
 	response.Ok("操作成功", c)
-}
+}

+ 3 - 3
logic/yb_community_question/yb_community_question_comment.go

@@ -427,8 +427,8 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 		extra = communityVideo.VarietyTagName
 	case 3:
 		sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByRoadVideoComment
-		remark = `您有新的视频评论待查阅`
-		content = `您有新的视频评论待查阅`
+		remark = `您有新的线上路演评论待查阅`
+		content = `您有新的线上路演评论待查阅`
 		messageSource = `线上路演`
 
 		communityVideo, e := yb_road_video.GetItemById(int(communityQuestionComment.CommunityQuestionID))
@@ -439,7 +439,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 		msgContent = communityVideo.Title
 		// 路演视频品种
 		if communityVideo.ChartPermissionIds != "" {
-			cpIds := utils.JoinStr2IntArr(communityVideo.ChartPermissionIds, ",")
+			cpIds := utils.JoinStr2IntArr(strings.ReplaceAll(communityVideo.ChartPermissionIds, `'`, ``), ",")
 			if len(cpIds) > 0 {
 				cpList, e := chart_permission.GetListByIds(cpIds)
 				if e != nil {

+ 21 - 15
models/response/community.go

@@ -95,25 +95,31 @@ type CommunityVideoItem struct {
 
 // RoadVideoItem 线上路演
 type RoadVideoItem struct {
-	RoadVideoID         int    `json:"road_video_id"`
-	Title               string `json:"title"`
-	ChartPermissionIds  string `json:"chart_permission_ids"`
-	ChartPermissionName string `json:"chart_permission_name"`
-	CoverImgUrl         string `json:"cover_img_url"`
-	VideoUrl            string `json:"video_url"`
-	VideoSeconds        string `json:"video_seconds"`
-	PublishState        int    `json:"publish_state"`
-	AdminId             int    `json:"admin_id"`
-	AdminRealName       string `json:"admin_real_name"`
-	PublishTime         string `json:"publish_time"`
-	CreateTime          string `json:"create_time"`
-	ModifyTime          string `json:"modify_time"`
+	RoadVideoID         int                                 `json:"road_video_id"`
+	Title               string                              `json:"title"`
+	ChartPermissionIds  string                              `json:"chart_permission_ids"`
+	ChartPermissionName string                              `json:"chart_permission_name"`
+	CoverImgUrl         string                              `json:"cover_img_url"`
+	VideoUrl            string                              `json:"video_url"`
+	VideoSeconds        string                              `json:"video_seconds"`
+	PublishState        int                                 `json:"publish_state"`
+	AdminId             int                                 `json:"admin_id"`
+	AdminRealName       string                              `json:"admin_real_name"`
+	PublishTime         string                              `json:"publish_time"`
+	CreateTime          string                              `json:"create_time"`
+	ModifyTime          string                              `json:"modify_time"`
+	OpType              int8                                `description:"类型. 1-点赞 2-吐槽" json:"op_type"`
+	LikeTotal           int                                 `json:"like_total" description:"点赞数"`
+	TeaseTotal          int                                 `json:"tease_total" description:"吐槽数"`
+	CommentTotal        int                                 `json:"comment_total" description:"总共评论数"`
+	CommentList         []*CommunityQuestionCommentListItem `json:"comment_list"`
 }
 
 type RoadVideoItemResp struct {
-	List []*RoadVideoItem `json:"list"`
-	Paging *PagingItem  	`json:"paging"`
+	List   []*RoadVideoItem `json:"list"`
+	Paging *PagingItem      `json:"paging"`
 }
+
 // RespCommunityQuestionLikeTease
 type RespCommunityQuestionLikeTease struct {
 	LikeTotal  int64 `description:"点赞总数" json:"like_total"`

+ 3 - 2
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -76,6 +76,7 @@ var YbCommunityQuestionCommentColumns = struct {
 }
 
 const (
-	SourceQuestion = iota + 1 // 问答社区->1
-	SourceVideo               // 视频社区->2
+	SourceQuestion  = iota + 1 // 问答社区->1
+	SourceVideo                // 视频社区->2
+	SourceRoadVideo            // 路演视频->3
 )

+ 3 - 2
models/tables/yb_community_question_like_tease/yb_community_question_like_tease.go

@@ -46,6 +46,7 @@ var YbCommunityQuestionLikeTeaseColumns = struct {
 }
 
 const (
-	SourceQuestion = iota + 1 // 问答社区->1
-	SourceVideo               // 视频社区->2
+	SourceQuestion  = iota + 1 // 问答社区->1
+	SourceVideo                // 视频社区->2
+	SourceRoadVideo            // 路演视频->3
 )

+ 98 - 0
services/community/video.go

@@ -393,3 +393,101 @@ func GetRoadVideoList(userInfo user.UserInfo, pageIndex, pageSize, videoId, char
 	resp.Paging = response.GetPaging(pageIndex, pageSize, int(total))
 	return
 }
+
+
+// HandleLikeOrTeaseByRoadVideoItemList 路演视频 点赞/吐槽 数据
+func HandleLikeOrTeaseByRoadVideoItemList(userId uint64, videoList []*response.RoadVideoItem) (err error) {
+	listLen := len(videoList)
+	if listLen == 0 {
+		return
+	}
+	idArr := make([]uint32, 0)
+	for i := 0; i < listLen; i++ {
+		idArr = append(idArr, uint32(videoList[i].RoadVideoID))
+	}
+
+	// 注:此处视频社区CommunityVideoID在点赞吐槽表中为CommunityQuestionID, 以source区分主键
+
+	// 获取点赞和吐槽数据
+	ybCommunityQuestionLikeTeaseMap := make(map[uint32]*yb_community_question_like_tease.YbCommunityQuestionLikeTease)
+	ybCommunityQuestionLikeTeaseList, err := yb_community_question_like_tease.GetByUserIdAndCommunityQuestionIds(userId, idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range ybCommunityQuestionLikeTeaseList {
+		ybCommunityQuestionLikeTeaseMap[v.CommunityQuestionID] = v
+	}
+
+	// 获取点赞和吐槽汇总数
+	likeMap := make(map[uint32]int)
+	teaseMap := make(map[uint32]int)
+
+	likeList, err := yb_community_question_like_tease.GetLikeNumCommentByCommunityQuestionIds(idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range likeList {
+		likeMap[v.CommunityQuestionID] = v.Total
+	}
+
+	teaseList, err := yb_community_question_like_tease.GetTeaseNumCommentByCommunityQuestionIds(idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range teaseList {
+		teaseMap[v.CommunityQuestionID] = v.Total
+	}
+
+	for _, v := range videoList {
+		if tmpTotal, ok := likeMap[uint32(v.RoadVideoID)]; ok {
+			v.LikeTotal = tmpTotal
+		}
+		if tmpTotal, ok := teaseMap[uint32(v.RoadVideoID)]; ok {
+			v.TeaseTotal = tmpTotal
+		}
+
+		if ybCommunityQuestionLikeTease, ok := ybCommunityQuestionLikeTeaseMap[uint32(v.RoadVideoID)]; ok {
+			//类型. 1-点赞 2-吐槽
+			v.OpType = ybCommunityQuestionLikeTease.OpType
+		}
+	}
+	return
+}
+
+// HandleCommentByRoadVideoItemList 路演视频 -论数据
+func HandleCommentByRoadVideoItemList(questionList []*response.RoadVideoItem) (err error) {
+	listLen := len(questionList)
+	if listLen == 0 {
+		return
+	}
+	idArr := make([]uint32, 0)
+
+	// 注:此处视频社区RoadVideoID在评论表中为CommunityQuestionID, 以source区分主键
+
+	// 问题ID-精选评论列表
+	questionIdCommentsMap := make(map[uint32][]*response.CommunityQuestionCommentListItem, 0)
+
+	for i := 0; i < listLen; i++ {
+		idArr = append(idArr, uint32(questionList[i].RoadVideoID))
+		questionIdCommentsMap[uint32(questionList[i].RoadVideoID)] = make([]*response.CommunityQuestionCommentListItem, 0)
+	}
+
+	// 精选评论数据
+	hotList, err := yb_community_question_comment.GetHotListByCommunityQuestionIds(idArr, yb_community_question_comment.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range hotList {
+		questionIdCommentsMap[v.CommunityQuestionID] = append(questionIdCommentsMap[v.CommunityQuestionID], &response.CommunityQuestionCommentListItem{
+			QaAvatarUrl: v.QaAvatarUrl,
+			Comment:     v.Content,
+		})
+	}
+
+	for _, v := range questionList {
+		comments := questionIdCommentsMap[uint32(v.RoadVideoID)]
+		v.CommentTotal = len(comments)
+		v.CommentList = comments
+	}
+	return
+}