Roc 2 жил өмнө
parent
commit
d628ab5a47

+ 27 - 102
controller/community/comment.go

@@ -6,8 +6,8 @@ import (
 	"hongze/hongze_yb/logic/yb_community_question"
 	"hongze/hongze_yb/models/request"
 	responseModel "hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/services"
 	userService "hongze/hongze_yb/services/user"
-	"hongze/hongze_yb/utils"
 	"strconv"
 )
 
@@ -49,126 +49,51 @@ func DeleteComment(c *gin.Context) {
 
 // HotList 获取精选留言
 func HotList(c *gin.Context) {
-	reqReportId := c.DefaultQuery("report_id", "")
-	reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
-	reqOldReportId := c.DefaultQuery("old_report_id", "")
-	reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
-	reqPageIndex := c.DefaultQuery("current_index", "1")
-	reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
-
-	pageIndex, err := strconv.Atoi(reqPageIndex)
-	if err != nil {
-		response.Fail("请输入正确的条数限制", c)
-		return
-	}
-	pageSize, err := strconv.Atoi(reqPageSize)
+	communityQuestionCommentIDStr := c.DefaultQuery("community_question_comment_id", "")
+	communityQuestionCommentID, err := strconv.Atoi(communityQuestionCommentIDStr)
 	if err != nil {
-		response.Fail("请输入正确的页码", c)
+		response.Fail("问答id异常", c)
 		return
 	}
-	var (
-		reportId           int
-		reportChapterId    int
-		oldReportId        int
-		oldReportChapterId int
-	)
-	if reqReportId != "" {
-		reportId, err = strconv.Atoi(reqReportId)
-		if err != nil {
-			response.Fail("报告ID格式有误", c)
-			return
-		}
-	}
-
-	if reqReportChapterId != "" {
-		reportChapterId, err = strconv.Atoi(reqReportChapterId)
-		if err != nil {
-			response.Fail("章节ID格式有误", c)
-			return
-		}
-	}
-
-	if reqOldReportId != "" {
-		oldReportId, err = strconv.Atoi(reqOldReportId)
-		if err != nil {
-			response.Fail("老报告ID格式有误", c)
-			return
-		}
-	}
-
-	if reqOldReportChapterId != "" {
-		oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
-		if err != nil {
-			response.Fail("章节ID格式有误", c)
-			return
-		}
-	}
-
 	userinfo := userService.GetInfoByClaims(c)
+	page := services.GetCurrPageByClaims(c)
+	pageSize := services.GetPageSizeByClaims(c)
 
-	list, err := yb_community_question.List(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId, true, pageIndex, pageSize)
+	list, total, err, errMsg := yb_community_question.List(userinfo.UserID, communityQuestionCommentID, true, page, pageSize)
 	if err != nil {
-		response.Fail(err.Error(), c)
+		response.FailMsg(errMsg, err.Error(), c)
 		return
 	}
-	response.OkData("查询成功", list, c)
+	response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
+		List:   list,
+		Paging: responseModel.GetPaging(page, pageSize, int(total)),
+	}, c)
+
 	return
 }
 
 // MyList 获取我的留言
 func MyList(c *gin.Context) {
-	reqReportId := c.DefaultQuery("report_id", "")
-	reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
-
-	reqOldReportId := c.DefaultQuery("old_report_id", "")
-	reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
-	var (
-		reportId           int
-		reportChapterId    int
-		oldReportId        int
-		oldReportChapterId int
-		err                error
-	)
-	if reqReportId != "" {
-		reportId, err = strconv.Atoi(reqReportId)
-		if err != nil {
-			response.Fail("报告ID格式有误", c)
-			return
-		}
-	}
-
-	if reqReportChapterId != "" {
-		reportChapterId, err = strconv.Atoi(reqReportChapterId)
-		if err != nil {
-			response.Fail("章节ID格式有误", c)
-			return
-		}
-	}
-
-	if reqOldReportId != "" {
-		oldReportId, err = strconv.Atoi(reqOldReportId)
-		if err != nil {
-			response.Fail("老报告ID格式有误", c)
-			return
-		}
-	}
-
-	if reqOldReportChapterId != "" {
-		oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
-		if err != nil {
-			response.Fail("章节ID格式有误", c)
-			return
-		}
+	communityQuestionCommentIDStr := c.DefaultQuery("community_question_comment_id", "")
+	communityQuestionCommentID, err := strconv.Atoi(communityQuestionCommentIDStr)
+	if err != nil {
+		response.Fail("问答id异常", c)
+		return
 	}
-
 	userinfo := userService.GetInfoByClaims(c)
+	page := services.GetCurrPageByClaims(c)
+	pageSize := services.GetPageSizeByClaims(c)
 
-	list, err := yb_community_question.MyList(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId)
+	list, total, isShowName, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionCommentID, page, pageSize)
 	if err != nil {
-		response.Fail(err.Error(), c)
+		response.FailMsg(errMsg, err.Error(), c)
 		return
 	}
-	response.OkData("查询成功", list, c)
+	response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
+		List:       list,
+		Paging:     responseModel.GetPaging(page, pageSize, int(total)),
+		IsShowName: isShowName,
+	}, c)
 	return
 }
 

