| | |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, siteId); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | //通过siteIds进行sql查询统计 |
| | | List<SixChargingDto> sixChargingDtos = generateLastSixMonths(); |
| | | List<SixChargingDto> chargingDtos = chargingOrderService.charge(sixBefore, siteIds, partnerView); |
| | | LocalDate statisticsEndMonth = resolveStatisticsEndMonth(LocalDate.now(), chargingDtos); |
| | | List<SixChargingDto> sixChargingDtos = generateLastSixMonths(statisticsEndMonth); |
| | | for (SixChargingDto sixChargingDto : sixChargingDtos) { |
| | | for (SixChargingDto chargingDto : chargingDtos) { |
| | | if (sixChargingDto.getMonth().equals(chargingDto.getMonth())){ |
| | |
| | | |
| | | |
| | | public static List<SixChargingDto> generateLastSixMonths() { |
| | | LocalDate today = LocalDate.now(); |
| | | return generateLastSixMonths(LocalDate.now()); |
| | | } |
| | | |
| | | static List<SixChargingDto> generateLastSixMonths(LocalDate endMonth) { |
| | | List<SixChargingDto> months = new ArrayList<>(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM"); |
| | | |
| | | for (int i = 5; i >= 0; i--) { |
| | | LocalDate date = today.minusMonths(i); |
| | | LocalDate date = endMonth.minusMonths(i); |
| | | String month = date.format(formatter); |
| | | SixChargingDto sixChargingDto = new SixChargingDto(); |
| | | sixChargingDto.setMonth(month); |
| | |
| | | |
| | | return months; |
| | | } |
| | | |
| | | static LocalDate resolveStatisticsEndMonth(LocalDate currentDate, List<SixChargingDto> statistics) { |
| | | if (statistics == null || statistics.isEmpty()) { |
| | | return currentDate; |
| | | } |
| | | int nextMonth = currentDate.plusMonths(1).getMonthValue(); |
| | | boolean hasNextMonthData = statistics.stream() |
| | | .map(SixChargingDto::getMonth) |
| | | .filter(Objects::nonNull) |
| | | .anyMatch(month -> { |
| | | try { |
| | | return Integer.parseInt(month) == nextMonth; |
| | | } catch (NumberFormatException ignored) { |
| | | return false; |
| | | } |
| | | }); |
| | | return hasNextMonthData ? currentDate.plusMonths(1) : currentDate; |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/platformRevenueAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |