From 9277a435f4b2c0ad2b9d5fbd831e57af3fc08fcb Mon Sep 17 00:00:00 2001 From: axiaoxin <254606826@qq.com> Date: Sat, 24 Jul 2021 22:08:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E8=82=A1=E6=A3=80=E6=B5=8B=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=9140=E6=97=A5=E4=B8=BB=E5=8A=9B?= =?UTF-8?q?=E8=B5=84=E9=87=91=E5=87=80=E6=B5=81=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datacenter/zszx/net_inflows.go | 38 ++++++++++++++++++++++ models/exportor_data.go | 22 +------------ models/stock.go | 4 +-- routes/routes.go | 1 - routes/stock.go | 44 ++------------------------ statics/html/stock_index.html | 19 ----------- statics/js/app.js | 58 +++------------------------------- 7 files changed, 49 insertions(+), 137 deletions(-) diff --git a/datacenter/zszx/net_inflows.go b/datacenter/zszx/net_inflows.go index 328f45f..1644000 100644 --- a/datacenter/zszx/net_inflows.go +++ b/datacenter/zszx/net_inflows.go @@ -37,6 +37,44 @@ type NetInflow struct { // NetInflowList 净流入详情列表 type NetInflowList []NetInflow +func (n NetInflowList) String() string { + ctx := context.Background() + netInflowsLen := len(n) + netInflow3days := "--" + if netInflowsLen >= 3 { + netInflow3days = fmt.Sprintf("近3日主力资金净流入:%.2f万元", n[:3].SumMainNetIn(ctx)) + } + netInflow5days := "--" + if netInflowsLen >= 5 { + netInflow5days = fmt.Sprintf("近5日主力资金净流入:%.2f万元", n[:5].SumMainNetIn(ctx)) + } + netInflow10days := "--" + if netInflowsLen >= 10 { + netInflow10days = fmt.Sprintf("近10日主力资金净流入:%.2f万元", n[:10].SumMainNetIn(ctx)) + } + netInflow20days := "--" + if netInflowsLen >= 20 { + netInflow20days = fmt.Sprintf("近20日主力资金净流入:%.2f万元", n[:20].SumMainNetIn(ctx)) + } + netInflow30days := "--" + if netInflowsLen >= 30 { + netInflow30days = fmt.Sprintf("近30日主力资金净流入:%.2f万元", n[:30].SumMainNetIn(ctx)) + } + netInflow40days := "--" + if netInflowsLen >= 40 { + netInflow40days = fmt.Sprintf("近40日主力资金净流入:%.2f万元", n[:40].SumMainNetIn(ctx)) + } + return fmt.Sprintf( + "%s%s%s%s%s%s", + netInflow3days, + netInflow5days, + netInflow10days, + netInflow20days, + netInflow30days, + netInflow40days, + ) +} + // SumMainNetIn 主力净流入列表求和 func (n NetInflowList) SumMainNetIn(ctx context.Context) float64 { var netFlowin float64 = 0.0 diff --git a/models/exportor_data.go b/models/exportor_data.go index 5550f86..ca97d09 100644 --- a/models/exportor_data.go +++ b/models/exportor_data.go @@ -4,7 +4,6 @@ package models import ( "context" - "fmt" "sort" "strings" @@ -172,25 +171,6 @@ func NewExportorData(ctx context.Context, stock Stock) ExportorData { return ExportorData{} } - netInflowsLen := len(stock.MainMoneyNetInflows) - netInflow3days := "--" - if netInflowsLen >= 3 { - netInflow3days = fmt.Sprintf("近3日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:3].SumMainNetIn(ctx)) - } - netInflow5days := "--" - if netInflowsLen >= 5 { - netInflow5days = fmt.Sprintf("近5日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:5].SumMainNetIn(ctx)) - } - netInflow10days := "--" - if netInflowsLen >= 10 { - netInflow10days = fmt.Sprintf("近10日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:10].SumMainNetIn(ctx)) - } - netInflow20days := "--" - if netInflowsLen >= 20 { - netInflow20days = fmt.Sprintf("近20日主力资金净流入:%.2f万元", stock.MainMoneyNetInflows[:20].SumMainNetIn(ctx)) - } - mainNetInflows := fmt.Sprintf("%s%s%s%s", netInflow3days, netInflow5days, netInflow10days, netInflow20days) - fina := stock.HistoricalFinaMainData[0] return ExportorData{ Name: stock.BaseInfo.SecurityNameAbbr, @@ -266,7 +246,7 @@ func NewExportorData(ctx context.Context, stock Stock) ExportorData { NetcashFinance: goutils.YiWanString(stock.NetcashFinance), NetcashFree: goutils.YiWanString(stock.NetcashFree), FreeHoldersTop10: stock.FreeHoldersTop10.String(), - MainMoneyNetInflows: mainNetInflows, + MainMoneyNetInflows: stock.MainMoneyNetInflows.String(), } } diff --git a/models/stock.go b/models/stock.go index 28057cc..1a0d27a 100644 --- a/models/stock.go +++ b/models/stock.go @@ -320,7 +320,7 @@ func NewStock(ctx context.Context, baseInfo eastmoney.StockInfo) (Stock, error) s.FreeHoldersTop10 = holders }(ctx, s) - // 获取最近30日的主力资金净流入 + // 获取最近60日的主力资金净流入 wg.Add(1) go func(ctx context.Context, s *Stock) { defer func() { @@ -328,7 +328,7 @@ func NewStock(ctx context.Context, baseInfo eastmoney.StockInfo) (Stock, error) }() now := time.Now() end := now.Format("2006-01-02") - d, _ := time.ParseDuration("-720h") + d, _ := time.ParseDuration("-1440h") start := now.Add(d).Format("2006-01-02") inflows, err := datacenter.Zszx.QueryMainMoneyNetInflows(ctx, s.BaseInfo.Secucode, start, end) if err != nil { diff --git a/routes/routes.go b/routes/routes.go index f222410..a3248bf 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -9,7 +9,6 @@ func Routes(app *gin.Engine) { app.GET("/", StockIndex) app.POST("/selector", StockSelector) app.POST("/checker", StockChecker) - app.POST("/chip", StockChip) app.GET("/fund", FundIndex) app.GET("/fund/filter", FundFilter) app.POST("/fund/check", FundCheck) diff --git a/routes/stock.go b/routes/stock.go index e2f97a3..70198e1 100644 --- a/routes/stock.go +++ b/routes/stock.go @@ -121,6 +121,7 @@ func StockChecker(c *gin.Context) { finaReportNames := []string{} finaAppointPublishDates := []string{} lines := [][]gin.H{} + mainInflows := []string{} type dataset struct { Label string `json:"label"` @@ -131,6 +132,7 @@ func StockChecker(c *gin.Context) { results = append(results, result) stockName := fmt.Sprintf("%s-%s", stock.BaseInfo.SecurityNameAbbr, stock.BaseInfo.Secucode) stockNames = append(stockNames, stockName) + mainInflows = append(mainInflows, stock.MainMoneyNetInflows.String()) finaReportName := "" if len(stock.HistoricalFinaMainData) > 0 { @@ -247,47 +249,7 @@ func StockChecker(c *gin.Context) { data["FinaReportNames"] = finaReportNames data["FinaAppointPublishDates"] = finaAppointPublishDates data["Lines"] = lines - c.JSON(http.StatusOK, data) - return -} - -// ParamStockChip StockChip 请求参数 -type ParamStockChip struct { - Keyword string `json:"keyword" form:"keyword"` -} - -// StockChip 筹码面 -func StockChip(c *gin.Context) { - data := gin.H{ - "Env": viper.GetString("env"), - "Version": version.Version, - "PageTitle": "X-STOCK | 股票 | 筹码面", - "Error": "", - } - param := ParamStockChip{} - if err := c.ShouldBind(¶m); err != nil { - data["Error"] = err.Error() - c.JSON(http.StatusOK, data) - return - } - if param.Keyword == "" { - data["Error"] = "请填写股票代码或简称" - c.JSON(http.StatusOK, data) - return - } - keywords := goutils.SplitStringFields(param.Keyword) - searcher := core.NewSearcher(c) - stocks, err := searcher.SearchStocks(c, keywords) - if err != nil { - data["Error"] = err.Error() - c.JSON(http.StatusOK, data) - return - } - mainNetInflows := gin.H{} - for _, stock := range stocks { - mainNetInflows[stock.BaseInfo.Secucode] = stock.MainMoneyNetInflows - } - data["MainMoneyNetInflows"] = mainNetInflows + data["MainMoneyNetInflows"] = mainInflows c.JSON(http.StatusOK, data) return } diff --git a/statics/html/stock_index.html b/statics/html/stock_index.html index 4837a83..7b979de 100644 --- a/statics/html/stock_index.html +++ b/statics/html/stock_index.html @@ -4,7 +4,6 @@
@@ -261,24 +260,6 @@ - - -