From 9d22d81cce58937ac7f83645e1534da92fca3909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Thu, 6 Mar 2025 17:00:30 +0800 Subject: [PATCH] cmb --- configs/config.yaml | 1 + internal/biz/bo/order_notify_bo.go | 7 +++- internal/biz/cmb/cmb.go | 3 ++ internal/biz/cmb/consume.go | 45 +++++++++++++++++------ internal/biz/consume.go | 19 ---------- internal/biz/repo/order_notify.go | 3 +- internal/biz/vo/order_notify_status.go | 38 ++++++++++++++++++++ internal/biz/vo/order_wechant_status.go | 48 ++++++++++++------------- internal/conf/conf.pb.go | 32 +++++++++++------ internal/conf/conf.proto | 3 +- internal/data/mixrepoimpl/cmb.go | 8 ++--- internal/data/model/order_notify.gen.go | 2 ++ internal/data/repoimpl/order_notify.go | 38 ++++++++++++++++++-- internal/service/cmb_mock.go | 5 +-- internal/service/consume.go | 33 ----------------- 15 files changed, 175 insertions(+), 110 deletions(-) create mode 100644 internal/biz/vo/order_notify_status.go diff --git a/configs/config.yaml b/configs/config.yaml index b43938a..94a2469 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -55,6 +55,7 @@ cmb: aid: "5efaa21263b94f669a1c90ed0279df20" keyAlias: "CO_PUB_KEY_SM2" cmbKeyAlias: "SM2_CMBLIFE" + orgNo: "orgNo" # 发码机构号,固定值,掌上生活优惠券系统提供 notifyUrl: "https://gateway.dev.cdlsxd.cn/ymt/jd/v1/notify" #配置日志 diff --git a/internal/biz/bo/order_notify_bo.go b/internal/biz/bo/order_notify_bo.go index 318dd1e..fcbf134 100644 --- a/internal/biz/bo/order_notify_bo.go +++ b/internal/biz/bo/order_notify_bo.go @@ -1,14 +1,19 @@ package bo -import "time" +import ( + "time" + "voucher/internal/biz/vo" +) // OrderNotifyBo 领域实体Bo结构,字段和模型字段保持一致 type OrderNotifyBo struct { ID uint64 OrderNo string OutRequestNo string + Status vo.OrderNotifyStatus Request string Responses string + Remark string NotifyUrl string CreateTime *time.Time UpdateTime *time.Time diff --git a/internal/biz/cmb/cmb.go b/internal/biz/cmb/cmb.go index a9f2f13..1bce54d 100644 --- a/internal/biz/cmb/cmb.go +++ b/internal/biz/cmb/cmb.go @@ -12,6 +12,7 @@ type Cmb struct { OrderRepo repo.OrderRepo OrderWechatRepo repo.OrderWechatRepo ProductRepo repo.ProductRepo + OrderNotifyRepo repo.OrderNotifyRepo WechatCpnRepo wechatrepo.WechatCpnRepo GenerateMixRepo mixrepos.GenerateMixRepo CmbMixRepo mixrepos.CmbMixRepo @@ -22,6 +23,7 @@ func NewCmb( orderRepo repo.OrderRepo, OrderWechatRepo repo.OrderWechatRepo, ProductRepo repo.ProductRepo, + OrderNotifyRepo repo.OrderNotifyRepo, WechatCpnRepo wechatrepo.WechatCpnRepo, GenerateMixRepo mixrepos.GenerateMixRepo, CmbMixRepo mixrepos.CmbMixRepo, @@ -31,6 +33,7 @@ func NewCmb( OrderRepo: orderRepo, OrderWechatRepo: OrderWechatRepo, ProductRepo: ProductRepo, + OrderNotifyRepo: OrderNotifyRepo, WechatCpnRepo: WechatCpnRepo, GenerateMixRepo: GenerateMixRepo, CmbMixRepo: CmbMixRepo, diff --git a/internal/biz/cmb/consume.go b/internal/biz/cmb/consume.go index 17b8bac..bd71705 100644 --- a/internal/biz/cmb/consume.go +++ b/internal/biz/cmb/consume.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" v1 "voucher/api/v1" "voucher/internal/biz/bo" "voucher/internal/biz/vo" @@ -41,7 +42,7 @@ func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo return } - return orderWechat.OutRequestNo, nil + return orderWechat.OutRequestNo, err } func (v *Cmb) create(ctx context.Context, order *bo.OrderBo) (*bo.OrderWechatBo, error) { @@ -91,10 +92,6 @@ func (v *Cmb) fail(ctx context.Context, order *bo.OrderBo, orderWechat *bo.Order return v.OrderRepo.Fail(ctx, order.ID) } -func (v *Cmb) QueryConsume(ctx context.Context, order *bo.OrderBo) (err error) { - return -} - func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequestNo string) error { orderWechat, err := v.OrderWechatRepo.GetByOutRequestNo(ctx, orderOutRequestNo) @@ -106,11 +103,15 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ return fmt.Errorf("微信订单状态错误,不能通知:%s", order.Status.GetText()) } + status, err := orderWechat.Status.GetCmbStatusText() + if err != nil { + return err + } req := &v1.CmbNotifyRequest{ Ticket: orderWechat.OrderNo, - Status: "", - TransDate: "", - OrgNo: "", + Status: status.GetValue(), + TransDate: time.Now().Format("20060102150405"), + OrgNo: v.bc.Cmb.OrgNo, Ext: "", } bizJsonBytes, err := json.Marshal(req) @@ -126,7 +127,31 @@ func (v *Cmb) NotifyConsume(ctx context.Context, order *bo.OrderBo, orderOutRequ return err } - // todo - fmt.Print(request) + requestBytes, err := json.Marshal(request) + if err != nil { + return err + } + + orderNotify, err := v.OrderNotifyRepo.Create(ctx, &bo.OrderNotifyBo{ + OrderNo: order.OrderNo, + OutRequestNo: orderWechat.OutRequestNo, + Request: string(requestBytes), + NotifyUrl: order.NotifyUrl, + }) + if err != nil { + return err + } + + // todo 发起请求 + fmt.Print(orderNotify) + return nil } + +func (v *Cmb) notifySuccess(ctx context.Context, id uint64) error { + return v.OrderNotifyRepo.Success(ctx, id, "") +} + +func (v *Cmb) notifyFail(ctx context.Context, id uint64, remark string) error { + return v.OrderNotifyRepo.Fail(ctx, id, remark) +} diff --git a/internal/biz/consume.go b/internal/biz/consume.go index de396e2..9b81c5b 100644 --- a/internal/biz/consume.go +++ b/internal/biz/consume.go @@ -80,25 +80,6 @@ func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err erro return } -func (v *VoucherBiz) QueryConsume(ctx context.Context, orderNo string) (err error) { - - err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("query_consume_%s", orderNo), func(ctx context.Context) error { - - order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo) - if err != nil { - return err - } - - if order.Type.IsCmb() { - return v.Cmb.QueryConsume(ctx, order) - } - - return fmt.Errorf("订单类型错误:%s", order.Type.GetText()) - }) - - return -} - func (v *VoucherBiz) NotifyConsume(ctx context.Context, orderNo, orderOutRequestNo string) (err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("notify_consume_%s", orderNo), func(ctx context.Context) error { diff --git a/internal/biz/repo/order_notify.go b/internal/biz/repo/order_notify.go index 39dd4b0..592fffc 100644 --- a/internal/biz/repo/order_notify.go +++ b/internal/biz/repo/order_notify.go @@ -7,5 +7,6 @@ import ( type OrderNotifyRepo interface { Create(ctx context.Context, req *bo.OrderNotifyBo) (*bo.OrderNotifyBo, error) - UpdateResponses(ctx context.Context, id uint64, responses string) error + Success(ctx context.Context, id uint64, responses string) error + Fail(ctx context.Context, id uint64, remark string) error } diff --git a/internal/biz/vo/order_notify_status.go b/internal/biz/vo/order_notify_status.go new file mode 100644 index 0000000..17c7bec --- /dev/null +++ b/internal/biz/vo/order_notify_status.go @@ -0,0 +1,38 @@ +package vo + +type OrderNotifyStatus uint8 + +const ( + OrderNotifyStatusWait OrderNotifyStatus = iota + 1 + OrderNotifyStatusSuccess + OrderNotifyStatusFail +) + +var OrderNotifyStatusMap = map[OrderNotifyStatus]string{ + OrderNotifyStatusWait: "待请求", + OrderNotifyStatusSuccess: "请求成功", + OrderNotifyStatusFail: "请求失败", +} + +func (s OrderNotifyStatus) GetText() string { + if t, ok := OrderNotifyStatusMap[s]; ok { + return t + } + return "未知请求状态" +} + +func (s OrderNotifyStatus) GetValue() uint8 { + return uint8(s) +} + +func (s OrderNotifyStatus) IsWait() bool { + return s == OrderNotifyStatusWait +} + +func (s OrderNotifyStatus) IsSuccess() bool { + return s == OrderNotifyStatusSuccess +} + +func (s OrderNotifyStatus) IsFail() bool { + return s == OrderNotifyStatusFail +} diff --git a/internal/biz/vo/order_wechant_status.go b/internal/biz/vo/order_wechant_status.go index dab6949..b9519af 100644 --- a/internal/biz/vo/order_wechant_status.go +++ b/internal/biz/vo/order_wechant_status.go @@ -12,6 +12,30 @@ const ( OrderWechatStatusExpired ) +func (s OrderWechatStatus) GetValue() uint8 { + return uint8(s) +} + +func (s OrderWechatStatus) IsWait() bool { + return s == OrderWechatStatusWait +} + +func (s OrderWechatStatus) IsSuccess() bool { + return s == OrderWechatStatusSuccess +} + +func (s OrderWechatStatus) IsFail() bool { + return s == OrderWechatStatusFail +} + +func (s OrderWechatStatus) IsUse() bool { + return s == OrderWechatStatusUse +} + +func (s OrderWechatStatus) CanNotify() bool { + return s.IsSuccess() || s.IsUse() +} + var OrderWechatStatusMap = map[OrderWechatStatus]string{ OrderWechatStatusWait: "待发放", OrderWechatStatusSuccess: "发放成功", @@ -38,27 +62,3 @@ func (s OrderWechatStatus) GetText() string { } return "未知状态" } - -func (s OrderWechatStatus) GetValue() uint8 { - return uint8(s) -} - -func (s OrderWechatStatus) IsWait() bool { - return s == OrderWechatStatusWait -} - -func (s OrderWechatStatus) IsSuccess() bool { - return s == OrderWechatStatusSuccess -} - -func (s OrderWechatStatus) IsFail() bool { - return s == OrderWechatStatusFail -} - -func (s OrderWechatStatus) IsUse() bool { - return s == OrderWechatStatusUse -} - -func (s OrderWechatStatus) CanNotify() bool { - return s.IsSuccess() || s.IsUse() -} diff --git a/internal/conf/conf.pb.go b/internal/conf/conf.pb.go index a03845f..a8f46a3 100644 --- a/internal/conf/conf.pb.go +++ b/internal/conf/conf.pb.go @@ -428,7 +428,8 @@ type Cmb struct { CmbSm2Puk string `protobuf:"bytes,6,opt,name=cmbSm2Puk,proto3" json:"cmbSm2Puk,omitempty"` KeyAlias string `protobuf:"bytes,7,opt,name=keyAlias,proto3" json:"keyAlias,omitempty"` CmbKeyAlias string `protobuf:"bytes,8,opt,name=cmbKeyAlias,proto3" json:"cmbKeyAlias,omitempty"` - NotifyUrl string `protobuf:"bytes,9,opt,name=notifyUrl,proto3" json:"notifyUrl,omitempty"` + OrgNo string `protobuf:"bytes,9,opt,name=orgNo,proto3" json:"orgNo,omitempty"` + NotifyUrl string `protobuf:"bytes,10,opt,name=notifyUrl,proto3" json:"notifyUrl,omitempty"` } func (x *Cmb) Reset() { @@ -519,6 +520,13 @@ func (x *Cmb) GetCmbKeyAlias() string { return "" } +func (x *Cmb) GetOrgNo() string { + if x != nil { + return x.OrgNo + } + return "" +} + func (x *Cmb) GetNotifyUrl() string { if x != nil { return x.NotifyUrl @@ -972,8 +980,8 @@ var file_conf_conf_proto_rawDesc = []byte{ 0x0a, 0x1a, 0x6d, 0x63, 0x68, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x1a, 0x6d, 0x63, 0x68, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, - 0x74, 0x65, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xf1, - 0x01, 0x0a, 0x03, 0x43, 0x6d, 0x62, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x74, 0x65, 0x53, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x87, + 0x02, 0x0a, 0x03, 0x43, 0x6d, 0x62, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x61, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6d, 0x32, 0x50, 0x72, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x6d, 0x32, 0x50, @@ -986,14 +994,16 @@ var file_conf_conf_proto_rawDesc = []byte{ 0x61, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x6d, 0x62, 0x4b, 0x65, 0x79, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x6d, 0x62, 0x4b, 0x65, 0x79, 0x41, - 0x6c, 0x69, 0x61, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x55, 0x72, - 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x55, - 0x72, 0x6c, 0x22, 0x3a, 0x0a, 0x04, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x75, - 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x75, - 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x17, - 0x5a, 0x15, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x2f, 0x63, 0x70, 0x6e, 0x2f, 0x63, 0x6f, - 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x69, 0x61, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x72, 0x67, 0x4e, 0x6f, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x72, 0x67, 0x4e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x6f, + 0x74, 0x69, 0x66, 0x79, 0x55, 0x72, 0x6c, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, + 0x6f, 0x74, 0x69, 0x66, 0x79, 0x55, 0x72, 0x6c, 0x22, 0x3a, 0x0a, 0x04, 0x4c, 0x6f, 0x67, 0x73, + 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x75, 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x62, 0x75, 0x73, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, + 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x42, 0x17, 0x5a, 0x15, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x2f, + 0x63, 0x70, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/conf/conf.proto b/internal/conf/conf.proto index f478acd..d105cd2 100644 --- a/internal/conf/conf.proto +++ b/internal/conf/conf.proto @@ -79,7 +79,8 @@ message Cmb { string cmbSm2Puk = 6; string keyAlias = 7; string cmbKeyAlias = 8; - string notifyUrl = 9; + string orgNo = 9; + string notifyUrl = 10; } message Logs { diff --git a/internal/data/mixrepoimpl/cmb.go b/internal/data/mixrepoimpl/cmb.go index 1e25a31..d4e57cf 100644 --- a/internal/data/mixrepoimpl/cmb.go +++ b/internal/data/mixrepoimpl/cmb.go @@ -76,12 +76,10 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) ( return nil, err } - date := time.Now().Format("20060102150405") - req := &v1.CmbRequest{ Mid: s.bc.Cmb.Mid, Aid: s.bc.Cmb.Aid, - Date: date, + Date: time.Now().Format("20060102150405"), Random: string(cmb.RandomBytes(16)), KeyAlias: s.bc.Cmb.KeyAlias, CmbKeyAlias: s.bc.Cmb.CmbKeyAlias, @@ -103,12 +101,10 @@ func (s *CmbMixRepoImpl) GetRequest(_ context.Context, reqBo *bo.CmbRequestBo) ( func (s *CmbMixRepoImpl) GetResponse(_ context.Context, reqBo *bo.CmbResponseBo) (*v1.CmbReply, error) { - date := time.Now().Format("20060102150405") - reply := &v1.CmbReply{ RespCode: reqBo.RespCode, RespMsg: reqBo.RespMsg, - Date: date, + Date: time.Now().Format("20060102150405"), KeyAlias: s.bc.Cmb.KeyAlias, CmbKeyAlias: s.bc.Cmb.CmbKeyAlias, EncryptBody: "", diff --git a/internal/data/model/order_notify.gen.go b/internal/data/model/order_notify.gen.go index 7536654..4401f6e 100644 --- a/internal/data/model/order_notify.gen.go +++ b/internal/data/model/order_notify.gen.go @@ -15,8 +15,10 @@ type OrderNotify struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` OrderNo string `gorm:"column:order_no;not null" json:"order_no"` OutRequestNo string `gorm:"column:out_request_no;not null" json:"out_request_no"` + Status uint8 `gorm:"column:status;not null;comment:状态" json:"status"` Request string `gorm:"column:request;not null" json:"request"` Responses string `gorm:"column:responses" json:"responses"` + Remark string `gorm:"column:remark" json:"remark"` NotifyUrl string `gorm:"column:notify_url;not null;comment:回调地址" json:"notify_url"` CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"` diff --git a/internal/data/repoimpl/order_notify.go b/internal/data/repoimpl/order_notify.go index f370be3..0116a93 100644 --- a/internal/data/repoimpl/order_notify.go +++ b/internal/data/repoimpl/order_notify.go @@ -4,8 +4,10 @@ import ( "context" "gorm.io/gorm" "time" + "unicode/utf8" "voucher/internal/biz/bo" "voucher/internal/biz/repo" + "voucher/internal/biz/vo" "voucher/internal/data" "voucher/internal/data/model" ) @@ -31,6 +33,7 @@ func (p *OrderNotifyRepoImpl) Create(ctx context.Context, req *bo.OrderNotifyBo) info := &model.OrderNotify{ OrderNo: req.OrderNo, OutRequestNo: req.OutRequestNo, + Status: vo.OrderNotifyStatusWait.GetValue(), Request: req.Request, NotifyUrl: req.NotifyUrl, CreateTime: &now, @@ -44,14 +47,16 @@ func (p *OrderNotifyRepoImpl) Create(ctx context.Context, req *bo.OrderNotifyBo) return p.ToBo(info), nil } -func (p *OrderNotifyRepoImpl) UpdateResponses(ctx context.Context, id uint64, responses string) error { +func (p *OrderNotifyRepoImpl) Success(ctx context.Context, id uint64, responses string) error { now := time.Now() res := p.db.DB(ctx). Where(model.OrderNotify{ - ID: id, + ID: id, + Status: vo.OrderNotifyStatusWait.GetValue(), }). Updates(model.OrderNotify{ + Status: vo.OrderNotifyStatusSuccess.GetValue(), Responses: responses, UpdateTime: &now, }) @@ -62,3 +67,32 @@ func (p *OrderNotifyRepoImpl) UpdateResponses(ctx context.Context, id uint64, re return nil } + +func (p *OrderNotifyRepoImpl) Fail(ctx context.Context, id uint64, remark string) error { + + if utf8.RuneCountInString(remark) > 100 { + runes := []rune(remark) + if len(runes) > 100 { + remark = string(runes[:100]) + } + } + + now := time.Now() + + res := p.db.DB(ctx). + Where(model.OrderNotify{ + ID: id, + Status: vo.OrderNotifyStatusWait.GetValue(), + }). + Updates(model.OrderNotify{ + Status: vo.OrderNotifyStatusFail.GetValue(), + Remark: remark, + UpdateTime: &now, + }) + + if res.Error != nil { + return res.Error + } + + return nil +} diff --git a/internal/service/cmb_mock.go b/internal/service/cmb_mock.go index 5910560..160f9bc 100644 --- a/internal/service/cmb_mock.go +++ b/internal/service/cmb_mock.go @@ -5,6 +5,7 @@ import ( "github.com/go-kratos/kratos/v2/transport/http" v1 "voucher/api/v1" "voucher/internal/biz/bo" + "voucher/internal/biz/vo" ) func (s *VoucherService) CmbOrderMock(ctx http.Context) error { @@ -20,7 +21,7 @@ func (s *VoucherService) CmbOrderMock(ctx http.Context) error { } reply, err := s.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{ - FuncName: cmbOrderFuncName, + FuncName: vo.CmbOrderFuncName, BizContent: string(bizJsonBytes), }) if err != nil { @@ -43,7 +44,7 @@ func (s *VoucherService) CmbProductQueryMock(ctx http.Context) error { } reply, err := s.CmbMixRepo.GetRequest(ctx, &bo.CmbRequestBo{ - FuncName: cmbProductQueryFuncName, + FuncName: vo.CmbProductQueryFuncName, BizContent: string(bizJsonBytes), }) if err != nil { diff --git a/internal/service/consume.go b/internal/service/consume.go index 09c459c..9ca2e5d 100644 --- a/internal/service/consume.go +++ b/internal/service/consume.go @@ -41,39 +41,6 @@ func (j *VoucherService) OrderConsumer(ctx context.Context, msg *mq.ConsumerMess return nil } -func (j *VoucherService) GetQueryConfig() *mq.ConsumerConfig { - elm, ok := j.bc.RocketMQ.EventMap["query"] - if !ok { - return nil - } - - if !elm.IsOpenConsumer { - log.Warnf("query MQ is not open") - return nil - } - - return &mq.ConsumerConfig{ - TopicName: elm.Topic, - GroupName: elm.Group, - PerCoroutineCnt: int(elm.PerCoroutineCnt), - } -} - -func (j *VoucherService) QueryConsumer(ctx context.Context, msg *mq.ConsumerMessage) error { - - orderNo := msg.GetShardingKey() - if orderNo == "" { - log.Error("orderQuery 消费异常,获取 orderNo 失败") - return errors.New("orderQuery 消费异常,获取 orderNo 失败") - } - - if err := j.VoucherBiz.QueryConsume(ctx, orderNo); err != nil { - log.Errorf("query 消费异常,orderNo:%s,error: %s", orderNo, err.Error()) - } - - return nil -} - func (j *VoucherService) GetNotifyConfig() *mq.ConsumerConfig { elm, ok := j.bc.RocketMQ.EventMap["notify"] if !ok {