浏览代码

新老报告详情新增点赞数

xiexiaoyuan 2 年之前
父节点
当前提交
57e2db94e2
共有 5 个文件被更改,包括 74 次插入3 次删除
  1. 15 1
      logic/report/research_report.go
  2. 5 1
      models/response/report.go
  3. 8 0
      services/report/report.go
  4. 8 1
      services/report/report_chapter.go
  5. 38 0
      services/yb_common.go

+ 15 - 1
logic/report/research_report.go

@@ -12,6 +12,7 @@ import (
 	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/models/tables/user_view_history"
 	"hongze/hongze_yb/models/tables/user_view_history"
 	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/wx_user"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 	"strconv"
 	"strconv"
 	"time"
 	"time"
@@ -22,6 +23,8 @@ type ResearchReportInfo struct {
 	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
 	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
 	HasMenu                       int                                                 `json:"has_menu"`
 	HasMenu                       int                                                 `json:"has_menu"`
 	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
 	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+	LikeNum                       int64                                               `description:"点赞总数" json:"like_num"`
+	LikeEnabled                   int8                                                `description:"是否已点赞: 0-未点赞 1-已点赞" json:"like_enabled"`
 }
 }
 
 
 // GetResearchReportInfo 获取报告详情
 // GetResearchReportInfo 获取报告详情
@@ -122,14 +125,19 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	//添加阅读日志的数据加入到redis
 	//添加阅读日志的数据加入到redis
 	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
 	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
 
 
+	//查询点赞数
+	likeNum,likeEnabled, _ := services.GetReportLikeByReportIdOldReportId(wxUserInfo.UserID, 0, 0, int(researchReportId),0)
+
 	result = ResearchReportInfo{
 	result = ResearchReportInfo{
 		ResearchReportInfo:     reportInfo,
 		ResearchReportInfo:     reportInfo,
 		ResearchReportTypeList: researchReportTypeList,
 		ResearchReportTypeList: researchReportTypeList,
 		HasMenu:                1,
 		HasMenu:                1,
+		LikeNum:                likeNum,
+		LikeEnabled:            likeEnabled,
 	}
 	}
 
 
 	if len(researchReportTypeList) <= 0 {
 	if len(researchReportTypeList) <= 0 {
-
+		
 	} else if len(researchReportTypeList) == 1 {
 	} else if len(researchReportTypeList) == 1 {
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		result.HasMenu = 0
 		result.HasMenu = 0
@@ -146,6 +154,8 @@ type ResearchReportTypeContentInfo struct {
 	ResearchReportTypeInfo        *research_report_type.ResearchReportTypeInfo `json:"research_report_type_info"`
 	ResearchReportTypeInfo        *research_report_type.ResearchReportTypeInfo `json:"research_report_type_info"`
 	Add                           int                                          `json:"add"`
 	Add                           int                                          `json:"add"`
 	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
 	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
+	LikeNum                       int64                                        `description:"点赞总数" json:"like_num"`
+	LikeEnabled                   int8                                         `description:"是否已点赞: 0-未点赞 1-已点赞" json:"like_enabled"`
 }
 }
 
 
 // GetResearchReportTypeContentInfo 获取报告章节详情
 // GetResearchReportTypeContentInfo 获取报告章节详情
@@ -247,10 +257,14 @@ func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (resu
 	//添加阅读日志的数据加入到redis
 	//添加阅读日志的数据加入到redis
 	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
 	go PushViewRecordNewRedisData(userViewHistory, int(wxUserInfo.CompanyID))
 
 
+	//查询点赞数
+	likeNum,likeEnabled, _ := services.GetReportLikeByReportIdOldReportId(wxUserInfo.UserID, 0, 0, int(researchReportTypeInfo.ResearchReportID), int(researchReportTypeInfo.ResearchReportTypeID))
 	result = ResearchReportTypeContentInfo{
 	result = ResearchReportTypeContentInfo{
 		ResearchReportTypeContentList: researchReportTypeContentList,
 		ResearchReportTypeContentList: researchReportTypeContentList,
 		ResearchReportTypeInfo:        researchReportTypeInfo,
 		ResearchReportTypeInfo:        researchReportTypeInfo,
 		Add:                           add,
 		Add:                           add,
+		LikeNum:                       likeNum,
+		LikeEnabled:                   likeEnabled,
 	}
 	}
 	return
 	return
 }
 }

