diff --git a/app.go b/app.go index 074aa65..c6b4f26 100644 --- a/app.go +++ b/app.go @@ -177,6 +177,11 @@ func addStockFollowData(follow data.FollowedStock, stockData *data.StockInfo) { //昨日收盘价 preClosePrice, _ := convertor.ToFloat(stockData.PreClose) + //当前价格依然为0 时 使用昨日收盘价为当前价格 + if price == 0 { + price = preClosePrice + } + //今日最高价 highPrice, _ := convertor.ToFloat(stockData.High) if highPrice == 0 { @@ -191,20 +196,34 @@ func addStockFollowData(follow data.FollowedStock, stockData *data.StockInfo) { //开盘价 //openPrice, _ := convertor.ToFloat(stockData.Open) - stockData.ChangePrice = mathutil.RoundToFloat(price-preClosePrice, 2) - stockData.ChangePercent = mathutil.RoundToFloat(mathutil.Div(price-preClosePrice, preClosePrice)*100, 3) - stockData.HighRate = mathutil.RoundToFloat(mathutil.Div(highPrice-preClosePrice, preClosePrice)*100, 3) - stockData.LowRate = mathutil.RoundToFloat(mathutil.Div(lowPrice-preClosePrice, preClosePrice)*100, 3) + if price > 0 { + stockData.ChangePrice = mathutil.RoundToFloat(price-preClosePrice, 2) + stockData.ChangePercent = mathutil.RoundToFloat(mathutil.Div(price-preClosePrice, preClosePrice)*100, 3) + } + if highPrice > 0 { + stockData.HighRate = mathutil.RoundToFloat(mathutil.Div(highPrice-preClosePrice, preClosePrice)*100, 3) + } + if lowPrice > 0 { + stockData.LowRate = mathutil.RoundToFloat(mathutil.Div(lowPrice-preClosePrice, preClosePrice)*100, 3) + } if follow.CostPrice > 0 && follow.Volume > 0 { - stockData.Profit = mathutil.RoundToFloat(mathutil.Div(price-follow.CostPrice, follow.CostPrice)*100, 3) - stockData.ProfitAmount = mathutil.RoundToFloat((price-follow.CostPrice)*float64(follow.Volume), 2) - stockData.ProfitAmountToday = mathutil.RoundToFloat((price-preClosePrice)*float64(follow.Volume), 2) + if price > 0 { + stockData.Profit = mathutil.RoundToFloat(mathutil.Div(price-follow.CostPrice, follow.CostPrice)*100, 3) + stockData.ProfitAmount = mathutil.RoundToFloat((price-follow.CostPrice)*float64(follow.Volume), 2) + stockData.ProfitAmountToday = mathutil.RoundToFloat((price-preClosePrice)*float64(follow.Volume), 2) + } else { + //未开盘时当前价格为昨日收盘价 + stockData.Profit = mathutil.RoundToFloat(mathutil.Div(preClosePrice-follow.CostPrice, follow.CostPrice)*100, 3) + stockData.ProfitAmount = mathutil.RoundToFloat((preClosePrice-follow.CostPrice)*float64(follow.Volume), 2) + stockData.ProfitAmountToday = mathutil.RoundToFloat((preClosePrice-preClosePrice)*float64(follow.Volume), 2) + } + } //logger.SugaredLogger.Debugf("stockData:%+v", stockData) - if follow.Price != price { + if follow.Price != price && price > 0 { go db.Dao.Model(follow).Where("stock_code = ?", follow.StockCode).Updates(map[string]interface{}{ - "price": stockData.Price, + "price": price, }) } } @@ -306,10 +325,8 @@ func (a *App) SendDingDingMessageByType(message string, stockCode string, msgTyp } stockInfo := &data.StockInfo{} db.Dao.Model(stockInfo).Where("code = ?", stockCode).First(stockInfo) - if !data.NewAlertWindowsApi("go-stock消息通知", getMsgTypeName(msgType), GenNotificationMsg(stockInfo), "").SendNotification() { - return data.NewDingDingAPI().SendDingDingMessage(message) - } - return "发送系统消息成功" + go data.NewAlertWindowsApi("go-stock消息通知", getMsgTypeName(msgType), GenNotificationMsg(stockInfo), "").SendNotification() + return data.NewDingDingAPI().SendDingDingMessage(message) } func GenNotificationMsg(stockInfo *data.StockInfo) string { diff --git a/backend/data/stock_data_api.go b/backend/data/stock_data_api.go index 793531b..d121e30 100644 --- a/backend/data/stock_data_api.go +++ b/backend/data/stock_data_api.go @@ -295,14 +295,19 @@ func (receiver StockDataApi) GetStockCodeRealTimeData(StockCodes ...string) (*[] continue } stockInfos = append(stockInfos, *stockData) + + go func() { + var count int64 + db.Dao.Model(&StockInfo{}).Where("code = ?", stockData.Code).Count(&count) + if count == 0 { + db.Dao.Model(&StockInfo{}).Create(stockData) + } else { + db.Dao.Model(&StockInfo{}).Where("code = ?", stockData.Code).Updates(stockData) + } + }() + } - //var count int64 - //db.Dao.Model(&StockInfo{}).Where("code = ?", StockCode).Count(&count) - //if count == 0 { - // go db.Dao.Model(&StockInfo{}).Create(stockData) - //} else { - // go db.Dao.Model(&StockInfo{}).Where("code = ?", StockCode).Updates(stockData) - //} + return &stockInfos, err } diff --git a/backend/data/stock_data_api_test.go b/backend/data/stock_data_api_test.go index e1fc41f..eab9b90 100644 --- a/backend/data/stock_data_api_test.go +++ b/backend/data/stock_data_api_test.go @@ -36,6 +36,7 @@ func TestParseFullSingleStockData(t *testing.T) { } func TestNewStockDataApi(t *testing.T) { + db.Init("../../data/stock.db") stockDataApi := NewStockDataApi() datas, _ := stockDataApi.GetStockCodeRealTimeData("sh600859", "sh600745") for _, data := range *datas { diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 8ffebf2..bfd3231 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "dependencies": { "@vicons/ionicons5": "^0.13.0", - "vue": "^3.2.25" + "vue": "^3.2.25", + "vue-router": "^4.5.0" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", @@ -801,6 +802,11 @@ "@vue/shared": "3.5.13" } }, + "node_modules/@vue/devtools-api": { + "version": "6.6.4", + "resolved": "https://registry.npmmirror.com/@vue/devtools-api/-/devtools-api-6.6.4.tgz", + "integrity": "sha512-sGhTPMuXqZ1rVOk32RylztWkfXTRhuS7vgAKv0zjqk8gbsHkJ7xfFf+jbySxt7tWObEJwyKaHMikV/WGDiQm8g==" + }, "node_modules/@vue/reactivity": { "version": "3.5.13", "resolved": "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.5.13.tgz", @@ -1241,6 +1247,20 @@ } } }, + "node_modules/vue-router": { + "version": "4.5.0", + "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-4.5.0.tgz", + "integrity": "sha512-HDuk+PuH5monfNuY+ct49mNmkCRK4xJAV9Ts4z9UFc4rzdDnxQLyCMGGc8pKhZhHTVzfanpNwB/lwqevcBwI4w==", + "dependencies": { + "@vue/devtools-api": "^6.6.4" + }, + "funding": { + "url": "https://github.com/sponsors/posva" + }, + "peerDependencies": { + "vue": "^3.2.0" + } + }, "node_modules/vueuc": { "version": "0.4.64", "resolved": "https://registry.npmmirror.com/vueuc/-/vueuc-0.4.64.tgz", diff --git a/frontend/package.json b/frontend/package.json index c5cb8d1..f402231 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,7 +10,8 @@ }, "dependencies": { "@vicons/ionicons5": "^0.13.0", - "vue": "^3.2.25" + "vue": "^3.2.25", + "vue-router": "^4.5.0" }, "devDependencies": { "@vitejs/plugin-vue": "^5.2.1", diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index c6cdb3e..d2ab4a7 100644 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -fda5308055dfd8a9cbfbd89ea27276c4 \ No newline at end of file +00b8e620dca5bab58d37996f0f350d0a \ No newline at end of file diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ef3d7ef..d2a27b7 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,13 +1,111 @@ +const isFullscreen = ref(false) +const activeKey = ref('stock') +const containerRef= ref({}) +const menuOptions = ref([ + { + label: '设置', + key: 'settings', + icon: renderIcon(SettingsOutline), + children: [ + { + type: 'group', + label: '开发中', + key: 'setting', + children: [ + // { + // label: '叙事者', + // key: 'narrator', + // icon: renderIcon(PersonIcon) + // }, + // { + // label: '羊男', + // key: 'sheep-man', + // icon: renderIcon(PersonIcon) + // } + ] + }, + ] + }, + { + label: ()=> h("a", { + href: '#', + onClick: toggleFullscreen + }, { default: () => '全屏' }), + key: 'full', + icon: renderIcon(ExpandOutline), + }, + { + label: ()=> h("a", { + href: '#', + onClick: WindowHide, + }, { default: () => '隐藏到托盘区' }), + key: 'hide', + icon: renderIcon(ReorderTwoOutline), + }, + { + label: () => + h( + 'a', + { + href: '/', + target: '_self' + }, + { default: () => '刷新' } + ), + key: 'stock', + icon: renderIcon(RefreshOutline) + }, + { + label: ()=> h("a", { + href: '#', + onClick: Quit, + }, { default: () => '退出程序' }), + key: 'exit', + icon: renderIcon(PowerOutline), + }, +]) +function renderIcon(icon) { + return () => h(NIcon, null, { default: () => h(icon) }) +} +function toggleFullscreen(e) { + console.log(e) + WindowIsFullscreen().then((isFull) => { + isFullscreen.value = isFull + if (isFull) { + WindowUnfullscreen() + e.target.innerHTML = '全屏' + } else { + WindowFullscreen() + e.target.innerHTML = '取消全屏' + } + }) +} + + diff --git a/main.go b/main.go index 496972c..4b6e617 100644 --- a/main.go +++ b/main.go @@ -82,14 +82,14 @@ func main() { err := wails.Run(&options.App{ Title: "go-stock", Width: 1366, - Height: 860, + Height: 920, MinWidth: 1024, MinHeight: 768, MaxWidth: 1280, MaxHeight: 960, DisableResize: false, Fullscreen: false, - Frameless: false, + Frameless: true, StartHidden: false, HideWindowOnClose: false, BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 255},