| | |
| | | package com.ruoyi.order.support; |
| | | |
| | | import com.ruoyi.chargingPile.api.model.TPartnerAppUser; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | private static final LocalDateTime END = LocalDateTime.of(2026, 7, 4, 0, 0); |
| | | |
| | | @Test |
| | | void countsDistinctChargingUsersAndBucketsBindingsOnTheirExactDate() { |
| | | void countsDistinctChargingUsersAndSumsPlatformNewUsersByRegistrationDay() { |
| | | List<TChargingOrder> orders = Arrays.asList( |
| | | order(1L, LocalDateTime.of(2026, 7, 1, 8, 0)), |
| | | order(1L, LocalDateTime.of(2026, 7, 1, 18, 0)), |
| | | order(1L, LocalDateTime.of(2026, 7, 2, 8, 0)), |
| | | order(2L, LocalDateTime.of(2026, 7, 2, 9, 0)) |
| | | ); |
| | | List<TPartnerAppUser> relations = Arrays.asList( |
| | | relation(1L, LocalDateTime.of(2026, 6, 30, 23, 59)), |
| | | relation(2L, LocalDateTime.of(2026, 7, 2, 10, 0)), |
| | | relation(3L, LocalDateTime.of(2026, 7, 2, 11, 0)), |
| | | relation(3L, LocalDateTime.of(2026, 7, 2, 12, 0)) |
| | | ); |
| | | Map<LocalDate, Long> newUsersByDay = new LinkedHashMap<>(); |
| | | newUsersByDay.put(LocalDate.of(2026, 7, 1), 3L); |
| | | newUsersByDay.put(LocalDate.of(2026, 7, 2), 2L); |
| | | |
| | | FranchiseeUserStatistics.Result result = FranchiseeUserStatistics.calculate(orders, relations, START, END); |
| | | FranchiseeUserStatistics.Result result = FranchiseeUserStatistics.calculate(orders, newUsersByDay, START, END); |
| | | |
| | | assertEquals(2L, result.getSummary().get("chargeUserCount")); |
| | | assertEquals(2L, result.getSummary().get("newUserCount")); |
| | | assertEquals(5L, result.getSummary().get("newUserCount")); |
| | | assertEquals(Arrays.asList("07-01", "07-02", "07-03"), result.getTrend().get("categories")); |
| | | assertEquals(Arrays.asList(1L, 2L, 0L), seriesData(result.getTrend(), 0)); |
| | | assertEquals(Arrays.asList(0L, 2L, 0L), seriesData(result.getTrend(), 1)); |
| | | assertEquals(Arrays.asList(3L, 2L, 0L), seriesData(result.getTrend(), 1)); |
| | | } |
| | | |
| | | @Test |
| | | void ignoresPlatformRegistrationsOutsideTheRange() { |
| | | Map<LocalDate, Long> newUsersByDay = new LinkedHashMap<>(); |
| | | newUsersByDay.put(LocalDate.of(2026, 6, 30), 99L); // 区间外,不计入 |
| | | newUsersByDay.put(LocalDate.of(2026, 7, 1), 1L); |
| | | |
| | | FranchiseeUserStatistics.Result result = FranchiseeUserStatistics.calculateByUserDays( |
| | | Collections.emptyMap(), newUsersByDay, START, END); |
| | | |
| | | assertEquals(1L, result.getSummary().get("newUserCount")); |
| | | assertEquals(Arrays.asList(1L, 0L, 0L), seriesData(result.getTrend(), 1)); |
| | | } |
| | | |
| | | @Test |
| | | void returnsZeroFilledSeriesWhenThereIsNoActivity() { |
| | | FranchiseeUserStatistics.Result result = FranchiseeUserStatistics.calculate( |
| | | Collections.emptyList(), Collections.emptyList(), START, END); |
| | | Collections.emptyList(), Collections.emptyMap(), START, END); |
| | | |
| | | assertEquals(0L, result.getSummary().get("chargeUserCount")); |
| | | assertEquals(0L, result.getSummary().get("newUserCount")); |
| | |
| | | order.setAppUserId(appUserId); |
| | | order.setEndTime(endTime); |
| | | return order; |
| | | } |
| | | |
| | | private TPartnerAppUser relation(Long appUserId, LocalDateTime createTime) { |
| | | TPartnerAppUser relation = new TPartnerAppUser(); |
| | | relation.setAppUserId(appUserId); |
| | | relation.setCreateTime(createTime); |
| | | return relation; |
| | | } |
| | | } |