| | |
| | | void overviewReadsRowsAndAggregatesThemInJava() { |
| | | EmindStorageDashboardMapper mapper = mock(EmindStorageDashboardMapper.class); |
| | | LocalDate yesterday = LocalDate.now().minusDays(1); |
| | | when(mapper.selectSnapshotRows(isNull())).thenReturn(Arrays.asList( |
| | | when(mapper.selectSnapshotRows(isNull(), isNull())).thenReturn(Arrays.asList( |
| | | row("incomeSum", "10", "capacity", "100", "surplusEnergy", "40", "elinkTotal", 2, "elinkOnline", 1), |
| | | row("incomeSum", "20", "capacity", "100", "surplusEnergy", "60", "elinkTotal", 3, "elinkOnline", 2))); |
| | | when(mapper.selectDailyRows(isNull(), any(), any())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), eq(yesterday), eq(yesterday))).thenReturn(Arrays.asList( |
| | | when(mapper.selectDailyRows(isNull(), isNull(), any(), any())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), isNull(), eq(yesterday), eq(yesterday))).thenReturn(Arrays.asList( |
| | | row("statDate", yesterday, "income", "12.5", "chargedEnergy", "5", "dischargedEnergy", "3"), |
| | | row("statDate", yesterday, "income", "7.5", "chargedEnergy", "2", "dischargedEnergy", "1"))); |
| | | when(mapper.selectCurveRows(isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectEnergyBlockRows(isNull())).thenReturn(Arrays.asList( |
| | | when(mapper.selectCurveRows(isNull(), isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectEnergyBlockRows(isNull(), isNull())).thenReturn(Arrays.asList( |
| | | row("runStatus", 1, "recordTime", "10:00"), row("runStatus", 5, "recordTime", "10:00"))); |
| | | |
| | | Map<String, Object> summary = (Map<String, Object>) new EmindStorageDashboardService(mapper) |
| | | .overview(new EmindDashboardQuery()).get("summary"); |
| | | |
| | | assertEquals(new BigDecimal("30"), summary.get("incomeSum")); |
| | | assertEquals(new BigDecimal("50"), summary.get("soc")); |
| | | assertEquals(0, new BigDecimal("50").compareTo((BigDecimal) summary.get("soc"))); |
| | | assertEquals(2, summary.get("eblockTotal")); |
| | | assertEquals(1L, summary.get("eblockOnline")); |
| | | assertEquals(new BigDecimal("20.0"), summary.get("incomeYesterday")); |
| | | assertEquals(new BigDecimal("7"), summary.get("chargedEnergyYesterday")); |
| | | verify(mapper).selectDailyRows(isNull(), eq(yesterday), eq(yesterday)); |
| | | verify(mapper).selectDailyRows(isNull(), isNull(), eq(yesterday), eq(yesterday)); |
| | | } |
| | | |
| | | @Test |
| | |
| | | EmindStorageDashboardMapper mapper = mock(EmindStorageDashboardMapper.class); |
| | | LocalDate start = LocalDate.of(2026, 7, 1); |
| | | LocalDate end = LocalDate.of(2026, 8, 31); |
| | | when(mapper.selectSnapshotRows(isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), any(), any())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), eq(start), eq(end))).thenReturn(Arrays.asList( |
| | | when(mapper.selectSnapshotRows(isNull(), isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), isNull(), any(), any())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectDailyRows(isNull(), isNull(), eq(start), eq(end))).thenReturn(Arrays.asList( |
| | | row("statDate", LocalDate.of(2026, 7, 1), "income", "2"), |
| | | row("statDate", LocalDate.of(2026, 7, 2), "income", "3"))); |
| | | when(mapper.selectCurveRows(isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectEnergyBlockRows(isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectCurveRows(isNull(), isNull())).thenReturn(Collections.emptyList()); |
| | | when(mapper.selectEnergyBlockRows(isNull(), isNull())).thenReturn(Collections.emptyList()); |
| | | EmindDashboardQuery query = new EmindDashboardQuery(); |
| | | query.setPeriod("YEAR"); query.setStartDate(start); query.setEndDate(end); |
| | | |