From 18b25a43b9e10335736878d9e2cbc61632077db3 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Mon, 19 Jan 2026 17:57:18 +0800 Subject: [PATCH] deving --- internal/logic/a/daily.go | 16 ++++++++++------ internal/models/stock_daily.go | 4 ++-- internal/models/stock_indicator.go | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/logic/a/daily.go b/internal/logic/a/daily.go index ed3fc28..f9aef3a 100644 --- a/internal/logic/a/daily.go +++ b/internal/logic/a/daily.go @@ -9,17 +9,21 @@ import ( ) func GetStockDaily() { - s, e := ReturnLastDay() + end := time.Now().Format("20060102") for _, code := range GetStockCodes() { + var start string = "20230101" + var last models.StockDaily + err := impl.DBService.Where("ts_code=?", code).Order("trade_date DESC").First(&last).Error + if err == nil && last.TradeDate != "" { + start = last.TradeDate + } params := map[string]string{ "ts_code": code, - "start_date": s, - "end_date": e, + "start_date": start, + "end_date": end, } - var cnt int64 - impl.DBService.Model(&models.StockDaily{}).Where("ts_code=? and trade_date in (?,?)", code, s, e).Count(&cnt) - if cnt == 2 { + if start == end { continue } diff --git a/internal/models/stock_daily.go b/internal/models/stock_daily.go index 2fe7563..8efb1cb 100644 --- a/internal/models/stock_daily.go +++ b/internal/models/stock_daily.go @@ -7,8 +7,8 @@ import ( // LastDaily 股票日线数据 type StockDaily struct { ID uint `gorm:"primarykey;autoIncrement" json:"id"` - TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code_trade_date;comment:股票代码" json:"ts_code"` - TradeDate string `gorm:"type:date;not null;index:idx_ts_code_trade_date;comment:交易日期" json:"trade_date"` + TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"` + TradeDate string `gorm:"type:date;not null;index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"` Open float64 `gorm:"type:decimal(10,4);comment:开盘价" json:"open"` High float64 `gorm:"type:decimal(10,4);comment:最高价" json:"high"` Low float64 `gorm:"type:decimal(10,4);comment:最低价" json:"low"` diff --git a/internal/models/stock_indicator.go b/internal/models/stock_indicator.go index 07386f2..6d92a46 100644 --- a/internal/models/stock_indicator.go +++ b/internal/models/stock_indicator.go @@ -7,8 +7,8 @@ import ( // StockIndicator 股票日线数据模型 type StockIndicator struct { ID uint `gorm:"primarykey;autoIncrement"` - TsCode string `gorm:"type:varchar(20);not null;comment:TS股票代码;index:idx_ts_code_trade_date"` - TradeDate string `gorm:"type:date;not null;comment:交易日期;index:idx_ts_code_trade_date"` + TsCode string `gorm:"type:varchar(20);not null;comment:TS股票代码;uniqueIndex:idx_ts_code;unique:un_code_date;"` + TradeDate string `gorm:"type:date;not null;comment:交易日期;uniqueIndex:idx_trade_date;unique:un_code_date;"` Close float64 `gorm:"type:decimal(10,4);comment:当日收盘价"` TurnoverRate float64 `gorm:"type:decimal(10,6);comment:换手率(%)"` TurnoverRateF float64 `gorm:"type:decimal(10,6);comment:换手率(自由流通股)"`