puzhibing
2026-08-19 70b5c8587de6376d463fba0278d123a9d0f32827
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.ruoyi.order.mapper;
 
import org.junit.jupiter.api.Test;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.stream.Collectors;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
class ChargingOrderActualIncomeMapperTest {
 
    @Test
    void refundedOrdersDoNotContributeToIncomeElectricOrServiceFees() throws IOException {
        InputStream input = getClass().getClassLoader()
                .getResourceAsStream("mapper/order/TChargingOrderMapper.xml");
        assertNotNull(input);
 
        String mapper;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
            mapper = reader.lines().collect(Collectors.joining("\n"));
        }
 
        String summarySql = mapper.substring(
                mapper.indexOf("<select id=\"chargingOrderBaseSummary\""),
                mapper.indexOf("<select id=\"chargingOrderNolimit\""))
                .toLowerCase(Locale.ROOT)
                .replaceAll("\\s+", " ");
 
        // 8/05 起汇总改为 summary 预计算表优先(性能优化),电费/服务费/收入仍须对全额退款订单(refund_status=2)计 0
        assertTrue(summarySql.contains("coalesce(summary.income"));
        assertTrue(summarySql.contains("coalesce(summary.electric_price"));
        assertTrue(summarySql.contains("coalesce(summary.service_price"));
        assertEquals(3, countOccurrences(summarySql, "when b.refund_status = 2 then 0"));
    }
 
    private static int countOccurrences(String value, String token) {
        int count = 0;
        int index = 0;
        while ((index = value.indexOf(token, index)) >= 0) {
            count++;
            index += token.length();
        }
        return count;
    }
}