소스 검색

fix: 修正仿真测试文件下载同名覆盖问题

HeWang 8 달 전
부모
커밋
9a5f3528fc
1개의 변경된 파일9개의 추가작업 그리고 3개의 파일을 삭제
  1. 9 3
      biz/handler/simulation_service/simulation_service.go

+ 9 - 3
biz/handler/simulation_service/simulation_service.go

@@ -18,6 +18,8 @@ import (
 	"pji_desktop_http/common/config/c_log"
 	"pji_desktop_http/common/entity"
 	"pji_desktop_http/common/util"
+	"strconv"
+	"strings"
 )
 
 // DownloadSimulationZipFile 根据请求id从oss拉取并打包仿真测试所需要的文件
@@ -257,7 +259,7 @@ func UploadBagFile(ctx context.Context, c *app.RequestContext) {
 	fileName := header.Filename
 	fmt.Println("filename", fileName)
 
-	ossObjectKey := config.SimulationOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + timeStamp + "/" + round + "/" + fileName
+	ossObjectKey := config.SimulationOssBasePrefix + "/" + equipmentNo + "/" + sceneNo + "/" + timeStamp + "/" + round + "/" + "test.bag"
 	fmt.Println("ossObjectKey", ossObjectKey)
 
 	f, _ := header.Open()
@@ -457,8 +459,12 @@ func generateZipByKey(ctx context.Context, keys []string, fileName string) (file
 	c_log.GlobalLogger.Info("创建文件打包根目录:", baseDir)
 
 	// 从oss下载文件到根目录
-	for _, file := range keys {
-		err = config.OssBucket.GetObjectToFile(file, filepath.Join(baseDir, filepath.Base(file)))
+	for i, file := range keys {
+		baseName := filepath.Base(file)
+		ext := filepath.Ext(baseName)
+		name := strings.TrimSuffix(baseName, ext)
+		newName := name + "-" + strconv.Itoa(i+1) + ext
+		err = config.OssBucket.GetObjectToFile(file, filepath.Join(baseDir, newName))
 		if err != nil {
 			fmt.Println("Error downloading file:", file, err)
 			return "", "", err