diff --git a/internal/data/db.go b/internal/data/db.go index a18626a..1e5c45d 100644 --- a/internal/data/db.go +++ b/internal/data/db.go @@ -15,6 +15,6 @@ func NewDb(db *GormDb) *Db { } } -func (d *Db) DB(_ context.Context) *gorm.DB { - return d.db.Client +func (d *Db) DB(ctx context.Context) *gorm.DB { + return d.db.Client.WithContext(ctx) } diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index a4c3329..8593e27 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -28,7 +28,7 @@ func NewOrderRepoImpl(db *data.Db) repo.OrderRepo { } func (p *OrderRepoImpl) DB(ctx context.Context) *gorm.DB { - return p.db.DB(ctx).WithContext(ctx).Model(model.Order{}) + return p.db.DB(ctx).Model(model.Order{}) } func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUseBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error { @@ -94,7 +94,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi info := &model.Order{} - db := p.db.DB(ctx).WithContext(ctx).Model(model.Order{}) + db := p.DB(ctx) tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).First(&info) if tx.Error != nil { diff --git a/internal/data/repoimpl/order_notify.go b/internal/data/repoimpl/order_notify.go index 34be51d..47d49fb 100644 --- a/internal/data/repoimpl/order_notify.go +++ b/internal/data/repoimpl/order_notify.go @@ -26,7 +26,7 @@ func NewOrderNotifyRepoImpl(db *data.Db) repo.OrderNotifyRepo { } func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB { - return p.db.DB(ctx).WithContext(ctx).Model(model.OrderNotify{}) + return p.db.DB(ctx).Model(model.OrderNotify{}) } func (p *OrderNotifyRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderNotifyBo, error) { diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go index b29858d..540bc5d 100644 --- a/internal/data/repoimpl/product.go +++ b/internal/data/repoimpl/product.go @@ -84,7 +84,7 @@ func (r *ProductRepoImpl) GetByProductNo(ctx context.Context, productNo string) func (r *ProductRepoImpl) getByProductNo(ctx context.Context, item *model.Product, productNo string) (*model.Product, error) { - db := r.db.DB(ctx).WithContext(ctx).Model(model.Product{}) + db := r.db.DB(ctx).Model(model.Product{}) tx := db.Where(model.Product{ProductNo: productNo}).First(&item) if tx.Error != nil { diff --git a/internal/data/repoimpl/wechat_notify_register_tag.go b/internal/data/repoimpl/wechat_notify_register_tag.go index 6816a7b..10a5feb 100644 --- a/internal/data/repoimpl/wechat_notify_register_tag.go +++ b/internal/data/repoimpl/wechat_notify_register_tag.go @@ -26,7 +26,7 @@ func NewWechatNotifyRegisterTagRepoImpl(db *data.Db) repo.WechatNotifyRegisterTa } func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB { - return p.db.DB(ctx).WithContext(ctx).Model(model.WechatNotifyRegisterTag{}) + return p.db.DB(ctx).Model(model.WechatNotifyRegisterTag{}) } func (p *WechatNotifyRegisterTagRepoImpl) GetByStockIdAndMchId(ctx context.Context, stockCreatorMchID, stockId string) (*bo.WechatNotifyRegisterTagBo, error) {