Bladeren bron

fix:新增获取报告章节详情接口

Roc 3 jaren geleden
bovenliggende
commit
12bfa2f4fa

+ 38 - 0
controller/report/research_report.go

@@ -45,3 +45,41 @@ func GetResearchReportInfo(c *gin.Context) {
 	}
 	response.OkData("获取成功", reportInfo, c)
 }
+
+// GetResearchReportChapter
+// @Tags 报告接口
+// @Summary  获取报告章节详情
+// @Description 获取报告章节详情
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param research_report_type_id query int true "章节ID"
+// @Success 200 {object} yb_activity.ActivityDetail
+// @failure 400 {string} string "获取失败"
+// @Router /report/research_report_chapter [get]
+func GetResearchReportChapter(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+
+	researchReportTypeIdStr := c.DefaultQuery("research_report_type_id", "")
+	if researchReportTypeIdStr == "" {
+		response.Fail("请传入报告章节id", c)
+		return
+	}
+	researchReportId, tmpErr := strconv.Atoi(researchReportTypeIdStr)
+	if tmpErr != nil {
+		response.Fail("报告章节id异常", c)
+		return
+	}
+
+	reportInfo, hasPermission, err := report.GetResearchReportTypeContentInfo(uint64(researchReportId), userInfo.UserID)
+	if err != nil {
+		response.Fail("获取报告章节失败", c)
+		return
+	}
+	if !hasPermission {
+		response.Fail("无权限", c)
+		return
+	}
+	response.OkData("获取成功", reportInfo, c)
+}

+ 79 - 6
logic/report/research_report.go

@@ -3,9 +3,18 @@ package report
 import (
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
+	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/utils"
 )
 
+type ResearchReportInfo struct {
+	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
+	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
+	HasMenu                       int                                                 `json:"has_menu"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+}
+
+// GetResearchReportInfo 获取报告详情
 func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
 	//获取报告详情
 	reportInfo, err := research_report.GetByResearchReportId(researchReportId)
@@ -61,7 +70,7 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	} else if len(researchReportTypeList) == 1 {
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		result.HasMenu = 0
-		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContent(researchReportTypeList[0].ResearchReportTypeId)
+		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContentList(researchReportTypeList[0].ResearchReportTypeId)
 		if tmpErr != nil {
 			return
 		}
@@ -70,9 +79,73 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	return
 }
 
-type ResearchReportInfo struct {
-	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
-	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
-	HasMenu                       int                                                 `json:"has_menu"`
-	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+type ResearchReportTypeContentInfo struct {
+	ResearchReportTypeInfo        *research_report_type.ResearchReportTypeInfo `json:"research_report_type_info"`
+	Add                           int                                          `json:"add"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
+}
+
+// GetResearchReportTypeContentInfo 获取报告章节详情
+func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (result ResearchReportTypeContentInfo, hasPermission bool, err error) {
+	//获取章节详情
+	researchReportTypeContentList, err := research_report.GetResearchReportTypeContentList(researchReportTypeId)
+	if err != nil {
+		return
+	}
+	researchReportTypeInfo, err := research_report_type.GetResearchReportTypeInfo(researchReportTypeId)
+	//获取报告详情
+	reportInfo, err := research_report.GetByResearchReportId(researchReportTypeInfo.ResearchReportID)
+	if err != nil {
+		return
+	}
+	reportType := reportInfo.Type
+
+	//这些个报告需要做权限校验
+	if utils.InArray(reportInfo.Type, []string{"week", "month", "two_week", "other"}) {
+		list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		if reportInfo.Type == "week" {
+			//周报校验章节是否在权限内
+			for _, v := range list {
+				if researchReportTypeInfo.ReportChapterTypeId == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		} else {
+			//双周报和月报校验 类型是否在权限内
+			for _, v := range list {
+				if reportInfo.ResearchReportID == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		}
+
+		if !hasPermission {
+			//permissionName, tmpErr := company_report_permission.GetPermissionNameByReportId(reportInfo.ResearchReportID, reportType)
+			//if tmpErr != nil {
+			//	err = tmpErr
+			//	return
+			//}
+			return
+		}
+	} else {
+		hasPermission = true
+	}
+	add := 1
+	if len(researchReportTypeContentList) > 0 {
+		add = 0
+	}
+
+	result = ResearchReportTypeContentInfo{
+		ResearchReportTypeContentList: researchReportTypeContentList,
+		ResearchReportTypeInfo:        researchReportTypeInfo,
+		Add:                           add,
+	}
+	return
 }

+ 2 - 2
models/tables/research_report/custom_query.go

@@ -17,8 +17,8 @@ type ResearchReportTypeContent struct {
 	LastUpdatedTime             time.Time `json:"last_updated_time" description:"最近一次更新时间"`
 }
 
-// GetResearchReportTypeContent 获取研究报告章节详情
-func GetResearchReportTypeContent(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
+// GetResearchReportTypeContentList 获取研究报告章节详情
+func GetResearchReportTypeContentList(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
 	sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
 from research_report_type rrt
 inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id

+ 26 - 0
models/tables/research_report_type/custom_query.go

@@ -0,0 +1,26 @@
+package research_report_type
+
+import (
+	"hongze/hongze_yb/global"
+)
+
+type ResearchReportTypeInfo struct {
+	ResearchReportTypeTitle string `json:"research_report_type_title" description:"研究报告标题"`
+	BannerUrl               string `json:"banner_url" description:"banner url"`
+	ReportChapterTypeName   string `json:"report_chapter_type_name" description:"章节名称"`
+	ResearchReportID        uint64 `json:"research_report_id" description:"报告id"`
+	ResearchReportTypeID    uint64 `json:"research_report_type_id" description:"研究报告id"`
+	TypeID                  int    `json:"type_id" description:"分类id"`
+	ReportChapterTypeId     uint64 `json:"report_chapter_type_id" description:"章节名称"`
+}
+
+// GetResearchReportTypeInfo 获取研究报告类型详情
+func GetResearchReportTypeInfo(researchReportTypeId uint64) (item *ResearchReportTypeInfo, err error) {
+	sql := ` select rrt.research_report_type_title,rct.banner_url,rct.report_chapter_type_name,rrt.research_report_id,rrt.research_report_type_id,rrt.type_id,rct.report_chapter_type_name,rct.report_chapter_type_id
+            from research_report_type rrt
+            left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
+            where rrt.research_report_type_id =? limit 1`
+
+	err = global.DEFAULT_MYSQL.Raw(sql, researchReportTypeId).Scan(&item).Error
+	return
+}

+ 1 - 0
routers/research_report.go

@@ -11,5 +11,6 @@ func InitResearchReport(r *gin.Engine) {
 	rGroup := r.Group("report").Use(middleware.Token())
 	{
 		rGroup.GET("/research_report", report.GetResearchReportInfo)
+		rGroup.GET("/research_report_chapter", report.GetResearchReportChapter)
 	}
 }