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;
|
}
|
}
|