|
|
@@ -19,15 +19,13 @@ import java.util.*;
|
|
19
|
19
|
public class ExcelExporter {
|
|
20
|
20
|
|
|
21
|
21
|
|
|
22
|
|
- public static void exportToExcel(List<GrainSituationCardVO> data, List<GrainSituationCardWarehouseRecord> records, List<BusinessQcQualityInspection> bq, Map<Integer, List<String>> jsonData, String fileName) throws IOException{
|
|
|
22
|
+ public static void exportToExcel(List<GrainSituationCardVO> data, List<GrainSituationCardWarehouseRecord> records, List<Map<String, String>> dataList, Map<Integer, List<String>> inspectionItems, String fileName) throws IOException{
|
|
23
|
23
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
24
|
24
|
XSSFSheet sheet = workbook.createSheet("原粮专卡");
|
|
25
|
25
|
|
|
26
|
26
|
// 设置列标题和样式
|
|
27
|
27
|
int rowIndex;
|
|
28
|
|
- rowIndex= 1;
|
|
29
|
|
- // 设置主标题并居中
|
|
30
|
|
- Row titleRow = sheet.createRow(rowIndex++);
|
|
|
28
|
+ rowIndex= 0;
|
|
31
|
29
|
|
|
32
|
30
|
Row headerRow = sheet.createRow(0);
|
|
33
|
31
|
CellStyle headerCellStyle = workbook.createCellStyle();
|
|
|
@@ -100,20 +98,27 @@ public class ExcelExporter {
|
|
100
|
98
|
cell.setCellValue(card.getKeepingWayName() != null ? card.getKeepingWayName() : "无");
|
|
101
|
99
|
} else if ("通风方式".equals(field)) {
|
|
102
|
100
|
cell.setCellValue(card.getDrafttypeName() != null ? card.getDrafttypeName() : "无");
|
|
|
101
|
+ } else if ("存储地点".equals(field)) {
|
|
|
102
|
+ cell.setCellValue(card.getOrgName() != null ? card.getOrgName() : "无");
|
|
|
103
|
+ }else if ("存储方式".equals(field)) {
|
|
|
104
|
+ cell.setCellValue(card.getKeepingWay() == null ? 0 : card.getKeepingWay());
|
|
|
105
|
+ }else if ("修改时间".equals(field)) {
|
|
|
106
|
+ cell.setCellValue(card.getUpdatedate() == null ? "" : sdf.format(card.getUpdatedate()));
|
|
103
|
107
|
}
|
|
104
|
108
|
}
|
|
105
|
109
|
}
|
|
106
|
110
|
|
|
107
|
|
- rowIndex++; // 新增一行用于标题
|
|
108
|
111
|
|
|
109
|
112
|
// 处理 GrainSituationCardWarehouseRecord 数据之前的表头
|
|
110
|
113
|
rowIndex++; // 新增一行作为记录变更的表头行
|
|
111
|
114
|
columnIndex = 0; // 重置列索引
|
|
|
115
|
+ Row headerForRowRecords = sheet.createRow(rowIndex);
|
|
112
|
116
|
for (String field : getFieldsss()) {
|
|
113
|
|
- Cell cell = sheet.createRow(rowIndex).createCell(columnIndex++);
|
|
|
117
|
+ Cell cell = headerForRowRecords.createCell(columnIndex++);
|
|
114
|
118
|
cell.setCellValue(field);
|
|
115
|
119
|
cell.setCellStyle(headerCellStyle);
|
|
116
|
120
|
}
|
|
|
121
|
+ // 填充 GrainSituationCardWarehouseRecord 数据
|
|
117
|
122
|
for (GrainSituationCardWarehouseRecord record : records) {
|
|
118
|
123
|
if (record == null) {
|
|
119
|
124
|
continue;
|
|
|
@@ -121,9 +126,10 @@ public class ExcelExporter {
|
|
121
|
126
|
|
|
122
|
127
|
rowIndex++; // 新增一行用于记录数据
|
|
123
|
128
|
columnIndex = 0;
|
|
124
|
|
- Row row = sheet.createRow(rowIndex++);
|
|
125
|
|
- for (String field : getFieldsss()) { // 假定使用getFieldsss()作为仓库记录的字段列表
|
|
126
|
|
- Cell cell = row.createCell(columnIndex++);
|
|
|
129
|
+ Row rowForRecord = sheet.createRow(rowIndex);
|
|
|
130
|
+ for (String field : getFieldsss()) {
|
|
|
131
|
+ Cell cell = rowForRecord.createCell(columnIndex++);
|
|
|
132
|
+
|
|
127
|
133
|
if ("变更时间".equals(field)) {
|
|
128
|
134
|
cell.setCellValue(record.getChangeTime() == null ? "" : sdf.format(record.getChangeTime()));
|
|
129
|
135
|
} else if ("新货位号".equals(field)) {
|
|
|
@@ -133,50 +139,89 @@ public class ExcelExporter {
|
|
133
|
139
|
} else if ("变更原因".equals(field)) {
|
|
134
|
140
|
cell.setCellValue(record.getChangeReason() != null ? record.getChangeReason() : "无");
|
|
135
|
141
|
}
|
|
136
|
|
- // 根据需要继续添加其它字段的处理逻辑
|
|
|
142
|
+ // 根据GrainSituationCardWarehouseRecord类的实际属性添加更多处理逻辑
|
|
137
|
143
|
}
|
|
138
|
144
|
}
|
|
139
|
145
|
|
|
|
146
|
+ rowIndex++; // 新增一行作为记录变更的表头行
|
|
|
147
|
+ columnIndex = 0; // 重置列索引
|
|
|
148
|
+ // 确定所有可能的检验项目
|
|
|
149
|
+ Set<String> allInspectionCategories = new HashSet<>();
|
|
|
150
|
+ for (List<String> values : inspectionItems.values()) {
|
|
|
151
|
+ for (String item : values) {
|
|
|
152
|
+ String category = item.split(":")[0].trim(); // 假设项目名称在冒号前
|
|
|
153
|
+ allInspectionCategories.add(category);
|
|
|
154
|
+ }
|
|
|
155
|
+ }
|
|
|
156
|
+ rowIndex++;
|
|
|
157
|
+ // 创建表头
|
|
|
158
|
+ Row headerRow1 = sheet.createRow(0);
|
|
|
159
|
+ headerRow1.createCell(0).setCellValue("质检报告单号");
|
|
|
160
|
+ headerRow1.createCell(1).setCellValue("检验类别");
|
|
|
161
|
+ int colIndex = 2; // 从第三列开始放置动态检验项目
|
|
|
162
|
+ for (String category : allInspectionCategories) {
|
|
|
163
|
+ headerRow1.createCell(colIndex++).setCellValue(category);
|
|
|
164
|
+ }
|
|
|
165
|
+ // 检查inspectionItems是否只有一个键,如果是,则获取该键
|
|
|
166
|
+ Integer singleKeyId = inspectionItems.keySet().iterator().next();
|
|
140
|
167
|
|
|
|
168
|
+ rowIndex ++; // 从第二行开始写入数据
|
|
|
169
|
+ for (Map<String, String> data2 : dataList) {
|
|
|
170
|
+ Row dataRow = sheet.createRow(rowIndex++);
|
|
|
171
|
+ dataRow.createCell(0).setCellValue(data2.getOrDefault("zjbgdh", ""));
|
|
|
172
|
+ dataRow.createCell(1).setCellValue(data2.getOrDefault("jylb", ""));
|
|
141
|
173
|
|
|
142
|
|
- rowIndex++; // 新增一行作为质量检验的表头行
|
|
143
|
|
- headerRow.createCell(0).setCellValue("质检报告单号");
|
|
144
|
|
- headerRow.createCell(1).setCellValue("检验时间");
|
|
145
|
|
- columnIndex = 0; // 重置列索引
|
|
146
|
|
- for (String field : getFieldss()) {
|
|
147
|
|
- Cell cell = sheet.createRow(rowIndex).createCell(columnIndex++);
|
|
148
|
|
- cell.setCellValue(field);
|
|
149
|
|
- cell.setCellStyle(headerCellStyle);
|
|
|
174
|
+
|
|
|
175
|
+ // 填充动态检验项目值,这里直接根据单个键获取其值列表
|
|
|
176
|
+ List<String> items = inspectionItems.get(singleKeyId);
|
|
|
177
|
+
|
|
|
178
|
+ // 填充动态检验项目值
|
|
|
179
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
180
|
+ String[] keyValue = items.get(i).split(": ");
|
|
|
181
|
+ dataRow.createCell(i + 2).setCellValue(keyValue.length > 1 ? keyValue[1] : "");
|
|
|
182
|
+ }
|
|
150
|
183
|
}
|
|
151
|
|
-// // 填充数据
|
|
152
|
|
- int rowNum = 1;
|
|
153
|
|
-// for (Map<String, Object> record : jsonData) {
|
|
154
|
|
-// Row row = sheet.createRow(rowNum++);
|
|
155
|
|
-// row.createCell(0).setCellValue((String) record.get("zjbgdh"));
|
|
156
|
|
-// row.createCell(1).setCellValue((String) record.get("jysj"));
|
|
157
|
|
-//
|
|
158
|
|
-// // 填充动态检验项目值
|
|
159
|
|
-// Map<String, Object> maps = (Map<String, Object>) record.get("maps");
|
|
160
|
|
-// if (maps != null) {
|
|
161
|
|
-// List<String> items = (List<String>) maps.get(record.get("id").toString());
|
|
162
|
|
-// if (items != null) {
|
|
163
|
|
-// int col = 2; // 从第2列开始填充动态数据
|
|
164
|
|
-// for (String item : allInspectionItems) {
|
|
165
|
|
-// String value = "";
|
|
166
|
|
-// for (String checkItem : items) {
|
|
167
|
|
-// if (checkItem.startsWith(item + ":")) {
|
|
168
|
|
-// value = checkItem.split(": ")[1];
|
|
169
|
|
-// break;
|
|
|
184
|
+
|
|
|
185
|
+
|
|
|
186
|
+// rowIndex++; // 新增一行作为质量检验的表头行
|
|
|
187
|
+// columnIndex = 0; // 重置列索引
|
|
|
188
|
+// Row rowForRecord = sheet.createRow(rowIndex);
|
|
|
189
|
+// for (String field : getFieldss()) {
|
|
|
190
|
+// Cell cell = sheet.createRow(rowIndex).createCell(columnIndex++);
|
|
|
191
|
+// cell.setCellValue(field);
|
|
|
192
|
+// cell.setCellStyle(headerCellStyle);
|
|
|
193
|
+// }
|
|
|
194
|
+//// // 填充数据
|
|
|
195
|
+// Row row = sheet.createRow(rowIndex++);
|
|
|
196
|
+// for (Map<String, String> data2 : dataList) {
|
|
|
197
|
+// if (data2 == null) {
|
|
|
198
|
+// continue;
|
|
|
199
|
+// }
|
|
|
200
|
+// row.createCell(0).setCellValue(data2.getOrDefault("zjbgdh", ""));
|
|
|
201
|
+// row.createCell(1).setCellValue(data2.getOrDefault("jylb", ""));
|
|
|
202
|
+// for (Map<Integer, Object> jd : jsonData) {
|
|
|
203
|
+// // 填充动态检验项目值
|
|
|
204
|
+// Map<String, Object> maps = (Map<String, Object>) jd.get("maps");
|
|
|
205
|
+// if (maps != null) {
|
|
|
206
|
+// List<String> items = (List<String>) maps.get(id.get("id").toString());
|
|
|
207
|
+// if (items != null) {
|
|
|
208
|
+// int col = 2; // 从第2列开始填充动态数据
|
|
|
209
|
+// for (String item : allInspectionItems) {
|
|
|
210
|
+// String value = "";
|
|
|
211
|
+// for (String checkItem : items) {
|
|
|
212
|
+// if (checkItem.startsWith(item + ":")) {
|
|
|
213
|
+// value = checkItem.split(": ")[1];
|
|
|
214
|
+// break;
|
|
|
215
|
+// }
|
|
170
|
216
|
// }
|
|
171
|
217
|
// }
|
|
|
218
|
+// row.createCell(col++).setCellValue(value);
|
|
172
|
219
|
// }
|
|
173
|
|
-// row.createCell(col++).setCellValue(value);
|
|
174
|
220
|
// }
|
|
175
|
221
|
// }
|
|
176
|
222
|
// }
|
|
177
|
|
-// }
|
|
178
|
223
|
//
|
|
179
|
|
-
|
|
|
224
|
+// }
|
|
180
|
225
|
|
|
181
|
226
|
|
|
182
|
227
|
|
|
|
@@ -194,7 +239,7 @@ public class ExcelExporter {
|
|
194
|
239
|
}
|
|
195
|
240
|
|
|
196
|
241
|
private static String[] getFieldsss() {
|
|
197
|
|
- return new String[]{"变更时间","新货位号"," 原货位号","变更原因"};
|
|
|
242
|
+ return new String[]{"变更时间","新货位号","原货位号","变更原因"};
|
|
198
|
243
|
}
|
|
199
|
244
|
private static String[] getFieldss() {
|
|
200
|
245
|
return new String[]{"检验类型","质检报告单号","容重","水分","杂质","不完善粒","色泽,气味","硬度指数",
|