|
@@ -319,86 +319,33 @@ func HandleCommentByCommunityQuestionItemList(userId uint64, questionList []*res
|
|
|
return
|
|
|
}
|
|
|
idArr := make([]uint32, 0)
|
|
|
- idMap := make(map[uint32]int)
|
|
|
|
|
|
- userIds := []uint64{userId} //所有的评论人
|
|
|
+ // 问题ID-精选评论列表
|
|
|
+ questionIdCommentsMap := make(map[uint32][]*response.CommunityQuestionCommentListItem, 0)
|
|
|
|
|
|
for i := 0; i < listLen; i++ {
|
|
|
idArr = append(idArr, uint32(questionList[i].CommunityQuestionID))
|
|
|
- idMap[uint32(questionList[i].CommunityQuestionID)] = 1
|
|
|
+ questionIdCommentsMap[uint32(questionList[i].CommunityQuestionID)] = make([]*response.CommunityQuestionCommentListItem, 0)
|
|
|
}
|
|
|
|
|
|
- //精选评论数据、我的评论数据
|
|
|
- ybCommunityQuestionCommentMap := make(map[uint32]*yb_community_question_comment.YbCommunityQuestionComment)
|
|
|
-
|
|
|
- //获取精选评论数据
|
|
|
- hotList, err := yb_community_question_comment.GetLastHotListByCommunityQuestionIds(idArr)
|
|
|
+ // 精选评论数据
|
|
|
+ hotList, err := yb_community_question_comment.GetHotListByCommunityQuestionIds(idArr)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
for _, v := range hotList {
|
|
|
- ybCommunityQuestionCommentMap[v.CommunityQuestionID] = v
|
|
|
- delete(idMap, v.CommunityQuestionID)
|
|
|
-
|
|
|
- //评论人id
|
|
|
- userIds = append(userIds, v.UserID)
|
|
|
- }
|
|
|
-
|
|
|
- //需要查询的我的问答的评论
|
|
|
- myIdArr := make([]uint32, 0)
|
|
|
- for id := range idMap {
|
|
|
- myIdArr = append(myIdArr, id)
|
|
|
- }
|
|
|
-
|
|
|
- //获取我的评论数据
|
|
|
- myList, err := yb_community_question_comment.GetLastMyListByCommunityQuestionIds(userId, myIdArr)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range myList {
|
|
|
- ybCommunityQuestionCommentMap[v.CommunityQuestionID] = v
|
|
|
- }
|
|
|
-
|
|
|
- // 获取留言汇总数
|
|
|
- numCommentMap := make(map[uint32]int)
|
|
|
- numCommentList, err := yb_community_question_comment.GetNumCommentByCommunityQuestionIds(idArr, userId)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range numCommentList {
|
|
|
- numCommentMap[v.CommunityQuestionID] = v.Total
|
|
|
- }
|
|
|
-
|
|
|
- var userOthers []*wx_user.WxUser
|
|
|
- if len(userIds) > 0 {
|
|
|
- userOthers, err = wx_user.GetByUserIds(userIds)
|
|
|
- if err != nil {
|
|
|
- err = errors.New("查询精选留言用户出错")
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- usersMap := make(map[uint64]*wx_user.WxUser)
|
|
|
- for _, v := range userOthers {
|
|
|
- usersMap[v.UserID] = v
|
|
|
+ questionIdCommentsMap[v.CommunityQuestionID] = append(questionIdCommentsMap[v.CommunityQuestionID], &response.CommunityQuestionCommentListItem{
|
|
|
+ QaAvatarUrl: v.QaAvatarUrl,
|
|
|
+ Comment: v.Content,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
for _, v := range questionList {
|
|
|
- //评论汇总数
|
|
|
- if tmpTotal, ok := numCommentMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
- v.CommentTotal = tmpTotal
|
|
|
- }
|
|
|
-
|
|
|
- //最近一条 精选/我的 评论
|
|
|
- if ybCommunityQuestionCommentInfo, ok := ybCommunityQuestionCommentMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
- v.Comment = ybCommunityQuestionCommentInfo.Content
|
|
|
- v.QaAvatarUrl = ybCommunityQuestionCommentInfo.QaAvatarUrl
|
|
|
- v.CommentUserName = "匿名用户" + strconv.Itoa(int(3333+ybCommunityQuestionCommentInfo.UserID))
|
|
|
- if info, ok := usersMap[ybCommunityQuestionCommentInfo.UserID]; ok && ybCommunityQuestionCommentInfo.IsShowName == 1 {
|
|
|
- v.CommentUserName = info.NickName
|
|
|
- //v.UserImgUrl = info.Headimgurl
|
|
|
- }
|
|
|
- }
|
|
|
+ comments := questionIdCommentsMap[uint32(v.CommunityQuestionID)]
|
|
|
+ v.CommentTotal = len(comments)
|
|
|
+ v.CommentList = comments
|
|
|
}
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|