孟令鑫 há 1 ano atrás
pai
commit
2ec58e88a5
1 ficheiros alterados com 3 adições e 61 exclusões
  1. 3 61
      pji/common/util/utils.go

+ 3 - 61
pji/common/util/utils.go

@@ -1,13 +1,11 @@
 package util
 
 import (
+	"cicv-data-closedloop/kinglong/common/log"
 	"cicv-data-closedloop/pji/common/cfg"
 	"cicv-data-closedloop/pji/common/ent"
 	"cicv-data-closedloop/pji/common/global"
-	"cicv-data-closedloop/pji/common/log"
 	"fmt"
-	"io"
-	"net/http"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -66,62 +64,6 @@ func GetBagTime(bagName string) string {
 	return s2
 }
 
-func HttpGetFile(url string, localFilePath string) {
-
-	// 发起GET请求获取文件
-	response, err := http.Get(url)
-	if err != nil {
-		fmt.Printf("下载文件时出错: %s\n", err)
-		return
-	}
-	defer func(Body io.ReadCloser) {
-		err := Body.Close()
-		if err != nil {
-			fmt.Printf("下载文件时出错: %s\n", err)
-		}
-	}(response.Body)
-
-	// 检查响应状态码
-	if response.StatusCode != http.StatusOK {
-		fmt.Printf("下载文件时服务器返回错误: %s\n", response.Status)
-		return
-	}
-
-	// 获取文件的父目录路径
-	directory := filepath.Dir(localFilePath)
-
-	// 检查目录是否存在
-	if _, err := os.Stat(directory); os.IsNotExist(err) {
-		// 如果目录不存在,创建父目录
-		err := os.MkdirAll(directory, os.ModePerm)
-		if err != nil {
-			log.GlobalLogger.Info("创建目录时发生错误", err)
-		}
-	}
-
-	// 创建本地文件用于保存下载的文件
-	out, err := os.Create(localFilePath)
-	if err != nil {
-		fmt.Printf("创建本地文件时出错: %s\n", err)
-		return
-	}
-	defer func(out *os.File) {
-		err := out.Close()
-		if err != nil {
-			fmt.Printf("创建本地文件时出错: %s\n", err)
-		}
-	}(out)
-
-	// 将HTTP响应的Body内容写入本地文件
-	_, err = io.Copy(out, response.Body)
-	if err != nil {
-		fmt.Printf("保存文件时出错: %s\n", err)
-		return
-	}
-
-	log.GlobalLogger.Info("文件下载完成")
-}
-
 func GetNowTimeCustom() string {
 	currentTime := time.Now()
 	formattedTime := currentTime.Format("2006-01-02-15-04-05")
@@ -267,11 +209,11 @@ func GetLastTimeWindow() *ent.TimeWindow {
 // SupplyCopyBags 如果 Copy目录下的包不够,则补充一些
 func SupplyCopyBags(currentTimeWindow ent.TimeWindow) {
 	// 如果bag包没有达到length,补充几个
-	copyBags := ListAbsolutePathWithSuffixAndSort(GetCopyDir(currentTimeWindow.FaultTime), ".bag")
+	copyBags, _ := ListAbsolutePathWithSuffixAndSort(GetCopyDir(currentTimeWindow.FaultTime), ".bag")
 	copyBagsLength := len(copyBags)
 	if copyBagsLength < currentTimeWindow.Length {
 		time.Sleep(time.Duration(copyBagsLength) * time.Second)
-		dataBags := ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
+		dataBags, _ := ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
 		gap := currentTimeWindow.Length - copyBagsLength
 		log.GlobalLogger.Info("故障 ", currentTimeWindow.FaultTime, "需要补充 ", gap, " 个 bag 包")
 		for _, bag := range dataBags {