From 2e648c09c381fe6bd5bd5ac8973425019e3290e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 14 Mar 2025 21:11:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/err/err.proto | 3 +++ internal/biz/cmb.go | 4 +--- internal/data/repoimpl/base.go | 8 ++++++++ internal/data/repoimpl/order.go | 8 ++++---- internal/data/repoimpl/order_notify.go | 2 +- internal/data/repoimpl/product.go | 2 +- internal/data/repoimpl/wechat_notify_register_tag.go | 2 +- internal/service/cmb.go | 2 +- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/api/err/err.proto b/api/err/err.proto index 935a194..4286531 100644 --- a/api/err/err.proto +++ b/api/err/err.proto @@ -10,6 +10,9 @@ enum Err { // 系统panic错误 SYSTEM_PANIC = 0 [(errors.code) = 599]; + + // DB数据未找到 + DB_NOT_FOUND = 2 [(errors.code) = 404]; } enum NotifyConsumeErr{ diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index a8bcc75..8ae448b 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -2,9 +2,7 @@ package biz import ( "context" - "errors" "fmt" - "gorm.io/gorm" "time" err2 "voucher/api/err" v1 "voucher/api/v1" @@ -21,7 +19,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (vo order, err := v.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, req.OutBizNo) - if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + if err != nil && !err2.IsDbNotFound(err) { return err } diff --git a/internal/data/repoimpl/base.go b/internal/data/repoimpl/base.go index 389469a..2f80a95 100644 --- a/internal/data/repoimpl/base.go +++ b/internal/data/repoimpl/base.go @@ -2,9 +2,17 @@ package repoimpl import ( "time" + err2 "voucher/api/err" "voucher/internal/pkg/mapstructure" ) +var ( + ErrOrderRecordNotFound = err2.ErrorDbNotFound("订单不存在") + ErrProductRecordNotFound = err2.ErrorDbNotFound("商品不存在") + ErrOrderNotifyRecordNotFound = err2.ErrorDbNotFound("订单通知数据不存在") + ErrWechatNotifyRegisterTagRecordNotFound = err2.ErrorDbNotFound("微信注册tag数据不存在") +) + type Base[D any, B any] struct{} func (*Base[D, B]) ToBo(d *D) *B { diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index e45918a..0b2f9f0 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -91,7 +91,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrOrderRecordNotFound } return p.ToBo(info), nil @@ -107,7 +107,7 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrOrderRecordNotFound } return p.ToBo(info), nil @@ -123,7 +123,7 @@ func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.O } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrOrderRecordNotFound } return p.ToBo(info), nil @@ -139,7 +139,7 @@ func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, vouch } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrOrderRecordNotFound } return p.ToBo(info), nil diff --git a/internal/data/repoimpl/order_notify.go b/internal/data/repoimpl/order_notify.go index 99799f4..8d8dac7 100644 --- a/internal/data/repoimpl/order_notify.go +++ b/internal/data/repoimpl/order_notify.go @@ -37,7 +37,7 @@ func (p *OrderNotifyRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.Order } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrOrderNotifyRecordNotFound } return p.ToBo(info), nil diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go index b3c7c6d..86d87f6 100644 --- a/internal/data/repoimpl/product.go +++ b/internal/data/repoimpl/product.go @@ -34,7 +34,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrProductRecordNotFound } return r.ToBo(&item), nil diff --git a/internal/data/repoimpl/wechat_notify_register_tag.go b/internal/data/repoimpl/wechat_notify_register_tag.go index 460bab5..7be7e23 100644 --- a/internal/data/repoimpl/wechat_notify_register_tag.go +++ b/internal/data/repoimpl/wechat_notify_register_tag.go @@ -37,7 +37,7 @@ func (p *WechatNotifyRegisterTagRepoImpl) GetByStockIdAndMchId(ctx context.Conte } if tx.RowsAffected == 0 { - return nil, gorm.ErrRecordNotFound + return nil, ErrWechatNotifyRegisterTagRecordNotFound } return p.ToBo(info), nil diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 993d671..f2a3f60 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -31,7 +31,7 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error { bizReply = &v1.CmbOrderReply{ RespCode: vo.CmbResponseStatusFail.GetValue(), - RespMsg: err.Error(), + RespMsg: se.Message, CodeNo: "", ThirdErrCode: se.Reason, }