From a01f04a949578901511dfbf1d646874efb10cc62 Mon Sep 17 00:00:00 2001 From: ziming Date: Thu, 16 Oct 2025 12:01:26 +0800 Subject: [PATCH] order by --- internal/data/gorm.go | 4 ++-- internal/data/repoimpl/order.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/data/gorm.go b/internal/data/gorm.go index 3ef0314..1459afe 100644 --- a/internal/data/gorm.go +++ b/internal/data/gorm.go @@ -36,8 +36,8 @@ func db(data *conf.Data_Database) *gorm.DB { panic("failed to gormDB " + err.Error()) } - sqlDB.SetMaxIdleConns(100) - sqlDB.SetMaxOpenConns(1000) + sqlDB.SetMaxIdleConns(50) + sqlDB.SetMaxOpenConns(200) return gormDB } diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index b62e9ea..830974b 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -55,7 +55,7 @@ func (p *OrderRepoImpl) SpecifyFindInBatches(ctx context.Context, req *bo.FindIn tx = tx.Where("voucher_no IN (?)", req.VoucherNos) } - tx.Order("") // 显式清除排序,移除默认的 ORDER BY + tx.Order("receive_success_time asc") // 显式清除排序,移除默认的 ORDER BY var results = make([]*model.Order, 0) @@ -95,9 +95,9 @@ func (p *OrderRepoImpl) FinSucByStockIdInBatches(ctx context.Context, req *do.We var results = make([]*model.Order, 0) - tx.Order("") // 显式清除排序,移除默认的 ORDER BY + tx.Order("receive_success_time asc") // 显式清除排序,移除默认的 ORDER BY - result := tx.FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { + result := tx.FindInBatches(&results, 1000, func(tx *gorm.DB, batch int) error { return fun(ctx, p.ToBos(results)) }) @@ -116,7 +116,7 @@ func (p *OrderRepoImpl) FinFailByStockIdInBatches(ctx context.Context, batchNo s result := p.DB(ctx). Where("batch_no = ?", batchNo). Where("`status` = ?", vo.OrderStatusFail.GetValue()). - Order(""). // 显式清除排序,移除默认的 ORDER BY + Order("receive_success_time asc"). // 显式清除排序,移除默认的 ORDER BY FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { return fun(ctx, p.ToBos(results)) }) @@ -135,7 +135,7 @@ func (p *OrderRepoImpl) FindIngInBatches(ctx context.Context, fun func(ctx conte result := p.DB(ctx). Where("`status` = ?", vo.OrderStatusIng.GetValue()). Limit(20). - Order(""). // 显式清除排序,移除默认的 ORDER BY + Order("receive_success_time asc"). // 显式清除排序,移除默认的 ORDER BY FindInBatches(&results, 10, func(tx *gorm.DB, batch int) error { return fun(ctx, p.ToBos(results)) }) @@ -155,7 +155,7 @@ func (p *OrderRepoImpl) FindInBatches(ctx context.Context, req *bo.FindInBatches Where("activity_id = ''"). Where("`status` IN (?)", []uint8{vo.OrderStatusSuccess.GetValue(), vo.OrderStatusUse.GetValue()}). Where("receive_success_time BETWEEN ? AND ?", req.StartTime, req.EndTime). - Order(""). // 显式清除排序,移除默认的 ORDER BY + Order("receive_success_time asc"). // 显式清除排序,移除默认的 ORDER BY FindInBatches(&results, 1000, func(tx *gorm.DB, batch int) error { // tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch) // 'batch' 变量表示当前批号(the current batch number)