|
@@ -301,7 +301,10 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
if reportUrl == `` {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ report, err := models.GetReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
// 先清空字段
|
|
|
if reportType == 1 {
|
|
|
err = models.UpdatePdfUrlReportById(reportId)
|
|
@@ -448,125 +451,126 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
}
|
|
|
}
|
|
|
}()
|
|
|
+ if report.ReportLayout != 3 {
|
|
|
+ // 移动端
|
|
|
+ go func() {
|
|
|
+ pdfPathMobile := `./static/` + reportCode + "_600.pdf"
|
|
|
+ jpegPathMobile := `./static/` + reportCode + "_600.jpg"
|
|
|
+
|
|
|
+ width := 600
|
|
|
+ err = ReportToPdf(width, reportUrl, pdfPathMobile)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
|
|
|
+ }
|
|
|
|
|
|
- // 移动端
|
|
|
- go func() {
|
|
|
- pdfPathMobile := `./static/` + reportCode + "_600.pdf"
|
|
|
- jpegPathMobile := `./static/` + reportCode + "_600.jpg"
|
|
|
-
|
|
|
- width := 600
|
|
|
- err = ReportToPdf(width, reportUrl, pdfPathMobile)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
|
|
|
- go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
|
|
|
- }
|
|
|
-
|
|
|
- file, err := os.Open(pdfPathMobile)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("Open failed: , error: \n" + err.Error())
|
|
|
- go alarm_msg.SendAlarmMsg("Open failed:"+err.Error(), 3)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- ext := path.Ext(file.Name())
|
|
|
+ file, err := os.Open(pdfPathMobile)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("Open failed: , error: \n" + err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg("Open failed:"+err.Error(), 3)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
- fileName := randStr + ext
|
|
|
- defer file.Close() //关闭上传文件
|
|
|
+ ext := path.Ext(file.Name())
|
|
|
|
|
|
- resourceUrl := ``
|
|
|
- ossClient := NewOssClient()
|
|
|
- if ossClient == nil {
|
|
|
- utils.FileLog.Info("初始化OSS服务失败")
|
|
|
- return
|
|
|
- }
|
|
|
- resourceUrl, err = ossClient.UploadFile(fileName, pdfPathMobile, "")
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("文件上传失败, Err: \n" + err.Error())
|
|
|
- go alarm_msg.SendAlarmMsg("文件上传失败:"+err.Error(), 3)
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- _ = os.Remove(pdfPathMobile)
|
|
|
- }()
|
|
|
+ randStr := utils.GetRandStringNoSpecialChar(28)
|
|
|
+ fileName := randStr + ext
|
|
|
+ defer file.Close() //关闭上传文件
|
|
|
|
|
|
- if reportType == 3 {
|
|
|
- // 更新pdf url
|
|
|
- ob := new(smart_report.SmartReport)
|
|
|
- ob.SmartReportId = reportId
|
|
|
- ob.DetailPdfUrlMobile = resourceUrl
|
|
|
- if err = ob.Update([]string{"DetailPdfUrlMobile"}); err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ resourceUrl := ``
|
|
|
+ ossClient := NewOssClient()
|
|
|
+ if ossClient == nil {
|
|
|
+ utils.FileLog.Info("初始化OSS服务失败")
|
|
|
return
|
|
|
}
|
|
|
- } else if reportType == 2 {
|
|
|
- err = models.ModifyEnglishReportPdfUrlMobile(reportId, resourceUrl)
|
|
|
+ resourceUrl, err = ossClient.UploadFile(fileName, pdfPathMobile, "")
|
|
|
if err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ utils.FileLog.Info("文件上传失败, Err: \n" + err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg("文件上传失败:"+err.Error(), 3)
|
|
|
return
|
|
|
}
|
|
|
- } else if reportType == 1 {
|
|
|
- err = models.ModifyReportPdfUrlMobile(reportId, resourceUrl)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
- return
|
|
|
+ defer func() {
|
|
|
+ _ = os.Remove(pdfPathMobile)
|
|
|
+ }()
|
|
|
+
|
|
|
+ if reportType == 3 {
|
|
|
+ // 更新pdf url
|
|
|
+ ob := new(smart_report.SmartReport)
|
|
|
+ ob.SmartReportId = reportId
|
|
|
+ ob.DetailPdfUrlMobile = resourceUrl
|
|
|
+ if err = ob.Update([]string{"DetailPdfUrlMobile"}); err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 2 {
|
|
|
+ err = models.ModifyEnglishReportPdfUrlMobile(reportId, resourceUrl)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 1 {
|
|
|
+ err = models.ModifyReportPdfUrlMobile(reportId, resourceUrl)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- time.Sleep(1 * time.Minute)
|
|
|
+ time.Sleep(1 * time.Minute)
|
|
|
|
|
|
- err = ReportToJpeg(width, reportUrl, jpegPathMobile)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())
|
|
|
- }
|
|
|
- file, err = os.Open(jpegPathMobile)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("open file failed: , error: \n" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
+ err = ReportToJpeg(width, reportUrl, jpegPathMobile)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())
|
|
|
+ }
|
|
|
+ file, err = os.Open(jpegPathMobile)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("open file failed: , error: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- ext = path.Ext(file.Name())
|
|
|
+ ext = path.Ext(file.Name())
|
|
|
|
|
|
- randStr = utils.GetRandStringNoSpecialChar(28)
|
|
|
- fileName = randStr + ext
|
|
|
- defer file.Close() //关闭上传文件
|
|
|
+ randStr = utils.GetRandStringNoSpecialChar(28)
|
|
|
+ fileName = randStr + ext
|
|
|
+ defer file.Close() //关闭上传文件
|
|
|
|
|
|
- resourceUrl = ``
|
|
|
- ossClient = NewOssClient()
|
|
|
- if ossClient == nil {
|
|
|
- utils.FileLog.Info("初始化OSS服务失败")
|
|
|
- return
|
|
|
- }
|
|
|
- resourceUrl, err = ossClient.UploadFile(fileName, jpegPathMobile, "")
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("文件上传失败, Err: \n" + err.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- _ = os.Remove(jpegPathMobile)
|
|
|
- }()
|
|
|
-
|
|
|
- if reportType == 3 {
|
|
|
- // 更新jpeg url
|
|
|
- ob := new(smart_report.SmartReport)
|
|
|
- ob.SmartReportId = reportId
|
|
|
- ob.DetailImgUrlMobile = resourceUrl
|
|
|
- if err = ob.Update([]string{"DetailImgUrlMobile"}); err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ resourceUrl = ``
|
|
|
+ ossClient = NewOssClient()
|
|
|
+ if ossClient == nil {
|
|
|
+ utils.FileLog.Info("初始化OSS服务失败")
|
|
|
return
|
|
|
}
|
|
|
- } else if reportType == 2 {
|
|
|
- err = models.ModifyEnglishReportImgUrlMobile(reportId, resourceUrl)
|
|
|
+ resourceUrl, err = ossClient.UploadFile(fileName, jpegPathMobile, "")
|
|
|
if err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ utils.FileLog.Info("文件上传失败, Err: \n" + err.Error())
|
|
|
return
|
|
|
}
|
|
|
- } else if reportType == 1 {
|
|
|
- err = models.ModifyReportImgUrlMobile(reportId, resourceUrl)
|
|
|
- if err != nil {
|
|
|
- utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
- return
|
|
|
+ defer func() {
|
|
|
+ _ = os.Remove(jpegPathMobile)
|
|
|
+ }()
|
|
|
+
|
|
|
+ if reportType == 3 {
|
|
|
+ // 更新jpeg url
|
|
|
+ ob := new(smart_report.SmartReport)
|
|
|
+ ob.SmartReportId = reportId
|
|
|
+ ob.DetailImgUrlMobile = resourceUrl
|
|
|
+ if err = ob.Update([]string{"DetailImgUrlMobile"}); err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 2 {
|
|
|
+ err = models.ModifyEnglishReportImgUrlMobile(reportId, resourceUrl)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 1 {
|
|
|
+ err = models.ModifyReportImgUrlMobile(reportId, resourceUrl)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("更新研报失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }()
|
|
|
+ }()
|
|
|
+ }
|
|
|
}
|