longz
2026-07-20 3776e4454d1368199929e1b21330369902d36f54
fix: 修复订单手机号查询超时
1个文件已添加
2个文件已修改
78 ■■■■■ 已修改文件
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/mapper/ChargingOrderPhoneFilterMapperTest.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -2603,13 +2603,6 @@
        String endTime1 = timeRange[2];
        String endTime2 = timeRange[3];
        PageInfo<ChargingOrderVO> pageInfo = new PageInfo<>(dto.getPageCurr(), dto.getPageSize());
        if (StringUtils.hasLength(dto.getPhone())) {
            List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData();
            if (data == null || data.isEmpty()) {
                return pageInfo;
            }
            dto.setUserIds(data);
        }
        Long userId = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userId).getData();
        Integer roleType = sysUser.getRoleType();
@@ -2631,13 +2624,6 @@
        String startTime2 = timeRange[1];
        String endTime1 = timeRange[2];
        String endTime2 = timeRange[3];
        if (StringUtils.hasLength(dto.getPhone())) {
            List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData();
            if (data == null || data.isEmpty()) {
                return tCharingOrderVO;
            }
            dto.setUserIds(data);
        }
        Long userId = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userId).getData();
        setChargingOrderAuthSiteIds(dto, sysUser, userId, sysUser.getRoleType());
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -94,6 +94,9 @@
        select t1.*,
        IFNULL(t1.whitelist_electric_refund_amount, 0) + IFNULL(t1.whitelist_service_refund_amount, 0) as whitelistRefundAmount
        from t_charging_order t1
        <if test="req.phone != null and req.phone != ''">
            inner join `charging_pile_account`.`t_app_user` app_user on app_user.id = t1.app_user_id
        </if>
        where t1.del_flag = 0
        <if test="null != req.code and req.code!=''">
            and t1.code LIKE CONCAT('%',#{req.code},'%')
@@ -103,6 +106,9 @@
            <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="req.phone != null and req.phone != ''">
            and app_user.phone LIKE CONCAT('%',#{req.phone},'%')
        </if>
        <if test="null != req.siteIds and req.siteIds.size()>0">
            and t1.site_id in
@@ -2188,6 +2194,9 @@
                #{item}
            </foreach>
        </if>
        <if test="req.phone != null and req.phone != ''">
            and app_user.phone LIKE CONCAT('%',#{req.phone},'%')
        </if>
        <if test="null != req.siteIds and req.siteIds.size()>0">
            and b.site_id in
            <foreach collection="req.siteIds" item="item" index="index" separator="," open="(" close=")">
@@ -2266,6 +2275,9 @@
            MAX(IFNULL(b.third_pay_amount, CASE WHEN b.pay_method = 3 THEN IFNULL(b.payment_amount, IFNULL(b.recharge_amount, 0)) ELSE 0 END) - IFNULL(b.third_refund_amount, CASE WHEN b.pay_method = 3 THEN IFNULL(b.refund_amount, 0) ELSE 0 END)) as thirdNetAmount
            from `charging_pile_order`.t_charging_order b
            left join `charging_pile_order`.t_charging_order_accounting_strategy a on a.charging_order_id = b.id
            <if test="req.phone != null and req.phone != ''">
                inner join `charging_pile_account`.`t_app_user` app_user on app_user.id = b.app_user_id
            </if>
            <include refid="ChargingOrderSummaryWhere"/>
            group by b.id,b.end_time,b.start_time,b.order_source
        ) as aa
@@ -2288,6 +2300,9 @@
            sum(a.period_electric_price + (CASE WHEN b.order_source = 1 THEN a.period_service_price ELSE a.period_service_price * 0.8 END)) as income
            from `charging_pile_order`.t_charging_order_accounting_strategy a
            left join `charging_pile_order`.t_charging_order b on (a.charging_order_id = b.id)
            <if test="req.phone != null and req.phone != ''">
                inner join `charging_pile_account`.`t_app_user` app_user on app_user.id = b.app_user_id
            </if>
            <include refid="ChargingOrderSummaryWhere"/>
            group by b.id,time
        ) as aa
@@ -2313,6 +2328,9 @@
            b.whitelist_service_refund_amount,
            IFNULL(b.third_pay_amount, CASE WHEN b.pay_method = 3 THEN IFNULL(b.payment_amount, IFNULL(b.recharge_amount, 0)) ELSE 0 END) - IFNULL(b.third_refund_amount, CASE WHEN b.pay_method = 3 THEN IFNULL(b.refund_amount, 0) ELSE 0 END) as thirdNetAmount
            from `charging_pile_order`.t_charging_order b
            <if test="req.phone != null and req.phone != ''">
                inner join `charging_pile_account`.`t_app_user` app_user on app_user.id = b.app_user_id
            </if>
            <include refid="ChargingOrderSummaryWhere"/>
        ) as aa
    </select>
@@ -2373,6 +2391,9 @@
    <select id="chargingOrderSummaryOrderIds" resultType="java.lang.Long">
        select b.id
        from `charging_pile_order`.t_charging_order b
        <if test="req.phone != null and req.phone != ''">
            inner join `charging_pile_account`.`t_app_user` app_user on app_user.id = b.app_user_id
        </if>
        <include refid="ChargingOrderSummaryWhere"/>
    </select>
ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/mapper/ChargingOrderPhoneFilterMapperTest.java
New file
@@ -0,0 +1,43 @@
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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ChargingOrderPhoneFilterMapperTest {
    @Test
    void filtersPhoneInsideOrderQueriesInsteadOfExpandingUserIds() 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"));
        }
        assertTrue(mapper.contains("app_user.phone LIKE CONCAT('%',#{req.phone},'%')"));
        assertEquals(5, countOccurrences(mapper,
                "inner join `charging_pile_account`.`t_app_user` app_user on app_user.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;
    }
}