Browse Source

点赞和留言模块兼容老报告

xiexiaoyuan 2 years ago
parent
commit
a394bc5249

+ 75 - 31
controller/comment/comment.go

@@ -48,6 +48,8 @@ func Delete(c *gin.Context) {
 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))
 
@@ -61,28 +63,47 @@ func HotList(c *gin.Context)  {
 		response.Fail("请输入正确的页码", c)
 		return
 	}
-
-	if reqReportId == ""{
-		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
+		}
 	}
-	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 reqReportChapterId == "" {
-		response.Fail("请输入章节ID", c)
-		return
+
+	if reqOldReportId != ""{
+		oldReportId, err = strconv.Atoi(reqOldReportId)
+		if err != nil {
+			response.Fail("老报告ID格式有误", c)
+			return
+		}
 	}
-	reportChapterId, err := strconv.Atoi(reqReportChapterId)
-	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)
 
-	list, err := commentService.List(userinfo, reportId, reportChapterId, true, pageIndex, pageSize)
+	list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId,true, pageIndex, pageSize)
 	if err != nil {
 		response.Fail(err.Error(), c)
 		return
@@ -95,28 +116,51 @@ func HotList(c *gin.Context)  {
 func MyList(c *gin.Context)  {
 	reqReportId := c.DefaultQuery("report_id", "")
 	reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
-	if reqReportId == ""{
-		response.Fail("请输入报告ID", c)
-		return
+
+	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
+		}
 	}
-	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 reqReportChapterId == "" {
-		response.Fail("请输入章节ID", c)
-		return
+
+	if reqOldReportId != ""{
+		oldReportId, err = strconv.Atoi(reqOldReportId)
+		if err != nil {
+			response.Fail("老报告ID格式有误", c)
+			return
+		}
 	}
-	reportChapterId, err := strconv.Atoi(reqReportChapterId)
-	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)
 
-	list, err := commentService.List(userinfo, reportId, reportChapterId, false, 0, 0)
+	list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId, false, 0, 0)
 	if err != nil {
 		response.Fail(err.Error(), c)
 		return

+ 2 - 0
models/request/comment/comment.go

@@ -6,6 +6,8 @@ type ReqComment struct {
 	ReportChapterId        int `description:"报告章节ID" json:"report_chapter_id" `
 	IsShowName             int8 `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
 	SourceAgent            int  `description:"留言入口来源,1:小程序,2:pc" json:"source_agent"`
+	OldReportId            int `description:"老后台报告ID (research_report_id)" json:"old_report_id" `
+	OldReportChapterId     int `description:"老后台报告章节ID(research_report_type_id)" json:"old_report_chapter_id" `
 }
 
 type ReqDel struct {

+ 3 - 3
models/request/like/like.go

@@ -3,7 +3,7 @@ package like
 type ReqLike struct {
 	ReportId               int `description:"报告ID" json:"report_id" `
 	ReportChapterId        int `description:"报告章节ID" json:"report_chapter_id" `
-	OldReportId            int `description:"老后台报告ID" json:"old_report_id" `
-	OldReportChapterId     int `description:"老后台报告章节ID" json:"old_report_chapter_id" `
-	SourceAgent            int  `description:"留言入口来源,1:小程序,2:pc" json:"source_agent"`
+	OldReportId            int `description:"老后台报告ID (research_report_id)" json:"old_report_id" `
+	OldReportChapterId     int `description:"老后台报告章节ID(research_report_type_id)" json:"old_report_chapter_id" `
+	SourceAgent            int `description:"点赞入口来源,1:小程序,2:小程序pc" json:"source_agent"`
 }

+ 10 - 0
models/tables/rddp/report/query.go

@@ -311,4 +311,14 @@ WHERE
 	`
 	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, typeIds).Count(&total).Error
 	return
+}
+
+// GetReportByOldReportId 根据老后台的research_report_id查找新的报告ID
+func GetReportByOldReportId(oldReportId uint64)(item *Report, err error)  {
+	err = global.MYSQL["rddp"].Model(Report{}).
+		Where("old_report_id=?", oldReportId).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
 }

+ 12 - 0
models/tables/rddp/report_chapter/query.go

@@ -113,4 +113,16 @@ func GetByTypeIdsAndReportIds(typeIds []int,  reportIds []int, classifyNameFirst
 		reportIds = append(reportIds, v.ReportId)
 	}
 	return
+}
+
+// GetChapterByReportIdTypeId 根据报告ID和章节类型ID查找章节
+func GetChapterByReportIdTypeId(reportId, typeId int) (chapter *ReportChapter, err error) {
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).
+		Select("report_id, type_id, report_chapter_id").
+		Where("report_id = ? and type_id = ?", reportId, typeId).
+		First(&chapter).Error
+	if err == utils.ErrNoRow {
+		err =nil
+	}
+	return
 }

