Skip to content

Commit a99393b

Browse files
author
spark
committed
实时数据只保留最新一条数据
1 parent 0e74372 commit a99393b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/data/stock_data_api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,13 @@ func (receiver StockDataApi) GetStockCodeRealTimeData(StockCode string) (*StockI
220220
return &StockInfo{}, nil
221221
}
222222
stockData, err := ParseFullSingleStockData(GB18030ToUTF8(resp.Body()))
223-
//go db.Dao.Model(&StockInfo{}).Create(stockData)
223+
var count int64
224+
db.Dao.Model(&StockInfo{}).Where("code = ?", StockCode).Count(&count)
225+
if count == 0 {
226+
go db.Dao.Model(&StockInfo{}).Create(stockData)
227+
} else {
228+
go db.Dao.Model(&StockInfo{}).Where("code = ?", StockCode).Updates(stockData)
229+
}
224230
return stockData, err
225231
}
226232

0 commit comments

Comments
 (0)