refactor(测试计划): 导出用例

This commit is contained in:
WangXu10 2024-08-09 16:08:04 +08:00 committed by Craftsman
parent 545077d397
commit 626b423396
3 changed files with 9 additions and 15 deletions

View File

@ -56,6 +56,7 @@ import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
@ -538,16 +539,9 @@ public class FunctionalCaseFileService {
List<FunctionalCaseExcelData> excelData = parseCaseData2ExcelData(subIds, rowMergeInfo, request, customFields, moduleMap, parameter.getParamValue());
List<List<Object>> data = parseExcelData2List(headList, excelData);
File createFile = new File(tmpZipPath + File.separatorChar + "Metersphere_case_" + project.getName() + count.get() + ".xlsx");
if (!createFile.exists()) {
try {
createFile.createNewFile();
} catch (IOException e) {
throw new MSException(e);
}
}
File createFile = new File(FilenameUtils.normalize(LocalRepositoryDir.getSystemTempDir() + File.separator + "Metersphere_case_" + project.getName() + count.get() + ".xlsx"));
//生成临时EXCEL
EasyExcel.write(createFile)
EasyExcel.write(createFile.getAbsolutePath())
.head(Optional.ofNullable(headList).orElse(new ArrayList<>()))
.registerWriteHandler(handler)
.registerWriteHandler(writeHandler)
@ -873,7 +867,7 @@ public class FunctionalCaseFileService {
Project project = projectMapper.selectByPrimaryKey(projectId);
byte[] bytes;
FileRequest fileRequest = new FileRequest();
fileRequest.setFileName(tasksFirst.getFileId().concat(tasksFirst.getFileType()));
fileRequest.setFileName(tasksFirst.getFileId().concat(".").concat(tasksFirst.getFileType()));
fileRequest.setFolder(DefaultRepositoryDir.getExportExcelTempDir());
fileRequest.setStorage(StorageType.MINIO.name());
try {
@ -881,7 +875,7 @@ public class FunctionalCaseFileService {
} catch (Exception e) {
throw new MSException("get file error");
}
String fileName = "Metersphere_case_" + project.getName() + tasksFirst.getFileType();
String fileName = "Metersphere_case_" + project.getName() + "." + tasksFirst.getFileType();
try {
return ResponseEntity.ok()

View File

@ -9,6 +9,7 @@ import io.metersphere.functional.socket.ExportWebSocketHandler;
import io.metersphere.functional.xmind.domain.FunctionalCaseXmindDTO;
import io.metersphere.functional.xmind.domain.FunctionalCaseXmindData;
import io.metersphere.functional.xmind.utils.XmindExportUtil;
import io.metersphere.sdk.constants.LocalRepositoryDir;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.MsgType;
import io.metersphere.sdk.dto.ExportMsgDTO;
@ -20,10 +21,10 @@ import io.metersphere.system.constants.ExportConstants;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
import io.metersphere.system.manager.ExportTaskManager;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -116,8 +117,7 @@ public class FunctionalCaseXmindService {
try {
FunctionalCaseXmindData xmindData = buildXmindData(ids, request);
File tmpFile = new File(getClass().getClassLoader().getResource(StringUtils.EMPTY).getPath() +
File.separatorChar + EXPORT_CASE_TMP_DIR + "_" + IDGenerator.nextStr() + ".xmind");
File tmpFile = new File(FilenameUtils.normalize(LocalRepositoryDir.getSystemTempDir() + File.separator + request.getFileId() + "." + XMIND));
List<TemplateCustomFieldDTO> templateCustomFields = functionalCaseFileService.getCustomFields(request.getProjectId());
TemplateCustomFieldDTO templateCustomFieldDTO = templateCustomFields.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get();
XmindExportUtil.export(xmindData, request, tmpFile, templateCustomFieldDTO);

View File

@ -59,7 +59,7 @@ public class ExportTaskManager {
exportTask.setUpdateUser(userId);
exportTask.setUpdateTime(System.currentTimeMillis());
exportTask.setProjectId(projectId);
exportTask.setFileType(fileId);
exportTask.setFileId(fileId);
exportTaskMapper.insertSelective(exportTask);
return exportTask;
}