优化财务仪表盘查询性能
This commit is contained in:
@@ -321,10 +321,11 @@ func TestSummaryReturnsNormalOrderCountAndScopedExceptionCount(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("读取提号汇总失败: %v", err)
|
||||
}
|
||||
summary, err := repo.summary(t.Context(), query, pickup)
|
||||
settlements, err := repo.dailySettlements(t.Context(), query)
|
||||
if err != nil {
|
||||
t.Fatalf("读取财务汇总失败: %v", err)
|
||||
t.Fatalf("读取每日结算汇总失败: %v", err)
|
||||
}
|
||||
summary := summaryWithPickup(summaryFromDailyRows(nil, settlements, nil), pickup)
|
||||
if summary.SettledOrderCount != 2 || summary.NormalOrderProfitAmountCent != 500 {
|
||||
t.Fatalf("普通订单数量或利润错误: %+v", summary)
|
||||
}
|
||||
@@ -332,3 +333,39 @@ func TestSummaryReturnsNormalOrderCountAndScopedExceptionCount(t *testing.T) {
|
||||
t.Fatalf("财务异常数 = %d, want 1", summary.FinancialExceptionCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryFromDailyRowsPreservesDashboardTotals(t *testing.T) {
|
||||
paymentRows := []dailyPaymentRow{
|
||||
{TotalFlowAmountCent: 1000, TotalRefundAmountCent: 100, PendingRefundAmountCent: 30, SuccessfulPayCount: 3, FullRefundCount: 1},
|
||||
{TotalFlowAmountCent: 2500, TotalRefundAmountCent: 400, PendingRefundAmountCent: 70, SuccessfulPayCount: 5, PartialRefundCount: 2, PendingRefundCount: 1},
|
||||
}
|
||||
settlementRows := []dailySettlementRow{
|
||||
{PlatformIncomeAmountCent: 300, OwnerShouldIncomeAmountCent: 900, OwnerWalletIncomeAmountCent: 850, OwnerEffectiveSettlementAmountCent: 850, OfflineSettlementAmountCent: 100, OfflineSettlementPendingAmountCent: 20, OfflineSettlementPendingCount: 1, FinancialExceptionCount: 2, SettledOrderCount: 3},
|
||||
{PlatformIncomeAmountCent: 200, OwnerShouldIncomeAmountCent: 600, OwnerWalletIncomeAmountCent: 500, OwnerEffectiveSettlementAmountCent: 550, OfflineSettlementAmountCent: 200, OfflineSettlementPendingAmountCent: 40, OfflineSettlementPendingCount: 2, FinancialExceptionCount: 1, SettledOrderCount: 2},
|
||||
}
|
||||
estimateRows := []dailyEstimatedRow{
|
||||
{EstimatedIncomeAmountCent: 120, PendingSettleOrderCount: 4},
|
||||
{EstimatedIncomeAmountCent: 80, PendingSettleOrderCount: 3},
|
||||
}
|
||||
pickup := &PickupSummaryDTO{ProfitAmountCent: 90, CompletedCount: 2, PendingAmountCent: 60, PendingCount: 3}
|
||||
|
||||
summary := summaryWithPickup(summaryFromDailyRows(paymentRows, settlementRows, estimateRows), pickup)
|
||||
if summary.TotalFlowAmountCent != 3500 || summary.TotalRefundAmountCent != 500 || summary.ChannelNetAmountCent != 3000 {
|
||||
t.Fatalf("支付汇总错误: %+v", summary)
|
||||
}
|
||||
if summary.PendingRefundAmountCent != 100 || summary.SuccessfulPayCount != 8 || summary.SuccessfulRefundCount != 3 || summary.FullRefundCount != 1 || summary.PartialRefundCount != 2 || summary.PendingRefundCount != 1 {
|
||||
t.Fatalf("支付笔数汇总错误: %+v", summary)
|
||||
}
|
||||
if summary.NormalOrderProfitAmountCent != 500 || summary.PickupProfitAmountCent != 90 || summary.PlatformIncomeAmountCent != 590 || summary.PickupCompletedCount != 2 {
|
||||
t.Fatalf("平台利润汇总错误: %+v", summary)
|
||||
}
|
||||
if summary.OwnerShouldIncomeAmountCent != 1500 || summary.OwnerWalletIncomeAmountCent != 1350 || summary.OwnerEffectiveSettlementAmountCent != 1400 || summary.SettlementDiffAmountCent != 100 {
|
||||
t.Fatalf("货主结算汇总错误: %+v", summary)
|
||||
}
|
||||
if summary.OfflineSettlementAmountCent != 300 || summary.OfflineSettlementPendingAmountCent != 120 || summary.OfflineSettlementPendingCount != 6 {
|
||||
t.Fatalf("线下结算汇总错误: %+v", summary)
|
||||
}
|
||||
if summary.EstimatedIncomeAmountCent != 200 || summary.PendingSettleOrderCount != 7 || summary.SettledOrderCount != 5 || summary.FinancialExceptionCount != 3 {
|
||||
t.Fatalf("订单状态汇总错误: %+v", summary)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user