+ 68 - 111
logic/yb_community_question/yb_community_question_comment.go

@@ -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
 }
 

+ 14 - 14
models/response/comment.go

@@ -3,19 +3,19 @@ package response
 import "time"
 
 type RespCommentList struct {
-	List       []*RespCommentItem   `json:"list"`
-	Paging     *PagingItem  		`json:"paging"`
+	List   []*RespCommentItem `json:"list"`
+	Paging *PagingItem        `json:"paging"`
 }
 type RespMyCommentList struct {
-	List       []*RespCommentItem   `json:"list"`
-	IsShowName int8 `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+	List       []*RespCommentItem `json:"list"`
+	IsShowName int8               `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
 }
 type RespCommentItem struct {
 	CommentId  uint64    `description:"留言ID" json:"comment_id"`
 	UserId     uint64    `description:"用户id" json:"user_id"`
 	Content    string    `description:"留言内容" json:"content"`
-	IsTop      int8      `description:"是否置顶(0-未置顶,1-置顶)json:"is_top""`
-	IsHot      int8      `description:"是否设置精选(0-未设置,1-已设置)json:"is_hot""`
+	IsTop      int8      `description:"是否置顶(0-未置顶,1-置顶)" json:"is_top"`
+	IsHot      int8      `description:"是否设置精选(0-未设置,1-已设置)" json:"is_hot"`
 	HotTopTime time.Time `description:"设置精选或者设置置顶的时间" json:"hot_top_time"`
 	IsShowName int8      `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
 	UserName   string    `description:"用户昵称" json:"user_name"`
@@ -25,15 +25,15 @@ type RespCommentItem struct {
 }
 
 type ReplyItem struct {
-	CommentId         uint64 `description:"留言ID" json:"comment_id"`
-	AdminId           uint64 `description:"发布留言回复的管理员ID" json:"admin_id"`
-	AdminName         string `description:"系统昵称" json:"admin_name"`
-	AdminImgUrl          string `description:"系统头像" json:"admin_img_url"`
-	Content           string `description:"回复内容" json:"content"`
-	ReplyCommentId    uint64 `description:"回复的留言ID" json:"reply_comment_id"`
-	CreateTime        time.Time `description:"留言创建时间" json:"create_time"`
+	CommentId      uint64    `description:"留言ID" json:"comment_id"`
+	AdminId        uint64    `description:"发布留言回复的管理员ID" json:"admin_id"`
+	AdminName      string    `description:"系统昵称" json:"admin_name"`
+	AdminImgUrl    string    `description:"系统头像" json:"admin_img_url"`
+	Content        string    `description:"回复内容" json:"content"`
+	ReplyCommentId uint64    `description:"回复的留言ID" json:"reply_comment_id"`
+	CreateTime     time.Time `description:"留言创建时间" json:"create_time"`
 }
 
 type RespCommentAdd struct {
-	CommentId    uint64 `description:"留言ID" json:"comment_id"`
+	CommentId uint64 `description:"留言ID" json:"comment_id"`
 }

+ 25 - 1
models/response/community.go

@@ -1,5 +1,7 @@
 package response
 
+import "time"
+
 type CommunityQuestionItem struct {
 	CommunityQuestionID     int    `json:"community_question_id"`
 	UserId                  int    `json:"user_id"`
@@ -88,7 +90,29 @@ type RespCommunityQuestionLikeRoast struct {
 	Enabled  int8  `description:"本次点赞/吐槽结果: 0-已取消赞 1-有效赞" json:"like_enabled"`
 }
 
-// RespCommunityQuestionCommentAdd 问答留言返回
+// RespCommunityQuestionCommentAdd 新增问答留言返回
 type RespCommunityQuestionCommentAdd struct {
 	CommunityQuestionCommentID uint64 `description:"留言ID" json:"community_question_comment_id"`
 }
+
+// RespCommunityQuestionCommentItem 问答留言列表的数据返回
+type RespCommunityQuestionCommentItem struct {
+	CommunityQuestionCommentID uint64    `description:"留言ID" json:"community_question_comment_id"`
+	UserId                     uint64    `description:"用户id" json:"user_id"`
+	Content                    string    `description:"留言内容" json:"content"`
+	IsTop                      int8      `description:"是否置顶(0-未置顶,1-置顶)" json:"is_top"`
+	IsHot                      int8      `description:"是否设置精选(0-未设置,1-已设置)" json:"is_hot"`
+	HotTopTime                 time.Time `description:"设置精选或者设置置顶的时间" json:"hot_top_time"`
+	IsShowName                 int8      `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+	UserName                   string    `description:"用户昵称" json:"user_name"`
+	UserImgUrl                 string    `description:"用户头像" json:"user_img_url"`
+	CreateTime                 time.Time `description:"留言创建时间" json:"create_time"`
+	ReplyList                  []*ReplyItem
+}
+
+// RespCommunityQuestionCommentList 问答留言列表接口返回
+type RespCommunityQuestionCommentList struct {
+	List       []*RespCommunityQuestionCommentItem `json:"list"`
+	Paging     *PagingItem                         `json:"paging"`
+	IsShowName int8                                `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+}

+ 18 - 41
models/tables/yb_community_question_comment/query.go

@@ -14,11 +14,11 @@ func GetByCommunityQuestionCommentId(communityQuestionCommentId uint64) (item *Y
 	return
 }
 
-// GetListByUserIdReportId 获取用户的留言列表
-func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list []*YbCommunityQuestionComment, err error) {
+// GetListByUserIdCommunityQuestionCommentID 获取用户的留言列表
+func GetListByUserIdCommunityQuestionCommentID(userId uint64, communityQuestionCommentID int) (list []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("user_id = ? and report_id = ? and report_chapter_id = ? and enabled = 1 ", userId, reportId, reportChapterId).
-		Order("create_time desc, comment_id desc").
+		Where("user_id = ? AND community_question_id = ? AND enabled = 1 ", userId, communityQuestionCommentID).
+		Order("create_time desc, community_question_comment_id desc").
 		Scan(&list).Error
 	if err == utils.ErrNoRow {
 		err = nil
@@ -26,52 +26,29 @@ func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list
 	return
 }
 
-// GetListByUserIdOldReportId 获取用户的留言列表
-func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbCommunityQuestionComment, err error) {
+// GetListTotalByUserIdCommunityQuestionCommentID 获取用户的留言总条数
+func GetListTotalByUserIdCommunityQuestionCommentID(userId uint64, communityQuestionCommentID int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ? and enabled = 1 ", userId, oldReportId, oldReportChapterId).
-		Order("create_time desc, comment_id desc").
-		Scan(&list).Error
-	if err == utils.ErrNoRow {
-		err = nil
-	}
-	return
-}
-
-// GetHotListByReportId 获取报告的精选留言列表
-func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
-	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
-		Order("is_top desc, hot_top_time desc, comment_id desc").
-		Offset(offset).
-		Limit(limit).
-		Scan(&list).Error
-	return
-}
-
-// GetHotListTotalByReportId 获取精选留言总条数
-func GetHotListTotalByReportId(reportId, reportChapterId int) (total int64, err error) {
-	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
+		Where("user_id = ? AND community_question_id = ? AND enabled = 1 ", userId, communityQuestionCommentID).
 		Count(&total).Error
 	return
 }
 
-// GetHotListByOldReportId 获取老报告的精选留言列表
-func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
+// GetHotListByCommunityQuestionCommentID 获取报告的精选留言列表
+func GetHotListByCommunityQuestionCommentID(communityQuestionCommentID int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
-		Order("is_top desc, hot_top_time desc, comment_id desc").
+		Where("community_question_id = ? AND enabled = 1 AND is_hot = 1 AND type = 1", communityQuestionCommentID).
+		Order("is_top desc, hot_top_time desc, community_question_comment_id desc").
 		Offset(offset).
 		Limit(limit).
 		Scan(&list).Error
 	return
 }
 
-// GetHotListTotalByOldReportId 获取老报告的精选留言总条数
-func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total int64, err error) {
+// GetHotListTotalByCommunityQuestionCommentID 获取精选留言总条数
+func GetHotListTotalByCommunityQuestionCommentID(communityQuestionCommentID int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
+		Where("community_question_id = ? AND enabled = 1 AND is_hot = 1 AND type = 1", communityQuestionCommentID).
 		Count(&total).Error
 	return
 }
@@ -80,7 +57,7 @@ func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total in
 func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
 		Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
-		Order("comment_id asc").
+		Order("community_question_comment_id asc").
 		Scan(&list).Error
 	return
 }
@@ -96,7 +73,7 @@ type SimpleYbCommunityQuestionComment struct {
 func GetSimpleByCommentId(commentId uint64) (item *SimpleYbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
 		Select("community_question_comment_id, user_id, type, enabled").
-		Where("comment_id = ?", commentId).First(&item).Error
+		Where("community_question_comment_id = ?", commentId).First(&item).Error
 	if err == utils.ErrNoRow {
 		err = nil
 	}
@@ -107,7 +84,7 @@ func GetSimpleByCommentId(commentId uint64) (item *SimpleYbCommunityQuestionComm
 func GetMyLatestComment(userId uint64) (item *YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
 		Select("comment_id, user_id, type, enabled, is_show_name").
-		Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
+		Where("user_id = ? and type=1", userId).Order("community_question_comment_id desc").First(&item).Error
 	return
 }
 
@@ -136,7 +113,7 @@ func GetLastHotListByCommunityQuestionIds(communityQuestionIds []uint32) (items
 // GetLastMyListByCommunityQuestionIds 根据问答id列表获取我最近的留言
 func GetLastMyListByCommunityQuestionIds(userId uint64, communityQuestionIds []uint32) (items []*YbCommunityQuestionComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
-		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE user_id=? AND community_question_id IN (?) AND enabled = 1 AND is_hot = 1 AND type = 1)", userId, communityQuestionIds).
+		Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE user_id=? AND community_question_id IN (?) AND enabled = 1 AND type = 1)", userId, communityQuestionIds).
 		Find(&items).Error
 	return
 }

+ 4 - 0
routers/community.go

@@ -8,6 +8,7 @@ import (
 
 func InitCommunity(r *gin.Engine) {
 	rGroup := r.Group("api/community").Use(middleware.Token(), middleware.CheckBaseAuth())
+
 	// 问答社区
 	rGroup.GET("/question/list", community.QuestionList)
 	rGroup.GET("/question/detail", community.QuestionDetail)
@@ -30,4 +31,7 @@ func InitCommunity(r *gin.Engine) {
 	rGroup.POST("/comment/delete", community.DeleteComment)
 	rGroup.GET("/need_anonymous_user_tips", community.GetNeedCommentAnonymousUserTips)
 	rGroup.POST("/set_anonymous_user_tips", community.SetCommentAnonymousUserTips)
+	rGroup.GET("/comment/hot", community.HotList)
+	rGroup.GET("/comment/my", community.MyList)
+
 }