perf(finance): 补齐财务仪表盘覆盖索引
This commit is contained in:
@@ -109,7 +109,7 @@ func (r *Repository) pickupSummary(ctx context.Context, query DashboardQuery) (*
|
||||
ProfitAmountCent int64
|
||||
CompletedCount int64
|
||||
}
|
||||
if err := db.Table("admin_pickups").
|
||||
if err := db.Table("admin_pickups USE INDEX (idx_admin_pickups_dashboard_completed)").
|
||||
Select(`COALESCE(SUM(settle_amount_cent), 0) AS settled_amount_cent, COALESCE(SUM(profit_amount_cent), 0) AS profit_amount_cent, COUNT(id) AS completed_count`).
|
||||
Where("status = ?", "completed").
|
||||
Where("completed_at >= ? AND completed_at <= ?", query.StartDate, query.EndDate).
|
||||
@@ -136,7 +136,7 @@ func (r *Repository) pickupSummary(ctx context.Context, query DashboardQuery) (*
|
||||
AmountCent int64
|
||||
Count int64
|
||||
}
|
||||
if err := db.Table("admin_pickups").
|
||||
if err := db.Table("admin_pickups USE INDEX (idx_admin_pickups_dashboard_offline_settlement)").
|
||||
Select(`COALESCE(SUM(settle_amount_cent), 0) AS amount_cent, COUNT(id) AS count`).
|
||||
Where("settlement_mode = ? AND offline_settlement_status = ? AND settle_amount_cent > 0", "platform_managed", "pending").
|
||||
Scan(&pending).Error; err != nil {
|
||||
@@ -240,7 +240,7 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) (dash
|
||||
}
|
||||
|
||||
pickupProfits := make([]dailyPickupProfitRow, 0)
|
||||
if err := db.Table("admin_pickups").
|
||||
if err := db.Table("admin_pickups USE INDEX (idx_admin_pickups_dashboard_completed)").
|
||||
Select(`DATE_FORMAT(completed_at, '%Y-%m-%d') AS date,
|
||||
COALESCE(SUM(profit_amount_cent), 0) AS profit_amount_cent,
|
||||
COUNT(id) AS completed_count`).
|
||||
@@ -388,7 +388,7 @@ func (r *Repository) dailyItems(ctx context.Context, query DashboardQuery) (dash
|
||||
|
||||
func (r *Repository) dailyEstimates(ctx context.Context, query DashboardQuery) ([]dailyEstimatedRow, error) {
|
||||
rows := make([]dailyEstimatedRow, 0)
|
||||
err := r.db.WithContext(ctx).Table("rental_orders").
|
||||
err := r.db.WithContext(ctx).Table("rental_orders USE INDEX (idx_rental_orders_dashboard_estimates)").
|
||||
Select(`DATE_FORMAT(created_at, '%Y-%m-%d') AS date,
|
||||
COALESCE(SUM(platform_fee_cent), 0) AS estimated_income_amount_cent,
|
||||
COUNT(id) AS pending_settle_order_count`).
|
||||
@@ -561,12 +561,12 @@ func (r *Repository) dailyPaidOrders(ctx context.Context, query DashboardQuery)
|
||||
items := make([]dailyPaidOrderRow, 0)
|
||||
err := r.db.WithContext(ctx).Table(`(
|
||||
SELECT DATE_FORMAT(paid_at, '%Y-%m-%d') AS date, COUNT(DISTINCT order_id) AS paid_order_count
|
||||
FROM payment_orders
|
||||
FROM payment_orders USE INDEX (idx_payment_orders_biz_status_paid_at_order)
|
||||
WHERE biz_type = 'order_pay' AND status = 'paid' AND paid_at >= ? AND paid_at <= ?
|
||||
GROUP BY DATE_FORMAT(paid_at, '%Y-%m-%d')
|
||||
UNION ALL
|
||||
SELECT DATE_FORMAT(completed_at, '%Y-%m-%d') AS date, COUNT(id) AS paid_order_count
|
||||
FROM admin_pickups
|
||||
FROM admin_pickups USE INDEX (idx_admin_pickups_dashboard_completed)
|
||||
WHERE status = 'completed' AND completed_at >= ? AND completed_at <= ?
|
||||
GROUP BY DATE_FORMAT(completed_at, '%Y-%m-%d')
|
||||
) AS daily_paid_orders`, query.StartDate, query.EndDate, query.StartDate, query.EndDate).
|
||||
|
||||
Reference in New Issue
Block a user