|
@@ -30,7 +30,6 @@ type GprRiskIndex struct {
|
|
|
}
|
|
|
|
|
|
func DownloadGprRiskFile() (err error) {
|
|
|
- // todo 设置下载频率, 如果有正在处理中的,则暂停下载
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
msg := "失败提醒" + "DownloadGprRiskFile ErrMsg:" + err.Error()
|
|
@@ -56,6 +55,7 @@ func DownloadGprRiskFile() (err error) {
|
|
|
defer out.Close()
|
|
|
|
|
|
// 发起下载请求
|
|
|
+ fmt.Println(time.Now().Format(utils.FormatDateTime), "开始下载 GPR地缘风险指数 文件")
|
|
|
resp, err := http.Get(url)
|
|
|
if err != nil {
|
|
|
err = fmt.Errorf("failed to make request: %w", err)
|
|
@@ -68,14 +68,16 @@ func DownloadGprRiskFile() (err error) {
|
|
|
err = fmt.Errorf("bad status: %s", resp.Status)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ fmt.Println(time.Now().Format(utils.FormatDateTime), "下载 GPR地缘风险指数 文件完成")
|
|
|
+ fmt.Println(time.Now().Format(utils.FormatDateTime), "开始写入文件")
|
|
|
// 将内容写入文件
|
|
|
- _, err = io.Copy(out, resp.Body)
|
|
|
+ buf := make([]byte, 4*1024*1024) // 4MB buffer
|
|
|
+ _, err = io.CopyBuffer(out, resp.Body, buf)
|
|
|
if err != nil {
|
|
|
err = fmt.Errorf("failed to copy content: %w", err)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ fmt.Println(time.Now().Format(utils.FormatDateTime), "开始转换文件格式")
|
|
|
// 转换文件格式
|
|
|
downloadFileXlsx := destPath + "x"
|
|
|
err = ConvertXlsToXlsx(destPath, downloadFileXlsx)
|
|
@@ -83,6 +85,7 @@ func DownloadGprRiskFile() (err error) {
|
|
|
err = fmt.Errorf("文件格式转换失败 convert excel, Err:%w", err)
|
|
|
return
|
|
|
}
|
|
|
+ fmt.Println(time.Now().Format(utils.FormatDateTime), "文件格式转换完成")
|
|
|
// 使用通道等待解析完成
|
|
|
done := make(chan error)
|
|
|
go func() {
|