Explorar el Código

Merge branch 'feature/poster_create_1209' into debug

hsun hace 2 semanas
padre
commit
52ed5d136f

+ 1 - 1
controller/report/report.go

@@ -199,7 +199,7 @@ func RddpShareImg(c *gin.Context) {
 		response.OkData("获取成功", defaultImg, c)
 		return
 	}
-	imgUrl, err := services.GetDynamicShareImg(req.Source, req.Pars)
+	imgUrl, err := services.GetDynamicShareImg(req.Source, req.Pars, req.ReportId, req.ReportChapterId, req.Version)
 	if err != nil {
 		response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
 		return

+ 5 - 2
models/request/public.go

@@ -1,8 +1,11 @@
 package request
 
 type RddpReportShareImgReq struct {
-	Source string `description:"来源" json:"source"`
-	Pars   string `description:"动态信息-JSON格式" json:"pars"`
+	Source          string `description:"来源" json:"source"`
+	Pars            string `description:"动态信息-JSON格式" json:"pars"`
+	ReportId        int    `description:"报告ID" json:"report_id"`
+	ReportChapterId int    `description:"报告章节ID" json:"report_chapter_id"`
+	Version         string `description:"版本号" json:"version"`
 }
 
 type WechatWarningReq struct {

+ 31 - 3
services/share_poster.go

@@ -391,17 +391,33 @@ func fillContent2HtmlV2(source, pars, sunCodeUrl string, height float64, ybPoste
 }
 
 // GetDynamicShareImg 生成动态分享图
-func GetDynamicShareImg(source, pars string) (imgUrl string, err error) {
+func GetDynamicShareImg(source, pars string, reportId, reportChapterId int, version string) (imgUrl string, err error) {
 	if source == "" {
 		err = errors.New("图片来源有误")
 		return
 	}
+
+	// 报告章节详情无需重复生成
+	var path string
+	if reportId > 0 {
+		path = fmt.Sprintf("reportDetailCover?ReportId=%d&ReportChapterId=%d", reportId, reportChapterId)
+		poster, e := yb_poster_resource.GetPosterByCondition(path, "poster", version)
+		if e != nil && e != utils.ErrNoRow {
+			err = fmt.Errorf("获取报告已生成海报失败, %e", e)
+			return
+		}
+		if poster != nil && poster.ImgURL != "" {
+			imgUrl = poster.ImgURL
+			return
+		}
+	}
+
+	// 生成海报
 	imgConfig, e := yb_poster_config.GetBySource(source)
 	if e != nil {
 		err = errors.New("获取图片配置失败")
 		return
 	}
-	// 填充html内容
 	content, newHeight, e := fillContent2HtmlV2(source, pars, "", imgConfig.Hight, *imgConfig)
 	if e != nil {
 		err = errors.New("html内容有误")
@@ -421,6 +437,18 @@ func GetDynamicShareImg(source, pars string) (imgUrl string, err error) {
 		return
 	}
 	imgUrl = res.Data
+
+	// 报告详情-记录海报信息
+	if reportId > 0 {
+		newPoster := &yb_poster_resource.YbPosterResource{
+			Path:       path,
+			ImgURL:     imgUrl,
+			Type:       "poster",
+			Version:    version,
+			CreateTime: time.Now(),
+		}
+		err = newPoster.Create()
+	}
 	return
 }
 
@@ -496,4 +524,4 @@ finally:
 		cmd.Process.Kill()
 	}()
 	return
-}
+}

+ 1 - 1
services/voice_broadcast.go

@@ -392,7 +392,7 @@ func createVoiceBroadcastShareImg(baseImg, sectionName, createTime string) (shar
 		err = e
 		return
 	}
-	shareImg, e = GetDynamicShareImg(VoiceBroadcastShareImgSource, string(parsByte))
+	shareImg, e = GetDynamicShareImg(VoiceBroadcastShareImgSource, string(parsByte), 0, 0, "")
 	if e != nil {
 		err = e
 		return