+ 5 - 1
models/response/report.go

@@ -9,6 +9,8 @@ type ReportDetail struct {
 	ReportChapterList        []*ReportChapterListItem `json:"report_chapter_list"`
 	ReportChapterList        []*ReportChapterListItem `json:"report_chapter_list"`
 	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	AuthOk              bool `json:"auth_ok"`
 	AuthOk              bool `json:"auth_ok"`
+	LikeNum             int64  `description:"点赞总数" json:"like_num"`
+	LikeEnabled         int8 `description:"是否已点赞: 0-未点赞 1-已点赞" json:"like_enabled"`
 }
 }
 
 
 type ReportChapterListItem struct {
 type ReportChapterListItem struct {
@@ -67,8 +69,10 @@ type ReportChapterItem struct {
 type ReportChapterDetail struct {
 type ReportChapterDetail struct {
 	ReportChapterItem  * ReportChapterItem  `json:"report_chapter_item"`
 	ReportChapterItem  * ReportChapterItem  `json:"report_chapter_item"`
 	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
 	PermissionCheck     *PermissionCheckInfo    `json:"permission_check"`
-	ReportChapterMenuList        []*ReportChapterMenu `json:"report_chapter_menu_list""`
+	ReportChapterMenuList        []*ReportChapterMenu `json:"report_chapter_menu_list"`
 	AuthOk              bool `json:"auth_ok"`
 	AuthOk              bool `json:"auth_ok"`
+	LikeNum             int64  `description:"点赞总数" json:"like_num"`
+	LikeEnabled         int8 `description:"是否已点赞: 0-未点赞 1-已点赞" json:"like_enabled"`
 }
 }
 
 
 type ReportChapterMenu struct {
 type ReportChapterMenu struct {

+ 8 - 0
services/report/report.go

@@ -19,6 +19,7 @@ import (
 	"hongze/hongze_yb/models/tables/rddp/report_chapter_ticker"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter_ticker"
 	"hongze/hongze_yb/models/tables/report_chapter_type"
 	"hongze/hongze_yb/models/tables/report_chapter_type"
 	"hongze/hongze_yb/models/tables/report_chapter_type_permission"
 	"hongze/hongze_yb/models/tables/report_chapter_type_permission"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/company"
 	elasticService "hongze/hongze_yb/services/elastic"
 	elasticService "hongze/hongze_yb/services/elastic"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/user"
@@ -443,17 +444,24 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 		}
 		}
 	}
 	}
 	//如果有权限则展示content
 	//如果有权限则展示content
+	var likeNum int64
+	var likeEnabled int8
 	if authOk {
 	if authOk {
 		task.Task(AddViewRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
 		task.Task(AddViewRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
 		reportItem.Content = html.UnescapeString(reportInfo.Content)
 		reportItem.Content = html.UnescapeString(reportInfo.Content)
 		reportItem.VideoUrl = reportInfo.VideoUrl
 		reportItem.VideoUrl = reportInfo.VideoUrl
+		//查询点赞数
+		likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(userinfo.UserID, reportInfo.Id, 0,0,0)
 	}
 	}
+
 	//新增用户访问日志
 	//新增用户访问日志
 	task.Task(AddUserAccessRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0, authOk)
 	task.Task(AddUserAccessRecord, userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0, authOk)
 	reportDetail.ReportInfo = reportItem
 	reportDetail.ReportInfo = reportItem
 	reportDetail.ReportChapterList = reportTypeList
 	reportDetail.ReportChapterList = reportTypeList
 	reportDetail.PermissionCheck = &permissionCheckInfo
 	reportDetail.PermissionCheck = &permissionCheckInfo
 	reportDetail.AuthOk = authOk
 	reportDetail.AuthOk = authOk
+	reportDetail.LikeNum = likeNum
+	reportDetail.LikeEnabled = likeEnabled
 	return
 	return
 }
 }
 
 

+ 8 - 1
services/report/report_chapter.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_yb/models/tables/rddp/report"
 	"hongze/hongze_yb/models/tables/rddp/report"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/report_chapter_type"
 	"hongze/hongze_yb/models/tables/report_chapter_type"
+	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/company"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/task"
 	"hongze/hongze_yb/task"
@@ -253,6 +254,8 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	reportChapterItem.Stage = reportChapter.Stage
 	reportChapterItem.Stage = reportChapter.Stage
 	reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
 	reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
 	reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
 	reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
+	var likeNum int64
+	var likeEnabled int8
 	if authOk {
 	if authOk {
 		reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
 		reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
 		reportChapterItem.VideoUrl = reportChapter.VideoUrl
 		reportChapterItem.VideoUrl = reportChapter.VideoUrl
@@ -262,17 +265,21 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		}else{
 		}else{
 			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
 			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
 		}
 		}
-
+		//查询点赞数
+		likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId,0,0)
 		task.Task(AddViewRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
 		task.Task(AddViewRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
 	}else{
 	}else{
 		reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
 		reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
 	}
 	}
+
 	task.Task(AddUserAccessRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
 	task.Task(AddUserAccessRecord, user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
 	reportChapterDetail = new(response.ReportChapterDetail)
 	reportChapterDetail = new(response.ReportChapterDetail)
 	reportChapterDetail.ReportChapterItem = reportChapterItem
 	reportChapterDetail.ReportChapterItem = reportChapterItem
 	reportChapterDetail.PermissionCheck = &permissionCheckInfo
 	reportChapterDetail.PermissionCheck = &permissionCheckInfo
 	reportChapterDetail.ReportChapterMenuList = chapterMenu
 	reportChapterDetail.ReportChapterMenuList = chapterMenu
 	reportChapterDetail.AuthOk = authOk
 	reportChapterDetail.AuthOk = authOk
+	reportChapterDetail.LikeNum = likeNum
+	reportChapterDetail.LikeEnabled = likeEnabled
 	return
 	return
 }
 }
 
 

+ 38 - 0
services/yb_common.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_yb/models/tables/rddp/report"
 	"hongze/hongze_yb/models/tables/rddp/report"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/models/tables/research_report_type"
+	"hongze/hongze_yb/models/tables/yb_like"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/services/user"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 	"strings"
 	"strings"
@@ -32,6 +33,11 @@ func GetReportIdReportChapterIdByOldReportId(oldReportId, oldReportChapterId uin
 			err = errors.New("报告ID和章节ID不一致")
 			err = errors.New("报告ID和章节ID不一致")
 			return
 			return
 		}
 		}
