sendwxtmplsystemdefaultmsglogic.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
  5. "app.yhyue.com/moapp/MessageCenter/util"
  6. qrpc "app.yhyue.com/moapp/jybase/rpc"
  7. "context"
  8. "strings"
  9. "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
  10. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type SendWxTmplSystemDefaultMsgLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewSendWxTmplSystemDefaultMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendWxTmplSystemDefaultMsgLogic {
  19. return &SendWxTmplSystemDefaultMsgLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // SendWxTmplSystemDefaultMsg 发送剑鱼系统通用模版消息
  26. func (l *SendWxTmplSystemDefaultMsgLogic) SendWxTmplSystemDefaultMsg(in *message.SystemDefaultMsg) (*message.SendMsgResponse, error) {
  27. total, uFlag := 0, 0
  28. var userArr []string
  29. if in.UserIds != "" {
  30. userArr, uFlag = strings.Split(in.UserIds, ","), 1
  31. } else if in.PositionIds != "" {
  32. userArr, uFlag = strings.Split(in.PositionIds, ","), 2
  33. }
  34. if len(userArr) == 0 {
  35. return &message.SendMsgResponse{
  36. Total: 0,
  37. Message: "用户列表为空",
  38. }, nil
  39. }
  40. for index, uId := range userArr {
  41. p := &common.WxTmplPush{
  42. MessageClass: in.MessageClass,
  43. PushTmplId: config.ConfigJson.WxTmplConfig.TmplSetting.SystemTmplId,
  44. }
  45. if uFlag == 1 {
  46. p.MgoId = uId
  47. } else if uFlag == 2 {
  48. p.Position = uId
  49. }
  50. // 消息模版 工单类型 {{thing19.DATA}} 工单标题 {{thing6.DATA}} 项目名称 {{thing13.DATA}} 服务时间 {{time25.DATA}} 服务地址 {{thing26.DATA}}
  51. err := p.SendMsg(in.Url, func() map[string]*qrpc.TmplItem {
  52. return map[string]*qrpc.TmplItem{
  53. "thing19": &qrpc.TmplItem{
  54. Value: common.AllMsgType()[in.MessageClass],
  55. },
  56. "thing6": &qrpc.TmplItem{
  57. Value: in.Title,
  58. },
  59. "thing13": &qrpc.TmplItem{
  60. Value: in.Detail,
  61. },
  62. "time25": &qrpc.TmplItem{
  63. Value: in.Date,
  64. },
  65. "thing26": &qrpc.TmplItem{
  66. Value: config.ConfigJson.WxTmplConfig.TmplSetting.CloseNotice,
  67. },
  68. }
  69. })
  70. if err != nil {
  71. logx.Error(err)
  72. } else {
  73. total++
  74. }
  75. if index%10 == 0 {
  76. logx.Infof("共%d条,已送达%d条,失败%d条", len(userArr), total, index-total)
  77. }
  78. }
  79. return &message.SendMsgResponse{
  80. Total: util.Int64All(total),
  81. }, nil
  82. }