Ver código fonte

专栏相关

xiexiaoyuan 3 anos atrás
pai
commit
e14268a304

+ 73 - 0
controller/report/classify.go

@@ -0,0 +1,73 @@
+package report
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/response"
+	reportService "hongze/hongze_yb/services/report"
+	userService "hongze/hongze_yb/services/user"
+	"strconv"
+)
+
+func ClassifyList(c *gin.Context)  {
+	classifyName := c.DefaultQuery("classify_name", "")
+	if classifyName == ""{
+		response.Fail("请输入一级分类名称", c)
+		return
+	}
+	userinfo := userService.GetInfoByClaims(c)
+
+	classList, err := reportService.GetClassListByClassifyName(userinfo, classifyName)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", classList, c )
+	return
+}
+
+func ClassifyDetail(c *gin.Context)  {
+	classifySecondName := c.DefaultQuery("classify_second_name", "")
+	if classifySecondName == "" {
+		response.Fail("请输入二级分类名称", c)
+		return
+	}
+	userinfo := userService.GetInfoByClaims(c)
+
+	detail, err := reportService.GetClassifyDetail(userinfo, classifySecondName)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", detail, c )
+	return
+}
+
+func ClassifyDetailReports(c *gin.Context)  {
+	classifySecondName := c.DefaultQuery("classify_second_name", "")
+	reqPageSize := c.DefaultQuery("page", "1")
+	reqPageLimit := c.DefaultQuery("limit", "10")
+	if classifySecondName == "" {
+		response.Fail("请输入二级分类名称", c)
+		return
+	}
+	pageSize, err := strconv.Atoi(reqPageSize)
+	if err != nil {
+		response.Fail("请输入正确的页码", c)
+		return
+	}
+	pageLimit, err := strconv.Atoi(reqPageLimit)
+	if err != nil {
+		response.Fail("请输入正确的条数限制", c)
+		return
+	}
+
+	userinfo := userService.GetInfoByClaims(c)
+
+	detail, err := reportService.GetClassifyReportList(userinfo, classifySecondName, pageSize, pageLimit)
+	if err != nil {
+		response.Fail(err.Error(), c)
+		return
+	}
+	response.OkData("查询成功", detail, c )
+	return
+}

+ 48 - 0
models/response/classify.go

@@ -0,0 +1,48 @@
+package response
+
+import (
+	"hongze/hongze_yb/services/company"
+	"time"
+)
+
+type ClassifyListItem struct {
+	ClassifySecondId                     int     `json:"classify_second_id"`
+	ClassifySecondName     	string  `json:"classify_second_name"`
+	ParentId		 		int     `json:"parent_id"`
+	ReportAuthor     		string  `json:"report_author"`
+	AuthorDescript   		string  `json:"author_descript"`
+	HomeImgUrl       		string	`json:"home_img_url"`
+	Stage                   int    `description:"期数" json:"stage"`
+	ProductName				string  `json:"product_name"`
+}
+
+type ClassifyDetail struct {
+	ClassifyListItem
+	AvatarImgUrl     string     `json:"avatar_img_url"`
+	Abstract         string		`json:"abstract"`
+	Descript         string     `json:"descript"`
+	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	AuthOk              bool `json:"auth_ok"`
+	IsVip           int       `json:"is_vip"'`
+}
+
+type ClassReportListItem struct {
+	ReportId                 int    `description:"报告Id" json:"report_id"`
+	ClassifyIdFirst    int    `description:"一级分类id" json:"classify_id_first"`
+	ClassifyNameFirst  string `description:"一级分类名称" json:"classify_name_first"`
+	ClassifyIdSecond   int    `description:"二级分类id" json:"classify_id_second"`
+	ClassifyNameSecond string `description:"二级分类名称" json:"classify_name_second"`
+	Title              string `description:"标题" json:"title"`
+	Abstract           string `description:"摘要" json:"abstract"`
+	Author             string `description:"作者" json:"author"`
+	AuthorImageUrl             string `description:"作者头像" json:"author_image_url"`
+	PublishTime        time.Time `description:"发布时间" json:"publish_time"`
+	Stage              int    `description:"期数" json:"stage"`
+	VideoUrl           string `description:"音频文件URL" json:"video_url"`
+}
+type ClassReportList struct {
+	List    []*ClassReportListItem   	`json:"list"`
+	PermissionCheck     *company.PermissionCheckInfo    `json:"permission_check"`
+	AuthOk              bool `json:"auth_ok"`
+	
+}

