微信错误处理
This commit is contained in:
parent
73a0321d99
commit
451169b22d
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
|
@ -37,10 +36,8 @@ func (p *OrderRepoImpl) FindIngInBatches(ctx context.Context, fun func(ctx conte
|
|||
|
||||
result := p.DB(ctx).
|
||||
Where("status = ?", vo.OrderStatusIng.GetValue()).
|
||||
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
||||
// tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch)
|
||||
// 'batch' 变量表示当前批号(the current batch number)
|
||||
// 返回 error 将阻止更多的批处理
|
||||
Limit(100).
|
||||
FindInBatches(&results, 20, func(tx *gorm.DB, batch int) error {
|
||||
return fun(ctx, p.ToBos(results))
|
||||
})
|
||||
|
||||
|
|
@ -95,12 +92,9 @@ func (p *OrderRepoImpl) Create(ctx context.Context, req *bo.OrderBo) (*bo.OrderB
|
|||
UpdateTime: &now,
|
||||
}
|
||||
|
||||
db := p.DB(ctx)
|
||||
tx := db.Create(info)
|
||||
tx := p.DB(ctx).Create(info)
|
||||
|
||||
if tx.Error != nil {
|
||||
sqlDB, _ := db.DB()
|
||||
log.Warnf("order create 当前打开连接数:%d,空闲连接数:%d", sqlDB.Stats().OpenConnections, sqlDB.Stats().Idle)
|
||||
return nil, fmt.Errorf("create db fail %w", tx.Error)
|
||||
}
|
||||
|
||||
|
|
@ -111,8 +105,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi
|
|||
|
||||
info := &model.Order{}
|
||||
|
||||
db := p.DB(ctx)
|
||||
tx := db.Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).First(&info)
|
||||
tx := p.DB(ctx).Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).First(&info)
|
||||
|
||||
if tx.Error != nil {
|
||||
|
||||
|
|
@ -120,11 +113,6 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi
|
|||
return nil, err2.ErrorDbNotFound("订单数据不存在")
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +208,6 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string
|
|||
tx := p.DB(ctx).
|
||||
Where(model.Order{
|
||||
ID: id,
|
||||
//Status: vo.OrderStatusIng.GetValue(),
|
||||
}).
|
||||
Updates(model.Order{
|
||||
Status: vo.OrderStatusSuccess.GetValue(),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"github.com/go-kratos/kratos/v2/errors"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
err2 "voucher/api/err"
|
||||
v1 "voucher/api/v1"
|
||||
"voucher/internal/biz/bo"
|
||||
|
|
@ -69,8 +68,6 @@ func (c *CmbService) OrderFail(ctx context.Context, err error) (*v1.CmbReply, er
|
|||
se.Reason = err2.CmbErr_CMB_UNKNOWN.String()
|
||||
}
|
||||
|
||||
log.Errorf("order fail: %v", se)
|
||||
|
||||
bizReply := &v1.CmbOrderReply{
|
||||
RespCode: vo.CmbResponseStatusFail.GetValue(),
|
||||
RespMsg: se.Message,
|
||||
|
|
|
|||
Loading…
Reference in New Issue