58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
wecom "lone-services/rpc/wecom/pb"
|
|
"lone-services/services/wecom/internal/dao"
|
|
"lone-services/services/wecom/internal/logic/message/sender"
|
|
"lone-services/services/wecom/internal/svc"
|
|
"lone-services/services/wecom/validator"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type SendMessageLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewSendMessageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendMessageLogic {
|
|
return &SendMessageLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *SendMessageLogic) SendMessage(in *wecom.SendMessageReq) (*wecom.Response, error) {
|
|
var req validator.SendMessageValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
ext := map[string]any{}
|
|
if req.Reason != utils.StringEmpty {
|
|
ext["reason"] = req.Reason
|
|
}
|
|
if req.Key != utils.StringEmpty {
|
|
ext["key"] = req.Key
|
|
}
|
|
|
|
job := dao.WeComJob{
|
|
BizId: int(req.BizId),
|
|
BizType: uint8(req.BizType),
|
|
Type: uint8(req.Type),
|
|
Action: uint8(req.Action),
|
|
Ext: ext,
|
|
}
|
|
if err := (sender.WecomSenderService{}).Send(l.ctx, job); err != nil {
|
|
l.Errorf("send wecom message: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
return okResponse(nil), nil
|
|
}
|