+ 33 - 2
models/tables/yb_comment/query.go

@@ -18,6 +18,18 @@ func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list
 	return
 }
 
+// GetListByUserIdOldReportId 获取用户的留言列表
+func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbComment{}).
+		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 []*YbComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
@@ -29,14 +41,33 @@ func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (lis
 	return
 }
 
-// GetHostListTotalByReportId 获取精选留言总条数
-func GetHostListTotalByReportId(reportId, reportChapterId int)(total int64, err error)  {
+// GetHotListTotalByReportId 获取精选留言总条数
+func GetHotListTotalByReportId(reportId, reportChapterId int)(total int64, err error)  {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
 		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
 		Count(&total).Error
 	return
 }
 
+// GetHotListByOldReportId 获取老报告的精选留言列表
+func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbComment{}).
+		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").
+		Offset(offset).
+		Limit(limit).
+		Scan(&list).Error
+	return
+}
+
+// GetHotListTotalByOldReportId 获取老报告的精选留言总条数
+func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int)(total int64, err error)  {
+	err = global.DEFAULT_MYSQL.Model(YbComment{}).
+		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
+		Count(&total).Error
+	return
+}
+
 // GetReplyListByReplyCommentId 获取报告的精选留言的回复列表
 func GetReplyListByReplyCommentId(reportId, reportChapterId int, replyCommentIds []uint64) (list []*YbComment, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).

+ 21 - 20
models/tables/yb_comment/yb_comment.go

@@ -4,26 +4,27 @@ import "time"
 
 // 研报 用户留言表
 type YbComment struct {
-	CommentId         uint64 `gorm:"primaryKey;column:comment_id;type:bigint(20) unsigned;not null" ` //留言ID
-	UserId            uint64 `gorm:"column:user_id"` //用户id
-	AdminId           uint64 `gorm:"column:admin_id"` //发布留言回复的管理员ID
-	ReportId          int `gorm:"column:report_id"` //报告ID
-	ReportChapterId   int `gorm:"column:report_chapter_id"` //报告章节ID
-	Content           string `gorm:"column:content"` //留言内容
-	SysIsRead         int8 `gorm:"column:sys_is_read"` //管理员是否已读 0-未读,1-已读
-	SysReadTime       time.Time `gorm:"column:sys_read_time"` //管理员已读时间
-	SysReadAdminId    int64 `gorm:"column:sys_read_admin_id"` //已读的管理员id
-	ReplyCommentId    uint64 `gorm:"column:reply_comment_id"` //回复的留言ID
-	IsTop             int8 `gorm:"column:is_top"` //是否置顶(0-未置顶,1-置顶)
-	IsHot             int8 `gorm:"column:is_hot"` //是否设置精选(0-未设置,1-已设置)
-	HotTime           time.Time `gorm:"column:hot_time"` //设置精选的时间
-	HotTopTime        time.Time `gorm:"column:hot_top_time"` //设置精选或者设置置顶的时间
-	Type              int8 `gorm:"column:type"` //留言类型 1-评论 2-回复
-	Enabled           int8 `gorm:"column:enabled"` //是否有效, 0-无效留言 1-有效留言
-	IsShowName        int8 `gorm:"column:is_show_name"` //是否匿名 0-匿名,1-不匿名
-	SourceAgent       int `gorm:"column:source_agent"` //留言入口来源,1:小程序,2:pc
-	CreateTime        time.Time `gorm:"column:create_time"` //创建时间
-	ModifyTime        time.Time `gorm:"column:modify_time"` //修改时间
+	CommentId                 uint64 `gorm:"primaryKey;column:comment_id;type:bigint(20) unsigned;not null" ` //留言ID
+	UserId                    uint64 `gorm:"column:user_id"` //用户id
+	AdminId                   uint64 `gorm:"column:admin_id"` //发布留言回复的管理员ID
+	ReportId                  int `gorm:"column:report_id"` //报告ID
+	ReportChapterId           int `gorm:"column:report_chapter_id"` //报告章节ID
+	Content                   string `gorm:"column:content"` //留言内容
+	SysIsRead                 int8 `gorm:"column:sys_is_read"` //管理员是否已读 0-未读,1-已读
+	SysReadTime               time.Time `gorm:"column:sys_read_time"` //管理员已读时间
+	SysReadAdminId            int64 `gorm:"column:sys_read_admin_id"` //已读的管理员id
+	ReplyCommentId            uint64 `gorm:"column:reply_comment_id"` //回复的留言ID
+	IsTop                     int8 `gorm:"column:is_top"` //是否置顶(0-未置顶,1-置顶)
+	IsHot                     int8 `gorm:"column:is_hot"` //是否设置精选(0-未设置,1-已设置)
+	HotTopTime                time.Time `gorm:"column:hot_top_time"` //设置精选或者设置置顶的时间
+	Type                      int8 `gorm:"column:type"` //留言类型 1-评论 2-回复
+	Enabled                   int8 `gorm:"column:enabled"` //是否有效, 0-无效留言 1-有效留言
+	IsShowName                int8 `gorm:"column:is_show_name"` //是否匿名 0-匿名,1-不匿名
+	SourceAgent               int `gorm:"column:source_agent"` //留言入口来源,1:小程序,2:pc
+	CreateTime                time.Time `gorm:"column:create_time"` //创建时间
+	ModifyTime                time.Time `gorm:"column:modify_time"` //修改时间
+	OldReportId               int `gorm:"column:old_report_id"  json:"old_report_id" ` //老报告ID
+	OldReportChapterId        int `gorm:"column:old_report_chapter_id" json:"old_report_chapter_id" ` //老报告章节ID
 }
 
 func (yc *YbComment) TableName() string {

+ 19 - 0
models/tables/yb_like/query.go

@@ -17,10 +17,29 @@ func GetLikeByUserIdAndReportId(userId uint64, reportId, reportChapterId int) (i
 	return
 }
 
+// GetLikeByUserIdAndOldReportId 获取点赞记录
+func GetLikeByUserIdAndOldReportId(userId uint64, oldReportId, oldReportChapterId int) (item *YbLike, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbLike{}).
+		Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ?", userId, oldReportId, oldReportChapterId).
+		First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
 // GetLikeNumByReportId 统计报告的点赞数
 func GetLikeNumByReportId(reportId, reportChapterId int) (num int64, err error) {
 	err = global.DEFAULT_MYSQL.Model(YbLike{}).
 		Where("report_id = ? and report_chapter_id = ? and enabled=1", reportId, reportChapterId).
 		Count(&num).Error
 	return
+}
+
+// GetLikeNumByOldReportId 统计报告的点赞数
+func GetLikeNumByOldReportId(oldReportId, oldReportChapterId int) (num int64, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbLike{}).
+		Where("old_report_id = ? and old_report_chapter_id = ? and enabled=1", oldReportId, oldReportChapterId).
+		Count(&num).Error
+	return
 }

+ 2 - 0
models/tables/yb_like/yb_like.go

