瀏覽代碼

Merge branch 'feature/eta_2.5.4_report_free_layout' into debug

kobe6258 3 周之前
父節點
當前提交
b1fcfc5f9e
共有 1 個文件被更改,包括 12 次插入10 次删除
  1. 12 10
      services/smart_report.go

+ 12 - 10
services/smart_report.go

@@ -136,12 +136,11 @@ func SmartReportElasticUpsert(smartReportId int, state int) (err error) {
 	return
 }
 
-func ReportToPdf(reportUrl, filePath string, top, bottom, left, right int) (err error) {
+func ReportToPdf(width int, reportUrl, filePath string, top, bottom, left, right int) (err error) {
 	pyCode := `
 import asyncio
 from pyppeteer import launch
 
-@asyncio.coroutine
 async def main():
     # 异步代码
     browser = await launch({
@@ -151,21 +150,22 @@ async def main():
     })
     page = await browser.newPage()
     await page.setViewport({
-        'width': 1920,
-        'height': 1080,
+        'width': %d,
+        'height': 1697
     })
     await page.goto('%s', {
         'waitUntil': 'networkidle0',
-        'timeout': 1000000  # 设置超时时间为 100 秒
+        'timeout': 3000000  # 设置超时时间为 100 秒
     })
 
     # 在生成PDF之前等待2秒
-    await asyncio.sleep(5)
+    await asyncio.sleep(15)
 
     await page.pdf({
+		'width': %d,
+        'height': 1697,
         'path': "%s",
         'printBackground': True,
-        'format': "A2",
         'margin': {
             'top': '%dpx',
             'bottom': '%dpx',
@@ -186,7 +186,7 @@ finally:
     loop.close()
 `
 
-	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, reportUrl, filePath, top, bottom, left, right)
+	pyCode = fmt.Sprintf(pyCode, utils.ChromePath, width, reportUrl, width, filePath, top, bottom, left, right)
 	utils.FileLog.Info("pdf pyCode: \n" + pyCode)
 	cmd := exec.Command("python3", "-c", pyCode)
 	output, e := cmd.CombinedOutput()
@@ -331,11 +331,12 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 	jpegPath := `./static/` + reportCode + "_1200.jpeg"
 
 	go func() {
+		width := 1200
 		top, bottom, left, right := 20, 20, 20, 20
 		if report.ReportLayout == 3 {
 			top, bottom, left, right = 0, 0, 0, 0
 		}
-		err := ReportToPdf(reportUrl, pdfPath, top, bottom, left, right)
+		err := ReportToPdf(width, reportUrl, pdfPath, top, bottom, left, right)
 		if err != nil {
 			utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
 			go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)
@@ -461,8 +462,9 @@ func Report2pdfAndJpeg(reportUrl string, reportId, reportType int) {
 	jpegPathMobile := `./static/` + reportCode + "_600.jpeg"
 	if report.ReportLayout != 3 {
 		go func() {
+			width := 600
 			top, bottom, left, right := 20, 20, 20, 20
-			err := ReportToPdf(reportUrl, pdfPathMobile, top, bottom, left, right)
+			err := ReportToPdf(width, reportUrl, pdfPathMobile, top, bottom, left, right)
 			if err != nil {
 				utils.FileLog.Info("ReportToPdf failed: , error: \n" + err.Error())
 				go alarm_msg.SendAlarmMsg("ReportToPdf failed:"+err.Error(), 3)