Browse Source

fix:兼容智能研报

Roc 10 months ago
parent
commit
c58714fdfb

+ 1 - 1
latest_mongolog

@@ -1 +1 @@
-log/mongolog/2024-05-08-00-00.log
+log/mongolog/2024-06-21-00-00.log

+ 13 - 0
models/response/report.go

@@ -54,6 +54,10 @@ type ReportItem struct {
 	ContentSub         string    `description:"内容前两个章节" json:"content_sub"`
 	BannerUrl          string    `description:"详情页banner" json:"banner_url"`
 	ShareBgImg         string    `description:"分享背景图" json:"share_bg_img"`
+	ReportLayout       int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1" json:"report_layout"`
+	HeadImg            string    `description:"报告头图地址" json:"head_img"`
+	EndImg             string    `description:"报告尾图地址" json:"end_img"`
+	CanvasColor        string    `description:"画布颜色" json:"canvas_color"`
 }
 
 type ReportChapterItem struct {
@@ -78,6 +82,10 @@ type ReportChapterItem struct {
 	ClassifyIdFirst       int       `description:"一级分类id" json:"classify_id_first"`
 	ClassifyNameFirst     string    `description:"一级分类名称" json:"classify_name_first"`
 	ShareBgImg            string    `description:"分享背景图" json:"share_bg_img"`
+	ReportLayout          int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1" json:"report_layout"`
+	HeadImg               string    `description:"报告头图地址" json:"head_img"`
+	EndImg                string    `description:"报告尾图地址" json:"end_img"`
+	CanvasColor           string    `description:"画布颜色" json:"canvas_color"`
 }
 
 type ReportChapterDetail struct {
@@ -115,6 +123,7 @@ type ReportListItem struct {
 	VideoList          []*VideoListItem `json:"video_list"`
 	AuthOk             bool             `json:"auth_ok"`
 	TitleInfo          string           `json:"title_info"`
+	HasChapter         int              `description:"是否有章节" json:"has_chapter"`
 }
 
 type VideoListItem struct {
@@ -141,6 +150,8 @@ type ReportCollectListItem struct {
 	PublishTime         time.Time `description:"发布时间" json:"publish_time"`
 	Title               string    `description:"标题" json:"title"`
 	ContentSub          string    `description:"内容前两个章节" json:"content_sub"`
+	ClassifyId          int       `description:"最小分类id" json:"classify_id"`
+	ClassifyName        string    `description:"最小分类名称" json:"classify_name"`
 }
 
 type ReportCollectList struct {
@@ -173,6 +184,8 @@ type EsReportItem struct {
 	Title              string `description:"标题"`
 	Abstract           string `description:"摘要"`
 	StageStr           string `description:"期数"`
+	ClassifyId         int    `description:"最小分类id"`
+	ClassifyName       string `description:"最小分类名称"`
 }
 
 type TickerDataItem struct {

+ 88 - 1
models/tables/rddp/report/query.go

@@ -225,7 +225,7 @@ func GetListCountByClassifyIdSecond(classifyIdSecond int) (total int64, err erro
 // GetReportList 获取报告列表
 func GetReportList(condition string, pars []interface{}, offset, limit int) (list []*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, author, create_time, video_url, video_name, video_play_seconds, abstract").
+		Select("id, classify_id_first, classify_name_first, classify_id_second, classify_name_second, title, stage, publish_time, author, create_time, video_url, video_name, video_play_seconds, abstract,has_chapter").
 		Where(condition, pars...).
 		Order("publish_time desc, id desc").
 		Offset(offset).
@@ -457,3 +457,90 @@ func GetListByReportIds(reportIds []int) (list []*Report, err error) {
 		Scan(&list).Error
 	return
 }
+
+// GetReportCollectListByPermissionV1
+// @Description: 根据权限相关的分类查询报告和章节
+// @author: Roc
+// @datetime 2024-06-21 10:24:14
+// @param chartPermissionId int
+// @param classifyIdSeconds []int
+// @param offset int
+// @param limit int
+// @return list []*response.ReportCollectListItem
+// @return err error
+func GetReportCollectListByPermissionV1(chartPermissionId int, classifyIdSeconds []int, offset, limit int) (list []*response.ReportCollectListItem, err error) {
+	sql := `( SELECT
+id AS report_id,
+0 AS report_chapter_id,
+classify_id_first,
+classify_id_second,
+classify_name_first,
+classify_name_second,
+0 as report_chapter_type_id,
+title,
+content_sub,
+publish_time 
+FROM
+	report
+WHERE
+	has_chapter != 1 
+	AND classify_id_second in ?
+	AND state IN (2, 6)
+	)
+UNION
+	
+( SELECT
+a.report_id,
+a.report_chapter_id,
+a.classify_id_first,
+0 as classify_id_second,
+a.classify_name_first,
+null as classify_name_second,
+a.type_id as report_chapter_type_id,
+a.title,
+a.content_sub,
+a.publish_time 
+FROM
+	report_chapter AS a 
+JOIN report_chapter_permission_mapping AS b on a.report_chapter_id=b.report_chapter_id
+WHERE
+	a.publish_state = 2
+AND b.chart_permission_id = ?
+	)
+	ORDER BY publish_time DESC, report_id desc LIMIT ? OFFSET ?
+	`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, chartPermissionId, limit, offset).Scan(&list).Error
+	return
+}
+
+// GetReportCollectCountByPermission 查询汇总报告总页数
+func GetReportCollectCountByPermissionV1(chartPermissionId int, classifyIdSeconds []int) (total int64, err error) {
+	sql := `select count(*) from ( (( SELECT
+id AS report_id,
+0 AS report_chapter_id
+FROM
+	report
+WHERE
+	has_chapter != 1 
+	AND classify_id_second in ?
+	AND state IN (2, 6)
+	)
+UNION
+	
+( SELECT 
+a.report_id,
+a.report_chapter_id
+FROM
+	report_chapter AS a 
+JOIN report_chapter_permission_mapping AS b on a.report_chapter_id=b.report_chapter_id
+WHERE
+	a.publish_state = 2
+AND b.chart_permission_id = ?
+	)
+)
+	
+) as ru
+	`
+	err = global.MYSQL["rddp"].Raw(sql, classifyIdSeconds, chartPermissionId).Count(&total).Error
+	return
+}

+ 5 - 0
models/tables/rddp/report/report.go

@@ -27,6 +27,11 @@ type Report struct {
 	ContentSub         string    `description:"内容前两个章节" json:"content_sub"`
 	ThsMsgIsSend       int       `description:"客户群消息是否已发送,0:否,1:是" json:"ths_msg_is_send"`
 	StageStr           string    `description:"期数" json:"stage_str"`
+	HasChapter         int       `description:"是否有章节" json:"has_chapter"`
+	ReportLayout       int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1" json:"report_layout"`
+	HeadImg            string    `description:"报告头图地址" json:"head_img"`
+	EndImg             string    `description:"报告尾图地址" json:"end_img"`
+	CanvasColor        string    `description:"画布颜色" json:"canvas_color"`
 }
 
 type UnReadItem struct {

+ 1 - 1
models/tables/rddp/report_chapter/query.go

@@ -59,7 +59,7 @@ func GetListByReportIdTypeIds(reportId int, typeIds []int, classifyNameFirst str
 
 // GetContentById 根据ID获取章节详情
 func GetContentById(id int, typeIds []int) (info *ReportChapter, err error) {
-	err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id,  is_edit, classify_name_first, classify_id_first, content, trend, type_id, type_name, abstract, title, author, stage, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size, report_type, video_size").
+	err = global.MYSQL["rddp"].Model(ReportChapter{}).Select("report_chapter_id, report_id,  is_edit, classify_name_first, classify_id_first, content, trend, type_id, type_name, abstract, title, author, stage, publish_time, content, content_sub, video_url, video_name, video_play_seconds, video_size, report_type, video_size,report_layout").
 		Where("report_chapter_id = ? and type_id in (?) AND publish_state = 2 ", id, typeIds).
 		First(&info).Error
 	if err == utils.ErrNoRow {

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

@@ -28,6 +28,7 @@ type ReportChapter struct {
 	VideoSize         string    `gorm:"column:video_size;type:varchar(255);not null;default:''"  json:"video_size"`                 //音频文件大小,单位M
 	CreateTime        time.Time `gorm:"column:create_time;type:datetime"  json:"create_time"`                                       //创建时间
 	ModifyTime        time.Time `gorm:"column:modify_time;type:datetime"  json:"modify_time"`                                       //修改时间
+	ReportLayout      int8      `description:"报告布局,1:常规布局,2:智能布局。默认:1" json:"report_layout"`
 }
 
 func (r *ReportChapter) TableName() string {

+ 35 - 40
services/elastic/report.go

@@ -11,9 +11,9 @@ import (
 )
 
 // 首页搜索
-func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
-	indexName := global.CONFIG.EsClient.Prefix+utils.ES_INDEX_RDDP_REPORT
-	var must  []map[string]interface{}
+func SearchReport(keyWord string, classifyIdList []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
+	indexName := global.CONFIG.EsClient.Prefix + utils.ES_INDEX_RDDP_REPORT
+	var must []map[string]interface{}
 
 	shouldSub := []map[string]interface{}{
 		/*map[string]interface{}{
@@ -78,17 +78,12 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 	filterMust := []map[string]interface{}{
 		map[string]interface{}{
 			"term": map[string]interface{}{
-				"PublishState": 2,                     //必须是已发布的报告
+				"PublishState": 2, //必须是已发布的报告
 			},
 		},
 		map[string]interface{}{
 			"terms": map[string]interface{}{
-				"ClassifyIdFirst":classifyIdFirsts,     //分类必须是正常显示状态
-			},
-		},
-		map[string]interface{}{
-			"terms": map[string]interface{}{
-				"ClassifyIdSecond":classifyIdSeconds,     //分类必须是正常显示状态
+				"ClassifyId": classifyIdList, //分类必须是正常显示状态
 			},
 		},
 	}
@@ -96,21 +91,21 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 		map[string]interface{}{
 			"term": map[string]interface{}{
 				"BodyContent.keyword": map[string]interface{}{
-					"value": "",                     //过滤没有内容的报告(晨报和周报)bodyContent 不能为空
+					"value": "", //过滤没有内容的报告(晨报和周报)bodyContent 不能为空
 				},
 			},
 		},
 	}
 	filterMap := map[string]interface{}{
 		"bool": map[string]interface{}{
-			"must": filterMust,
+			"must":     filterMust,
 			"must_not": filterMustNot,
 		},
 	}
 	source := map[string]interface{}{
 		"query": map[string]interface{}{
 			"bool": map[string]interface{}{
-				"must": must,
+				"must":   must,
 				"filter": filterMap,
 			},
 		},
@@ -119,31 +114,31 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 	source["size"] = pageSize
 	source["highlight"] = map[string]interface{}{
 		"fields": map[string]interface{}{
-			"Title":map[string]interface{}{},
-			"Categories":map[string]interface{}{},
-			"BodyContent":map[string]interface{}{
-			//	"pre_tags" : "{{highlight}}",
-			//	"post_tags": "{{/highlight}}",
+			"Title":       map[string]interface{}{},
+			"Categories":  map[string]interface{}{},
+			"BodyContent": map[string]interface{}{
+				//	"pre_tags" : "{{highlight}}",
+				//	"post_tags": "{{/highlight}}",
 			},
 		},
-		"pre_tags" : "<span style=\"color:#E3B377\">",
+		"pre_tags":  "<span style=\"color:#E3B377\">",
 		"post_tags": "</span>",
 	}
 
 	source["sort"] = []map[string]interface{}{
 		map[string]interface{}{
-			"PublishTime.keyword":map[string]interface{}{
-				"order":"desc",
+			"PublishTime.keyword": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 		map[string]interface{}{
-			"_score":map[string]interface{}{
-				"order":"desc",
+			"_score": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 	}
 	jsonstr, err := json.Marshal(source)
-	fmt.Printf("%s",jsonstr)
+	fmt.Printf("%s", jsonstr)
 	request := global.EsClient.Search(indexName).Source(source) // sets the JSON request
 
 	searchResp, err = request.Do(context.Background())
@@ -164,8 +159,8 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 
 // ReportListSearch 报告列表页的搜索
 func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
-	indexName := global.CONFIG.EsClient.Prefix+utils.ES_INDEX_RDDP_REPORT
-	var must  []map[string]interface{}
+	indexName := global.CONFIG.EsClient.Prefix + utils.ES_INDEX_RDDP_REPORT
+	var must []map[string]interface{}
 	shouldSub := []map[string]interface{}{
 		map[string]interface{}{
 			"match": map[string]interface{}{
@@ -233,12 +228,12 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
 		},
 		map[string]interface{}{
 			"term": map[string]interface{}{
-				"ReportChapterId":0,     //排除章节内容
+				"ReportChapterId": 0, //排除章节内容
 			},
 		},
 		map[string]interface{}{
 			"term": map[string]interface{}{
-				"ClassifyIdFirst":classifyIdFirst,
+				"ClassifyIdFirst": classifyIdFirst,
 			},
 		},
 		map[string]interface{}{
@@ -250,7 +245,7 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
 	source := map[string]interface{}{
 		"query": map[string]interface{}{
 			"bool": map[string]interface{}{
-				"must": must,
+				"must":   must,
 				"filter": filter,
 			},
 		},
@@ -260,29 +255,29 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
 	source["size"] = pageSize
 	source["highlight"] = map[string]interface{}{
 		"fields": map[string]interface{}{
-			"Title":map[string]interface{}{},
-			"Abstract":map[string]interface{}{},
-			"StageStr":map[string]interface{}{},
-			"ClassifyNameSecond":map[string]interface{}{},
+			"Title":              map[string]interface{}{},
+			"Abstract":           map[string]interface{}{},
+			"StageStr":           map[string]interface{}{},
+			"ClassifyNameSecond": map[string]interface{}{},
 		},
-		"pre_tags" : "<span style=\"color:#E3B377\">",
+		"pre_tags":  "<span style=\"color:#E3B377\">",
 		"post_tags": "</span>",
 	}
 
 	source["sort"] = []map[string]interface{}{
 		map[string]interface{}{
-			"PublishTime.keyword":map[string]interface{}{
-				"order":"desc",
+			"PublishTime.keyword": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 		map[string]interface{}{
-			"_score":map[string]interface{}{
-				"order":"desc",
+			"_score": map[string]interface{}{
+				"order": "desc",
 			},
 		},
 	}
 	jsonstr, err := json.Marshal(source)
-	fmt.Printf("%s",jsonstr)
+	fmt.Printf("%s", jsonstr)
 	request := global.EsClient.Search(indexName).Source(source) // sets the JSON request
 	searchResp, err = request.Do(context.Background())
 	if err != nil {
@@ -298,4 +293,4 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
 	}
 	total = searchResp.TotalHits()
 	return
-}
+}

+ 80 - 1
services/report/report.go

@@ -431,6 +431,10 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
 	reportItem.Frequency = reportInfo.Frequency
 	reportItem.VideoName = reportInfo.VideoName
+	reportItem.ReportLayout = reportInfo.ReportLayout
+	reportItem.HeadImg = reportInfo.HeadImg
+	reportItem.EndImg = reportInfo.EndImg
+	reportItem.CanvasColor = reportInfo.CanvasColor
 	if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
 		reportItem.VideoName = reportInfo.Title
 	}
@@ -920,6 +924,7 @@ func GetReportList(user user.UserInfo, keyWord string, classifyIdFirst, classify
 		for _, reportInfo := range list {
 			reportItem := new(response.ReportListItem)
 			reportItem.ReportId = reportInfo.Id
+			reportItem.HasChapter = reportInfo.HasChapter
 			// 样式限制行数
 			reportItem.Title = "<div style=\"-webkit-line-clamp: 2;-webkit-box-orient: vertical;display: -webkit-box;overflow: hidden;text-overflow: ellipsis;\">" + reportInfo.Title + "</div>"
 			reportItem.PublishTime = reportInfo.PublishTime
@@ -1034,6 +1039,76 @@ func GetCollectReportList(user user.UserInfo, chartPermissionId, pageIndex, page
 		return
 	}
 
+	var reportList []*response.ReportCollectListItem
+	list := response.ReportCollectListResp{}
+	var total int64
+
+	{
+		offset := (pageIndex - 1) * pageSize
+		reportList, err = report.GetReportCollectListByPermissionV1(chartPermissionId, classifySecondIds, offset, pageSize)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询报告信息出错")
+			return
+		}
+		listMap := make(map[string]*response.ReportCollectList)
+		for _, v := range reportList {
+			v.ContentSub = GetReportContentSub(v.ContentSub, true)
+			if _, ok := listMap[v.PublishTime.Format("2006-01-02")]; !ok {
+				temp := new(response.ReportCollectList)
+				temp.Date = v.PublishTime.Format("2006-01-02")
+				listMap[v.PublishTime.Format("2006-01-02")] = temp
+			}
+			listMap[v.PublishTime.Format("2006-01-02")].SubList = append(listMap[v.PublishTime.Format("2006-01-02")].SubList, v)
+		}
+		for _, v := range listMap {
+			list = append(list, v)
+		}
+		total, err = report.GetReportCollectCountByPermissionV1(chartPermissionId, classifySecondIds)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询报告总数出错")
+			return
+		}
+		if len(list) > 0 {
+			sort.Sort(list)
+		}
+	}
+
+	ret = new(response.ReportCollectResp)
+	ret.List = list
+	ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
+	return
+}
+
+func GetCollectReportListBak(user user.UserInfo, chartPermissionId, pageIndex, pageSize int) (ret *response.ReportCollectResp, err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("GetCollectReportList: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	// 查询权限的基本信息
+	permissionInfo, err := chart_permission.GetByChartPermissionId(chartPermissionId)
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询权限出错")
+		return
+	}
+
+	if permissionInfo.ChartPermissionID == 0 {
+		err = errors.New("权限不存在")
+		return
+	}
+	// 除了晨报和周报以外的其他报告
+	classifySecondIds, err := chart_permission_search_key_word_mapping.GetClassifyIdsByChartPermissionId(chartPermissionId, "rddp")
+	if err != nil {
+		errMsg = err.Error()
+		err = errors.New("查询权限对应的分类出错")
+		return
+	}
+
 	//var classifySecondIds []int
 	//if len(classifyNames) > 0 {
 	//	classifySecondIds, err = classify.GetSecondIdsByClassifyNames(classifyNames)
@@ -1107,6 +1182,7 @@ func SearchReport(user user.UserInfo, keyWord string, pageIndex, pageSize int) (
 		err = errors.New("分类查询出错")
 		return
 	}
+	classifyIdList := make([]int, 0)
 	var classifyIdFirsts []int
 	classifyIdSeconds := []int{0}
 	for _, v := range classifys {
@@ -1115,9 +1191,10 @@ func SearchReport(user user.UserInfo, keyWord string, pageIndex, pageSize int) (
 		} else {
 			classifyIdSeconds = append(classifyIdSeconds, v.Id)
 		}
+		classifyIdList = append(classifyIdList, v.Id)
 	}
 	keyWord = addAliasToKeyword(keyWord)
-	searchResp, total, err := elasticService.SearchReport(keyWord, classifyIdFirsts, classifyIdSeconds, pageIndex, pageSize)
+	searchResp, total, err := elasticService.SearchReport(keyWord, classifyIdList, pageIndex, pageSize)
 	if err != nil {
 		errMsg = err.Error()
 		err = errors.New("查询失败")
@@ -1146,6 +1223,8 @@ func SearchReport(user user.UserInfo, keyWord string, pageIndex, pageSize int) (
 			temp.ClassifyNameFirst = reportItem.ClassifyNameFirst
 			temp.ClassifyIdSecond = reportItem.ClassifyIdSecond
 			temp.ClassifyNameSecond = reportItem.ClassifyNameSecond
+			temp.ClassifyId = reportItem.ClassifyId
+			temp.ClassifyName = reportItem.ClassifyName
 			temp.Title = reportItem.Title
 			temp.ContentSub = reportItem.BodyContent
 			temp.PublishTime, err = time.ParseInLocation(utils.FormatDateTime, reportItem.PublishTime, time.Local)

+ 4 - 0
services/report/report_chapter.go

@@ -251,6 +251,10 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	reportChapterItem.PublishTime = reportChapter.PublishTime
 	reportChapterItem.VideoPlaySeconds = reportChapter.VideoPlaySeconds
 	reportChapterItem.VideoName = reportChapter.VideoName
+	reportChapterItem.ReportLayout = reportChapter.ReportLayout
+	reportChapterItem.HeadImg = reportInfo.HeadImg
+	reportChapterItem.EndImg = reportInfo.EndImg
+	reportChapterItem.CanvasColor = reportInfo.CanvasColor
 	if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
 		reportChapterItem.VideoName = reportChapter.Title
 	}