@@ -12,6 +12,8 @@ type YbLike struct {
 	ReportId               int `gorm:"column:report_id"  json:"report_id" ` //报告ID
 	ReportChapterId        int `gorm:"column:report_chapter_id" json:"report_chapter_id" ` //报告章节ID
 	SourceAgent            int `gorm:"column:source_agent"` //留言入口来源,1:小程序,2:pc
+	OldReportId               int `gorm:"column:old_report_id"  json:"old_report_id" ` //老报告ID
+	OldReportChapterId        int `gorm:"column:old_report_chapter_id" json:"old_report_chapter_id" ` //老报告章节ID
 }
 
 func (yl *YbLike) TableName() string {

+ 75 - 54
services/comment/comment.go

@@ -6,10 +6,9 @@ import (
 	"hongze/hongze_yb/global"
 	reqComment "hongze/hongze_yb/models/request/comment"
 	"hongze/hongze_yb/models/response"
-	report "hongze/hongze_yb/models/tables/rddp/report"
-	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_comment"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
@@ -33,52 +32,35 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
 		err = errors.New("请输入留言内容")
 		return
 	}
-	if req.ReportId <= 0 && req.ReportChapterId <= 0 {
-		err = errors.New("请输入报告ID")
-		return
-	}
+	reportId := req.ReportId
+	reportChapterId := req.ReportChapterId
+
 	if req.SourceAgent == 0 {
 		err = errors.New("请输入留言来源")
 		return
 	}
-
-	//todo 校验权限
-	// 校验报告是否存在
-	reportInfo, err := report.GetByReportId(req.ReportId)
-	if err != nil {
-		errMsg = err.Error()
-		err = errors.New("查询报告出错")
-		return
-	}
-	if reportInfo.Id <=0  {
-		err = errors.New("报告不存在")
+	if req.ReportChapterId <=0 && req.ReportId <=0 && req.OldReportId <=0 && req.OldReportChapterId <=0{
+		err = errors.New("请输入报告ID")
 		return
 	}
-
-	if (reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报") && req.ReportChapterId <=0 {
-		err = errors.New("请输入报告章节ID")
+	// todo 判断是否有留言权限
+	err, errMsg = services.CheckSimpleCompanyProduct(user)
+	if err != nil {
 		return
 	}
-
-	if req.ReportChapterId > 0 {
-		reportChapterInfo, tErr := report_chapter.GetTypeIdById(req.ReportChapterId)
-		if tErr != nil {
-			errMsg = tErr.Error()
-			err = errors.New("查询章节失败")
-			return
-		}
-
-		if reportChapterInfo.ReportChapterId == 0 {
-			err = errors.New("章节不存在或者未发布")
+	//处理老报告, 转化成新报告ID
+	if req.ReportChapterId <=0 && req.ReportId <=0 && (req.OldReportId >0 || req.OldReportChapterId > 0) {
+		reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(req.OldReportId), uint64(req.OldReportChapterId))
+		if err != nil {
 			return
 		}
-
-		if reportChapterInfo.ReportId != req.ReportId {
-			err = errors.New("章节ID和报告ID不匹配")
+	} else {
+		// 判断报告ID是否正确
+		err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
+		if err != nil {
 			return
 		}
 	}
-
 	// 敏感词过滤
 	checkResult, err := wx_app.MsgSecCheck(user.OpenID, req.Content)
 	if err != nil {
@@ -95,14 +77,16 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
 	commentInfo := &yb_comment.YbComment{
 		UserId: user.UserID,
 		Content: req.Content,
-		ReportId: req.ReportId,
-		ReportChapterId: req.ReportChapterId,
+		ReportId: reportId,
+		ReportChapterId: reportChapterId,
 		IsShowName: req.IsShowName,
 		SourceAgent: req.SourceAgent,
 		Type: 1,
 		Enabled: 1,
 		CreateTime: now,
 		ModifyTime: now,
+		OldReportId:    req.OldReportId,
+		OldReportChapterId: req.OldReportChapterId,
 	}
 	err = commentInfo.Create()
 	if err != nil {
@@ -158,7 +142,7 @@ func Delete(user user.UserInfo, req *reqComment.ReqDel) (err error) {
 }
 
 // List 查询精选留言列表或我的留言列表
-func List(user user.UserInfo,  reportId, reportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
+func List(user user.UserInfo,  reportId, reportChapterId, oldReportId, oldReportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -166,31 +150,68 @@ func List(user user.UserInfo,  reportId, reportChapterId int, hotFlag bool, page
 		}
 	}()
 
+	if reportId <=0 && reportChapterId <=0 && oldReportId <=0 && oldReportChapterId <=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))
+		if err != nil {
+			return
+		}
+	}
 	offset := (pageIndex -1)*pageSize
 	var commentList []*yb_comment.YbComment
 	var total int64
 	//查询精选留言
 	if hotFlag {
-		commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
-		if err != nil {
-			errMsg = err.Error()
-			err = errors.New("查询精选留言列表出错")
-			return
-		}
-		total, err = yb_comment.GetHostListTotalByReportId(reportId, reportChapterId)
-		if err != nil {
-			errMsg = err.Error()
-			err = errors.New("查询精选留言总数出错")
-			return
+		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 {
 		//查询个人留言
-		commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
-		if err != nil {
-			errMsg = err.Error()
-			err = errors.New("查询精选留言列表出错")
-			return
+		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
+			}
 		}
+
 	}
 
 	var commentIds []uint64

+ 40 - 8
services/like/like.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_yb/models/request/like"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/yb_like"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/user"
 	"time"
 )
@@ -19,20 +20,43 @@ func SetLike(user user.UserInfo, req like.ReqLike) (resp response.RespLike, err
 			global.LOG.Critical(fmt.Sprintf("GetReportList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
 		}
 	}()
+	reportId := req.ReportId
+	reportChapterId := req.ReportChapterId
+
 	if req.SourceAgent == 0 {
 		err = errors.New("请输入点赞来源")
 		return
 	}
-	//todo 判断是否是老报告
-	if req.ReportChapterId <=0 && req.ReportId <=0 {
+	if req.ReportChapterId <=0 && req.ReportId <=0 && req.OldReportId <=0 && req.OldReportChapterId <=0{
 		err = errors.New("请输入报告ID")
 		return
 	}
-	//todo 判断是否有点赞权限, 判断报告ID是否正确
-
+	// todo 判断是否有点赞权限
+	err, errMsg = services.CheckSimpleCompanyProduct(user)
+	if err != nil {
+		return
+	}
+	//处理老报告, 转化成新报告ID
+	if req.ReportChapterId <=0 && req.ReportId <=0 && (req.OldReportId >0 || req.OldReportChapterId > 0) {
+		reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(req.OldReportId), uint64(req.OldReportChapterId))
+		if err != nil {
+			return
+		}
+	} else {
+		// 判断报告ID是否正确
+		err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
+		if err != nil {
+			return
+		}
+	}
 
 	//查询用户对研报的点赞状态
-	likeItem, err := yb_like.GetLikeByUserIdAndReportId(user.UserID, req.ReportId, req.ReportChapterId)
+	var likeItem *yb_like.YbLike
+	if reportId > 0 {
+		likeItem, err = yb_like.GetLikeByUserIdAndReportId(user.UserID, reportId, reportChapterId)
+	} else {
+		likeItem, err = yb_like.GetLikeByUserIdAndOldReportId(user.UserID, req.OldReportId, req.OldReportChapterId)
+	}
 	if err != nil {
 		errMsg = err.Error()
 		err = errors.New("查询用户点赞记录出错")
@@ -42,13 +66,15 @@ func SetLike(user user.UserInfo, req like.ReqLike) (resp response.RespLike, err
 	now :=  time.Now()
 	if likeItem.LikeId <= 0 {
 		likeItem = &yb_like.YbLike{
-			ReportId:          req.ReportId,
-			ReportChapterId:   req.ReportChapterId,
+			ReportId:          reportId,
+			ReportChapterId:   reportChapterId,
 			UserId:            user.UserID,
 			Enabled:         1,
 			CreateTime:     now,
 			ModifyTime:     now,
 			SourceAgent:    req.SourceAgent,
+			OldReportId:    req.OldReportId,
+			OldReportChapterId: req.OldReportChapterId,
 		}
 		err = likeItem.Create()
 		if err != nil {
@@ -82,7 +108,13 @@ func SetLike(user user.UserInfo, req like.ReqLike) (resp response.RespLike, err
 		}
 	}
 	//查询总的点赞数
-	likeNum, err := yb_like.GetLikeNumByReportId(req.ReportId, req.ReportChapterId)
+	var likeNum int64
+	if reportId > 0 {
+		likeNum, err = yb_like.GetLikeNumByReportId(reportId, reportChapterId)
+	}else{
+		likeNum, err = yb_like.GetLikeNumByOldReportId(req.OldReportId, req.OldReportChapterId)
+	}
+
 	if err != nil {
 		errMsg = err.Error()
 		err = errors.New("查询点赞数出错")

+ 136 - 0
services/yb_common.go

@@ -0,0 +1,136 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_yb/models/tables/company_product"
+	"hongze/hongze_yb/models/tables/rddp/report"
+	"hongze/hongze_yb/models/tables/rddp/report_chapter"
+	"hongze/hongze_yb/models/tables/research_report_type"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
+	"strings"
+)
+
+// GetReportIdReportChapterIdByOldReportId 根据老报告的ID查询对应的新报告ID
+func GetReportIdReportChapterIdByOldReportId(oldReportId, oldReportChapterId uint64) (reportId int, reportChapterId int, err error, errMsg string)  {
+	var reportNew *report.Report
+	if oldReportChapterId >0 {
+		//查询章节详情,根据章节类型ID和老报告ID,根据老报告ID,查询新报告ID,根据新报告ID和type_id 找到新的章节ID
+		var oldReportChapter *research_report_type.ResearchReportTypeInfo
+		var reportChapterNew *report_chapter.ReportChapter
+		oldReportChapter, err = research_report_type.GetResearchReportTypeInfo(oldReportChapterId)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("找不到报告章节")
+			return
+		}
+		if  oldReportChapter == nil {
+			err = errors.New("找不到报告章节")
+			return
+		}
+		if oldReportId != oldReportChapter.ResearchReportID {
+			err = errors.New("报告ID和章节ID不一致")
+			return
+		}
+		reportNew, err = report.GetReportByOldReportId(oldReportChapter.ResearchReportID)
+		if err != nil {
+			errMsg = err.Error()
+			//err = errors.New("找不到新版报告")
+			return
+		}
+		if reportNew.Id <=0 {
+			//err = errors.New("找不到新版报告")
+			return
+		}
+		reportChapterNew, err = report_chapter.GetChapterByReportIdTypeId(reportNew.Id, oldReportChapter.TypeID)
+		if err != nil {
+			errMsg = err.Error()
+			return
+		}
+		if reportChapterNew.ReportChapterId <= 0 {
+			//err = errors.New("找不到新版章节")
+			return
+		}
+		reportId = reportNew.Id
+		reportChapterId = reportChapterNew.ReportChapterId
+		return
+	}else if oldReportId > 0 {
+		// 查询新报告ID
+		reportNew, err = report.GetReportByOldReportId(oldReportId)
+		if err != nil {
+			errMsg = err.Error()
+			//err = errors.New("找不到新版报告")
+			return
+		}
+		reportId = reportNew.Id
+        return
+	}
+	return
+}
+// CheckReportExistByReportIdReportChapterId 评论和点赞时,校验传入的报告ID是否正确
+func CheckReportExistByReportIdReportChapterId(reportId, reportChapterId int)(err error, errMsg string) {
+	reportInfo, err := report.GetByReportId(reportId)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询报告出错")
+		return
+	}
+	if reportInfo.Id <=0  {
+		err = errors.New("报告不存在")
+		return
+	}
+
+	if (reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报") && reportChapterId <=0 {
+		err = errors.New("请输入报告章节ID")
+		return
+	}
+
+	if reportChapterId > 0 {
+		reportChapterInfo, tErr := report_chapter.GetTypeIdById(reportChapterId)
+		if tErr != nil {
+			errMsg = tErr.Error()
+			err = errors.New("查询章节失败")
+			return
+		}
+
+		if reportChapterInfo.ReportChapterId == 0 {
+			err = errors.New("章节不存在或者未发布")
+			return
+		}
+
+		if reportChapterInfo.ReportId != reportId {
+			err = errors.New("章节ID和报告ID不匹配")
+			return
+		}
+	}
+	return
+}
+
+// CheckSimpleCompanyProduct 校验用户是否FICC产品的已购或者试用状态
+func CheckSimpleCompanyProduct(userinfo user.UserInfo) (err error, errMsg string){
+	// 判断用户状态是否是正常和永续
+	var productAuthOk bool
+	companyProduct, err := company_product.GetByCompany2ProductId(userinfo.CompanyID, 1)
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询用户购买产品出错")
+		return
+	}
+	if companyProduct != nil {
+		// 无FICC权限的客户不可见
+		if companyProduct.CompanyProductID > 0 {
+			// 已购或者试用用户可见
+			if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
+				productAuthOk = true
+			}
+		}
+	}
+	if !productAuthOk {
+		err = errors.New("无权操作")
+		return
+	}
+	return
+}