From 1b3c043ce6b084cdaab8b13b154eed5aad2825f8 Mon Sep 17 00:00:00 2001 From: sparkmemory Date: Sat, 4 Jan 2025 20:54:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(stock):=20=E5=A2=9E=E5=8A=A0=E8=82=A1?= =?UTF-8?q?=E4=BB=B7=E6=8F=90=E9=86=92=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=8A=A5=E8=AD=A6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SetAlarmChangePercent 函数中添加 alarmPrice 参数 - 在前端添加股价提醒输入框 - 修改报警逻辑,支持同时根据涨跌幅和股价进行提醒 - 更新数据库模型,添加 AlarmPrice 字段 --- app.go | 4 ++-- backend/data/stock_data_api.go | 8 ++++++-- frontend/src/components/stock.vue | 23 ++++++++++++++++------- frontend/wailsjs/go/main/App.d.ts | 2 +- frontend/wailsjs/go/main/App.js | 4 ++-- frontend/wailsjs/go/models.ts | 2 ++ 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app.go b/app.go index ddaaa06..3cee6d2 100644 --- a/app.go +++ b/app.go @@ -107,8 +107,8 @@ func (a *App) SetCostPriceAndVolume(stockCode string, price float64, volume int6 return data.NewStockDataApi().SetCostPriceAndVolume(price, volume, stockCode) } -func (a *App) SetAlarmChangePercent(val float64, stockCode string) string { - return data.NewStockDataApi().SetAlarmChangePercent(val, stockCode) +func (a *App) SetAlarmChangePercent(val, alarmPrice float64, stockCode string) string { + return data.NewStockDataApi().SetAlarmChangePercent(val, alarmPrice, stockCode) } func (a *App) SendDingDingMessage(message string, stockCode string) string { diff --git a/backend/data/stock_data_api.go b/backend/data/stock_data_api.go index 9b309ba..2d11e16 100644 --- a/backend/data/stock_data_api.go +++ b/backend/data/stock_data_api.go @@ -135,6 +135,7 @@ type FollowedStock struct { PriceChange float64 ChangePercent float64 AlarmChangePercent float64 + AlarmPrice float64 Time time.Time Sort int64 IsDel soft_delete.DeletedAt `gorm:"softDelete:flag"` @@ -310,8 +311,11 @@ func (receiver StockDataApi) SetCostPriceAndVolume(price float64, volume int64, return "设置成功" } -func (receiver StockDataApi) SetAlarmChangePercent(val float64, stockCode string) string { - err := db.Dao.Model(&FollowedStock{}).Where("stock_code = ?", stockCode).Update("alarm_change_percent", val).Error +func (receiver StockDataApi) SetAlarmChangePercent(val, alarmPrice float64, stockCode string) string { + err := db.Dao.Model(&FollowedStock{}).Where("stock_code = ?", stockCode).Updates(&map[string]any{ + "alarm_change_percent": val, + "alarm_price": alarmPrice, + }).Error if err != nil { logger.SugaredLogger.Error(err.Error()) return "设置失败" diff --git a/frontend/src/components/stock.vue b/frontend/src/components/stock.vue index eafc6f0..2063e6a 100644 --- a/frontend/src/components/stock.vue +++ b/frontend/src/components/stock.vue @@ -32,6 +32,7 @@ const formModel = ref({ costPrice: 0.000, volume: 0, alarm: 0, + alarmPrice:0, }) const data = reactive({ @@ -203,7 +204,7 @@ async function monitor() { }else if(result.profitAmount<0){ result.profitType="success" } - if(res[0].AlarmChangePercent>0&&Math.abs(roundedNum)>res[0].AlarmChangePercent){ + if((res[0].AlarmChangePercent>0&&Math.abs(roundedNum)>res[0].AlarmChangePercent)||(res[0].AlarmPrice>0&&result["当前价格"]>res[0].AlarmPrice)){ SendMessage(result) } } @@ -236,6 +237,7 @@ function setStock(code,name){ formModel.value.volume=res[0].Volume formModel.value.costPrice=res[0].CostPrice formModel.value.alarm=res[0].AlarmChangePercent + formModel.value.alarmPrice=res[0].AlarmPrice modalShow.value=true } @@ -253,10 +255,9 @@ function showK(code,name){ } -function updateCostPriceAndVolumeNew(code,price,volume,alarm){ - console.log(code,price,volume) - if(alarm){ - SetAlarmChangePercent(alarm,code).then(result => { +function updateCostPriceAndVolumeNew(code,price,volume,alarm,formModel){ + if(alarm||formModel.alarmPrice){ + SetAlarmChangePercent(alarm,formModel.alarmPrice,code).then(result => { //message.success(result) }) } @@ -383,7 +384,7 @@ function SendMessage(result){ @@ -401,9 +402,17 @@ function SendMessage(result){ + + + + + + diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 150cab0..cfc168a 100644 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -12,7 +12,7 @@ export function Greet(arg1:string):Promise; export function SendDingDingMessage(arg1:string,arg2:string):Promise; -export function SetAlarmChangePercent(arg1:number,arg2:string):Promise; +export function SetAlarmChangePercent(arg1:number,arg2:number,arg3:string):Promise; export function SetCostPriceAndVolume(arg1:string,arg2:number,arg3:number):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 745ac69..676fe02 100644 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -22,8 +22,8 @@ export function SendDingDingMessage(arg1, arg2) { return window['go']['main']['App']['SendDingDingMessage'](arg1, arg2); } -export function SetAlarmChangePercent(arg1, arg2) { - return window['go']['main']['App']['SetAlarmChangePercent'](arg1, arg2); +export function SetAlarmChangePercent(arg1, arg2, arg3) { + return window['go']['main']['App']['SetAlarmChangePercent'](arg1, arg2, arg3); } export function SetCostPriceAndVolume(arg1, arg2, arg3) { diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index b01da60..e27828a 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -9,6 +9,7 @@ export namespace data { PriceChange: number; ChangePercent: number; AlarmChangePercent: number; + AlarmPrice: number; // Go type: time Time: any; Sort: number; @@ -28,6 +29,7 @@ export namespace data { this.PriceChange = source["PriceChange"]; this.ChangePercent = source["ChangePercent"]; this.AlarmChangePercent = source["AlarmChangePercent"]; + this.AlarmPrice = source["AlarmPrice"]; this.Time = this.convertValues(source["Time"], null); this.Sort = source["Sort"]; this.IsDel = source["IsDel"];