msg.go 942 B

123456789101112131415161718192021222324252627282930
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/mcn/model"
  5. "go-common/library/log"
  6. "go-common/library/net/metadata"
  7. )
  8. // sendMsg send msg
  9. func (s *Service) sendMsg(c context.Context, arg *model.ArgMsg) error {
  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 nil
  15. }
  16. if err = s.msg.MutliSendSysMsg(c, mids, code, title, content, metadata.String(c, metadata.RemoteIP)); err != nil {
  17. log.Error("s.msg.MutliSendSysMsg(%+v,%s,%s,%s,%s) error(%+v)", mids, code, title, content, metadata.String(c, metadata.RemoteIP), err)
  18. }
  19. return err
  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. }