From 67d56687c0f6ca7fb1dfadc2b58dfc6502264067 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 29 Feb 2024 17:46:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84xlsx=E6=96=87=E4=BB=B6=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036464 --user=宋天阳 【缺陷管理】导出缺陷文件名称错误 https://www.tapd.cn/55049933/s/1467203 --- .../io/metersphere/bug/dto/BugExportHeaderModel.java | 2 ++ .../io/metersphere/bug/service/BugExportService.java | 8 ++++---- .../main/java/io/metersphere/bug/service/BugService.java | 9 +++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportHeaderModel.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportHeaderModel.java index 321103e55f..92aa80c0d5 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportHeaderModel.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/BugExportHeaderModel.java @@ -14,6 +14,8 @@ import java.util.Map; @NoArgsConstructor @AllArgsConstructor public class BugExportHeaderModel { + //xlsx文件前缀 + private String xlsxFileNamePrefix; /** * 导出的表头列 diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugExportService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugExportService.java index 33cd7e1b7c..e29c094584 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugExportService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugExportService.java @@ -49,11 +49,11 @@ public class BugExportService { int index = 1; while (list.size() > BATCH_PROCESS_QUANTITY) { List excelBugList = list.subList(0, BATCH_PROCESS_QUANTITY); - this.generateExcelFile(excelBugList, index, filesFolder, headerModel); + this.generateExcelFile(excelBugList, headerModel.getXlsxFileNamePrefix() + index + ".xlsx", filesFolder, headerModel); list.removeAll(excelBugList); index += 1; } - this.generateExcelFile(list, index, filesFolder, headerModel); + this.generateExcelFile(list, headerModel.getXlsxFileNamePrefix() + index + ".xlsx", filesFolder, headerModel); } catch (Exception e) { LogUtils.error(e.getMessage()); throw new MSException(e.getMessage()); @@ -61,7 +61,7 @@ public class BugExportService { return filesFolder; } - private void generateExcelFile(List list, int fileIndex, String excelPath, BugExportHeaderModel headerModel) throws Exception { + private void generateExcelFile(List list, String xlsxFileName, String excelPath, BugExportHeaderModel headerModel) throws Exception { if (CollectionUtils.isNotEmpty(list)) { // 准备数据 {评论, 内容, 关联用例数} boolean exportComment = this.exportComment(headerModel.getExportColumns()); @@ -84,7 +84,7 @@ public class BugExportService { //生成excel文件 List> data = bugExportExcelModel.getData(); - File createFile = new File(excelPath + File.separatorChar + "bug_" + fileIndex + ".xlsx"); + File createFile = new File(excelPath + File.separatorChar + xlsxFileName); createFile.createNewFile(); EasyExcel.write(createFile).excelType(ExcelTypeEnum.XLSX).sheet("sheet").doWrite(data); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 2cd22024d0..86034567f6 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -1334,8 +1334,13 @@ public class BugService { Map statusMap = statusOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); // 表头自定义字段 List headerCustomFields = getHeaderCustomFields(request.getProjectId()); - ExportUtils exportUtils = new ExportUtils(bugs, BugExportHeaderModel.builder().exportColumns(request.getExportColumns()).headerCustomFields(headerCustomFields) - .handleUserMap(handleUserMap).statusMap(statusMap).build()); + String xlsxFileNamePrefix = "MeterSphere_bug_" + project.getName() + "_"; + ExportUtils exportUtils = new ExportUtils(bugs, + BugExportHeaderModel.builder() + .exportColumns(request.getExportColumns()) + .headerCustomFields(headerCustomFields) + .handleUserMap(handleUserMap).statusMap(statusMap) + .xlsxFileNamePrefix(xlsxFileNamePrefix).build()); // 导出 byte[] bytes = exportUtils.exportToZipFile(bugExportService::generateExcelFiles); String zipName = "MeterSphere_bug_" + URLEncoder.encode(project.getName(), StandardCharsets.UTF_8) + ".zip";