|
@@ -430,7 +430,7 @@ public class AppOrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public File exportCondition(ExportConditionDTO exportConditionDTO) throws IOException {
|
|
|
+ public byte[] exportCondition(ExportConditionDTO exportConditionDTO) throws IOException {
|
|
|
List<ExportConditionOutVO> exportConditionOutVO = appGameMapper.exportCondition(exportConditionDTO);
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
int index = 1;
|
|
@@ -475,114 +475,126 @@ public class AppOrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> i
|
|
|
index++;
|
|
|
}
|
|
|
|
|
|
- // 生成 Excel 文件
|
|
|
+ // 生成 Excel 文件并返回字节数组
|
|
|
return generateExcel(list);
|
|
|
}
|
|
|
|
|
|
- // 优化后的 generateExcel 方法
|
|
|
- private File generateExcel(List<Map<String, Object>> dataList) throws IOException {
|
|
|
- // 创建工作簿和工作表
|
|
|
- Workbook workbook = new XSSFWorkbook();
|
|
|
- Sheet sheet = workbook.createSheet("报名信息");
|
|
|
-
|
|
|
- // 设置列宽
|
|
|
- sheet.setColumnWidth(0, 3000); // 序号
|
|
|
- sheet.setColumnWidth(1, 8000); // 赛事名称
|
|
|
- sheet.setColumnWidth(2, 6000); // 个人/团队赛
|
|
|
- sheet.setColumnWidth(3, 6000); // 报名项目
|
|
|
- sheet.setColumnWidth(4, 6000); // 队名
|
|
|
- sheet.setColumnWidth(5, 6000); // 队徽
|
|
|
- sheet.setColumnWidth(6, 10000); // 社保证明
|
|
|
- sheet.setColumnWidth(7, 4000); // 报名人员
|
|
|
- sheet.setColumnWidth(8, 4000); // 联系电话
|
|
|
-
|
|
|
- // 创建标题样式
|
|
|
- CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
-
|
|
|
- // 创建内容样式
|
|
|
- CellStyle contentStyle = createContentStyle(workbook);
|
|
|
-
|
|
|
- // 写入表头
|
|
|
- Row headerRow = sheet.createRow(0);
|
|
|
- String[] headers = {"序号", "赛事名称", "个人/团队赛", "报名项目", "队名", "队徽", "社保证明", "报名人员", "联系电话"};
|
|
|
- for (int i = 0; i < headers.length; i++) {
|
|
|
- Cell cell = headerRow.createCell(i);
|
|
|
- cell.setCellValue(headers[i]);
|
|
|
- cell.setCellStyle(headerStyle);
|
|
|
- }
|
|
|
+ // 修改 generateExcel 方法返回字节数组
|
|
|
+ private byte[] generateExcel(List<Map<String, Object>> dataList) throws IOException {
|
|
|
+ Workbook workbook = null;
|
|
|
|
|
|
- // 写入数据
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
- Map<String, Object> rowMap = dataList.get(i);
|
|
|
- Row dataRow = sheet.createRow(i + 1);
|
|
|
- // 设置行高,为图片留出空间
|
|
|
- dataRow.setHeightInPoints(80);
|
|
|
-
|
|
|
- // 序号
|
|
|
- Cell cell0 = dataRow.createCell(0);
|
|
|
- cell0.setCellValue((Integer) rowMap.get("序号"));
|
|
|
- cell0.setCellStyle(contentStyle);
|
|
|
-
|
|
|
- // 赛事名称
|
|
|
- Cell cell1 = dataRow.createCell(1);
|
|
|
- cell1.setCellValue((String) rowMap.get("赛事名称"));
|
|
|
- cell1.setCellStyle(contentStyle);
|
|
|
-
|
|
|
- // 个人/团队赛
|
|
|
- Cell cell2 = dataRow.createCell(2);
|
|
|
- cell2.setCellValue((int) rowMap.get("个人/团队赛") == 3 ? "个人" : "团队");
|
|
|
- cell2.setCellStyle(contentStyle);
|
|
|
-
|
|
|
- // 报名项目
|
|
|
- Cell cell3 = dataRow.createCell(3);
|
|
|
- cell3.setCellValue((String) rowMap.get("报名项目"));
|
|
|
- cell3.setCellStyle(contentStyle);
|
|
|
-
|
|
|
- // 队名
|
|
|
- Cell cell4 = dataRow.createCell(4);
|
|
|
- cell4.setCellValue((String) rowMap.get("队名"));
|
|
|
- cell4.setCellStyle(contentStyle);
|
|
|
-
|
|
|
- // 队徽:插入图片(嵌入单元格)
|
|
|
- String teamEmblemImg = (String) rowMap.get("队徽");
|
|
|
- Cell cell5 = dataRow.createCell(5);
|
|
|
- cell5.setCellStyle(contentStyle);
|
|
|
- if (teamEmblemImg != null && !teamEmblemImg.isEmpty()) {
|
|
|
- insertImageToCell(workbook, sheet, teamEmblemImg, 5, i + 1);
|
|
|
+ try {
|
|
|
+ // 创建工作簿和工作表
|
|
|
+ workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("报名信息");
|
|
|
+
|
|
|
+ // 设置列宽
|
|
|
+ sheet.setColumnWidth(0, 3000); // 序号
|
|
|
+ sheet.setColumnWidth(1, 8000); // 赛事名称
|
|
|
+ sheet.setColumnWidth(2, 6000); // 个人/团队赛
|
|
|
+ sheet.setColumnWidth(3, 6000); // 报名项目
|
|
|
+ sheet.setColumnWidth(4, 6000); // 队名
|
|
|
+ sheet.setColumnWidth(5, 6000); // 队徽
|
|
|
+ sheet.setColumnWidth(6, 10000); // 社保证明
|
|
|
+ sheet.setColumnWidth(7, 4000); // 报名人员
|
|
|
+ sheet.setColumnWidth(8, 4000); // 联系电话
|
|
|
+
|
|
|
+ // 创建标题样式
|
|
|
+ CellStyle headerStyle = createHeaderStyle(workbook);
|
|
|
+
|
|
|
+ // 创建内容样式
|
|
|
+ CellStyle contentStyle = createContentStyle(workbook);
|
|
|
+
|
|
|
+ // 写入表头
|
|
|
+ Row headerRow = sheet.createRow(0);
|
|
|
+ String[] headers = {"序号", "赛事名称", "个人/团队赛", "报名项目", "队名", "队徽", "社保证明", "报名人员", "联系电话"};
|
|
|
+ for (int i = 0; i < headers.length; i++) {
|
|
|
+ Cell cell = headerRow.createCell(i);
|
|
|
+ cell.setCellValue(headers[i]);
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
}
|
|
|
|
|
|
- // 社保证明:多个图片,放在同一单元格内,按行排列
|
|
|
- String certificationStr = (String) rowMap.get("社保证明");
|
|
|
- Cell cell6 = dataRow.createCell(6);
|
|
|
- cell6.setCellStyle(contentStyle);
|
|
|
+ // 写入数据
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
+ Map<String, Object> rowMap = dataList.get(i);
|
|
|
+ Row dataRow = sheet.createRow(i + 1);
|
|
|
+ // 设置行高,为图片留出空间
|
|
|
+ dataRow.setHeightInPoints(80);
|
|
|
+
|
|
|
+ // 序号
|
|
|
+ Cell cell0 = dataRow.createCell(0);
|
|
|
+ cell0.setCellValue((Integer) rowMap.get("序号"));
|
|
|
+ cell0.setCellStyle(contentStyle);
|
|
|
+
|
|
|
+ // 赛事名称
|
|
|
+ Cell cell1 = dataRow.createCell(1);
|
|
|
+ cell1.setCellValue((String) rowMap.get("赛事名称"));
|
|
|
+ cell1.setCellStyle(contentStyle);
|
|
|
+
|
|
|
+ // 个人/团队赛
|
|
|
+ Cell cell2 = dataRow.createCell(2);
|
|
|
+ cell2.setCellValue((int) rowMap.get("个人/团队赛") == 3 ? "个人" : "团队");
|
|
|
+ cell2.setCellStyle(contentStyle);
|
|
|
+
|
|
|
+ // 报名项目
|
|
|
+ Cell cell3 = dataRow.createCell(3);
|
|
|
+ cell3.setCellValue((String) rowMap.get("报名项目"));
|
|
|
+ cell3.setCellStyle(contentStyle);
|
|
|
+
|
|
|
+ // 队名
|
|
|
+ Cell cell4 = dataRow.createCell(4);
|
|
|
+ cell4.setCellValue((String) rowMap.get("队名"));
|
|
|
+ cell4.setCellStyle(contentStyle);
|
|
|
+
|
|
|
+ // 队徽:插入图片(嵌入单元格)
|
|
|
+ String teamEmblemImg = (String) rowMap.get("队徽");
|
|
|
+ Cell cell5 = dataRow.createCell(5);
|
|
|
+ cell5.setCellStyle(contentStyle);
|
|
|
+ if (teamEmblemImg != null && !teamEmblemImg.isEmpty()) {
|
|
|
+ insertImageToCell(workbook, sheet, teamEmblemImg, 5, i + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 社保证明:多个图片,放在同一单元格内,按行排列
|
|
|
+ String certificationStr = (String) rowMap.get("社保证明");
|
|
|
+ Cell cell6 = dataRow.createCell(6);
|
|
|
+ cell6.setCellStyle(contentStyle);
|
|
|
|
|
|
- if (certificationStr != null && !certificationStr.isEmpty()) {
|
|
|
- List<String> allImageUrls = extractImageUrls(certificationStr);
|
|
|
- if (!allImageUrls.isEmpty()) {
|
|
|
- insertMultipleImagesToCell(workbook, sheet, allImageUrls, 6, i + 1);
|
|
|
+ if (certificationStr != null && !certificationStr.isEmpty()) {
|
|
|
+ List<String> allImageUrls = extractImageUrls(certificationStr);
|
|
|
+ if (!allImageUrls.isEmpty()) {
|
|
|
+ insertMultipleImagesToCell(workbook, sheet, allImageUrls, 6, i + 1);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 报名人员
|
|
|
- Cell cell7 = dataRow.createCell(7);
|
|
|
- cell7.setCellValue((String) rowMap.get("报名人员"));
|
|
|
- cell7.setCellStyle(contentStyle);
|
|
|
+ // 报名人员
|
|
|
+ Cell cell7 = dataRow.createCell(7);
|
|
|
+ cell7.setCellValue((String) rowMap.get("报名人员"));
|
|
|
+ cell7.setCellStyle(contentStyle);
|
|
|
|
|
|
- // 联系电话
|
|
|
- Cell cell8 = dataRow.createCell(8);
|
|
|
- cell8.setCellValue((String) rowMap.get("联系电话"));
|
|
|
- cell8.setCellStyle(contentStyle);
|
|
|
- }
|
|
|
+ // 联系电话
|
|
|
+ Cell cell8 = dataRow.createCell(8);
|
|
|
+ cell8.setCellValue((String) rowMap.get("联系电话"));
|
|
|
+ cell8.setCellStyle(contentStyle);
|
|
|
+ }
|
|
|
|
|
|
- // 输出文件
|
|
|
- File file = File.createTempFile("export_condition_", ".xlsx");
|
|
|
- try (FileOutputStream fos = new FileOutputStream(file)) {
|
|
|
- workbook.write(fos);
|
|
|
+ // 将工作簿写入字节数组
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ return outputStream.toByteArray();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ // 关闭工作簿
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.err.println("关闭工作簿时出错: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- workbook.close();
|
|
|
- return file;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 创建表头样式
|
|
|
private CellStyle createHeaderStyle(Workbook workbook) {
|
|
|
CellStyle headerStyle = workbook.createCellStyle();
|