123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package logic
- import (
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
- "app.yhyue.com/moapp/MessageCenter/util"
- "context"
- "fmt"
- "strings"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
- "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type SendWxTmplMsgLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewSendWxTmplMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendWxTmplMsgLogic {
- return &SendWxTmplMsgLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // SendWxTmplMsg 发送剑鱼微信模版消息
- func (l *SendWxTmplMsgLogic) SendWxTmplMsg(in *message.WxTmplMsgRequest) (*message.SendMsgResponse, error) {
- uFlag := 0
- var userArr []string
- if in.UserIds != "" {
- userArr, uFlag = strings.Split(in.UserIds, ","), 1
- } else if in.PositionIds != "" {
- userArr, uFlag = strings.Split(in.PositionIds, ","), 2
- }
- messageTotal, messageSendOk := len(userArr), 0
- if len(userArr) == 0 {
- return &message.SendMsgResponse{
- Total: 0,
- Message: "用户列表为空",
- }, nil
- }
- pushConfig, err := common.GetWxTmplConfig(in.MsgType)
- if err != nil {
- return &message.SendMsgResponse{
- Total: 0,
- Message: err.Error(),
- }, nil
- }
- for index, uId := range userArr {
- if uId == "" {
- continue
- }
- p := &common.WxTmplPush{
- Config: pushConfig,
- }
- if uFlag == 1 {
- p.MgoId = uId
- } else if uFlag == 2 {
- p.Position = uId
- }
- // 消息模版 工单类型 {{thing19.DATA}} 工单标题 {{thing6.DATA}} 项目名称 {{thing13.DATA}} 服务时间 {{time25.DATA}} 服务地址 {{thing26.DATA}}
- err = p.SendMsg(in.Url, in.Title, in.Detail, in.Date, in.Row4, "")
- if err != nil {
- logx.Error(fmt.Sprintf("SendWxTmplMsg uId %s Error %s", uId, err.Error()))
- } else {
- logx.Infof("SendWxTmplMsg uId success %s ", uId)
- messageSendOk++
- }
- if index%10 == 0 {
- logx.Infof("共%d条,已送达%d条,失败%d条", messageTotal, messageSendOk, messageTotal-messageSendOk)
- }
- }
- if messageTotal == 1 {
- if err != nil {
- return &message.SendMsgResponse{
- Total: util.Int64All(messageSendOk),
- Message: err.Error(),
- }, nil
- }
- return &message.SendMsgResponse{
- Total: util.Int64All(messageSendOk),
- }, nil
- } else {
- logx.Infof("共%d条,已送达%d条,失败%d条", messageTotal, messageSendOk, messageTotal-messageSendOk)
- return &message.SendMsgResponse{
- Total: util.Int64All(messageSendOk),
- }, nil
- }
- }
|