fix(用例管理): 修复复制用例附件无法复制成功问题
--bug=1036216 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036216
This commit is contained in:
parent
f02b147f2e
commit
f1a74283c5
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.functional.request;
|
||||
|
||||
import io.metersphere.functional.dto.CaseCustomFieldDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseAttachmentDTO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
@ -74,5 +75,8 @@ public class FunctionalCaseAddRequest implements Serializable {
|
|||
@Schema(description = "评审id")
|
||||
private String reviewId;
|
||||
|
||||
@Schema(description = "附件信息")
|
||||
private List<FunctionalCaseAttachmentDTO> attachments;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class FunctionalCaseAttachmentService {
|
|||
* @param userId userId
|
||||
*/
|
||||
public void saveCaseAttachment(String fileId, MultipartFile file, String caseId, Boolean isLocal, String userId) {
|
||||
FunctionalCaseAttachment caseAttachment = creatModule(fileId, file.getOriginalFilename(), file.getSize(), caseId, isLocal, userId);
|
||||
FunctionalCaseAttachment caseAttachment = creatAttachment(fileId, file.getOriginalFilename(), file.getSize(), caseId, isLocal, userId);
|
||||
functionalCaseAttachmentMapper.insertSelective(caseAttachment);
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,8 @@ public class FunctionalCaseAttachmentService {
|
|||
* @param projectId projectId
|
||||
* @param files files
|
||||
*/
|
||||
public void uploadFile(String projectId, String caseId, List<MultipartFile> files, Boolean isLocal, String userId) {
|
||||
public List<String> uploadFile(String projectId, String caseId, List<MultipartFile> files, Boolean isLocal, String userId) {
|
||||
List<String>fileIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
files.forEach(file -> {
|
||||
String fileId = IDGenerator.nextStr();
|
||||
|
@ -103,11 +104,13 @@ public class FunctionalCaseAttachmentService {
|
|||
throw new MSException("save file error");
|
||||
}
|
||||
saveCaseAttachment(fileId, file, caseId, isLocal, userId);
|
||||
fileIds.add(fileId);
|
||||
});
|
||||
}
|
||||
return fileIds;
|
||||
}
|
||||
|
||||
private FunctionalCaseAttachment creatModule(String fileId, String fileName, long fileSize, String caseId, Boolean isLocal, String userId) {
|
||||
public FunctionalCaseAttachment creatAttachment(String fileId, String fileName, long fileSize, String caseId, Boolean isLocal, String userId) {
|
||||
FunctionalCaseAttachment caseAttachment = new FunctionalCaseAttachment();
|
||||
caseAttachment.setId(IDGenerator.nextStr());
|
||||
caseAttachment.setCaseId(caseId);
|
||||
|
|
|
@ -155,9 +155,6 @@ public class FunctionalCaseService {
|
|||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private ProjectApplicationMapper projectApplicationMapper;
|
||||
@Resource
|
||||
private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper;
|
||||
|
||||
|
||||
public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List<MultipartFile> files, String userId, String organizationId) {
|
||||
String caseId = IDGenerator.nextStr();
|
||||
|
@ -165,7 +162,7 @@ public class FunctionalCaseService {
|
|||
FunctionalCase functionalCase = addCase(caseId, request, userId);
|
||||
|
||||
//上传文件
|
||||
functionalCaseAttachmentService.uploadFile(request.getProjectId(), caseId, files, true, userId);
|
||||
List<String> uploadFileIds = functionalCaseAttachmentService.uploadFile(request.getProjectId(), caseId, files, true, userId);
|
||||
|
||||
//上传副文本里的文件
|
||||
functionalCaseAttachmentService.uploadMinioFile(caseId, request.getProjectId(), request.getCaseDetailFileIds(), userId, CaseFileSourceType.CASE_DETAIL.toString());
|
||||
|
@ -175,6 +172,11 @@ public class FunctionalCaseService {
|
|||
functionalCaseAttachmentService.association(request.getRelateFileMetaIds(), caseId, userId, ADD_FUNCTIONAL_CASE_FILE_LOG_URL, request.getProjectId());
|
||||
}
|
||||
|
||||
//处理复制时的已存在的文件
|
||||
if (CollectionUtils.isNotEmpty(request.getAttachments())) {
|
||||
copyAttachment(request, userId, uploadFileIds, caseId);
|
||||
}
|
||||
|
||||
addCaseReviewCase(request.getReviewId(), caseId, userId);
|
||||
|
||||
//记录日志
|
||||
|
@ -184,6 +186,25 @@ public class FunctionalCaseService {
|
|||
return functionalCase;
|
||||
}
|
||||
|
||||
private void copyAttachment(FunctionalCaseAddRequest request, String userId, List<String> uploadFileIds, String caseId) {
|
||||
//获取用例已经上传的文件ID
|
||||
Map<String, FunctionalCaseAttachmentDTO> attachmentDTOMap = request.getAttachments().stream().collect(Collectors.toMap(FunctionalCaseAttachmentDTO::getId, t -> t));
|
||||
List<String> attachmentFileIds = request.getAttachments().stream().filter(t-> !t.isDeleted()).map(FunctionalCaseAttachmentDTO::getId).filter(t -> !uploadFileIds.contains(t)).toList();
|
||||
if (CollectionUtils.isEmpty(attachmentFileIds)) {
|
||||
return;
|
||||
}
|
||||
FunctionalCaseAttachmentExample functionalCaseAttachmentExample = new FunctionalCaseAttachmentExample();
|
||||
functionalCaseAttachmentExample.createCriteria().andCaseIdEqualTo(caseId).andFileIdIn(attachmentFileIds);
|
||||
List<FunctionalCaseAttachment> functionalCaseAttachments = functionalCaseAttachmentMapper.selectByExample(functionalCaseAttachmentExample);
|
||||
List<String> attachmentFileIdInDBs = functionalCaseAttachments.stream().map(FunctionalCaseAttachment::getFileId).toList();
|
||||
List<String> saveAttachmentFileIds = attachmentFileIds.stream().filter(t -> !attachmentFileIdInDBs.contains(t)).toList();
|
||||
for (String saveAttachmentFileId : saveAttachmentFileIds) {
|
||||
FunctionalCaseAttachmentDTO functionalCaseAttachmentDTO = attachmentDTOMap.get(saveAttachmentFileId);
|
||||
FunctionalCaseAttachment caseAttachment = functionalCaseAttachmentService.creatAttachment(saveAttachmentFileId, functionalCaseAttachmentDTO.getFileName(), functionalCaseAttachmentDTO.getSize(), caseId, Boolean.TRUE, userId);
|
||||
functionalCaseAttachmentMapper.insertSelective(caseAttachment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加用例评审和用例关联关系
|
||||
|
@ -777,7 +798,7 @@ public class FunctionalCaseService {
|
|||
|
||||
private void handleCustomFields(FunctionalCaseBatchEditRequest request, String userId, List<String> ids) {
|
||||
boolean customField = Optional.ofNullable(request.getCustomField()).map(o -> o.getFieldId()).isPresent();
|
||||
if(customField){
|
||||
if (customField) {
|
||||
functionalCaseCustomFieldService.batchUpdate(request.getCustomField(), ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package io.metersphere.functional.controller;
|
||||
|
||||
import io.metersphere.functional.domain.FunctionalCase;
|
||||
import io.metersphere.functional.domain.FunctionalCaseAttachment;
|
||||
import io.metersphere.functional.domain.FunctionalCaseAttachmentExample;
|
||||
import io.metersphere.functional.domain.FunctionalCaseCustomField;
|
||||
import io.metersphere.functional.dto.CaseCustomFieldDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseAttachmentDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCasePageDTO;
|
||||
import io.metersphere.functional.dto.response.FunctionalCaseImportResponse;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseAttachmentMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper;
|
||||
import io.metersphere.functional.request.*;
|
||||
import io.metersphere.functional.result.CaseManagementResultCode;
|
||||
|
@ -36,6 +40,7 @@ import io.metersphere.system.uid.IDGenerator;
|
|||
import io.metersphere.system.utils.Pager;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -47,7 +52,6 @@ import org.springframework.test.web.servlet.MvcResult;
|
|||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
@ -91,6 +95,9 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
@Resource
|
||||
private OperationHistoryService operationHistoryService;
|
||||
|
||||
@Resource
|
||||
private FunctionalCaseAttachmentMapper functionalCaseAttachmentMapper;
|
||||
|
||||
protected static String functionalCaseId;
|
||||
|
||||
|
||||
|
@ -163,6 +170,35 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
//复制
|
||||
List<FunctionalCaseAttachmentDTO> attachmentDTOS = new ArrayList<>();
|
||||
FunctionalCaseAttachmentDTO functionalCaseAttachmentDTO = new FunctionalCaseAttachmentDTO();
|
||||
functionalCaseAttachmentDTO.setId("12345677");
|
||||
functionalCaseAttachmentDTO.setFileName("测试复制");
|
||||
functionalCaseAttachmentDTO.setAssociationId("4444");
|
||||
functionalCaseAttachmentDTO.setLocal(true);
|
||||
functionalCaseAttachmentDTO.setFileSource("ATTACHMENT");
|
||||
functionalCaseAttachmentDTO.setSize(111745L);
|
||||
functionalCaseAttachmentDTO.setCreateUser("gyq");
|
||||
functionalCaseAttachmentDTO.setCreateTime(System.currentTimeMillis());
|
||||
functionalCaseAttachmentDTO.setDeleted(false);
|
||||
attachmentDTOS.add(functionalCaseAttachmentDTO);
|
||||
request = creatFunctionalCase();
|
||||
request.setAttachments(attachmentDTOS);
|
||||
paramMap = new LinkedMultiValueMap<>();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
paramMap.add("files", new LinkedMultiValueMap<>());
|
||||
functionalCaseMvcResult = this.requestMultipartWithOkAndReturn(FUNCTIONAL_CASE_ADD_URL, paramMap);
|
||||
returnData = functionalCaseMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
functionalCase = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), FunctionalCase.class);
|
||||
FunctionalCaseAttachmentExample functionalCaseAttachmentExample = new FunctionalCaseAttachmentExample();
|
||||
functionalCaseAttachmentExample.createCriteria().andCaseIdEqualTo(functionalCase.getId()).andFileIdEqualTo("12345677");
|
||||
List<FunctionalCaseAttachment> functionalCaseAttachments = functionalCaseAttachmentMapper.selectByExample(functionalCaseAttachmentExample);
|
||||
Assertions.assertEquals(1, functionalCaseAttachments.size());
|
||||
}
|
||||
|
||||
public String uploadTemp(MultipartFile file) {
|
||||
|
|
Loading…
Reference in New Issue