|
@@ -6,6 +6,7 @@ import (
|
|
|
"fmt"
|
|
|
"hongze/hongze_yb/global"
|
|
|
"hongze/hongze_yb/models/tables/yb_poster_resource"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_suncode_pars"
|
|
|
"hongze/hongze_yb/services/wx_app"
|
|
|
"hongze/hongze_yb/utils"
|
|
|
"io/ioutil"
|
|
@@ -33,6 +34,10 @@ func CreatePosterFromSource(codePage, codeScene, source, version, pars string) (
|
|
|
go SendEmail(utils.APPNAME+"【"+global.CONFIG.Serve.RunMode+"】"+"失败提醒", "生成分享海报失败, "+errMsg+", CreatePosterFromSource: "+err.Error(), utils.EmailSendToUsers)
|
|
|
}
|
|
|
}()
|
|
|
+ if codePage == "" || codeScene == "" || source == "" || pars == "" {
|
|
|
+ errMsg = "参数有误"
|
|
|
+ return
|
|
|
+ }
|
|
|
path := fmt.Sprint(codePage, "?", codeScene)
|
|
|
// 获取海报, 无海报则生成
|
|
|
poster, err := yb_poster_resource.GetPosterByCondition(path, "poster", version)
|
|
@@ -45,18 +50,28 @@ func CreatePosterFromSource(codePage, codeScene, source, version, pars string) (
|
|
|
}
|
|
|
// 图片长宽
|
|
|
heightMap := map[string]int{
|
|
|
- "chapter_detail": 370,
|
|
|
- "chapter_list": 369,
|
|
|
- "chart_detail": 1536,
|
|
|
- //"chart_detail": 381,
|
|
|
- "chart_list": 338,
|
|
|
- "report_detail": 355,
|
|
|
- "report_list": 369,
|
|
|
- }
|
|
|
- //width := 294
|
|
|
- width := 1176
|
|
|
+ "activity_detail": 1210,
|
|
|
+ "activity_list": 1948,
|
|
|
+ "chapter_detail": 1480,
|
|
|
+ "chapter_list": 1548,
|
|
|
+ "chart_detail": 1536,
|
|
|
+ "chart_list": 1352,
|
|
|
+ "report_detail": 1420,
|
|
|
+ "report_list": 1344,
|
|
|
+ }
|
|
|
+ widthMap := map[string]int{
|
|
|
+ "activity_detail": 1280,
|
|
|
+ "activity_list": 1280,
|
|
|
+ "chapter_detail": 1176,
|
|
|
+ "chapter_list": 1176,
|
|
|
+ "chart_detail": 1176,
|
|
|
+ "chart_list": 1176,
|
|
|
+ "report_detail": 1176,
|
|
|
+ "report_list": 1176,
|
|
|
+ }
|
|
|
+ width := widthMap[source]
|
|
|
height := heightMap[source]
|
|
|
- if height == 0 {
|
|
|
+ if width == 0 || height == 0 {
|
|
|
errMsg = "图片长度有误"
|
|
|
err = errors.New(errMsg)
|
|
|
return "", err
|
|
@@ -67,24 +82,15 @@ func CreatePosterFromSource(codePage, codeScene, source, version, pars string) (
|
|
|
return
|
|
|
}
|
|
|
// 填充html内容
|
|
|
- reqContent := ""
|
|
|
- switch source {
|
|
|
- case "chart_detail":
|
|
|
- if reqContent, err = FillContent2ChartDetailHtml(pars, sunCodeUrl); err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- default:
|
|
|
- err = errors.New("来源有误")
|
|
|
- return
|
|
|
- }
|
|
|
- if reqContent == "" {
|
|
|
+ contentStr, err := fillContent2Html(source, pars, sunCodeUrl)
|
|
|
+ if err != nil {
|
|
|
errMsg = "html内容有误"
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|
|
|
// 请求python服务htm2img
|
|
|
htm2ImgReq := make(map[string]interface{})
|
|
|
- htm2ImgReq["html_content"] = reqContent
|
|
|
+ htm2ImgReq["html_content"] = contentStr
|
|
|
htm2ImgReq["width"] = width
|
|
|
htm2ImgReq["height"] = height
|
|
|
res, err := postHtml2Img(htm2ImgReq)
|
|
@@ -110,34 +116,6 @@ func CreatePosterFromSource(codePage, codeScene, source, version, pars string) (
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// ChartDetailPosterReq 图标详情页海报动态信息
|
|
|
-type ChartDetailPosterReq struct {
|
|
|
- ChartInfoId int `json:"chart_info_id"`
|
|
|
- ChartName string `json:"chart_name"`
|
|
|
- ChartImage string `json:"chart_image"`
|
|
|
-}
|
|
|
-
|
|
|
-// 生成html文本-图表详情页
|
|
|
-func FillContent2ChartDetailHtml(pars, sunCodeUrl string) (contentStr string, err error) {
|
|
|
- // 解析html填充的参数
|
|
|
- params := new(ChartDetailPosterReq)
|
|
|
- if err = json.Unmarshal([]byte(pars), ¶ms); err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- // 获取模板内容
|
|
|
- demoPath := "static/htm2img/chart_detail.html"
|
|
|
- contentByte, err := ioutil.ReadFile(demoPath)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- // 替换模板内容
|
|
|
- contentStr = string(contentByte)
|
|
|
- contentStr = strings.ReplaceAll(contentStr, "{{CHART_NAME}}", params.ChartName)
|
|
|
- contentStr = strings.ReplaceAll(contentStr, "{{CHART_IMAGE}}", params.ChartImage)
|
|
|
- contentStr = strings.ReplaceAll(contentStr, "{{SUN_CODE}}", sunCodeUrl)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
type Html2ImgResp struct {
|
|
|
Code int `json:"code"`
|
|
|
Msg string `json:"msg"`
|
|
@@ -203,9 +181,9 @@ func CreateAndUploadSunCode(page, scene, version string) (imgUrl string, err err
|
|
|
if exist != nil && exist.ImgURL != "" {
|
|
|
return exist.ImgURL, nil
|
|
|
}
|
|
|
- // 参数超过32位会生成失败,md5处理至32位
|
|
|
- scene = utils.MD5(scene)
|
|
|
- picByte, err := wx_app.GetSunCode(page, scene)
|
|
|
+ // scene超过32位会生成失败,md5处理至32位
|
|
|
+ sceneMD5 := utils.MD5(scene)
|
|
|
+ picByte, err := wx_app.GetSunCode(page, sceneMD5)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -239,5 +217,156 @@ func CreateAndUploadSunCode(page, scene, version string) (imgUrl string, err err
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
err = newPoster.Create()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 记录参数md5
|
|
|
+ newPars := &yb_suncode_pars.YbSuncodePars{
|
|
|
+ Scene: scene,
|
|
|
+ Key: sceneMD5,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ }
|
|
|
+ err = newPars.Create()
|
|
|
return
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+type PosterParsReq struct {
|
|
|
+ ActivityTitle string `json:"activity_title"`
|
|
|
+ ActivitySpeaker string `json:"activity_speaker"`
|
|
|
+ ActivityTime string `json:"activity_time"`
|
|
|
+ ChartName string `json:"chart_name"`
|
|
|
+ ChartImage string `json:"chart_image"`
|
|
|
+ ReportType string `json:"report_type"`
|
|
|
+ ReportAvatar string `json:"report_avatar"`
|
|
|
+ ReportTitle string `json:"report_title"`
|
|
|
+ ReportAbstract string `json:"report_abstract"`
|
|
|
+ Stage1 string `json:"stage_1"`
|
|
|
+ Avatar1 string `json:"avatar_1"`
|
|
|
+ Title1 string `json:"title_1"`
|
|
|
+ Author1 string `json:"author_1"`
|
|
|
+ Tag1 string `json:"tag_1"`
|
|
|
+ Img1 string `json:"img_1"`
|
|
|
+ Time1 string `json:"time_1"`
|
|
|
+ Abstract1 string `json:"abstract_1"`
|
|
|
+ Status1 string `json:"status_1"`
|
|
|
+ Speaker1 string `json:"speaker_1"`
|
|
|
+ Stage2 string `json:"stage_2"`
|
|
|
+ Avatar2 string `json:"avatar_2"`
|
|
|
+ Title2 string `json:"title_2"`
|
|
|
+ Author2 string `json:"author_2"`
|
|
|
+ Tag2 string `json:"tag_2"`
|
|
|
+ Img2 string `json:"img_2"`
|
|
|
+ Abstract2 string `json:"abstract_2"`
|
|
|
+ Time2 string `json:"time_2"`
|
|
|
+ Status2 string `json:"status_2"`
|
|
|
+ Speaker2 string `json:"speaker_2"`
|
|
|
+ ListTitle string `json:"list_title"`
|
|
|
+}
|
|
|
+
|
|
|
+// fillContent2Html 填充HTML动态内容
|
|
|
+func fillContent2Html(source string, pars, sunCodeUrl string) (contentStr string, err error) {
|
|
|
+ params := new(PosterParsReq)
|
|
|
+ if err = json.Unmarshal([]byte(pars), ¶ms); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ template := fmt.Sprint("static/htm2img/", source, ".html")
|
|
|
+ contentByte, err := ioutil.ReadFile(template)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ contentStr = string(contentByte)
|
|
|
+ // TODO:列表的动态内容不完整的用默认内容的填充
|
|
|
+ if strings.Contains(source, "list") {
|
|
|
+ if params.Title1 == "" || params.Title2 == "" {
|
|
|
+ params = &PosterParsReq{
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 填充指定内容
|
|
|
+ switch source {
|
|
|
+ case "activity_detail":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{ACTIVITY_TITLE}}", params.ActivityTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{ACTIVITY_SPEAKER}}", params.ActivitySpeaker, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{ACTIVITY_TIME}}", params.ActivityTime, 1)
|
|
|
+ case "chapter_detail":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_AVATAR}}", params.ReportAvatar, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_TITLE}}", params.ReportTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_ABSTRACT}}", params.ReportAbstract, 1)
|
|
|
+ case "chart_detail":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{CHART_NAME}}", params.ChartName, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{CHART_IMAGE}}", params.ChartImage, 1)
|
|
|
+ case "report_detail":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_TYPE}}", params.ReportType, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_TITLE}}", params.ReportTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{REPORT_ABSTRACT}}", params.ReportAbstract, 1)
|
|
|
+ case "chapter_list":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{LIST_TITLE}}", params.ListTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{STAGE_1}}", params.Stage1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AVATAR_1}}", params.Avatar1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_1}}", params.Title1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AUTHOR_1}}", params.Author1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TAG_1}}", params.Tag1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{STAGE_2}}", params.Stage2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AVATAR_2}}", params.Avatar2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_2}}", params.Title2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AUTHOR_2}}", params.Author2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TAG_2}}", params.Tag2, 1)
|
|
|
+ case "chart_list":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{LIST_TITLE}}", params.ListTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_1}}", params.Title1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{IMG_1}}", params.Img1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_2}}", params.Title2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{IMG_2}}", params.Img2, 1)
|
|
|
+ case "report_list":
|
|
|
+ contentStr = strings.Replace(contentStr, "{{LIST_TITLE}}", params.ListTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_1}}", params.Title1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{ABSTRACT_1}}", params.Abstract1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{IMG_1}}", params.Img1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TIME_1}}", params.Time1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_2}}", params.Title2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{ABSTRACT_2}}", params.Abstract2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{IMG_2}}", params.Img2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TIME_2}}", params.Time2, 1)
|
|
|
+ case "activity_list":
|
|
|
+ bgColorMap := map[string]string{
|
|
|
+ "未开始": "#3385FF",
|
|
|
+ "进行中": "#A2A2A2",
|
|
|
+ "已结束": "#E3B377",
|
|
|
+ }
|
|
|
+ statusItemMap := map[string]string{
|
|
|
+ "未开始": "block",
|
|
|
+ "进行中": "none",
|
|
|
+ "已结束": "none",
|
|
|
+ }
|
|
|
+ offlineMap := map[string]string{
|
|
|
+ "线上会议": "block",
|
|
|
+ "线下沙龙": "none",
|
|
|
+ }
|
|
|
+ onlineMap := map[string]string{
|
|
|
+ "线上会议": "none",
|
|
|
+ "线下沙龙": "block",
|
|
|
+ }
|
|
|
+ contentStr = strings.Replace(contentStr, "{{LIST_TITLE}}", params.ListTitle, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{BG_COLORE_1}}", bgColorMap[params.Status1], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{STATUS_1}}", params.Status1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AVATAR_1}}", params.Avatar1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_1}}", params.Title1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SPEAKER_1}}", params.Speaker1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TIME_1}}", params.Time1, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_ITEM_1}}", statusItemMap[params.Status1], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_OFFLINE_1}}", offlineMap[params.ListTitle], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_ONLINE_1}}", onlineMap[params.ListTitle], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{BG_COLORE_2}}", bgColorMap[params.Status2], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{STATUS_2}}", params.Status2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{AVATAR_2}}", params.Avatar2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TITLE_2}}", params.Title2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SPEAKER_2}}", params.Speaker2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{TIME_2}}", params.Time2, 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_ITEM_2}}", statusItemMap[params.Status2], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_OFFLINE_2}}", statusItemMap[params.ListTitle], 1)
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SHOW_ONLINE_2}}", onlineMap[params.ListTitle], 1)
|
|
|
+ }
|
|
|
+ contentStr = strings.Replace(contentStr, "{{SUN_CODE}}", sunCodeUrl, 1)
|
|
|
+ return
|
|
|
+}
|