소스 검색

Merge branch 'eta/1.8.3' into debug

# Conflicts:
#	models/tables/rddp/report_chapter/query.go
#	services/elastic/report.go
Roc 10 달 전
부모
커밋
027292fb2f

+ 4 - 1
controller/public.go

@@ -688,7 +688,10 @@ func BannerDowload(c *gin.Context) {
 		randStr := utils.GetRandStringNoSpecialChar(28)
 		jpegPath := `./static/` + randStr + ".jpeg"
 		err := services.ReportToJpeg(req.BannerUrl, jpegPath)
-
+		if err != nil {
+			response.FailData("图片转jpeg失败", "图片转jpeg失败,Err:"+err.Error(), c)
+			return
+		}
 		dateDir := time.Now().Format("20060102")
 		uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
 		err = os.MkdirAll(uploadDir, 0766)

+ 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, abstract, 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, abstract, 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 {

+ 4 - 9
services/elastic/report.go

@@ -11,7 +11,7 @@ import (
 )
 
 // 首页搜索
-func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
+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{}
 
@@ -83,12 +83,7 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 		},
 		map[string]interface{}{
 			"terms": map[string]interface{}{
-				"ClassifyIdFirst": classifyIdFirsts, //分类必须是正常显示状态
-			},
-		},
-		map[string]interface{}{
-			"terms": map[string]interface{}{
-				"ClassifyIdSecond": classifyIdSeconds, //分类必须是正常显示状态
+				"ClassifyId": classifyIdList, //分类必须是正常显示状态
 			},
 		},
 	}
@@ -126,8 +121,8 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
 	source["collapse"] = filteCollapse
 	source["highlight"] = map[string]interface{}{
 		"fields": map[string]interface{}{
-			"Title":      map[string]interface{}{},
-			"Categories": map[string]interface{}{},
+			"Title":       map[string]interface{}{},
+			"Categories":  map[string]interface{}{},
 			"BodyContent": map[string]interface{}{
 				//	"pre_tags" : "{{highlight}}",
 				//	"post_tags": "{{/highlight}}",

+ 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
 	}