Эх сурвалжийг харах

Merge branch 'report_share_img_20220729' into debug

hsun 2 жил өмнө
parent
commit
4e6b8d2eba

+ 4 - 4
controller/report/report.go

@@ -199,19 +199,19 @@ func TickerData(c *gin.Context)  {
 	return
 }
 
-// RddpShareImg 日度点评分享图(要得急,先这么写吧=_=!)
+// RddpShareImg 获取报告分享图
 func RddpShareImg(c *gin.Context)  {
 	var req request.RddpReportShareImgReq
 	if c.ShouldBind(&req) != nil {
 		response.Fail("参数异常", c)
 		return
 	}
-	defaultImg := "https://hzstatic.hzinsights.com/static/icon/hzyb/rddp-share-bg.png"
-	if req.Title == "" {
+	defaultImg := utils.DEFAULT_REPORT_SHARE_BG_IMG
+	if req.Source == "" {
 		response.OkData("获取成功", defaultImg, c)
 		return
 	}
-	imgUrl, err := services.GetRddpShareImg(req.Title)
+	imgUrl, err := services.GetDynamicShareImg(req.Source, req.Pars)
 	if err != nil {
 		response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
 		return

+ 2 - 1
models/request/public.go

@@ -1,5 +1,6 @@
 package request
 
 type RddpReportShareImgReq struct {
-	Title string `description:"标题" json:"title"`
+	Source string `description:"来源" json:"source"`
+	Pars   string `description:"动态信息-JSON格式" json:"pars"`
 }

+ 2 - 0
models/response/report.go

@@ -46,6 +46,7 @@ type ReportItem struct {
 	VideoImg           string    `description:"音频播放条的图片" json:"video_img"`
 	ContentSub         string    `description:"内容前两个章节" json:"content_sub"`
 	BannerUrl          string    `description:"详情页banner" json:"banner_url"`
+	ShareBgImg         string    `description:"分享背景图" json:"share_bg_img"`
 }
 
 type ReportChapterItem struct {
@@ -69,6 +70,7 @@ type ReportChapterItem struct {
 	Stage                 int       `description:"期数" json:"stage"`
 	ClassifyIdFirst       int       `description:"一级分类id" json:"classify_id_first"`
 	ClassifyNameFirst     string    `description:"一级分类名称" json:"classify_name_first"`
+	ShareBgImg            string    `description:"分享背景图" json:"share_bg_img"`
 }
 
 type ReportChapterDetail struct {

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

@@ -30,8 +30,9 @@ type Classify struct {
 	YbFiccPcIcon      string    `gorm:"column:yb_ficc_pc_icon" db:"yb_ficc_pc_icon" json:"yb_ficc_pc_icon" form:"yb_ficc_pc_icon"`             //研报 pc端ficc页码图标
 	YbFiccSort        int       `gorm:"column:yb_ficc_sort" db:"yb_ficc_sort" json:"yb_ficc_sort" form:"yb_ficc_sort"`                         //研报小程序端ficc页面排序
 	YbListImg         string    `gorm:"column:yb_list_img" db:"yb_list_img" json:"yb_list_img" form:"yb_list_img"`                             //研报小程序端报告列表封面图
+	YbShareBgImg      string    `gorm:"column:yb_share_bg_img;" db:"yb_share_bg_img" json:"yb_share_bg_img" form:"yb_share_bg_img"`            // 研报小程序-报告分享背景图
 }
 
 func (c *Classify) TableName() string {
 	return "classify"
-}
+}

+ 4 - 0
services/report/report.go

@@ -433,6 +433,10 @@ func GetReportDetail(userinfo user.UserInfo, reportId int) (reportDetail respons
 	reportItem.VideoSize = reportInfo.VideoSize
 	reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
 	reportItem.Author = reportInfo.Author
+	reportItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
+	if firstClassify.YbShareBgImg != "" {
+		reportItem.ShareBgImg = firstClassify.YbShareBgImg
+	}
 	var reportTypeList []*response.ReportChapterListItem
 
 	if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {

+ 11 - 0
services/report/report_chapter.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/chart_permission_chapter_mapping"
 	"hongze/hongze_yb/models/tables/company_product"
+	"hongze/hongze_yb/models/tables/rddp/classify"
 	"hongze/hongze_yb/models/tables/rddp/report"
 	"hongze/hongze_yb/models/tables/rddp/report_chapter"
 	"hongze/hongze_yb/models/tables/report_chapter_type"
@@ -258,6 +259,16 @@ func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDet
 	reportChapterItem.Stage = reportChapter.Stage
 	reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
 	reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
+	// 分享背景图
+	reportChapterItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
+	firstClassify, e := classify.GetByClassifyId(reportInfo.ClassifyIdFirst)
+	if e != nil {
+		err = errors.New("报告一级分类有误")
+		return
+	}
+	if firstClassify.YbShareBgImg != "" {
+		reportChapterItem.ShareBgImg = firstClassify.YbShareBgImg
+	}
 	var likeNum int64
 	var likeEnabled int8
 	if authOk {

+ 1 - 31
services/share_poster.go

@@ -148,36 +148,6 @@ func CreateAndUploadSunCode(page, scene, version string) (imgUrl string, err err
 	return
 }
 
-// GetRddpShareImg 获取日度点评分享图
-func GetRddpShareImg(title string) (imgUrl string, err error) {
-	if title == "" {
-		return
-	}
-	template := fmt.Sprint("static/htm2img/rddp-share.html")
-	contentByte, e := ioutil.ReadFile(template)
-	if e != nil {
-		err = errors.New("读取模板失败, Err: " + e.Error())
-		return
-	}
-	contentStr := string(contentByte)
-	contentStr = strings.Replace(contentStr, "{{TITLE}}", title, 1)
-	htm2ImgReq := make(map[string]interface{})
-	htm2ImgReq["html_content"] = contentStr
-	htm2ImgReq["width"] = 1000
-	htm2ImgReq["height"] = 800
-	res, e := postHtml2Img(htm2ImgReq)
-	if e != nil || res == nil {
-		err = errors.New("html转图片请求失败")
-		return
-	}
-	if res.Code != 200 {
-		err = errors.New("html转图片请求失败: " + res.Msg)
-		return
-	}
-	imgUrl = res.Data
-	return
-}
-
 // CreatePosterFromSourceV2 生成分享海报(通过配置获取相关信息)
 func CreatePosterFromSourceV2(codePage, codeScene, source, version, pars string) (imgUrl string, err error) {
 	var errMsg string
@@ -439,4 +409,4 @@ func GetDynamicShareImg(source, pars string) (imgUrl string, err error) {
 	}
 	imgUrl = res.Data
 	return
-}
+}

+ 5 - 0
utils/constants.go

@@ -175,3 +175,8 @@ var SystemSourceList = []int{
 	DATA_SOURCE_CALCULATE_LJZTBPJ,    //累计值同比拼接->24
 	DATA_SOURCE_PYTHON,               //python代码->27
 }
+
+// 报告
+const (
+	DEFAULT_REPORT_SHARE_BG_IMG = "https://hzstatic.hzinsights.com/static/icon/hzyb/rddp-share-bg.png"	// 分享默认背景图
+)