Browse Source

章节详情页底部菜单查询

xiexiaoyuan 3 years ago
parent
commit
678ad2e59f

+ 10 - 2
models/response/report.go

@@ -7,12 +7,12 @@ import (
 
 type ReportDetail struct {
 	ReportInfo          *ReportItem  `json:"report_info"`
-	ReportTypeList        []*ReportTypeListItem `json:"report_type_list"`
+	ReportChapterList        []*ReportChapterListItem `json:"report_chapter_list"`
 	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
 	AuthOk              bool `json:"auth_ok"`
 }
 
-type ReportTypeListItem struct {
+type ReportChapterListItem struct {
 	ReportChapterId    int    `json:"report_chapter_id"`
 	ReportId        int    `json:"report_id"`
 	Title           string    `json:"title"`
@@ -69,5 +69,13 @@ type ReportChapterItem struct {
 type ReportChapterDetail struct {
 	ReportChapterItem  * ReportChapterItem
 	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	ReportChapterMenuList        []*ReportChapterMenu `json:"report_chapter_menu_list""`
 	AuthOk              bool `json:"auth_ok"`
+}
+
+type ReportChapterMenu struct {
+	ReportChapterId    int    `json:"report_chapter_id"`
+	ReportId        int    `json:"report_id"`
+	ReportChapterTypeName   string       `json:"report_chapter_type_name"`
+	ReportChapterTypeThumb  string	    `json:"report_chapter_type_thumb"`
 }

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

@@ -37,6 +37,16 @@ func GetListByReportId(reportId int) (list []*ReportChapter, err error)  {
 	return
 }
 
+// GetListByReportIdTypeIds 根据报告ID、章节类型ID获取章节列表
+func GetListByReportIdTypeIds(reportId int, typeIds []int) (list []*ReportChapter, err error)  {
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).
+		Select("report_chapter_id, report_id, type_id, type_name, abstract, title, author, publish_time").
+		Where("report_id = ? AND type_id in (?) AND is_edit = 1 AND publish_state = 2 ", reportId, typeIds).
+		Order("sort asc, report_chapter_id asc").
+		Scan(&list).Error
+	return
+}
+
 // GetContentById 根据ID获取章节详情
 func GetContentById(id int, typeIds []int) (info *ReportChapter, err error)  {
 	err = global.MYSQL["rddp"].Select("report_chapter_id, report_id,  content, trend, type_id, type_name, abstract, title, author, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size").

+ 1 - 1
services/purchase/purchase.go

@@ -15,7 +15,7 @@ func GetLatestReportAndActivity(user user.UserInfo) (list purchase.PurchaseList,
 	if err != nil {
 		return
 	}
-	if len(permissionIds) <= 0 {
+	if len(permissionIds) == 0 {
 		err = errors.New("用户无权限")
 		return
 	}

+ 2 - 2
services/report/report.go

@@ -223,7 +223,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
 	reportItem.Author = reportInfo.Author
 
-	var reportTypeList []*response.ReportTypeListItem
+	var reportTypeList []*response.ReportChapterListItem
 	if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
 		reportTypeList, err = GetChapterListByReport(reportInfo.ClassifyNameFirst, reportInfo.Id, userinfo.CompanyID)
 		if err != nil {
@@ -237,7 +237,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 		reportItem.VideoUrl = reportInfo.VideoUrl
 	}
 	reportDetail.ReportInfo = reportItem
-	reportDetail.ReportTypeList = reportTypeList
+	reportDetail.ReportChapterList = reportTypeList
 	reportDetail.PermissionCheck = &permissionCheckInfo
 	reportDetail.AuthOk = authOk
 	return

+ 47 - 5
services/report/report_chapter.go

@@ -57,7 +57,7 @@ func GetWeekTypeIdsByPermissionIds(permissionIds []int, typeIds []int) (newTypeI
 }
 
 // GetChapterListByReport 根据报告获取章节列表
-func GetChapterListByReport(classifyNameFirst string, reportId int, companyId int64) (reportTypeList[]*response.ReportTypeListItem, err error) {
+func GetChapterListByReport(classifyNameFirst string, reportId int, companyId int64) (reportTypeList[]*response.ReportChapterListItem, err error) {
 	var errMsg string
 	defer func() {
 		if err != nil {
@@ -118,9 +118,8 @@ func GetChapterListByReport(classifyNameFirst string, reportId int, companyId in
 					continue
 				}
 			}
-			temp := new(response.ReportTypeListItem)
+			temp := new(response.ReportChapterListItem)
 			temp.ReportChapterId = item.ReportChapterId
-			temp.ReportId = item.ReportId
 			temp.TypeId = item.TypeId
 			temp.Title = item.Title
 			temp.ReportId = item.ReportId
@@ -200,9 +199,8 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		return
 	}
 
-
+	var newTypeIds []int
 	if reportInfo.ClassifyNameFirst == "周报" {
-		var newTypeIds []int
 		newTypeIds, err = GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
 		if err != nil && err != utils.ErrNoRow{
 			errMsg = tErr.Error()
@@ -216,6 +214,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		}
 		authOk = chapterAuthOk
 	}
+	var chapterMenu []*response.ReportChapterMenu
 	reportChapterItem := new(response.ReportChapterItem)
 	reportChapterItem.ReportChapterId = reportChapter.ReportChapterId
 	reportChapterItem.ReportId = reportChapter.ReportId
@@ -229,12 +228,55 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	if authOk {
 		reportChapterItem.Content = reportChapter.Content
 		reportChapterItem.VideoUrl = reportChapter.VideoUrl
+		//底部菜单切换
+		if reportInfo.ClassifyNameFirst == "周报" {
+			chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds)
+		}else{
+			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds)
+		}
 	}else{
 		reportChapterItem.ContentSub = reportChapter.ContentSub
 	}
 	reportChapterDetail = new(response.ReportChapterDetail)
 	reportChapterDetail.ReportChapterItem = reportChapterItem
 	reportChapterDetail.PermissionCheck = &permissionCheckInfo
+	reportChapterDetail.ReportChapterMenuList = chapterMenu
 	reportChapterDetail.AuthOk = authOk
 	return
+}
+
+func GetMenuChapter(reportId int, typeIds []int) (reportTypeList []*response.ReportChapterMenu, err error)  {
+	//查询有效的章节
+	typeList, tErr := report_chapter_type.GetEffectTypes()
+	if tErr != nil {
+		return
+	}
+	if len(typeList) == 0 {
+		err = errors.New("无有效的章节")
+		return
+	}
+
+	typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
+	for _, v := range typeList {
+		typeMap[v.ReportChapterTypeId] = v
+	}
+
+	//获取所有当前研报的章节
+	chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds)
+	if tErr != nil && tErr != utils.ErrNoRow{
+		return
+	}
+	if len(chapterList) > 0 {
+		for _, item := range chapterList {
+			if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
+				temp := new(response.ReportChapterMenu)
+				temp.ReportChapterId = item.ReportChapterId
+				temp.ReportId = item.ReportId
+				temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
+				temp.ReportChapterTypeThumb = typeItem.ReportChapterTypeThumb
+				reportTypeList = append(reportTypeList, temp)
+			}
+		}
+	}
+	return
 }