| | |
| | | Map<String, Object> series = new LinkedHashMap<>(); series.put("name", name); series.put("data", data); chart.put("series", new ArrayList<>(Collections.singletonList(series))); return chart; |
| | | } |
| | | private Map<String, Object> franchiseeOrderTrend(List<FranchiseeDayStat> stats, LocalDateTime[] range) { |
| | | if (franchiseeUseMonthlyTrend(range)) { |
| | | return franchiseeMonthlyOrderTrend(stats, range); |
| | | } |
| | | Map<String, Object> chart = franchiseeDailyTrend(stats, range, "充电金额", FranchiseeDayStat::getOrderAmountEffective); |
| | | ((List<Map<String, Object>>) chart.get("series")).get(0).put("type", "column"); |
| | | Map<LocalDate, FranchiseeDayStat> byDay = dayStatByDay(stats); |
| | |
| | | for (int i = 0; i < categories.size(); i++) { LocalDate day = start.plusDays(i); FranchiseeDayStat stat = byDay.get(day); countData.add(BigDecimal.valueOf(stat == null ? 0L : numberValue(stat.getOrderCount()))); } |
| | | Map<String, Object> countSeries = new LinkedHashMap<>(); countSeries.put("name", "充电订单"); countSeries.put("data", countData); countSeries.put("type", "line"); countSeries.put("style", "curve"); countSeries.put("index", 1); ((List<Map<String, Object>>) chart.get("series")).add(countSeries); return chart; |
| | | } |
| | | |
| | | /** Long date ranges use monthly buckets so the mobile chart stays readable. */ |
| | | private boolean franchiseeUseMonthlyTrend(LocalDateTime[] range) { |
| | | if (range == null || range.length < 2 || range[0] == null || range[1] == null) { |
| | | return false; |
| | | } |
| | | return range[0].toLocalDate().plusDays(90).isBefore(range[1].toLocalDate()); |
| | | } |
| | | |
| | | private Map<String, Object> franchiseeMonthlyOrderTrend(List<FranchiseeDayStat> stats, LocalDateTime[] range) { |
| | | Map<YearMonth, List<FranchiseeDayStat>> statsByMonth = stats.stream() |
| | | .filter(stat -> stat != null && stat.getStatDay() != null) |
| | | .collect(Collectors.groupingBy(stat -> YearMonth.from(stat.getStatDay()))); |
| | | LocalDate start = range[0].toLocalDate(); |
| | | LocalDate end = range[1].toLocalDate(); |
| | | YearMonth firstMonth = YearMonth.from(start); |
| | | YearMonth lastMonth = YearMonth.from(end.minusDays(1)); |
| | | List<String> categories = new ArrayList<>(); |
| | | List<BigDecimal> amountData = new ArrayList<>(); |
| | | List<BigDecimal> countData = new ArrayList<>(); |
| | | for (YearMonth month = firstMonth; !month.isAfter(lastMonth); month = month.plusMonths(1)) { |
| | | List<FranchiseeDayStat> monthStats = statsByMonth.getOrDefault(month, Collections.emptyList()); |
| | | categories.add(month.toString()); |
| | | amountData.add(sum(monthStats, FranchiseeDayStat::getOrderAmountEffective)); |
| | | countData.add(BigDecimal.valueOf(monthStats.stream().mapToLong(stat -> numberValue(stat.getOrderCount())).sum())); |
| | | } |
| | | Map<String, Object> amountSeries = new LinkedHashMap<>(); amountSeries.put("name", "充电金额"); amountSeries.put("data", amountData); amountSeries.put("type", "column"); |
| | | Map<String, Object> countSeries = new LinkedHashMap<>(); countSeries.put("name", "充电订单"); countSeries.put("data", countData); countSeries.put("type", "line"); countSeries.put("style", "curve"); countSeries.put("index", 1); |
| | | Map<String, Object> chart = new LinkedHashMap<>(); chart.put("categories", categories); chart.put("series", new ArrayList<>(Arrays.asList(amountSeries, countSeries))); return chart; |
| | | } |
| | | private Map<String, Object> franchiseePhaseRing(List<Integer> siteIds, LocalDateTime[] range) { |
| | | Map<Integer, BigDecimal> phase = new LinkedHashMap<>(); phase.put(1, BigDecimal.ZERO); phase.put(2, BigDecimal.ZERO); phase.put(3, BigDecimal.ZERO); phase.put(4, BigDecimal.ZERO); |
| | | if (siteIds != null && !siteIds.isEmpty() && range != null && range[0] != null && range[1] != null) { |