longz
2026-08-05 3aab2ba53d5132263f07b0666dffc7888bd46701
fix: fill missing platform income months
1个文件已添加
3个文件已修改
102 ■■■■■ 已修改文件
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/mapper/TChargingOrderMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/service/impl/MonthlyIncomeFallbackTest.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/mapper/TChargingOrderMapper.java
@@ -180,6 +180,8 @@
    List<SixChargingDto> chargeSettlement(@Param("sixBefore") String sixBefore, @Param("siteIds") List<Integer> siteIds);
    List<SixChargingDto> chargeOrderHistory(@Param("sixBefore") String sixBefore, @Param("siteIds") List<Integer> siteIds);
    List<SixChargingDto> chargeCurrentMonth(@Param("siteIdsCsv") String siteIdsCsv);
    List<SixCircleDto> circle(@Param("siteIds") List<Integer> siteIds, @Param("sixBefore") LocalDate sixBefore, @Param("partnerView") Boolean partnerView);
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -3532,9 +3532,8 @@
            }
        } else {
            List<SixChargingDto> settlementIncome = this.baseMapper.chargeSettlement(sixBeforeValue, siteIds);
            if (settlementIncome != null) {
                result.addAll(settlementIncome);
            }
            List<SixChargingDto> orderHistoryIncome = this.baseMapper.chargeOrderHistory(sixBeforeValue, siteIds);
            result.addAll(mergeMissingMonthlyIncome(settlementIncome, orderHistoryIncome));
            String siteIdsCsv = siteIds == null ? null : siteIds.stream()
                    .filter(Objects::nonNull)
                    .map(String::valueOf)
@@ -3569,6 +3568,45 @@
        return result;
    }
    static List<SixChargingDto> mergeMissingMonthlyIncome(List<SixChargingDto> settlementIncome,
                                                            List<SixChargingDto> orderHistoryIncome) {
        List<SixChargingDto> merged = new ArrayList<>();
        Set<Integer> settledMonths = new HashSet<>();
        if (settlementIncome != null) {
            for (SixChargingDto item : settlementIncome) {
                if (item == null) {
                    continue;
                }
                merged.add(item);
                Integer month = incomeMonth(item);
                if (month != null) {
                    settledMonths.add(month);
                }
            }
        }
        if (orderHistoryIncome != null) {
            for (SixChargingDto item : orderHistoryIncome) {
                Integer month = incomeMonth(item);
                if (item != null && month != null && settledMonths.add(month)) {
                    merged.add(item);
                }
            }
        }
        return merged;
    }
    private static Integer incomeMonth(SixChargingDto item) {
        if (item == null || item.getMonth() == null) {
            return null;
        }
        try {
            int month = Integer.parseInt(item.getMonth());
            return month >= 1 && month <= 12 ? month : null;
        } catch (NumberFormatException ignored) {
            return null;
        }
    }
    @Override
    public List<SixCircleDto> circle(List<Integer> siteIds, LocalDate sixBefore, Boolean partnerView) {
        List<SixCircleDto> result = this.baseMapper.circle(siteIds, sixBefore, partnerView);
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -830,6 +830,31 @@
        GROUP BY EXTRACT(MONTH FROM billing_cycle)
    </select>
    <select id="chargeOrderHistory" resultType="com.ruoyi.order.dto.SixChargingDto">
        SELECT EXTRACT(MONTH FROM create_time) AS MONTH,
               SUM(IFNULL(electrovalence, 0)) AS electrovalence,
               SUM(CASE
                       WHEN order_source = 2
                           THEN IFNULL(service_charge, 0) * 0.8
                       ELSE IFNULL(service_charge, 0)
                   END) AS service_charge
        FROM t_charging_order
        WHERE del_flag = 0
          AND status = 5
          AND recharge_payment_status = 2
          AND create_time &lt; DATE_FORMAT(CURDATE(), '%Y-%m-01')
        <if test="sixBefore != null and sixBefore != ''">
            AND create_time &gt;= #{sixBefore}
        </if>
        <if test="siteIds != null and siteIds.size() > 0">
            AND site_id IN
            <foreach collection="siteIds" item="siteId" open="(" separator="," close=")">
                #{siteId}
            </foreach>
        </if>
        GROUP BY EXTRACT(MONTH FROM create_time)
    </select>
    <select id="chargeCurrentMonth" resultType="com.ruoyi.order.dto.SixChargingDto">
        SELECT DATE_FORMAT(CURDATE(), '%m') AS MONTH,
               IFNULL(SUM(IFNULL(electrovalence, 0)), 0) AS electrovalence,
ruoyi-service/ruoyi-order/src/test/java/com/ruoyi/order/service/impl/MonthlyIncomeFallbackTest.java
New file
@@ -0,0 +1,31 @@
package com.ruoyi.order.service.impl;
import com.ruoyi.order.dto.SixChargingDto;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MonthlyIncomeFallbackTest {
    @Test
    void addsOnlyOrderMonthsMissingFromSettlementIncome() {
        SixChargingDto settlementApril = month("04");
        SixChargingDto orderMarch = month("03");
        SixChargingDto orderApril = month("04");
        List<SixChargingDto> merged = TChargingOrderServiceImpl.mergeMissingMonthlyIncome(
                Arrays.asList(settlementApril), Arrays.asList(orderMarch, orderApril));
        assertEquals(Arrays.asList("04", "03"), Arrays.asList(
                merged.get(0).getMonth(), merged.get(1).getMonth()));
    }
    private SixChargingDto month(String value) {
        SixChargingDto dto = new SixChargingDto();
        dto.setMonth(value);
        return dto;
    }
}