longz
2026-07-21 eb04fd37f070e52920032f850826e0e12fb48c64
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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.stream.Collectors;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
class PayOrderQueryPerformanceMapperTest {
 
    @Test
    void readsRefundStatusFromOrderTablesWithoutJoiningRefundDetails() 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 payOrderQuery = mapper.substring(
                mapper.indexOf("<select id=\"payOrderQuery\""),
                mapper.indexOf("<select id=\"getRefundList\""));
        assertEquals(3, countOccurrences(payOrderQuery, "a.refund_status as refund_status"));
        assertFalse(payOrderQuery.contains("t_charging_order_refund"));
        assertFalse(payOrderQuery.contains("t_shopping_order_refund"));
        assertFalse(payOrderQuery.contains("t_vip_order_refund"));
    }
 
    @Test
    void refundListAppliesPartnerSiteScopeInsidePagedQuery() 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 refundQuery = mapper.substring(
                mapper.indexOf("<select id=\"getRefundList\""),
                mapper.indexOf("<select id=\"chargingOrderGroup\""));
        assertTrue(refundQuery.contains("data.siteIds"));
        assertTrue(refundQuery.contains("o.site_id IN"));
        assertEquals(3, countOccurrences(refundQuery, "as site_id"));
    }
 
    private int countOccurrences(String text, String target) {
        int count = 0;
        int index = 0;
        while ((index = text.indexOf(target, index)) >= 0) {
            count++;
            index += target.length();
        }
        return count;
    }
}