|
@@ -182,10 +182,13 @@ finally:
|
|
|
pyCode = fmt.Sprintf(pyCode, utils.ChromePath, reportUrl, filePath)
|
|
|
utils.FileLog.Info("pdf pyCode: \n" + pyCode)
|
|
|
cmd := exec.Command("python3", "-c", pyCode)
|
|
|
- _, err = cmd.CombinedOutput()
|
|
|
- if err != nil {
|
|
|
+ output, e := cmd.CombinedOutput()
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
|
|
|
+ utils.FileLog.Info("Output: %s\n", string(output))
|
|
|
go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
|
|
|
+ go alarm_msg.SendAlarmMsg("Output :"+string(output), 3)
|
|
|
}
|
|
|
defer func() {
|
|
|
cmd.Process.Kill()
|
|
@@ -193,7 +196,7 @@ finally:
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func ReportToJpeg(reportUrl, filePath string) (err error) {
|
|
|
+func ReportToJpeg(width int, reportUrl, filePath string) (err error) {
|
|
|
pyCode := `
|
|
|
import asyncio
|
|
|
from pyppeteer import launch, errors
|
|
@@ -212,7 +215,7 @@ async def main():
|
|
|
|
|
|
# 设置视口大小
|
|
|
await page.setViewport({
|
|
|
- 'width': 1920,
|
|
|
+ 'width': %d,
|
|
|
'height': 1080
|
|
|
})
|
|
|
|
|
@@ -221,11 +224,15 @@ async def main():
|
|
|
'waitUntil': 'networkidle0',
|
|
|
'timeout': 1000000 # 设置超时时间为 100 秒
|
|
|
})
|
|
|
-
|
|
|
- # 截取全页面的屏幕截图
|
|
|
+ # Customizing footer for page numbers starting from page 2
|
|
|
+
|
|
|
+ # 在这里添加两秒的等待
|
|
|
+ await asyncio.sleep(2)
|
|
|
+
|
|
|
await page.screenshot({
|
|
|
'path': "%s",
|
|
|
'fullPage': True,
|
|
|
+ 'quality':100
|
|
|
})
|
|
|
|
|
|
except errors.BrowserError as e:
|
|
@@ -250,14 +257,17 @@ finally:
|
|
|
loop.close()
|
|
|
`
|
|
|
|
|
|
- pyCode = fmt.Sprintf(pyCode, utils.ChromePath, reportUrl, filePath)
|
|
|
+ pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, filePath)
|
|
|
utils.FileLog.Info("jpeg pyCode: \n" + pyCode)
|
|
|
cmd := exec.Command("python3", "-c", pyCode)
|
|
|
|
|
|
- _, err = cmd.CombinedOutput()
|
|
|
- if err != nil {
|
|
|
+ output, e := cmd.CombinedOutput()
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())
|
|
|
+ utils.FileLog.Info("Output: %s\n", string(output))
|
|
|
go alarm_msg.SendAlarmMsg("ReportToJpeg failed:"+err.Error(), 3)
|
|
|
+ go alarm_msg.SendAlarmMsg("Output :"+string(output), 3)
|
|
|
}
|
|
|
defer func() {
|
|
|
cmd.Process.Kill()
|
|
@@ -265,7 +275,7 @@ finally:
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func Report2pdfAndJpeg(reportUrl string, reportId,reportType int) {
|
|
|
+func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
|
|
|
var err error
|
|
|
|
|
|
defer func() {
|
|
@@ -274,6 +284,28 @@ func Report2pdfAndJpeg(reportUrl string, reportId,reportType int) {
|
|
|
utils.FileLog.Info("Report2pdfAndJpeg failed: , error: \n" + err.Error())
|
|
|
}
|
|
|
}()
|
|
|
+
|
|
|
+ // 先清空字段
|
|
|
+ if reportType == 1 {
|
|
|
+ err = models.UpdatePdfUrlReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("清空pdf长图字段失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 2 {
|
|
|
+ err = models.UpdatePdfUrlEnglishReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("清空pdf长图字段失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else if reportType == 3 {
|
|
|
+ err = smart_report.UpdatePdfUrlSmartReportById(reportId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("清空pdf长图字段失败, Err: \n" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
reportCode := utils.MD5(strconv.Itoa(reportId))
|
|
|
|
|
|
pdfPath := `./static/` + reportCode + ".pdf"
|
|
@@ -341,7 +373,11 @@ func Report2pdfAndJpeg(reportUrl string, reportId,reportType int) {
|
|
|
}()
|
|
|
|
|
|
go func() {
|
|
|
- err := ReportToJpeg(reportUrl, jpegPath)
|
|
|
+ width := 1200
|
|
|
+ if reportType == 3 {
|
|
|
+ width = 800
|
|
|
+ }
|
|
|
+ err := ReportToJpeg(width, reportUrl, jpegPath)
|
|
|
if err != nil {
|
|
|
utils.FileLog.Info("ReportToJpeg failed: , error: \n" + err.Error())
|
|
|
}
|
|
@@ -396,4 +432,4 @@ func Report2pdfAndJpeg(reportUrl string, reportId,reportType int) {
|
|
|
}
|
|
|
|
|
|
}()
|
|
|
-}
|
|
|
+}
|