cmb
This commit is contained in:
parent
83f007b423
commit
5e584c1353
|
|
@ -59,6 +59,10 @@ message CmbOrderRequest {
|
|||
string timestamp = 13 [json_name = "timestamp", (validate.rules).string = {min_len: 1,max_len: 20}];
|
||||
}
|
||||
message CmbOrderReply {
|
||||
// 接口调用返回码,1000 成功,1001 失败
|
||||
string respCode = 1 [json_name = "respCode"];
|
||||
// 返回话术,失败信息落此字段
|
||||
string respMsg = 2 [json_name = "respMsg"];
|
||||
// 业务参数
|
||||
// 权益标识,优惠券券码,最大长度为50位
|
||||
string codeNo = 9 [json_name = "codeNo"];
|
||||
|
|
@ -71,6 +75,10 @@ message CmbQueryProductRequest {
|
|||
string activityId = 9 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
||||
}
|
||||
message CmbQueryProductReply {
|
||||
// 接口调用返回码,1000 成功,1001 失败
|
||||
string respCode = 1 [json_name = "respCode"];
|
||||
// 返回话术,失败信息落此字段
|
||||
string respMsg = 2 [json_name = "respMsg"];
|
||||
// 业务参数
|
||||
// 批次名称
|
||||
string activityName = 9 [json_name = "activityName"];
|
||||
|
|
|
|||
|
|
@ -24,22 +24,6 @@ func (v *VoucherBiz) PushOrderMQ(ctx context.Context, orderNo string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) PushQueryDelayMQ(ctx context.Context, orderNo string) error {
|
||||
|
||||
eventMap := v.bc.RocketMQ.EventMap["query"]
|
||||
sendOption := []mq.SendOption{
|
||||
mq.WithSendShardingKeysOption(orderNo),
|
||||
mq.WithOpenTelemetryOption(trace.SpanFromContext(ctx).SpanContext().TraceID().String()),
|
||||
mq.WithSendDelayLevelOption(300),
|
||||
}
|
||||
|
||||
if err := v.MqSendMixRepo.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
||||
return fmt.Errorf("查询入队投递失败[%v]", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo string) error {
|
||||
|
||||
eventMap := v.bc.RocketMQ.EventMap["notify"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"voucher/internal/conf"
|
||||
"voucher/internal/pkg/mq"
|
||||
)
|
||||
|
||||
func Test_OrderProducer(t *testing.T) {
|
||||
m := make(map[string]*conf.EventMap)
|
||||
|
||||
m["order"] = &conf.EventMap{
|
||||
Topic: "order",
|
||||
}
|
||||
|
||||
c := &conf.RocketMQ{
|
||||
Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080",
|
||||
AccessKey: "Qecl4cea2IAZPKoD",
|
||||
SecretKey: "Z3596KCFA9RAUR6k",
|
||||
SecretToken: "",
|
||||
EventMap: m,
|
||||
}
|
||||
|
||||
mqx, err := buildMqProducer(c)
|
||||
if err != nil {
|
||||
t.Errorf("buildMqProducer() error = %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
orderNo := ""
|
||||
|
||||
eventMap := c.EventMap["order"]
|
||||
sendOption := []mq.SendOption{
|
||||
mq.WithSendShardingKeysOption(orderNo),
|
||||
}
|
||||
|
||||
if err = mqx.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
||||
t.Errorf("入队失败 error = %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func Test_NotifyProducer(t *testing.T) {
|
||||
m := make(map[string]*conf.EventMap)
|
||||
|
||||
m["notify"] = &conf.EventMap{
|
||||
Topic: "notify",
|
||||
}
|
||||
|
||||
c := &conf.RocketMQ{
|
||||
Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080",
|
||||
AccessKey: "Qecl4cea2IAZPKoD",
|
||||
SecretKey: "Z3596KCFA9RAUR6k",
|
||||
SecretToken: "",
|
||||
EventMap: m,
|
||||
}
|
||||
|
||||
mqx, err := buildMqProducer(c)
|
||||
if err != nil {
|
||||
t.Errorf("buildMqProducer() error = %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
orderNo := ""
|
||||
|
||||
eventMap := c.EventMap["notify"]
|
||||
sendOption := []mq.SendOption{
|
||||
mq.WithSendShardingKeysOption(orderNo),
|
||||
}
|
||||
|
||||
if err = mqx.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
||||
t.Errorf("入队失败 error = %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -15,45 +15,45 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
|||
err error
|
||||
)
|
||||
|
||||
bizReply, err := s.cmbOrder(ctx)
|
||||
orderNo, err := s.cmbOrder(ctx)
|
||||
|
||||
if err != nil {
|
||||
reply, err = s.CmbMixRepo.GetResponse(
|
||||
ctx,
|
||||
&bo.CmbResponseBo{
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||
RespMsg: err.Error(),
|
||||
BizContent: "",
|
||||
},
|
||||
)
|
||||
})
|
||||
} else {
|
||||
bizReply := &v1.CmbOrderReply{
|
||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||
RespMsg: "成功",
|
||||
CodeNo: orderNo,
|
||||
}
|
||||
replyBizContent, _ := json.Marshal(bizReply)
|
||||
reply, err = s.CmbMixRepo.GetResponse(
|
||||
ctx,
|
||||
&bo.CmbResponseBo{
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||
RespMsg: "成功",
|
||||
BizContent: string(replyBizContent),
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return ctx.JSON(200, reply)
|
||||
}
|
||||
|
||||
func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
||||
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err := ctx.BindForm(&req); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
boReq := &bo.OrderCreateReqBo{
|
||||
|
|
@ -66,12 +66,10 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
|||
|
||||
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
return &v1.CmbOrderReply{
|
||||
CodeNo: orderNo,
|
||||
}, nil
|
||||
return orderNo, nil
|
||||
}
|
||||
|
||||
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||
|
|
@ -83,9 +81,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|||
|
||||
bizReply, err := s.cmbProductQuery(ctx)
|
||||
if err != nil {
|
||||
reply, err = s.CmbMixRepo.GetResponse(
|
||||
ctx,
|
||||
&bo.CmbResponseBo{
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||
RespMsg: err.Error(),
|
||||
BizContent: "",
|
||||
|
|
@ -93,8 +89,7 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|||
)
|
||||
} else {
|
||||
replyBizContent, _ := json.Marshal(bizReply)
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx,
|
||||
&bo.CmbResponseBo{
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||
RespMsg: "成功",
|
||||
BizContent: string(replyBizContent),
|
||||
|
|
|
|||
Loading…
Reference in New Issue