kobe6258 4 veckor sedan
förälder
incheckning
af5f458b35

+ 4 - 2
eta_data_analysis.iml

@@ -3,8 +3,10 @@
   <component name="Go" enabled="true" />
   <component name="NewModuleRootManager" inherit-compiler-output="true">
     <exclude-output />
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/venv" />
+    </content>
+    <orderEntry type="jdk" jdkName="Python 3.7 (eta_data_analysis)" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
   <component name="TemplatesService">

+ 31 - 16
services/pdf/pdf_service.go

@@ -40,8 +40,8 @@ var (
 			Width:  1200,
 		},
 	}
-	pdfPathTemplate  = "./static/pdf/%s_%d.pdf"
-	jpegPathTemplate = "./static/image/%s_%d.jpg"
+	pdfPathTemplate  = "./static/%s_%d.pdf"
+	jpegPathTemplate = "./static/%s_%d.jpg"
 )
 
 type PDFParams struct {
@@ -73,8 +73,7 @@ func uploadFile(ossClient utils.OssClient, filePath string, fileType string) (re
 	}()
 	return
 }
-func generateAndUploadPDF(params PDFParams, reportUrl, pdfPath string, wg *sync.WaitGroup, ossClient utils.OssClient) (resourceUrl string, err error) {
-	defer wg.Done()
+func generateAndUploadPDF(params PDFParams, reportUrl, pdfPath string, ossClient utils.OssClient) (resourceUrl string, err error) {
 	if reportUrl == "" {
 		return
 	}
@@ -91,8 +90,7 @@ func generateAndUploadPDF(params PDFParams, reportUrl, pdfPath string, wg *sync.
 	return
 }
 
-func generateAndUploadJPEG(params PDFParams, reportUrl, pdfPath string, wg *sync.WaitGroup, ossClient utils.OssClient) (resourceUrl string, err error) {
-	defer wg.Done()
+func generateAndUploadJPEG(params PDFParams, reportUrl, pdfPath string, ossClient utils.OssClient) (resourceUrl string, err error) {
 	if reportUrl == "" {
 		return
 	}
@@ -124,34 +122,51 @@ func Report2pdfAndJpeg(reportUrl string, reportId int, ReportLayout string) (pdf
 		err = fmt.Errorf("获取OSS客户端未初始化,生成PDF失败")
 	}
 	defer func() {
-
 		if err != nil {
-			utils.FileLog.Info("生成PDF失败m,error: \n" + err.Error())
+			utils.FileLog.Info("生成PDF失败,error: \n" + err.Error())
 		}
 	}()
 	// 并发执行
 	var wg sync.WaitGroup
 	wg.Add(2)
+	pdfChan := make(chan result, 1)
+	jpegChan := make(chan result, 1)
 	go func() {
-		pdfUrl, err = generateAndUploadPDF(params, reportUrl, pdfPath, &wg, ossClient)
-		if err != nil {
-
-		}
+		defer wg.Done()
+		url, pdfErr := generateAndUploadPDF(params, reportUrl, pdfPath, ossClient)
+		pdfChan <- result{url, pdfErr}
 	}()
 	go func() {
-		jpegUrl, err = generateAndUploadJPEG(params, reportUrl, jpegPath, &wg, ossClient)
-		if err != nil {
-
-		}
+		defer wg.Done()
+		url, jpgErr := generateAndUploadJPEG(params, reportUrl, jpegPath, ossClient)
+		jpegChan <- result{url, jpgErr}
 	}()
 	wg.Wait()
+	close(pdfChan)
+	close(jpegChan)
+
+	pdfResult := <-pdfChan
+	jpegResult := <-jpegChan
+	if pdfResult.err != nil || jpegResult.err != nil {
+		utils.FileLog.Info("生成PDF失败,error: \n" + pdfResult.err.Error() + jpegResult.err.Error())
+		err = fmt.Errorf("生成PDF失败,error: \n" + pdfResult.err.Error() + jpegResult.err.Error())
+		return
+	}
+
 	return
 }
+
+type result struct {
+	url string
+	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({

BIN
static/c4ca4238a0b923820dcc509a6f75849b_1200.jpg


BIN
static/c4ca4238a0b923820dcc509a6f75849b_1200.pdf


+ 16 - 16
static/ccf_chart_addition_rule.json

@@ -1,18 +1,18 @@
 [
-    {
-        "Name": "CCFMEG港口库存指数",
-        "ClassifyId": 21,
-        "Frequency": "周度",
-        "prodNames": "kc-221000",
-        "LastNYear": 3,
-        "IndexType": "周均"
-    },
-    {
-        "Name": "CCFPTA FOB中国",
-        "ClassifyId": 22,
-        "Frequency": "日度",
-        "prodNames": "zs-235",
-        "LastNYear": 3,
-        "IndexType": "日均"
-    }
+  {
+    "Name": "CCFMEG港口库存指数",
+    "ClassifyId": 21,
+    "Frequency": "周度",
+    "prodNames": "kc-221000",
+    "LastNYear": 3,
+    "IndexType": "周均"
+  },
+  {
+    "Name": "CCFPTA FOB中国",
+    "ClassifyId": 22,
+    "Frequency": "日度",
+    "prodNames": "zs-235",
+    "LastNYear": 3,
+    "IndexType": "日均"
+  }
 ]

+ 1 - 1
static/ccf_chart_rule.json

@@ -7,4 +7,4 @@
   {"Name":"原料负荷","ClassifyId": 23,"CustNo": 6,"Frequency": "周度", "IndexType": "周均"},
   {"Name":"聚酯负荷","ClassifyId": 23,"CustNo": 7,"Frequency": "周度", "IndexType": "周均"},
   {"Name":"终端负荷","ClassifyId": 23,"CustNo": 8,"Frequency": "周度", "IndexType": "周均"}
-]
+]