+		//判断是否是晨报或者周报的章节ID,双周报的章节ID不记录
+		if oldReportChapter.TypeID == 0 {
+			err = errors.New("只允许传晨报和周报的章节ID")
+			return
+		}
 		reportNew, err = report.GetReportByOldReportId(oldReportChapter.ResearchReportID)
 		reportNew, err = report.GetReportByOldReportId(oldReportChapter.ResearchReportID)
 		if err != nil {
 		if err != nil {
 			errMsg = err.Error()
 			errMsg = err.Error()
@@ -133,4 +139,36 @@ func CheckSimpleCompanyProduct(userinfo user.UserInfo) (err error, errMsg string
 		return
 		return
 	}
 	}
 	return
 	return
+}
+
+func GetReportLikeByReportIdOldReportId(userId uint64,reportId, reportChapterId int, oldReportId, oldReportChapterId int) (likeNum int64, likeEnabled int8, err error)  {
+	// 根据老报告找到新报告的ID
+	if reportId == 0 && oldReportId > 0{
+		reportId, reportChapterId, err, _ = GetReportIdReportChapterIdByOldReportId(uint64(oldReportId), uint64(oldReportChapterId))
+	}
+	//查询总的点赞数
+	if reportId > 0{
+		likeNum, err = yb_like.GetLikeNumByReportId(reportId, reportChapterId)
+	} else if oldReportId > 0{
+		likeNum, err = yb_like.GetLikeNumByOldReportId(oldReportId, oldReportChapterId)
+	}
+
+	if err != nil {
+		err = errors.New("查询点赞数出错")
+		return
+	}
+
+	//查询用户对研报的点赞状态
+	var likeItem *yb_like.YbLike
+	if reportId > 0 {
+		likeItem, err = yb_like.GetLikeByUserIdAndReportId(userId, reportId, reportChapterId)
+	} else {
+		likeItem, err = yb_like.GetLikeByUserIdAndOldReportId(userId, oldReportId, oldReportChapterId)
+	}
+	if err != nil {
+		err = errors.New("查询用户点赞记录出错")
+		return
+	}
+	likeEnabled = likeItem.Enabled
+	return
 }
 }