|
@@ -0,0 +1,90 @@
|
|
|
|
+package logic
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
|
|
|
|
+ "app.yhyue.com/moapp/MessageCenter/util"
|
|
|
|
+ "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 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.MessageClass)
|
|
|
|
+ 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)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logx.Error(err)
|
|
|
|
+ } else {
|
|
|
|
+ messageSendOk++
|
|
|
|
+ }
|
|
|
|
+ if index%10 == 0 {
|
|
|
|
+ logx.Infof("共%d条,已送达%d条,失败%d条", messageTotal, messageSendOk, messageTotal-messageSendOk)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if messageTotal == 1 {
|
|
|
|
+ return &message.SendMsgResponse{
|
|
|
|
+ Total: util.Int64All(messageSendOk),
|
|
|
|
+ Message: err.Error(),
|
|
|
|
+ }, nil
|
|
|
|
+ } else {
|
|
|
|
+ logx.Infof("共%d条,已送达%d条,失败%d条", messageTotal, messageSendOk, messageTotal-messageSendOk)
|
|
|
|
+ return &message.SendMsgResponse{
|
|
|
|
+ Total: util.Int64All(messageSendOk),
|
|
|
|
+ }, nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return &message.SendMsgResponse{}, nil
|
|
|
|
+}
|