puzhibing
2026-09-02 54b8d039c03b2a94b7e6dcd74b8bd18ee979f55d
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TCardChargingOrderServiceImpl.java
@@ -24,6 +24,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
@@ -76,11 +77,70 @@
        if (result == null) {
            result = new HashMap<>();
        }
        result.putIfAbsent("platformIncome", BigDecimal.ZERO);
        result.putIfAbsent("partnerIncome", BigDecimal.ZERO);
        BigDecimal platformIncome = BigDecimal.ZERO;
        BigDecimal partnerIncome = BigDecimal.ZERO;
        Map<String, BigDecimal> accountingSummary = emptyAccountingSummary();
        List<Long> orderIds = baseMapper.summaryOrderIds(query, timeRange[0], timeRange[1], timeRange[2], timeRange[3]);
        if (orderIds != null && !orderIds.isEmpty()) {
            int batchSize = 500;
            for (int i = 0; i < orderIds.size(); i += batchSize) {
                List<Long> batchIds = orderIds.subList(i, Math.min(i + batchSize, orderIds.size()));
                Map<String, Object> shareSummary = baseMapper.shareIncomeSummaryByOrderIds(batchIds);
                platformIncome = platformIncome.add(summaryDecimal(shareSummary, "platformIncome"));
                partnerIncome = partnerIncome.add(summaryDecimal(shareSummary, "partnerIncome"));
                mergeAccountingSummary(accountingSummary, baseMapper.accountingSummaryByOrderIds(batchIds));
            }
        }
        result.put("platformIncome", platformIncome);
        result.put("partnerIncome", partnerIncome);
        result.put("platformIncomeTotal", platformIncome);
        result.put("partnerIncomeTotal", partnerIncome);
        result.put("capacityProportion", buildProportion(accountingSummary, "capacity"));
        result.put("serviceProportion", buildProportion(accountingSummary, "service"));
        result.put("electronicProportion", buildProportion(accountingSummary, "electric"));
        return result;
    }
    private Map<String, BigDecimal> emptyAccountingSummary() {
        Map<String, BigDecimal> summary = new HashMap<>();
        for (String prefix : new String[]{"capacity", "service", "electric"}) {
            summary.put(prefix + "Total", BigDecimal.ZERO);
            for (int type = 1; type <= 4; type++) {
                summary.put(prefix + type, BigDecimal.ZERO);
            }
        }
        return summary;
    }
    private void mergeAccountingSummary(Map<String, BigDecimal> total, Map<String, Object> batch) {
        if (batch == null) {
            return;
        }
        for (String key : total.keySet()) {
            total.put(key, total.get(key).add(summaryDecimal(batch, key)));
        }
    }
    private BigDecimal summaryDecimal(Map<String, Object> summary, String key) {
        if (summary == null || summary.get(key) == null) {
            return BigDecimal.ZERO;
        }
        Object value = summary.get(key);
        return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString());
    }
    private String buildProportion(Map<String, BigDecimal> summary, String prefix) {
        BigDecimal denominator = summary.get(prefix + "Total");
        List<String> proportions = new ArrayList<>(4);
        for (int type = 1; type <= 4; type++) {
            BigDecimal percentage = denominator.signum() == 0 ? BigDecimal.ZERO
                    : summary.get(prefix + type).multiply(new BigDecimal("100"))
                    .divide(denominator, 2, RoundingMode.HALF_UP).stripTrailingZeros();
            proportions.add(percentage.toPlainString() + "%");
        }
        return String.join("-", proportions);
    }
    @Override
    public List<ChargingOrderVO> exportList(CardChargingOrderQuery query) {
        String[] timeRange = parseTimeRange(query);