1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package logic
- import (
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
- "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
- "app.yhyue.com/moapp/MessageCenter/util"
- qrpc "app.yhyue.com/moapp/jybase/rpc"
- "context"
- "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 SendWxTmplSystemDefaultMsgLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- func NewSendWxTmplSystemDefaultMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendWxTmplSystemDefaultMsgLogic {
- return &SendWxTmplSystemDefaultMsgLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- // SendWxTmplSystemDefaultMsg 发送剑鱼系统通用模版消息
- func (l *SendWxTmplSystemDefaultMsgLogic) SendWxTmplSystemDefaultMsg(in *message.SystemDefaultMsg) (*message.SendMsgResponse, error) {
- total, uFlag := 0, 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
- }
- if len(userArr) == 0 {
- return &message.SendMsgResponse{
- Total: 0,
- Message: "用户列表为空",
- }, nil
- }
- for index, uId := range userArr {
- p := &common.WxTmplPush{
- MessageClass: in.MessageClass,
- PushTmplId: config.ConfigJson.WxTmplConfig.TmplSetting.SystemTmplId,
- }
- 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, func() map[string]*qrpc.TmplItem {
- return map[string]*qrpc.TmplItem{
- "thing19": &qrpc.TmplItem{
- Value: common.AllMsgType()[in.MessageClass],
- },
- "thing6": &qrpc.TmplItem{
- Value: in.Title,
- },
- "thing13": &qrpc.TmplItem{
- Value: in.Detail,
- },
- "time25": &qrpc.TmplItem{
- Value: in.Date,
- },
- "thing26": &qrpc.TmplItem{
- Value: config.ConfigJson.WxTmplConfig.TmplSetting.CloseNotice,
- },
- }
- })
- if err != nil {
- logx.Error(err)
- } else {
- total++
- }
- if index%10 == 0 {
- logx.Infof("共%d条,已送达%d条,失败%d条", len(userArr), total, index-total)
- }
- }
- return &message.SendMsgResponse{
- Total: util.Int64All(total),
- }, nil
- }
|