modify notify
This commit is contained in:
@@ -97,7 +97,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
user.ForEachUser(func(u *user.User) bool {
|
user.ForEachUser(func(u *user.User) bool {
|
||||||
if u.IsStop() {
|
if u.IsStop() {
|
||||||
return true
|
return true
|
||||||
@@ -172,6 +171,10 @@ func main() {
|
|||||||
logx.Errorf("get stock err: %v", err)
|
logx.Errorf("get stock err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !st.Notify() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
msg_ := st.Msg()
|
msg_ := st.Msg()
|
||||||
if msg_ != "" {
|
if msg_ != "" {
|
||||||
err = msg.Send(msg_)
|
err = msg.Send(msg_)
|
||||||
@@ -199,6 +202,8 @@ func main() {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
st.FinishSendAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type stock struct {
|
|||||||
lastRise float64
|
lastRise float64
|
||||||
nowRise float64
|
nowRise float64
|
||||||
nowRiseStr string
|
nowRiseStr string
|
||||||
|
needSend bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stock) Code() string {
|
func (s *stock) Code() string {
|
||||||
@@ -59,6 +60,7 @@ func (s *stock) notify() bool {
|
|||||||
s.nowRiseStr = fmt.Sprintf("%.2f%%", s.nowRise)
|
s.nowRiseStr = fmt.Sprintf("%.2f%%", s.nowRise)
|
||||||
if (s.lastRise == 0 && rs != 0) || rs-s.lastRise >= cfg.ThresholdValue || s.lastRise-rs >= cfg.ThresholdValue {
|
if (s.lastRise == 0 && rs != 0) || rs-s.lastRise >= cfg.ThresholdValue || s.lastRise-rs >= cfg.ThresholdValue {
|
||||||
s.lastRise = rs
|
s.lastRise = rs
|
||||||
|
s.needSend = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -250,12 +252,32 @@ func (sk *stocks) Update() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sk *stocks) Notify() bool {
|
||||||
|
sk.mx.RLock()
|
||||||
|
defer sk.mx.RUnlock()
|
||||||
|
var notify bool
|
||||||
|
for _, s := range sk.stkMap {
|
||||||
|
if s.notify() {
|
||||||
|
notify = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notify
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sk *stocks) FinishSendAll() {
|
||||||
|
sk.mx.Lock()
|
||||||
|
defer sk.mx.Unlock()
|
||||||
|
for _, s := range sk.stkMap {
|
||||||
|
s.needSend = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (sk *stocks) Msg() string {
|
func (sk *stocks) Msg() string {
|
||||||
sk.mx.RLock()
|
sk.mx.RLock()
|
||||||
defer sk.mx.RUnlock()
|
defer sk.mx.RUnlock()
|
||||||
var resp string
|
var resp string
|
||||||
for _, s := range sk.stkMap {
|
for _, s := range sk.stkMap {
|
||||||
if s.notify() {
|
if s.needSend {
|
||||||
msg := s.Msg()
|
msg := s.Msg()
|
||||||
resp = resp + msg + "\n"
|
resp = resp + msg + "\n"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user