Browse Source

temp commit

hsun 1 year ago
parent
commit
6ab8c0348e
3 changed files with 37 additions and 7 deletions
  1. 23 6
      controllers/smart_report/smart_report.go
  2. 6 0
      models/smart_report/smart_report.go
  3. 8 1
      utils/config.go

+ 23 - 6
controllers/smart_report/smart_report.go

@@ -367,9 +367,15 @@ func (this *SmartReportController) Publish() {
 		return
 	}
 
+	cols := []string{"State", "ModifyTime"}
 	item.State = req.PublishState
 	item.ModifyTime = time.Now().Local()
-	cols := []string{"State", "ModifyTime"}
+	// 取消发布时同时清除掉Img和PDF的文件地址
+	if req.PublishState == 1 {
+		cols = append(cols, "DetailImgUrl", "DetailPdfUrl")
+		item.DetailImgUrl = ""
+		item.DetailPdfUrl = ""
+	}
 	if e = item.Update(cols); e != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "更新研报失败, Err: " + e.Error()
@@ -936,7 +942,7 @@ func (this *SmartReportController) DetailImg() {
 	}
 
 	reportOB := new(smart_report.SmartReport)
-	_, e := reportOB.GetItemById(reportId)
+	item, e := reportOB.GetItemById(reportId)
 	if e != nil {
 		if e.Error() == utils.ErrNoRow() {
 			br.Msg = "报告不存在, 请刷新页面"
@@ -946,10 +952,21 @@ func (this *SmartReportController) DetailImg() {
 		br.ErrMsg = "获取报告失败, Err: " + e.Error()
 		return
 	}
+	if item.DetailImgUrl != "" {
+		br.Data = item.DetailImgUrl
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		return
+	}
 
-	// TODO:调用python服务生成长图
+	// TODO:生成一个长图或者PDF需要个2min左右, 加个锁避免重复请求生成服务
 
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取成功"
+	// TODO:未生成, 则调用eta_report的详情转换接口去生成一次
+	go func() {
+
+	}()
+
+	br.Msg = "图片正在生成中, 请稍后下载"
+	return
 }

+ 6 - 0
models/smart_report/smart_report.go

@@ -44,6 +44,8 @@ type SmartReport struct {
 	PreMsgSend         int       `description:"定时发布后是否推送模版消息:0-否;1-是"`
 	MsgIsSend          int       `description:"消息是否已发送:0-否;1-是"`
 	MsgSendTime        time.Time `description:"模版消息发送时间"`
+	DetailImgUrl       string    `description:"报告详情长图地址"`
+	DetailPdfUrl       string    `description:"报告详情PDF地址"`
 	CreateTime         time.Time `description:"创建时间"`
 	ModifyTime         time.Time `description:"修改时间"`
 }
@@ -182,6 +184,8 @@ type SmartReportItem struct {
 	State              int    `description:"发布状态:1-待发布;2-已发布"`
 	PublishTime        string `description:"发布时间"`
 	MsgIsSend          int    `description:"消息是否已发送:0-否;1-是"`
+	DetailImgUrl       string `description:"报告详情长图地址"`
+	DetailPdfUrl       string `description:"报告详情PDF地址"`
 	CreateTime         string `description:"创建时间"`
 	ModifyTime         string `description:"修改时间"`
 	CanEdit            bool   `description:"是否可编辑"`
@@ -217,6 +221,8 @@ func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
 	item.State = origin.State
 	item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
 	item.MsgIsSend = origin.MsgIsSend
+	item.DetailImgUrl = origin.DetailImgUrl
+	item.DetailPdfUrl = origin.DetailPdfUrl
 	item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
 	item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
 	return

+ 8 - 1
utils/config.go

@@ -124,8 +124,9 @@ var (
 
 // 对象存储客户端
 var (
-	ObjectStorageClient string       // 目前有oss minio,默认oss
+	ObjectStorageClient string // 目前有oss minio,默认oss
 )
+
 // 阿里云配置
 var (
 	Bucketname       string
@@ -204,6 +205,9 @@ var (
 	MinIoRegion           string
 )
 
+// PythonUrlReport2Img 生成长图服务地址
+var PythonUrlReport2Img string
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -449,6 +453,9 @@ func init() {
 		MinIoRegion = config["minio_region"]
 	}
 
+	// 生成长图服务地址
+	PythonUrlReport2Img = config["python_url_report2img"]
+
 	// 初始化ES
 	initEs()
 }