From fcf1c3012870facd1c8e5fb426f600e7e68de1d6 Mon Sep 17 00:00:00 2001 From: jager Date: Mon, 27 Dec 2021 18:40:28 +0800 Subject: [PATCH] add dingtalk msg --- cmd/stock/main.go | 20 ++++++++++++++++++++ stock/stock.go | 13 +------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cmd/stock/main.go b/cmd/stock/main.go index 40ec226..90ca4bd 100644 --- a/cmd/stock/main.go +++ b/cmd/stock/main.go @@ -88,6 +88,13 @@ func main() { } fund.Clear() + + msg_ := fund.FundsMsg(user.Codes(true)...) + err = msg.Send(msg_) + if err != nil { + logx.Errorf("fund msg send err: %v", err) + } + user.ForEachUser(func(u *user.User) bool { if u.IsStop() { return true @@ -157,6 +164,19 @@ func main() { continue } + st, err := stock.GetStocks(user.Codes(false)...) + if err != nil { + logx.Errorf("get stock err: %v", err) + } + + msg_ := st.Msg() + if msg_ != "" { + err = msg.Send(msg_) + if err != nil { + logx.Errorf("msg send err: %v", err) + } + } + user.ForEachUser(func(u *user.User) bool { if u.IsStop() { return true diff --git a/stock/stock.go b/stock/stock.go index 612ff7b..514b481 100644 --- a/stock/stock.go +++ b/stock/stock.go @@ -251,17 +251,6 @@ func (sk *stocks) Update() error { } func (sk *stocks) Msg() string { - sk.mx.RLock() - defer sk.mx.RUnlock() - var resp string - for _, s := range sk.stkMap { - msg := s.Msg() - resp = resp + msg + "\n" - } - return resp -} - -func (sk *stocks) msg() string { sk.mx.RLock() defer sk.mx.RUnlock() var resp string @@ -275,7 +264,7 @@ func (sk *stocks) msg() string { } func (sk *stocks) Arg(openid string) map[string]interface{} { - msg := sk.msg() + msg := sk.Msg() if msg == "" { return nil }