浏览代码

fix:英文研报也需要通过接口获取链接token

Roc 3 周之前
父节点
当前提交
34b3a5ef80
共有 4 个文件被更改,包括 123 次插入14 次删除
  1. 66 4
      controllers/english_report/report.go
  2. 9 4
      models/business_conf.go
  3. 42 0
      services/english_report.go
  4. 6 6
      services/report_v2.go

+ 66 - 4
controllers/english_report/report.go

@@ -696,8 +696,9 @@ func (this *EnglishReportController) PublishReport() {
 			}()
 
 			// 生成报告pdf和长图
-			if req.ReportUrl != "" {
-				go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
+			pdfUrl := services.GetGeneralEnglishReportPdfUrl(report.Id, report.ReportCode)
+			if pdfUrl != "" {
+				go services.Report2pdfAndJpeg(pdfUrl, report.Id, 2)
 			}
 		} else {
 			// 从无审批切换为有审批, 状态重置
@@ -799,8 +800,9 @@ func (this *EnglishReportController) PrePublishReport() {
 	}
 
 	// 生成报告pdf和长图
-	if req.ReportUrl != "" {
-		go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
+	pdfUrl := services.GetGeneralEnglishReportPdfUrl(report.Id, report.ReportCode)
+	if pdfUrl != "" {
+		go services.Report2pdfAndJpeg(pdfUrl, report.Id, 2)
 	}
 
 	br.Ret = 200
@@ -1448,3 +1450,63 @@ func (this *EnglishReportController) CancelApprove() {
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// @Title 获取报告分享链接
+// @Description 获取报告分享链接
+// @Param   ReportId   query   int  true       "报告id"
+// @Success 200 {object} models.EnglishReportDetailView
+// @router /share_url [get]
+func (this *EnglishReportController) GetShareUrl() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	/*var req models.ReportDetailReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ReportId <= 0 {
+		br.Msg = "参数错误"
+		return
+	}*/
+	reportId, err := this.GetInt("ReportId")
+	if err != nil {
+		br.Msg = "获取参数失败!"
+		br.ErrMsg = "获取参数失败,Err:" + err.Error()
+		return
+	}
+	if reportId <= 0 {
+		br.Msg = "参数错误"
+		return
+	}
+	item, err := models.GetEnglishReportById(reportId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
+			return
+		}
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	token, err := services.GetEnglishReportToken(reportId, item.ReportCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "报告已被删除"
+			return
+		}
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	br.Data = token
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 9 - 4
models/business_conf.go

@@ -52,10 +52,15 @@ const (
 	BusinessConfTencentApiSecretKey          = "TencentApiSecretKey"          // 腾讯云API-密钥对
 	BusinessConfTencentApiRecTaskCallbackUrl = "TencentApiRecTaskCallbackUrl" // 腾讯云API-语音识别回调地址
 	BusinessConfSmsJhgjVariable              = "SmsJhgjVariable"              // 聚合国际短信变量
-	BusinessConfEsIndexNameExcel             = "EsIndexNameExcel"             // ES索引名称-表格
-	BusinessConfEsIndexNameDataSource        = "EsIndexNameDataSource"        // 聚合国际短信变量
-	BusinessConfIsOpenChartExpired           = "IsOpenChartExpired"           // 是否开启图表有效期鉴权/报告禁止复制
-	BusinessConfReportChartExpiredTime       = "ReportChartExpiredTime"       // 图表有效期鉴权时间,单位:分钟
+
+	BusinessConfEdbStopRefreshRule = "EdbStopRefreshRule" // 是否停止指标刷新规则
+	BusinessConfReport2ImgUrl      = "Report2ImgUrl"      // 报告转长图地址(用于兼容内外网环境的)
+	BusinessConfReportViewUrl      = "ReportViewUrl"      // 报告详情地址     // 报告详情地址
+
+	BusinessConfEsIndexNameExcel       = "EsIndexNameExcel"       // ES索引名称-表格
+	BusinessConfEsIndexNameDataSource  = "EsIndexNameDataSource"  // 聚合国际短信变量
+	BusinessConfIsOpenChartExpired     = "IsOpenChartExpired"     // 是否开启图表有效期鉴权/报告禁止复制
+	BusinessConfReportChartExpiredTime = "ReportChartExpiredTime" // 图表有效期鉴权时间,单位:分钟
 )
 
 const (

+ 42 - 0
services/english_report.go

@@ -964,3 +964,45 @@ func UpdateEnglishCompanyEnabledByCompanyId(companyId int) (err error) {
 	}
 	return
 }
+
+// GetEnglishReportToken
+// @Description: 获取token
+// @author: Roc
+// @datetime 2025-03-18 10:35:11
+// @param reportId int
+// @param reportCode string
+// @return token string
+// @return err error
+func GetEnglishReportToken(reportId int, reportCode string) (token string, err error) {
+	// 图表授权token
+	token = utils.MD5(fmt.Sprint(reportCode, time.Now().UnixNano()/1e6))
+	err = generalReportAuthToken(token, `en:`, reportId)
+
+	return
+}
+
+func GetGeneralEnglishReportPdfUrl(reportId int, reportCode string) (pdfUrl string) {
+	// 优先取Report2ImgUrl(用于兼容内外网环境的), 没有的话取报告详情地址
+	var reportUrl string
+	conf, _ := models.GetBusinessConfByKey(models.BusinessConfReport2ImgUrl)
+	if conf != nil && conf.ConfVal != "" {
+		reportUrl = conf.ConfVal
+	}
+	if reportUrl == "" {
+		conf, e := models.GetBusinessConfByKey(models.BusinessConfReportViewUrl)
+		if e != nil {
+			return
+		}
+		reportUrl = conf.ConfVal
+	}
+
+	token := utils.MD5(fmt.Sprint(pdfUrl, time.Now().UnixNano()/1e6))
+	e := generalReportAuthToken(token, `en:`, reportId)
+	if e == nil {
+		pdfUrl = fmt.Sprintf("%s&authToken=%s", pdfUrl, token)
+	}
+
+	pdfUrl = fmt.Sprintf("%s/reportshare_pdf_en?code=%s&authToken=%s", reportUrl, reportCode, token)
+
+	return
+}

+ 6 - 6
services/report_v2.go

@@ -1520,7 +1520,7 @@ func GetGeneralPdfUrl(reportId int, reportCode string, reportLayout int8) (pdfUr
 
 	if pdfUrl != "" {
 		token := utils.MD5(fmt.Sprint(pdfUrl, time.Now().UnixNano()/1e6))
-		e := generalReportAuthToken(token, reportId)
+		e := generalReportAuthToken(token, ``, reportId)
 		if e == nil {
 			pdfUrl = fmt.Sprintf("%s&authToken=%s", pdfUrl, token)
 		}
@@ -1709,7 +1709,7 @@ func GeneralReportToken(linkToken string, reportId int) (token string, err error
 	}
 
 	// 生成报告的图表授权token
-	err = generalReportAuthToken(token, reportId)
+	err = generalReportAuthToken(token, ``, reportId)
 	if err != nil {
 		return
 	}
@@ -1724,9 +1724,9 @@ func GeneralReportToken(linkToken string, reportId int) (token string, err error
 // @param token string
 // @param reportId int
 // @return err error
-func generalReportAuthToken(token string, reportId int) (err error) {
+func generalReportAuthToken(token, source string, reportId int) (err error) {
 	// 缓存key
-	reportTokenKey := getReportTokenKey(token)
+	reportTokenKey := getReportTokenKey(token, source)
 	err = utils.Rc.Put(reportTokenKey, reportId, utils.BusinessConfReportChartExpiredTime)
 
 	return
@@ -1760,8 +1760,8 @@ func GetReportAuthToken(linkToken string) string {
 // @datetime 2025-03-17 14:00:14
 // @param linkToken string
 // @return string
-func getReportTokenKey(token string) string {
-	return fmt.Sprint(utils.CACHE_REPORT_AUTH, token)
+func getReportTokenKey(token, source string) string {
+	return fmt.Sprint(utils.CACHE_REPORT_AUTH, source, token)
 }
 
 // HandleReportContentStruct