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