liding
4 天以前 02f0f418d2409a8a19b440101601c6b604e21606
main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
@@ -482,7 +482,7 @@
        // 4. 批量查询煤种信息并填充到结果中
        if (!coalIds.isEmpty()) {
            List<CoalInfo> coalInfos = coalInfoMapper.selectBatchIds(coalIds);
            List<CoalInfo> coalInfos = coalInfoMapper.selectByIds(coalIds);
            for (CoalInfo coalInfo : coalInfos) {
                Map<String, Object> record = resultMap.get(coalInfo.getId());
                if (record != null) {
@@ -491,8 +491,33 @@
            }
        }
        // 最终结果是一个List<Map>,每个Map包含合并后的销售数据和对应的煤种信息
        List<Map<String, Object>> results = new ArrayList<>(resultMap.values());
        //月度数据
        //查询所有煤种信息
        List<CoalInfo> allCoalTypes = coalInfoMapper.selectList(
                new QueryWrapper<CoalInfo>().orderByAsc("id")
        );
        //预计算销量:按coalId分组统计总销量
        Map<Long, BigDecimal> salesByCoalId = salesRecords.stream()
                .collect(Collectors.groupingBy(
                        SalesRecord::getCoalId,
                        Collectors.reducing(
                                BigDecimal.ZERO,
                                SalesRecord::getSaleQuantity,
                                BigDecimal::add
                        )
                ));
        //构建结果(保持煤种顺序,销量默认为0)
        List<Map<String, Object>> resultMouth = new ArrayList<>();
        for (CoalInfo coal : allCoalTypes) {
            Map<String, Object> item = new LinkedHashMap<>();
            item.put("coal", coal.getCoal()); // 煤种名称
            item.put("saleQuantity", salesByCoalId.getOrDefault(coal.getId(), BigDecimal.valueOf(0))); // 销量
            resultMouth.add(item);
        }
        result.put("revenueAmount", revenueAmount.setScale(2, RoundingMode.HALF_UP));
        result.put("changeRate", changeRate);
        result.put("trend", trend);
@@ -501,6 +526,7 @@
        result.put("trendQuantity", trendQuantity);
        result.put("revenueDistribution", revenueDistribution);
        result.put("salesResults", results);
        result.put("resultMouth", resultMouth);
        return result;
    }