Browse Source

修复批量下载pdf斜杠/bug

animeic 2 years ago
parent
commit
cb2805d6e3
2 changed files with 15 additions and 2 deletions
  1. 11 2
      boxcost/api/plan.go
  2. 4 0
      boxcost/boxcost.log

+ 11 - 2
boxcost/api/plan.go

@@ -11,6 +11,7 @@ import (
 	"io"
 	"os"
 	"path/filepath"
+	"regexp"
 	"strings"
 	"sync"
 	"time"
@@ -273,7 +274,10 @@ func DownLoadPlanBillsPdf(c *gin.Context, apictx *ApiSession) (interface{}, erro
 	}
 
 	companyName := getCompanyName(apictx)
-	planName := plan.Name
+	_planName := plan.Name
+	r := regexp.MustCompile(`/`)
+	planName := r.ReplaceAllString(_planName, `&`)
+	// fmt.Println(planName)
 	// 打包pdf的缓存目录
 	saveTmpDir := fmt.Sprintf("tmp1/%s", planName)
 
@@ -384,7 +388,12 @@ func DownLoadPlanBillsPdf(c *gin.Context, apictx *ApiSession) (interface{}, erro
 		billExcel.SetIsPdf("true")
 		billExcel.Draws()
 		buf, _ := f.WriteToBuffer()
-		targePdfName := fmt.Sprintf("%s-%s.pdf", productName, supplierName)
+
+		// r := regexp.MustCompile(`/`)
+		_productName := r.ReplaceAllString(productName, `&`)
+		_supplierName := r.ReplaceAllString(supplierName, `&`)
+		targePdfName := fmt.Sprintf("%s-%s.pdf", _productName, _supplierName)
+		// fmt.Println(targePdfName)
 
 		wg.Add(1)
 		go toPdfAndSaveTask(buf, apictx.Svc.Conf.PdfApiAddr, saveTmpDir, targePdfName, c1, &wg)

+ 4 - 0
boxcost/boxcost.log

@@ -225,3 +225,7 @@
 {"level":"error","timestamp":"2023-03-10 18:40:55","message":"[Post \"http://localhost:3001/convert/office\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)]","service_name":"boxcost"}
 {"level":"error","timestamp":"2023-03-10 18:40:55","message":"[Post \"http://localhost:3001/convert/office\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)]","service_name":"boxcost"}
 {"level":"info","timestamp":"2023-03-24 17:08:54","message":"[<nil>]","service_name":"boxcost"}
+{"level":"error","timestamp":"2023-03-30 09:52:24","message":"[Post \"http://localhost:3001/convert/office\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)]","service_name":"boxcost"}
+{"level":"error","timestamp":"2023-03-30 10:09:36","message":"[open tmp1/4枚\\/8枚蓝莓盒卡片+不干胶/4枚/8枚蓝莓盒卡片+不干胶(8000套)--卡片--UV印刷(双面)起价-泓瑞包装.pdf: no such file or directory]","service_name":"boxcost"}
+{"level":"error","timestamp":"2023-03-30 10:10:58","message":"[open tmp1/4枚-8枚蓝莓盒卡片+不干胶/4枚/8枚蓝莓盒卡片+不干胶(8000套)--卡片--UV印刷(双面)起价-泓瑞包装.pdf: no such file or directory]","service_name":"boxcost"}
+{"level":"error","timestamp":"2023-03-30 10:24:42","message":"[open tmp1/4枚&8枚蓝莓盒卡片+不干胶/4枚\\/8枚蓝莓盒卡片+不干胶(8000套)--卡片--UV印刷(双面)起价-泓瑞包装.pdf: no such file or directory]","service_name":"boxcost"}