|
|
@@ -1,17 +1,21 @@
|
|
|
package com.zksy.WaterSupply.PipeNetworkStatistics;
|
|
|
|
|
|
import com.zksy.WaterSupply.PipeNetworkStatistics.dto.PipeNetworkStatisticsDashboardDTO;
|
|
|
+import com.zksy.WaterSupply.PipeNetworkStatistics.dto.FacilityStatisticItemDTO;
|
|
|
import com.zksy.WaterSupply.PipeNetworkStatistics.service.impl.PipeNetworkStatisticsExportServiceImpl;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
|
|
class PipeNetworkStatisticsExportServiceContractTest {
|
|
|
@Test
|
|
|
@@ -28,4 +32,55 @@ class PipeNetworkStatisticsExportServiceContractTest {
|
|
|
assertEquals(List.of("综合概览", "管网统计", "水厂统计", "泵站统计", "水源地统计", "用水户统计"), sheetNames);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void exportUsesFacilitySpecificStatusLabels() throws Exception {
|
|
|
+ PipeNetworkStatisticsDashboardDTO dashboard = new PipeNetworkStatisticsDashboardDTO();
|
|
|
+ dashboard.setFacilityOverview(Arrays.asList(
|
|
|
+ facility("source", "水源地", 3L, 2L, 1L, 0L, 0L),
|
|
|
+ facility("plant", "水厂", 3L, 2L, 1L, 0L, 0L),
|
|
|
+ facility("pumpStation", "泵站", 4L, 2L, 1L, 1L, 0L),
|
|
|
+ facility("pipe", "供水管网", 3L, 2L, 1L, 0L, 0L),
|
|
|
+ facility("user", "用水户", 4L, 2L, 1L, 1L, 0L)
|
|
|
+ ));
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ new PipeNetworkStatisticsExportServiceImpl().write(output, dashboard);
|
|
|
+
|
|
|
+ try (Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(output.toByteArray()))) {
|
|
|
+ var sheet = workbook.getSheet("综合概览");
|
|
|
+ assertOverviewRow(sheet, "水源地-正常", 2D);
|
|
|
+ assertOverviewRow(sheet, "水源地-异常", 1D);
|
|
|
+ assertOverviewRow(sheet, "水厂-停产", 1D);
|
|
|
+ assertOverviewRow(sheet, "泵站-故障停运", 1D);
|
|
|
+ assertOverviewRow(sheet, "泵站-检修中", 1D);
|
|
|
+ assertOverviewRow(sheet, "供水管网-停用", 1D);
|
|
|
+ assertOverviewRow(sheet, "用水户-欠费", 1D);
|
|
|
+ assertOverviewRow(sheet, "用水户-停用", 1D);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FacilityStatisticItemDTO facility(
|
|
|
+ String type, String name, Long total, Long normal, Long abnormal, Long warning, Long unknown
|
|
|
+ ) {
|
|
|
+ FacilityStatisticItemDTO item = new FacilityStatisticItemDTO();
|
|
|
+ item.setFacilityType(type);
|
|
|
+ item.setFacilityTypeName(name);
|
|
|
+ item.setTotalCount(total);
|
|
|
+ item.setNormalCount(normal);
|
|
|
+ item.setAbnormalCount(abnormal);
|
|
|
+ item.setWarningCount(warning);
|
|
|
+ item.setUnknownCount(unknown);
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assertOverviewRow(Sheet sheet, String label, double expectedValue) {
|
|
|
+ for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
+ var row = sheet.getRow(rowIndex);
|
|
|
+ if (row != null && label.equals(row.getCell(1).getStringCellValue())) {
|
|
|
+ assertEquals(expectedValue, row.getCell(2).getNumericCellValue());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fail("Missing export status row: " + label);
|
|
|
+ }
|
|
|
}
|