+ 14 - 0
models/tables/chart_permission_search_key_word_mapping/chart_permission_search_key_word_mapping.go

@@ -0,0 +1,14 @@
+package chart_permission_search_key_word_mapping
+
+type ChartPermissionSearchKeyWordMapping struct {
+	Id        		  int  `orm:"primaryKey;column:id;type:int(11) unsigned;not null" json:"-"`
+	ChartPermissionId int  	`gorm:"column:chart_permission_id;type:int(11)" json:"chart_permission_id"`
+	KeyWord          string  `gorm:"column:key_word;type:varchar(100)" json:"key_word"`
+	From             string   `gorm:"column:from;type:varchar(100)" json:"from"`
+	TacticType       string	 `gorm:"column:tactic_type;type:varchar(100)" json:"tactic_type"`
+	TeleconferenceSort int		`gorm:"column:teleconference_sort;type:int(11)" json:"teleconference_sort"`
+}
+
+func (c *ChartPermissionSearchKeyWordMapping) TableName() string {
+	return "chart_permission_search_key_word_mapping"
+}

+ 21 - 0
models/tables/chart_permission_search_key_word_mapping/query.go

@@ -0,0 +1,21 @@
+package chart_permission_search_key_word_mapping
+
+import (
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetChartPermissionIdsByKeyWord 查询二级分类中的权限
+func GetChartPermissionIdsByKeyWord(keyWord string) (ids []int, err error)  {
+	var list []*ChartPermissionSearchKeyWordMapping
+	err = global.DEFAULT_MYSQL.Model(ChartPermissionSearchKeyWordMapping{}).Where("key_word = ?", keyWord).Scan(&list).Error
+	if err != nil && err != utils.ErrNoRow {
+		return
+	}
+	if len(list) > 0 {
+		for _, item := range list {
+			ids = append(ids, item.ChartPermissionId)
+		}
+	}
+	return
+}

+ 3 - 2
models/tables/rddp/classify/classify.go

@@ -3,8 +3,8 @@ package classify
 import "time"
 
 type Classify struct {
-	Id               int  	`gorm:"primaryKey;column:report_chapter_id;type:int(10) unsigned;not null" json:"-"`
-	ClassifyName     string `gorm:"column:class_name" json:"classify_name"`
+	Id               int  	`gorm:"primaryKey;column:id;type:int(10) unsigned;not null" json:"-"`
+	ClassifyName     string `gorm:"column:classify_name" json:"classify_name"`
 	Sort			 int8
 	ParentId		 int
 	CreateTime       time.Time
@@ -20,6 +20,7 @@ type Classify struct {
 	IsHomeColumn     int8
 	HomeImgUrl       string
 	ClassifyLabel    string
+	IsVip            int
 }
 
 func (c *Classify) TableName() string  {

+ 22 - 1
models/tables/rddp/classify/query.go

@@ -1,8 +1,29 @@
 package classify
 
-import "hongze/hongze_yb/global"
+import (
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
 
 func GetAll()(list []*Classify, err error)  {
 	err = global.MYSQL["rddp"].Model(Classify{}).Scan(&list).Error
 	return
 }
+
+// GetByClassifyName 根据分类名称查找专栏详情
+func GetByClassifyName(classifyName string) (item *Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("classify_name = ?", classifyName).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
+// GetListByPid 根据分类名称查找专栏列表
+func GetListByPid(pid int) (list []*Classify, err error) {
+	err = global.MYSQL["rddp"].Model(Classify{}).Where("parent_id = ? ", pid).Order("sort asc, id asc").Scan(&list).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}

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

@@ -78,4 +78,40 @@ func GetByReportId(id int) (item *Report, err error) {
 func GetLatestDay() (item *Report, err error) {
 	err = global.MYSQL["rddp"].Where("state = 2 and classify_name_first= 'day'").Order("publish_time desc, id desc").First(&item).Error
 	return
+}
+
+// GetLatestReportsByClassifyNameFirst 查询当前一级分类下,二级分类中,最新的报告
+func GetLatestReportsByClassifyNameFirst(classifyNameFirst string) (reportList []*Report, err error) {
+	sql := `SELECT
+	max( publish_time ) as publish_time,
+	classify_id_first,
+	classify_name_first,
+	classify_id_second,
+	classify_name_second,
+	id,
+	stage
+FROM
+	report 
+WHERE
+	state = 2 
+	AND classify_name_first = ?
+GROUP BY
+	classify_id_second`
+	err = global.MYSQL["rddp"].Raw(sql, classifyNameFirst).Scan(&reportList).Error
+	return
+}
+
+// GetListByClassSecond 按照二级类型分页查询
+func GetListByClassSecond(classifyNameSecond string,  offset , limit int) (reportList []*Report, err error) {
+	err = global.MYSQL["rddp"].Model(Report{}).
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time").
+		Where("classify_name_second=? and state = 2 ", classifyNameSecond).
+		Order("publish_time desc, id desc").
+		Offset(offset).
+		Limit(limit).
+		Scan(&reportList).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
 }

+ 1 - 0
models/tables/rddp/report_view_record/report_view_record.go

@@ -11,6 +11,7 @@ type ReportViewRecord struct {
 	RealName    string    `description:"用户实际姓名"`
 	CompanyName string    `description:"公司名称"`
 	CreateTime  time.Time `description:"创建时间"`
+	ReportChapterId     int `description:"报告章节ID,0表示目录页"`
 }
 
 func (r *ReportViewRecord) TableName() string  {

+ 5 - 0
routers/report.go

@@ -10,4 +10,9 @@ func InitReport(r *gin.Engine)  {
 	rGroup := r.Group("report").Use(middleware.Token())
 	rGroup.GET("/detail", report.Detail)
 	rGroup.GET("/chapter/detail", report.ChapterDetail)
+
+	rGroup2 := r.Group("classify").Use(middleware.Token())
+	rGroup2.GET("/list", report.ClassifyList)
+	rGroup2.GET("/detail", report.ClassifyDetail)
+	rGroup2.GET("/detail/reports", report.ClassifyDetailReports)
 }

+ 206 - 0
services/report/classify.go

@@ -0,0 +1,206 @@
+package report
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/chart_permission_search_key_word_mapping"
+	"hongze/hongze_yb/models/tables/rddp/classify"
+	"hongze/hongze_yb/models/tables/rddp/report"
+	"hongze/hongze_yb/services/company"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
+	"log"
+)
+
+// GetClassListByClassifyName 查询二级分类列表
+func GetClassListByClassifyName(user user.UserInfo, classifyName string) (list []*response.ClassifyListItem, err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassListByClassifyName: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	classifyInfo, err := classify.GetByClassifyName(classifyName)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+
+	if classifyInfo.Id == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+
+	if classifyInfo.ParentId != 0 {
+		err = errors.New("不允许查询二级分类")
+		return
+	}
+
+	classifyList, err := classify.GetListByPid(classifyInfo.Id)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("二级分类查询出错")
+		return
+	}
+
+	//查询二级分类中最新的报告ID
+	reportList, err := report.GetLatestReportsByClassifyNameFirst(classifyName)
+	if err != nil && err != utils.ErrNoRow {
+		errMsg = err.Error()
+		err = errors.New("报告查询出错")
+		return
+	}
+
+	reportMap := make(map[int]*report.Report)
+	for _, v := range reportList {
+		reportMap[v.ClassifyIdSecond] = v
+	}
+	for _, item := range classifyList {
+		temp := new(response.ClassifyListItem)
+		temp.ClassifySecondId = item.Id
+		temp.ParentId = item.ParentId
+		temp.AuthorDescript = item.AuthorDescript
+		temp.ReportAuthor = item.ReportAuthor
+		temp.HomeImgUrl = item.HomeImgUrl
+		temp.ClassifySecondName = item.ClassifyName
+		if _, ok := reportMap[item.Id]; ok {
+			temp.Stage = reportMap[item.Id].Stage
+		}
+		if classifyName == "权益研报" {
+			temp.ProductName = "权益"
+		} else {
+			temp.ProductName = "FICC"
+		}
+
+		list = append(list, temp)
+	}
+	return
+}
+
+func GetClassifyDetail(user user.UserInfo, classifySecondName string) (detail *response.ClassifyDetail, err error)  {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+	classifyInfo, err := classify.GetByClassifyName(classifySecondName)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+
+	if classifyInfo.Id == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+	if classifyInfo.ParentId == 0 {
+		err = errors.New("只允许查询二级分类")
+		return
+	}
+	//查询权限, 查询当前分类下的最新的报告,
+	permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyInfo.ClassifyName)
+	log.Println(permissionIds)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类权限查询出错")
+		return
+	}
+	authOk, permissionCheckInfo, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
+	if err != nil && err != utils.ErrNoRow {
+		errMsg = err.Error()
+		err = errors.New("权限查询出错")
+		return
+	}
+
+	detail = new(response.ClassifyDetail)
+	detail.ClassifySecondId = classifyInfo.Id
+	detail.ParentId = classifyInfo.ParentId
+	detail.AuthorDescript = classifyInfo.AuthorDescript
+	detail.ReportAuthor = classifyInfo.ReportAuthor
+	detail.AvatarImgUrl = classifyInfo.AvatarImgUrl
+	detail.ClassifySecondName = classifyInfo.ClassifyName
+	detail.Abstract = classifyInfo.Abstract
+	detail.Descript = classifyInfo.Descript
+	detail.IsVip = classifyInfo.IsVip
+	detail.PermissionCheck = &permissionCheckInfo
+	detail.AuthOk = authOk
+
+	return
+}
+
+// GetClassifyReportList 查询二级分类下的报告列表
+func GetClassifyReportList(user user.UserInfo, classifySecondName string, page, limit int) (list *response.ClassReportList, err error)  {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetClassifyDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+	classifyInfo, err := classify.GetByClassifyName(classifySecondName)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类查询出错")
+		return
+	}
+
+	if classifyInfo.Id == 0 {
+		err = errors.New("分类不存在")
+		return
+	}
+	if classifyInfo.ParentId == 0 {
+		err = errors.New("只允许查询二级分类")
+		return
+	}
+	//查询权限, 查询当前分类下的最新的报告,
+	permissionIds, err := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(classifyInfo.ClassifyName)
+	log.Println(permissionIds)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("分类权限查询出错")
+		return
+	}
+	authOk, permissionCheckInfo, err := company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
+	if err != nil && err != utils.ErrNoRow {
+		errMsg = err.Error()
+		err = errors.New("权限查询出错")
+		return
+	}
+	//查询 report列表
+	offset := (page - 1) * limit
+	reportList, err := report.GetListByClassSecond(classifySecondName, offset, limit)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询报告列表出错")
+		return
+	}
+	var newList []*response.ClassReportListItem
+	if len(reportList) > 0 {
+		for _, reportInfo := range reportList {
+			reportItem := new(response.ClassReportListItem)
+			reportItem.ReportId = reportInfo.Id
+			reportItem.Title = reportInfo.Title
+			reportItem.PublishTime = reportInfo.PublishTime
+			reportItem.ClassifyNameFirst = reportInfo.ClassifyNameFirst
+			reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
+			reportItem.Stage = reportInfo.Stage
+			reportItem.Abstract = reportInfo.Abstract
+			reportItem.Author = reportInfo.Author
+			if authOk {
+				reportItem.VideoUrl = reportInfo.VideoUrl
+			}
+			newList = append(newList, reportItem)
+		}
+	}
+	list = new(response.ClassReportList)
+	list.List = newList
+	list.PermissionCheck = &permissionCheckInfo
+	list.AuthOk = authOk
+
+	return
+}

