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}];
|
string timestamp = 13 [json_name = "timestamp", (validate.rules).string = {min_len: 1,max_len: 20}];
|
||||||
}
|
}
|
||||||
message CmbOrderReply {
|
message CmbOrderReply {
|
||||||
|
// 接口调用返回码,1000 成功,1001 失败
|
||||||
|
string respCode = 1 [json_name = "respCode"];
|
||||||
|
// 返回话术,失败信息落此字段
|
||||||
|
string respMsg = 2 [json_name = "respMsg"];
|
||||||
// 业务参数
|
// 业务参数
|
||||||
// 权益标识,优惠券券码,最大长度为50位
|
// 权益标识,优惠券券码,最大长度为50位
|
||||||
string codeNo = 9 [json_name = "codeNo"];
|
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}];
|
string activityId = 9 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
||||||
}
|
}
|
||||||
message CmbQueryProductReply {
|
message CmbQueryProductReply {
|
||||||
|
// 接口调用返回码,1000 成功,1001 失败
|
||||||
|
string respCode = 1 [json_name = "respCode"];
|
||||||
|
// 返回话术,失败信息落此字段
|
||||||
|
string respMsg = 2 [json_name = "respMsg"];
|
||||||
// 业务参数
|
// 业务参数
|
||||||
// 批次名称
|
// 批次名称
|
||||||
string activityName = 9 [json_name = "activityName"];
|
string activityName = 9 [json_name = "activityName"];
|
||||||
|
|
|
||||||
|
|
@ -24,22 +24,6 @@ func (v *VoucherBiz) PushOrderMQ(ctx context.Context, orderNo string) error {
|
||||||
return nil
|
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 {
|
func (v *VoucherBiz) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo string) error {
|
||||||
|
|
||||||
eventMap := v.bc.RocketMQ.EventMap["notify"]
|
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
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
bizReply, err := s.cmbOrder(ctx)
|
orderNo, err := s.cmbOrder(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reply, err = s.CmbMixRepo.GetResponse(
|
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||||
ctx,
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
&bo.CmbResponseBo{
|
RespMsg: err.Error(),
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
BizContent: "",
|
||||||
RespMsg: err.Error(),
|
})
|
||||||
BizContent: "",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
|
bizReply := &v1.CmbOrderReply{
|
||||||
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
|
RespMsg: "成功",
|
||||||
|
CodeNo: orderNo,
|
||||||
|
}
|
||||||
replyBizContent, _ := json.Marshal(bizReply)
|
replyBizContent, _ := json.Marshal(bizReply)
|
||||||
reply, err = s.CmbMixRepo.GetResponse(
|
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||||
ctx,
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
&bo.CmbResponseBo{
|
RespMsg: "成功",
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
BizContent: string(replyBizContent),
|
||||||
RespMsg: "成功",
|
})
|
||||||
BizContent: string(replyBizContent),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(200, reply)
|
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
|
var req *v1.CmbRequest
|
||||||
if err := ctx.BindForm(&req); err != nil {
|
if err := ctx.BindForm(&req); err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := req.Validate(); err != nil {
|
if err := req.Validate(); err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req)
|
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
boReq := &bo.OrderCreateReqBo{
|
boReq := &bo.OrderCreateReqBo{
|
||||||
|
|
@ -66,12 +66,10 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
||||||
|
|
||||||
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1.CmbOrderReply{
|
return orderNo, nil
|
||||||
CodeNo: orderNo,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||||
|
|
@ -83,22 +81,19 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||||
|
|
||||||
bizReply, err := s.cmbProductQuery(ctx)
|
bizReply, err := s.cmbProductQuery(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reply, err = s.CmbMixRepo.GetResponse(
|
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||||
ctx,
|
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||||
&bo.CmbResponseBo{
|
RespMsg: err.Error(),
|
||||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
BizContent: "",
|
||||||
RespMsg: err.Error(),
|
},
|
||||||
BizContent: "",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
replyBizContent, _ := json.Marshal(bizReply)
|
replyBizContent, _ := json.Marshal(bizReply)
|
||||||
reply, err = s.CmbMixRepo.GetResponse(ctx,
|
reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{
|
||||||
&bo.CmbResponseBo{
|
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
||||||
RespCode: vo.CmbResponseStatusSuccess.GetValue(),
|
RespMsg: "成功",
|
||||||
RespMsg: "成功",
|
BizContent: string(replyBizContent),
|
||||||
BizContent: string(replyBizContent),
|
},
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue