This commit is contained in:
parent
345f7c6da4
commit
31c2da9027
|
|
@ -36,7 +36,7 @@ func Test_db(t *testing.T) {
|
|||
defer wg.Done()
|
||||
|
||||
var m model.Product
|
||||
tx := gormDb.Model(model.Product{}).Where(model.Product{ProductNo: "001"}).Find(&m)
|
||||
tx := gormDb.Model(model.Product{}).Where(model.Product{ProductNo: "000"}).First(&m)
|
||||
if tx.Error != nil {
|
||||
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
|
||||
t.Errorf("未找到记录")
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package repoimpl
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -83,18 +84,17 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB
|
|||
}
|
||||
|
||||
func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBizNo string) (*bo.OrderBo, error) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 20*time.Second) // 设置查询超时
|
||||
defer cancel()
|
||||
|
||||
info := &model.Order{}
|
||||
|
||||
db := p.DB(ctx)
|
||||
tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info)
|
||||
tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
|
||||
if errors.Is(tx.Error, context.DeadlineExceeded) {
|
||||
sqlDB, _ := db.DB()
|
||||
log.Warnf("order当前打开连接数:%d,空闲连接数:%d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi
|
|||
func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, error) {
|
||||
info := &model.Order{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.Order{ID: id}).Find(&info)
|
||||
tx := p.DB(ctx).Where(model.Order{ID: id}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
||||
|
|
@ -125,7 +125,7 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er
|
|||
func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.OrderBo, error) {
|
||||
info := &model.Order{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).Find(&info)
|
||||
tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, fmt.Errorf("order db fail %w", tx.Error)
|
||||
|
|
@ -141,7 +141,7 @@ func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.O
|
|||
func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, voucherNo string) (*bo.OrderBo, error) {
|
||||
info := &model.Order{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.Order{MerchantNo: merchantNo, BatchNo: batchNo, VoucherNo: voucherNo}).Find(&info)
|
||||
tx := p.DB(ctx).Where(model.Order{MerchantNo: merchantNo, BatchNo: batchNo, VoucherNo: voucherNo}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, fmt.Errorf("db fail %w", tx.Error)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB {
|
|||
func (p *OrderNotifyRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderNotifyBo, error) {
|
||||
info := &model.OrderNotify{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.OrderNotify{ID: id}).Find(&info)
|
||||
tx := p.DB(ctx).Where(model.OrderNotify{ID: id}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product
|
|||
func (r *ProductRepoImpl) getByPNO(ctx context.Context, item *model.Product, PNO string) (*model.Product, error) {
|
||||
|
||||
db := r.DB(ctx)
|
||||
tx := db.Where(model.Product{ProductNo: PNO}).Find(&item)
|
||||
tx := db.Where(model.Product{ProductNo: PNO}).First(&item)
|
||||
|
||||
if tx.Error != nil {
|
||||
sqlDB, _ := db.DB()
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB {
|
|||
func (p *WechatNotifyRegisterTagRepoImpl) GetByStockIdAndMchId(ctx context.Context, stockCreatorMchID, stockId string) (*bo.WechatNotifyRegisterTagBo, error) {
|
||||
info := &model.WechatNotifyRegisterTag{}
|
||||
|
||||
tx := p.DB(ctx).Where(model.WechatNotifyRegisterTag{StockCreatorMchID: stockCreatorMchID, StockID: stockId}).Find(&info)
|
||||
tx := p.DB(ctx).Where(model.WechatNotifyRegisterTag{StockCreatorMchID: stockCreatorMchID, StockID: stockId}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
|
|
|
|||
Loading…
Reference in New Issue