msg.go 852 B

123456789101112131415161718192021222324252627282930
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/mcn/model"
  5. "go-common/library/log"
  6. )
  7. // sendMsg send msg
  8. func (s *Service) sendMsg(arg *model.ArgMsg) {
  9. s.worker.Add(func() {
  10. var err error
  11. mids, title, content, code := arg.MsgInfo(s.msgMap[arg.MSGType])
  12. if len(mids) == 0 || title == "" || content == "" || code == "" {
  13. log.Warn("mid(%+v) title(%s) content(%s) code(%s) sth is empty!", mids, title, content, code)
  14. return
  15. }
  16. if err = s.msg.MutliSendSysMsg(context.Background(), mids, code, title, content, ""); err != nil {
  17. log.Error("s.msg.MutliSendSysMsg(%+v,%s,%s,%s,%s) error(%+v)", mids, code, title, content, "", err)
  18. }
  19. })
  20. }
  21. func (s *Service) setMsgTypeMap() {
  22. s.msgMap = make(map[model.MSGType]*model.MSG, len(s.c.Property.MSG))
  23. for _, msg := range s.c.Property.MSG {
  24. s.msgMap[msg.MSGType] = msg
  25. }
  26. }