+ 1 - 1
services/report/report.go

@@ -233,7 +233,7 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	}
 	//如果有权限则展示content
 	if authOk  {
-		AddViewRecord(userinfo, reportInfo.Id)
+		_ = AddViewRecord(userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
 		reportItem.Content = reportInfo.Content
 		reportItem.VideoUrl = reportInfo.VideoUrl
 	}

+ 29 - 22
services/report/report_chapter.go

@@ -187,27 +187,31 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		err = errors.New("章节未编辑")
 		return
 	}
-	//判断权限
-	permissionIds, tErr := company.GetValidPermissionIdListByCompany2ProductId(user.CompanyID, 1)
-	if tErr != nil && tErr != utils.ErrNoRow {
-		errMsg = tErr.Error()
-		err = errors.New("权限查询出错")
-		return
-	}
-
-	//TODO 修改权限校验接口,如果用户没有权限也要允许用户查看部分内容
-	authOk, permissionCheckInfo, tErr = company.GetCheckPermission(user.CompanyID, int(user.UserID), permissionIds)
-	if tErr != nil && tErr != utils.ErrNoRow{
-		errMsg = tErr.Error()
-		err = errors.New("权限查询出错")
-		return
-	}
-
+	//判断权限 TODO 查询章节相关的报告的charPermissionId
 	var newTypeIds []int
