|
@@ -9,7 +9,6 @@ import (
|
|
|
"hongze/hongze_yb/models/tables/yb_comment"
|
|
|
"hongze/hongze_yb/models/tables/yb_comment_anonymous_user"
|
|
|
"hongze/hongze_yb/models/tables/yb_community_question_comment"
|
|
|
- "hongze/hongze_yb/services"
|
|
|
"hongze/hongze_yb/services/user"
|
|
|
"hongze/hongze_yb/services/wx_app"
|
|
|
"hongze/hongze_yb/utils"
|
|
@@ -141,129 +140,90 @@ func Delete(user user.UserInfo, communityQuestionCommentID uint64) (err error, e
|
|
|
}
|
|
|
|
|
|
// MyList 我的留言列表
|
|
|
-func MyList(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportChapterId int) (ret response.RespMyCommentList, err error) {
|
|
|
- list, err := List(user, reportId, reportChapterId, oldReportId, oldReportChapterId, false, 0, 0)
|
|
|
+func MyList(userId uint64, communityQuestionCommentID int, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, total int64, isShowName int8, err error, errMsg string) {
|
|
|
+ list, total, err, errMsg = List(userId, communityQuestionCommentID, false, page, pageSize)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
//查询我的最新一条留言是否勾选匿名的设置
|
|
|
- lastComment, tErr := yb_comment.GetMyLatestComment(user.UserID)
|
|
|
+ lastComment, tErr := yb_comment.GetMyLatestComment(userId)
|
|
|
if tErr == nil {
|
|
|
- ret.IsShowName = lastComment.IsShowName
|
|
|
+ isShowName = lastComment.IsShowName
|
|
|
}
|
|
|
- ret.List = list.List
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// List 查询精选留言列表或我的留言列表
|
|
|
-func List(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
|
|
|
- var errMsg string
|
|
|
+func List(userId uint64, communityQuestionCommentID int, hotFlag bool, page, pageSize int) (list []*response.RespCommunityQuestionCommentItem, total int64, err error, errMsg string) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- global.LOG.Critical(fmt.Sprintf("comment List: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
|
|
|
+ global.LOG.Critical(fmt.Sprintf("comment List: userId=%d, err:%s, errMsg:%s", userId, err.Error(), errMsg))
|
|
|
}
|
|
|
}()
|
|
|
+ list = make([]*response.RespCommunityQuestionCommentItem, 0)
|
|
|
|
|
|
- if reportId <= 0 && reportChapterId <= 0 && oldReportId <= 0 && oldReportChapterId <= 0 {
|
|
|
- err = errors.New("请输入报告ID")
|
|
|
- return
|
|
|
- }
|
|
|
- if reportId <= 0 && oldReportId <= 0 {
|
|
|
- err = errors.New("请输入报告ID")
|
|
|
+ if communityQuestionCommentID <= 0 {
|
|
|
+ err = errors.New("请输入问答ID")
|
|
|
return
|
|
|
}
|
|
|
- //处理老报告, 转化成新报告ID
|
|
|
- if reportId <= 0 && reportChapterId <= 0 && (oldReportId > 0 || oldReportChapterId > 0) {
|
|
|
- reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(oldReportId), uint64(oldReportChapterId))
|
|
|
+
|
|
|
+ var commentList []*yb_community_question_comment.YbCommunityQuestionComment
|
|
|
+ //查询精选留言
|
|
|
+ if hotFlag {
|
|
|
+ commentList, err = yb_community_question_comment.GetHotListByCommunityQuestionCommentID(communityQuestionCommentID, (page-1)*pageSize, pageSize)
|
|
|
if err != nil {
|
|
|
+ errMsg = `查询精选留言列表出错`
|
|
|
return
|
|
|
}
|
|
|
- } else {
|
|
|
- // 判断报告ID是否正确
|
|
|
- err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
|
|
|
+ total, err = yb_community_question_comment.GetHotListTotalByCommunityQuestionCommentID(communityQuestionCommentID)
|
|
|
if err != nil {
|
|
|
+ errMsg = `查询精选留言总数出错`
|
|
|
return
|
|
|
}
|
|
|
- }
|
|
|
- offset := (pageIndex - 1) * pageSize
|
|
|
- var commentList []*yb_comment.YbComment
|
|
|
- var total int64
|
|
|
- //查询精选留言
|
|
|
- if hotFlag {
|
|
|
- if reportId > 0 {
|
|
|
- commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
- }
|
|
|
- total, err = yb_comment.GetHotListTotalByReportId(reportId, reportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言总数出错")
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- commentList, err = yb_comment.GetHotListByOldReportId(oldReportId, oldReportChapterId, offset, pageSize)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
- }
|
|
|
- total, err = yb_comment.GetHotListTotalByOldReportId(oldReportId, oldReportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言总数出错")
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
} else {
|
|
|
//查询个人留言
|
|
|
- if reportId > 0 {
|
|
|
- commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- commentList, err = yb_comment.GetListByUserIdOldReportId(user.UserID, oldReportId, oldReportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
- }
|
|
|
+ commentList, err = yb_community_question_comment.GetListByUserIdCommunityQuestionCommentID(userId, communityQuestionCommentID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询我的留言列表出错`
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err = yb_community_question_comment.GetListTotalByUserIdCommunityQuestionCommentID(userId, communityQuestionCommentID)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = `查询我的留言总数出错`
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
var commentIds []uint64
|
|
|
var userIds []uint64
|
|
|
for _, v := range commentList {
|
|
|
- commentIds = append(commentIds, v.CommentId)
|
|
|
- userIds = append(userIds, v.UserId)
|
|
|
+ commentIds = append(commentIds, v.CommunityQuestionCommentID)
|
|
|
+ userIds = append(userIds, v.UserID)
|
|
|
}
|
|
|
+
|
|
|
// 查询所有的回复列表
|
|
|
- replyListMap := make(map[uint64][]*response.ReplyItem)
|
|
|
- if len(commentIds) > 0 {
|
|
|
- replyList, tErr := yb_comment.GetReplyListByReplyCommentId(commentIds)
|
|
|
- if tErr != nil {
|
|
|
- errMsg = tErr.Error()
|
|
|
- err = errors.New("查询回复出错")
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range replyList {
|
|
|
- t := new(response.ReplyItem)
|
|
|
- t.CommentId = v.CommentId
|
|
|
- t.Content = v.Content
|
|
|
- t.AdminId = v.AdminId
|
|
|
- t.CreateTime = v.CreateTime
|
|
|
- t.ReplyCommentId = v.ReplyCommentId
|
|
|
- t.AdminName = "弘则研究"
|
|
|
- t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
|
|
|
- replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
|
|
|
- }
|
|
|
- }
|
|
|
+ //{
|
|
|
+ // replyListMap := make(map[uint64][]*response.ReplyItem)
|
|
|
+ // if len(commentIds) > 0 {
|
|
|
+ // replyList, tErr := yb_community_question_comment.GetReplyListByReplyCommentId(commentIds)
|
|
|
+ // if tErr != nil {
|
|
|
+ // errMsg = tErr.Error()
|
|
|
+ // err = errors.New("查询回复出错")
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // for _, v := range replyList {
|
|
|
+ // t := new(response.ReplyItem)
|
|
|
+ // t.CommentId = v.CommunityQuestionCommentID
|
|
|
+ // t.Content = v.Content
|
|
|
+ // t.AdminId = v.AdminID
|
|
|
+ // t.CreateTime = v.CreateTime
|
|
|
+ // t.ReplyCommentId = v.ReplyCommentId
|
|
|
+ // t.AdminName = "弘则研究"
|
|
|
+ // t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
|
|
|
+ // replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
// 查询精选留言相关的用户
|
|
|
var userOthers []*wx_user.WxUser
|
|
@@ -279,32 +239,29 @@ func List(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportC
|
|
|
for _, v := range userOthers {
|
|
|
usersMap[v.UserID] = v
|
|
|
}
|
|
|
- var list []*response.RespCommentItem
|
|
|
for _, v := range commentList {
|
|
|
- tmp := new(response.RespCommentItem)
|
|
|
- tmp.CommentId = v.CommentId
|
|
|
- tmp.UserId = v.UserId
|
|
|
- tmp.UserName = "匿名用户" + strconv.Itoa(int(3333+v.UserId))
|
|
|
- tmp.UserImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
|
|
|
- if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
|
|
|
+ tmp := &response.RespCommunityQuestionCommentItem{
|
|
|
+ CommunityQuestionCommentID: v.CommunityQuestionCommentID,
|
|
|
+ UserId: v.UserID,
|
|
|
+ Content: v.Content,
|
|
|
+ IsTop: v.IsTop,
|
|
|
+ IsHot: v.IsHot,
|
|
|
+ HotTopTime: v.HotTopTime,
|
|
|
+ IsShowName: v.IsShowName,
|
|
|
+ UserName: "匿名用户" + strconv.Itoa(int(3333+v.UserID)),
|
|
|
+ UserImgUrl: utils.DEFAULT_HONGZE_USER_LOGO,
|
|
|
+ CreateTime: v.CreateTime,
|
|
|
+ ReplyList: nil,
|
|
|
+ }
|
|
|
+ if info, ok := usersMap[v.UserID]; ok && v.IsShowName == 1 {
|
|
|
tmp.UserName = info.NickName
|
|
|
tmp.UserImgUrl = info.Headimgurl
|
|
|
}
|
|
|
- tmp.Content = v.Content
|
|
|
- tmp.IsHot = v.IsHot
|
|
|
- tmp.IsTop = v.IsTop
|
|
|
- tmp.HotTopTime = v.HotTopTime
|
|
|
- tmp.CreateTime = v.CreateTime
|
|
|
- tmp.IsShowName = v.IsShowName
|
|
|
- if existList, ok := replyListMap[v.CommentId]; ok {
|
|
|
- tmp.ReplyList = existList
|
|
|
- }
|
|
|
+ //if existList, ok := replyListMap[v.CommentId]; ok {
|
|
|
+ // tmp.ReplyList = existList
|
|
|
+ //}
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
- ret.List = list
|
|
|
- if hotFlag {
|
|
|
- ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
|
|
|
- }
|
|
|
return
|
|
|
}
|
|
|
|