|
@@ -326,8 +326,9 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
|
|
|
reportCode := utils.MD5(strconv.Itoa(reportId))
|
|
|
|
|
|
- pdfPath := `./static/` + reportCode + ".pdf"
|
|
|
- jpegPath := `./static/` + reportCode + ".jpeg"
|
|
|
+ // pc端
|
|
|
+ pdfPath := `./static/` + reportCode + "_1200.pdf"
|
|
|
+ jpegPath := `./static/` + reportCode + "_1200.jpeg"
|
|
|
|
|
|
go func() {
|
|
|
err := ReportToPdf(reportUrl, pdfPath)
|
|
@@ -392,9 +393,9 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
|
|
|
go func() {
|
|
|
width := 1200
|
|
|
- if reportType == 3 {
|
|
|
+ /*if reportType == 3 {
|
|
|
width = 800
|
|
|
- }
|
|
|
+ }*/
|
|
|
err := ReportToJpeg(width, reportUrl, jpegPath)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())
|
|
@@ -450,4 +451,127 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
}
|
|
|
|
|
|
}()
|
|
|
+
|
|
|
+ // 移动端
|
|
|
+ pdfPathMobile := `./static/` + reportCode + "_600.pdf"
|
|
|
+ jpegPathMobile := `./static/` + reportCode + "_600.jpeg"
|
|
|
+
|
|
|
+ go func() {
|
|
|
+ err := ReportToPdf(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())
|
|
|
+
|
|
|
+ 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, pdfPathMobile, "")
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("文件上传失败, Err: \n" + err.Error())
|
|
|
+ go alarm_msg.SendAlarmMsg("文件上传失败:"+err.Error(), 3)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }()
|
|
|
+
|
|
|
+ go func() {
|
|
|
+ width := 600
|
|
|
+ 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())
|
|
|
+
|
|
|
+ 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())
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }()
|
|
|
}
|