From 4baaefc8c583748c25819d88d693e888ad97dd31 Mon Sep 17 00:00:00 2001 From: sparkmemory Date: Sun, 23 Feb 2025 18:29:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend/data):=E4=BF=AE=E5=A4=8D=E9=A6=99?= =?UTF-8?q?=E6=B8=AF=E8=82=A1=E7=A5=A8=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=97=A5=E6=9C=9F=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ParseHKStockData函数中,增加 ";" 字符的分割,以解决数据格式问题- 优化日期和时间的解析,将日期格式从 "/" 改为 "-",时间格式进行相应调整 - 注释掉测试文件中的一个测试调用,可能是为了临时跳过该测试 --- backend/data/stock_data_api.go | 6 +++--- backend/data/stock_data_api_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/data/stock_data_api.go b/backend/data/stock_data_api.go index 28a3ff6..c0a3b12 100644 --- a/backend/data/stock_data_api.go +++ b/backend/data/stock_data_api.go @@ -455,7 +455,7 @@ func ParseFullSingleStockData(data string) (*StockInfo, error) { func ParseHKStockData(datas []string) (map[string]string, error) { code := strings.Split(datas[0], "hq_str_")[1] result := make(map[string]string) - parts := strutil.SplitAndTrim(datas[1], ",", "\"") + parts := strutil.SplitAndTrim(datas[1], ",", "\"", ";") //parts := strings.Split(data, ",") if len(parts) < 19 { return nil, fmt.Errorf("invalid data format") @@ -488,8 +488,8 @@ func ParseHKStockData(datas []string) (map[string]string, error) { result["今日最高价"] = parts[4] result["今日最低价"] = parts[5] result["当前价格"] = parts[6] - result["日期"] = parts[17] - result["时间"] = parts[18] + result["日期"] = strings.ReplaceAll(parts[17], "/", "-") + result["时间"] = strings.ReplaceAll(parts[18], "\";", ":00") logger.SugaredLogger.Infof("股票数据解析完成: %v", result) return result, nil } diff --git a/backend/data/stock_data_api_test.go b/backend/data/stock_data_api_test.go index e5bd5e9..9da6a13 100644 --- a/backend/data/stock_data_api_test.go +++ b/backend/data/stock_data_api_test.go @@ -44,7 +44,7 @@ func TestSearchStockInfoByCode(t *testing.T) { func TestSearchStockPriceInfo(t *testing.T) { SearchStockPriceInfo("hk00927", 30) - SearchStockPriceInfo("sh600859", 30) + //SearchStockPriceInfo("sh600859", 30) } func TestParseFullSingleStockData(t *testing.T) {