-	if reportInfo.ClassifyNameFirst == "周报" {
+	if reportInfo.ClassifyNameFirst == "晨报"{
+		authOk, permissionCheckInfo, err = CheckDayReportPermission(user)
+		if err != nil && err != utils.ErrNoRow {
+			errMsg = err.Error()
+			err = errors.New("权限查询出错")
+			return
+		}
+	}else if reportInfo.ClassifyNameFirst == "周报"{
+		authOk, permissionCheckInfo, err = CheckWeekReportPermission(user, reportInfo.Id)
+		if err != nil && err != utils.ErrNoRow {
+			errMsg = err.Error()
+			err = errors.New("权限查询出错")
+			return
+		}
+		permissionIds, tErr := company.GetValidPermissionIdListByCompany2ProductId(user.CompanyID, 1)
+		if tErr != nil && tErr != utils.ErrNoRow{
+			errMsg = tErr.Error()
+			err = errors.New("权限查询出错")
+			return
+		}
 		newTypeIds, err = GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
 		if err != nil && err != utils.ErrNoRow{
-			errMsg = tErr.Error()
+			errMsg = err.Error()
 			err = errors.New("周报章节权限查询出错")
 			return
 		}
@@ -218,6 +222,7 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		}
 		authOk = chapterAuthOk
 	}
