task.go 921 B

123456789101112131415161718192021222324252627282930313233
  1. package common
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/entity"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
  5. "app.yhyue.com/moapp/jybase/common"
  6. "fmt"
  7. "github.com/robfig/cron/v3"
  8. )
  9. var GlobMsgMap map[int]map[string]interface{}
  10. func LoadTask() {
  11. // 每隔10分钟执行一次
  12. LoadMsgOnTime()
  13. c := cron.New(cron.WithSeconds())
  14. c.AddFunc(config.ConfigJson.GlobMsgLoadTime, LoadMsgOnTime)
  15. go c.Start()
  16. defer c.Stop()
  17. }
  18. func LoadMsgOnTime() {
  19. fmt.Println("开始执行")
  20. msgMap := make(map[int]map[string]interface{})
  21. m := entity.Mysql.SelectBySql("SELECT id,msg_type,title,content,send_time,menu_name,link,group_id,sign FROM message_send_log WHERE send_status = 4 AND isdel = 1 ORDER BY send_time DESC limit 2000")
  22. if m != nil && len(*m) > 0 {
  23. for _, val := range *m {
  24. msgMap[common.IntAll(val["id"])] = val
  25. }
  26. GlobMsgMap = msgMap
  27. }
  28. fmt.Println("GlobMsgMap len", len(GlobMsgMap))
  29. }