fix(stock):修复股票代码错误导致的重复问题

- 在前端 stock 组件中增加了对股票代码是否已存在于 stocks.value 中的检查
- 如果股票代码不存在,则删除对应的 result.key
- 在后端 app.go 中增加了对股票价格变化的判断,只有在价格变化时才发送事件
This commit is contained in:
ArvinLovegood 2025-04-07 12:25:40 +08:00
parent b45d5dc762
commit 65bc8cde47
2 changed files with 6 additions and 1 deletions

4
app.go
View File

@ -443,10 +443,12 @@ func MonitorStockPrices(a *App) {
total += stockInfo.ProfitAmountToday
price, _ := convertor.ToFloat(stockInfo.Price)
if stockInfo.PrePrice != price {
//logger.SugaredLogger.Infof("-----------------------股票代码: %s, 股票名称: %s, 股票价格: %s,盘前盘后:%s", stockInfo.Code, stockInfo.Name, stockInfo.Price, stockInfo.BA)
//logger.SugaredLogger.Infof("-----------sz------------股票代码: %s, 股票名称: %s, 股票价格: %s,盘前盘后:%s", stockInfo.Code, stockInfo.Name, stockInfo.Price, stockInfo.BA)
go runtime.EventsEmit(a.ctx, "stock_price", stockInfo)
}
}
if total != 0 {
title := "go-stock " + time.Now().Format(time.DateTime) + fmt.Sprintf(" %.2f¥", total)

View File

@ -518,6 +518,9 @@ async function updateData(result) {
//result.key=result.sort
result.key=GetSortKey(result.sort,result["股票代码"])
results.value[GetSortKey(result.sort,result["股票代码"])]=result
if(!stocks.value.includes(result["股票代码"])) {
delete results.value[result.key]
}
console.log("updateData",result)
}