+
 	var chapterMenu []*response.ReportChapterMenu
 	reportChapterItem := new(response.ReportChapterItem)
 	reportChapterItem.ReportChapterId = reportChapter.ReportChapterId
@@ -238,6 +243,8 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 		}else{
 			chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst)
 		}
+
+		_ = AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
 	}else{
 		reportChapterItem.ContentSub = reportChapter.ContentSub
 	}
@@ -301,10 +308,10 @@ func CheckDayReportPermission(userInfo user.UserInfo) (authOk bool, permissionCh
 	if err != nil && err != utils.ErrNoRow {
 		return
 	}
-	var permissionIds []int
-	for _, item := range permissions {
-		permissionIds = append(permissionIds, item.ChartPermissionID)
+	if len(permissions) > 0 {
+		authOk = true
+		return
 	}
-	authOk, permissionCheckInfo, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
+	authOk, permissionCheckInfo, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), []int{})
 	return
 }

+ 4 - 1
services/report/report_view_record.go

@@ -7,7 +7,7 @@ import (
 	"time"
 )
 
-func AddViewRecord(user user.UserInfo, reportId int) (err error) {
+func AddViewRecord(user user.UserInfo, reportId int, classifyName string, reportChapterId int) (err error) {
 	companyInfo, err := company.GetByCompanyId(user.CompanyID)
 	if err != nil {
 		return
@@ -20,6 +20,9 @@ func AddViewRecord(user user.UserInfo, reportId int) (err error) {
 	record.RealName = user.RealName
 	record.CompanyName = companyInfo.CompanyName
 	record.CreateTime = time.Now()
+	if classifyName == "晨报" || classifyName == "周报" {
+		record.ReportChapterId = reportChapterId
+	}
 	err = report_view_record.Create(record)
 	if err != nil {
 		return