65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package repoimpl
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"voucher/internal/biz/bo"
|
|
"voucher/internal/biz/repo"
|
|
"voucher/internal/biz/vo"
|
|
"voucher/internal/data"
|
|
"voucher/internal/data/model"
|
|
)
|
|
|
|
// OrderBakRepoImpl .
|
|
type OrderBakRepoImpl struct {
|
|
Base[model.OrderBak, bo.OrderBo]
|
|
db *data.Db
|
|
}
|
|
|
|
// NewOrderBakRepoImpl .
|
|
func NewOrderBakRepoImpl(db *data.Db) repo.OrderBakRepo {
|
|
return &OrderBakRepoImpl{db: db}
|
|
}
|
|
|
|
func (p *OrderBakRepoImpl) DB(ctx context.Context) *gorm.DB {
|
|
return p.db.DB(ctx).Model(model.OrderBak{})
|
|
}
|
|
|
|
func (p *OrderBakRepoImpl) FindInBatches(ctx context.Context, req *bo.FindInBatchesBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error {
|
|
|
|
tx := p.DB(ctx).Where("status = ?", vo.OrderStatusSuccess.GetValue())
|
|
|
|
if req.ProductNo != "" {
|
|
tx = tx.Where("product_no = ?", req.ProductNo)
|
|
}
|
|
|
|
if req.StartTime != nil && req.EndTime != nil {
|
|
tx = tx.Where("receive_success_time BETWEEN ? AND ?", req.StartTime, req.EndTime)
|
|
}
|
|
|
|
if req.OrderNo != nil {
|
|
tx = tx.Where("order_no IN (?)", req.OrderNo)
|
|
}
|
|
|
|
if req.OutBizNo != nil {
|
|
tx = tx.Where("out_biz_no IN (?)", req.OutBizNo)
|
|
}
|
|
|
|
if req.VoucherNo != nil {
|
|
tx = tx.Where("voucher_no IN (?)", req.VoucherNo)
|
|
}
|
|
|
|
var results = make([]*model.OrderBak, 0)
|
|
|
|
result := tx.FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
|
|
|
return fun(ctx, p.ToBos(results))
|
|
})
|
|
|
|
if result.Error != nil {
|
|
return result.Error
|
|
}
|
|
|
|
return nil
|
|
}
|