This commit is contained in:
2021-12-22 16:38:38 +08:00
parent b8d1391bde
commit 05a5c7c82f
7 changed files with 249 additions and 147 deletions

View File

@@ -1,84 +0,0 @@
/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: main
* @Date: 2021/12/20 2:24 下午
* @package: ss
* @Version: v1.0.0
*
* @Description:
*
*/
package main
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/contextx"
"github.com/jageros/hawox/httpx"
"github.com/jageros/hawox/logx"
"net/http"
"stock/msg"
"time"
)
func main() {
ctx, cancel := contextx.Default()
defer cancel()
logx.Init(logx.DebugLevel, logx.SetCaller(), logx.SetRequest())
defer logx.Sync()
httpx.InitializeHttpServer(ctx, func(engine *gin.Engine) {
r := engine.Group("/api")
r.GET("/sayhello", func(c *gin.Context) {
httpx.PkgMsgWrite(c, map[string]interface{}{"say": "hello world!"})
})
r.POST("/receive", func(c *gin.Context) {
rMsg := &msg.RData{}
err := c.BindXML(rMsg)
if err != nil {
logx.Error(err)
} else {
logx.Info(rMsg)
}
wMsg := &xml{
ToUserName: rMsg.FromUserName,
FromUserName: rMsg.ToUserName,
CreateTime: int(time.Now().Unix()),
MsgType: "text",
Content: "收到,谢谢!",
}
c.XML(http.StatusOK, wMsg)
//c.XML(http.StatusOK, wMsg)
//err = msg.Rcv(rMsg.FromUserName)
//if err != nil {
// logx.Error(err)
//}
//c.String(http.StatusOK, "success")
})
r.GET("/receive", func(c *gin.Context) {
echostr := c.Query("echostr")
logx.Infof("=== %s ===", echostr)
c.String(http.StatusOK, echostr)
})
}, func(s *httpx.Server) {
s.Mode = "debug"
s.Port = 8567
})
err := ctx.Wait()
logx.Infof("Stop With: %v", err)
}
type xml struct {
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Content string `xml:"Content"`
}

View File

@@ -46,8 +46,14 @@ func main() {
logx.Fatal(err)
}
timer.AddTicker(time.Second*1200, func() {
logx.Info("开始保存用户数据进MongoDB...")
user.SaveAll()
logx.Info("保存用户数进MongoDB结束")
})
stockCodes := user.Codes(false)
fundCodes := user.Codes(true)
timer.RunEveryDay(9, 25, 0, func() {
if !stock.IsSellDay(time.Now()) {
@@ -80,12 +86,17 @@ func main() {
logx.Info("今天不是交易日!")
return
}
text := fund.FundsMsg(fundCodes...)
if text == "" {
logx.Errorf("收集基金数据为空!")
return
}
err := msg.Send(text)
fund.Clear()
user.ForEachUser(func(u module.IUser) bool {
codes := u.Codes(true)
stk := fund.NewFundArg(codes...)
err = wxgzh.Send(u.OpenID(), stk)
if err != nil {
logx.Error(err)
}
return true
})
if err != nil {
logx.Errorf("dingtalk.SendMsg(基金信息) err: %v", err)
} else {
@@ -93,9 +104,11 @@ func main() {
}
})
err = stock.Init(stockCodes...)
if err != nil {
logx.Fatal(err)
if len(stockCodes) > 0 {
err = stock.Init(stockCodes...)
if err != nil {
logx.Error(err)
}
}
ctx.Go(func(ctx contextx.Context) error {
@@ -152,20 +165,6 @@ func main() {
}
return true
})
//text := ss.Msg()
//if text == "" {
// logx.Info("已更新数据,未超过阈值,无警告!")
// continue
//}
//err = msg.Send(text)
//if err != nil {
// count++
// logx.Errorf("SendMsg ErrCount=%d err=%v", count, err)
// if count > 10 {
// return err
// }
//}
}
}
})
@@ -185,7 +184,13 @@ func main() {
})
}, func(s *httpx.Server) {
s.Mode = "debug"
s.Port = 8567
s.Port = 16888
})
ctx.Go(func(ctx contextx.Context) error {
<-ctx.Done()
user.SaveAll()
return nil
})
err = ctx.Wait() // 等待停止信号