|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+package com.ruoyi.web.modules.industryservice.support;
|
|
|
2
|
+
|
|
|
3
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
4
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
5
|
+
|
|
|
6
|
+import java.io.ByteArrayInputStream;
|
|
|
7
|
+import java.util.Collections;
|
|
|
8
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
9
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
10
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
11
|
+import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
12
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
13
|
+import org.junit.jupiter.api.Test;
|
|
|
14
|
+import com.ruoyi.web.modules.industryservice.domain.BizVaccinationData;
|
|
|
15
|
+
|
|
|
16
|
+@DisplayName("VaccinationDataExcelExporter")
|
|
|
17
|
+class VaccinationDataExcelExporterTest
|
|
|
18
|
+{
|
|
|
19
|
+ private final VaccinationDataExcelExporter exporter = new VaccinationDataExcelExporter();
|
|
|
20
|
+
|
|
|
21
|
+ @Test
|
|
|
22
|
+ @DisplayName("导出填表时间默认为系统当月,且标题统计月与填表月可不同")
|
|
|
23
|
+ void exportFillerDateDefaultsToCurrentMonth() throws Exception
|
|
|
24
|
+ {
|
|
|
25
|
+ java.time.LocalDate today = java.time.LocalDate.now();
|
|
|
26
|
+ String expectedFill = today.getYear() + "年" + today.getMonthValue() + "月";
|
|
|
27
|
+ int exportMonth = today.getMonthValue() == 1 ? 12 : today.getMonthValue() - 1;
|
|
|
28
|
+ int exportYear = today.getMonthValue() == 1 ? today.getYear() - 1 : today.getYear();
|
|
|
29
|
+
|
|
|
30
|
+ BizVaccinationData row = new BizVaccinationData();
|
|
|
31
|
+ row.setTownName("雅安镇");
|
|
|
32
|
+ row.setVillageDeptId(201L);
|
|
|
33
|
+ row.setVillageName("雅安镇荣嘎村");
|
|
|
34
|
+ row.setShouldVaccinateCount(100);
|
|
|
35
|
+ row.setActualVaccinateCount(90);
|
|
|
36
|
+
|
|
|
37
|
+ byte[] bytes = exporter.export(exportYear, exportMonth, Collections.singletonList(row), "测试用户");
|
|
|
38
|
+ try (Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bytes)))
|
|
|
39
|
+ {
|
|
|
40
|
+ Sheet sheet = VaccinationDataExcelParser.resolveSheet(wb);
|
|
|
41
|
+ Row fillerRow = sheet.getRow(1);
|
|
|
42
|
+ assertNotNull(fillerRow);
|
|
|
43
|
+ String fillerText = VaccinationDataExcelParser.cellString(fillerRow, 0);
|
|
|
44
|
+ assertNotNull(fillerText);
|
|
|
45
|
+ assertTrue(fillerText.contains("测试用户"), fillerText);
|
|
|
46
|
+ assertTrue(fillerText.contains(expectedFill), "填表时间应为当月: " + fillerText);
|
|
|
47
|
+ assertTrue(!fillerText.contains("X月"), fillerText);
|
|
|
48
|
+ String title = VaccinationDataExcelParser.cellString(sheet.getRow(0), 0);
|
|
|
49
|
+ assertTrue(title.contains(exportYear + "年"), title);
|
|
|
50
|
+ assertTrue(title.contains("(" + exportMonth + "月)"), title);
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+}
|