|
|
@@ -1,17 +1,22 @@
|
|
1
|
1
|
package com.ruoyi.web.modules.industryservice.support;
|
|
2
|
2
|
|
|
|
3
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
4
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
3
|
5
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
4
|
6
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
5
|
7
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
6
|
8
|
|
|
7
|
9
|
import java.io.ByteArrayInputStream;
|
|
|
10
|
+import java.util.ArrayList;
|
|
8
|
11
|
import java.util.Collections;
|
|
|
12
|
+import java.util.List;
|
|
9
|
13
|
import org.apache.poi.ss.usermodel.BorderStyle;
|
|
10
|
14
|
import org.apache.poi.ss.usermodel.Cell;
|
|
11
|
15
|
import org.apache.poi.ss.usermodel.Row;
|
|
12
|
16
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
13
|
17
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
14
|
18
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
19
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
15
|
20
|
import org.junit.jupiter.api.DisplayName;
|
|
16
|
21
|
import org.junit.jupiter.api.Test;
|
|
17
|
22
|
import com.ruoyi.web.modules.industryservice.domain.BizLivestockOwnershipHousehold;
|
|
|
@@ -83,4 +88,58 @@ class LivestockOwnershipHouseholdExcelExporterTest
|
|
83
|
88
|
}
|
|
84
|
89
|
}
|
|
85
|
90
|
}
|
|
|
91
|
+
|
|
|
92
|
+ @Test
|
|
|
93
|
+ @DisplayName("数据行不应继承模板合计行的合并单元格")
|
|
|
94
|
+ void exportDataRowsHaveNoMergedTownVillage() throws Exception
|
|
|
95
|
+ {
|
|
|
96
|
+ List<BizLivestockOwnershipHousehold> list = new ArrayList<>();
|
|
|
97
|
+ for (int i = 0; i < 4; i++)
|
|
|
98
|
+ {
|
|
|
99
|
+ BizLivestockOwnershipHousehold row = new BizLivestockOwnershipHousehold();
|
|
|
100
|
+ row.setTownName("雅安镇");
|
|
|
101
|
+ row.setVillageDeptId(200L + i);
|
|
|
102
|
+ row.setVillageName("测试村" + i);
|
|
|
103
|
+ row.setWithLivestockHouseholdCount(10 + i);
|
|
|
104
|
+ row.setWithoutLivestockHouseholdCount(1);
|
|
|
105
|
+ list.add(row);
|
|
|
106
|
+ }
|
|
|
107
|
+ byte[] bytes = exporter.export(2026, 5, list, "admin");
|
|
|
108
|
+ try (Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bytes)))
|
|
|
109
|
+ {
|
|
|
110
|
+ Sheet sheet = LivestockOwnershipHouseholdExcelParser.resolveSheet(wb);
|
|
|
111
|
+ int header = LivestockOwnershipHouseholdExcelParser.detectHeaderRow(sheet);
|
|
|
112
|
+ int dataStart = header + 2;
|
|
|
113
|
+ int totalIdx = dataStart + list.size();
|
|
|
114
|
+ for (int r = dataStart; r < totalIdx; r++)
|
|
|
115
|
+ {
|
|
|
116
|
+ Row row = sheet.getRow(r);
|
|
|
117
|
+ assertNotNull(row);
|
|
|
118
|
+ assertEquals("雅安镇",
|
|
|
119
|
+ LivestockOwnershipHouseholdExcelParser.cellString(row, LivestockOwnershipHouseholdExcelParser.COL_TOWN));
|
|
|
120
|
+ assertTrue(LivestockOwnershipHouseholdExcelParser
|
|
|
121
|
+ .cellString(row, LivestockOwnershipHouseholdExcelParser.COL_VILLAGE).startsWith("测试村"));
|
|
|
122
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++)
|
|
|
123
|
+ {
|
|
|
124
|
+ CellRangeAddress region = sheet.getMergedRegion(i);
|
|
|
125
|
+ assertFalse(region.getFirstRow() <= r && region.getLastRow() >= r
|
|
|
126
|
+ && region.getFirstColumn() <= LivestockOwnershipHouseholdExcelParser.COL_TOWN
|
|
|
127
|
+ && region.getLastColumn() >= LivestockOwnershipHouseholdExcelParser.COL_TOWN,
|
|
|
128
|
+ "数据行 " + r + " 不应合并乡镇/村列");
|
|
|
129
|
+ }
|
|
|
130
|
+ }
|
|
|
131
|
+ boolean totalMerged = false;
|
|
|
132
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++)
|
|
|
133
|
+ {
|
|
|
134
|
+ CellRangeAddress region = sheet.getMergedRegion(i);
|
|
|
135
|
+ if (region.getFirstRow() == totalIdx && region.getLastRow() == totalIdx
|
|
|
136
|
+ && region.getFirstColumn() == 0
|
|
|
137
|
+ && region.getLastColumn() == LivestockOwnershipHouseholdExcelParser.COL_VILLAGE)
|
|
|
138
|
+ {
|
|
|
139
|
+ totalMerged = true;
|
|
|
140
|
+ }
|
|
|
141
|
+ }
|
|
|
142
|
+ assertTrue(totalMerged, "仅合计行应合并序号~村三列");
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
86
|
145
|
}
|