refactor(测试用例): 优化用例批量复制逻辑
This commit is contained in:
parent
dee7e496d1
commit
719a13786e
|
@ -32,10 +32,7 @@ import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.file.FileCenter;
|
import io.metersphere.sdk.file.FileCenter;
|
||||||
import io.metersphere.sdk.file.FileCopyRequest;
|
import io.metersphere.sdk.file.FileCopyRequest;
|
||||||
import io.metersphere.sdk.file.FileRepository;
|
import io.metersphere.sdk.file.FileRepository;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.*;
|
||||||
import io.metersphere.sdk.util.JSON;
|
|
||||||
import io.metersphere.sdk.util.LogUtils;
|
|
||||||
import io.metersphere.sdk.util.Translator;
|
|
||||||
import io.metersphere.system.domain.CustomFieldOption;
|
import io.metersphere.system.domain.CustomFieldOption;
|
||||||
import io.metersphere.system.domain.OperationHistoryExample;
|
import io.metersphere.system.domain.OperationHistoryExample;
|
||||||
import io.metersphere.system.domain.User;
|
import io.metersphere.system.domain.User;
|
||||||
|
@ -63,7 +60,6 @@ import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -823,7 +819,6 @@ public class FunctionalCaseService {
|
||||||
* @param request request
|
* @param request request
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
*/
|
*/
|
||||||
@Async
|
|
||||||
public void batchCopyFunctionalCase(FunctionalCaseBatchMoveRequest request, String userId, String organizationId) {
|
public void batchCopyFunctionalCase(FunctionalCaseBatchMoveRequest request, String userId, String organizationId) {
|
||||||
List<String> ids = doSelectIds(request, request.getProjectId());
|
List<String> ids = doSelectIds(request, request.getProjectId());
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
|
@ -840,6 +835,13 @@ public class FunctionalCaseService {
|
||||||
|
|
||||||
AtomicReference<Long> nextOrder = new AtomicReference<>(getNextOrder(request.getProjectId()));
|
AtomicReference<Long> nextOrder = new AtomicReference<>(getNextOrder(request.getProjectId()));
|
||||||
|
|
||||||
|
List<FunctionalCase> addList = new ArrayList<>();
|
||||||
|
List<FunctionalCaseBlob> addBlobList = new ArrayList<>();
|
||||||
|
List<FunctionalCaseAttachment> addAttachMentList = new ArrayList<>();
|
||||||
|
List<FunctionalCaseCustomField> addCustomFieldList = new ArrayList<>();
|
||||||
|
Map<String, List<String>> addFileAssociationMap = new HashMap<>();
|
||||||
|
Map<FunctionalCase, FunctionalCaseHistoryLogDTO> addLogMap = new HashMap<>();
|
||||||
|
|
||||||
for (String s : ids) {
|
for (String s : ids) {
|
||||||
String id = IDGenerator.nextStr();
|
String id = IDGenerator.nextStr();
|
||||||
FunctionalCase functionalCase = functionalCaseMap.get(s);
|
FunctionalCase functionalCase = functionalCaseMap.get(s);
|
||||||
|
@ -862,10 +864,10 @@ public class FunctionalCaseService {
|
||||||
functional.setUpdateUser(userId);
|
functional.setUpdateUser(userId);
|
||||||
functional.setCreateTime(System.currentTimeMillis());
|
functional.setCreateTime(System.currentTimeMillis());
|
||||||
functional.setUpdateTime(System.currentTimeMillis());
|
functional.setUpdateTime(System.currentTimeMillis());
|
||||||
functionalCaseMapper.insert(functional);
|
addList.add(functional);
|
||||||
|
|
||||||
functionalCaseBlob.setId(id);
|
functionalCaseBlob.setId(id);
|
||||||
functionalCaseBlobMapper.insert(functionalCaseBlob);
|
addBlobList.add(functionalCaseBlob);
|
||||||
nextOrder.updateAndGet(v -> v + ServiceUtils.POS_STEP);
|
nextOrder.updateAndGet(v -> v + ServiceUtils.POS_STEP);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -875,20 +877,20 @@ public class FunctionalCaseService {
|
||||||
attachment.setCaseId(id);
|
attachment.setCaseId(id);
|
||||||
attachment.setCreateUser(userId);
|
attachment.setCreateUser(userId);
|
||||||
attachment.setCreateTime(System.currentTimeMillis());
|
attachment.setCreateTime(System.currentTimeMillis());
|
||||||
|
addAttachMentList.add(attachment);
|
||||||
});
|
});
|
||||||
functionalCaseAttachmentService.batchSaveAttachment(caseAttachments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(customFields)) {
|
if (CollectionUtils.isNotEmpty(customFields)) {
|
||||||
customFields.forEach(customField -> {
|
customFields.forEach(customField -> {
|
||||||
customField.setCaseId(id);
|
customField.setCaseId(id);
|
||||||
|
addCustomFieldList.add(customField);
|
||||||
});
|
});
|
||||||
functionalCaseCustomFieldService.batchSaveCustomField(customFields);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(fileAssociationList)) {
|
if (CollectionUtils.isNotEmpty(fileAssociationList)) {
|
||||||
List<String> fileIds = fileAssociationList.stream().map(FileAssociation::getFileId).collect(Collectors.toList());
|
List<String> fileIds = fileAssociationList.stream().map(FileAssociation::getFileId).collect(Collectors.toList());
|
||||||
functionalCaseAttachmentService.association(fileIds, id, userId, FUNCTIONAL_CASE_BATCH_COPY_FILE_LOG_URL, request.getProjectId());
|
addFileAssociationMap.put(id, fileIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
//日志
|
//日志
|
||||||
|
@ -898,8 +900,27 @@ public class FunctionalCaseService {
|
||||||
historyLogDTO.setCustomFields(customFields);
|
historyLogDTO.setCustomFields(customFields);
|
||||||
historyLogDTO.setCaseAttachments(caseAttachments);
|
historyLogDTO.setCaseAttachments(caseAttachments);
|
||||||
historyLogDTO.setFileAssociationList(fileAssociationList);
|
historyLogDTO.setFileAssociationList(fileAssociationList);
|
||||||
saveAddDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
addLogMap.put(functionalCase, historyLogDTO);
|
||||||
}
|
}
|
||||||
|
SubListUtils.dealForSubList(addList, 500, subList -> {
|
||||||
|
functionalCaseMapper.batchInsert(subList);
|
||||||
|
});
|
||||||
|
SubListUtils.dealForSubList(addBlobList, 500, subList -> {
|
||||||
|
functionalCaseBlobMapper.batchInsert(addBlobList);
|
||||||
|
});
|
||||||
|
SubListUtils.dealForSubList(addAttachMentList, 500, subList -> {
|
||||||
|
functionalCaseAttachmentService.batchSaveAttachment(addAttachMentList);
|
||||||
|
});
|
||||||
|
SubListUtils.dealForSubList(addCustomFieldList, 500, subList -> {
|
||||||
|
functionalCaseCustomFieldService.batchSaveCustomField(addCustomFieldList);
|
||||||
|
});
|
||||||
|
addFileAssociationMap.entrySet().forEach(entry -> {
|
||||||
|
functionalCaseAttachmentService.association(entry.getValue(), entry.getKey(), userId, FUNCTIONAL_CASE_BATCH_COPY_FILE_LOG_URL, request.getProjectId());
|
||||||
|
});
|
||||||
|
addLogMap.entrySet().forEach(entry -> {
|
||||||
|
saveAddDataLog(entry.getKey(), new FunctionalCaseHistoryLogDTO(), entry.getValue(), userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
||||||
|
});
|
||||||
|
|
||||||
User user = userMapper.selectByPrimaryKey(userId);
|
User user = userMapper.selectByPrimaryKey(userId);
|
||||||
functionalCaseNoticeService.batchSendNotice(request.getProjectId(), ids, user, NoticeConstants.Event.CREATE);
|
functionalCaseNoticeService.batchSendNotice(request.getProjectId(), ids, user, NoticeConstants.Event.CREATE);
|
||||||
|
|
||||||
|
|
|
@ -615,8 +615,6 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
||||||
request.setModuleId("TEST_MOVE_MODULE_ID");
|
request.setModuleId("TEST_MOVE_MODULE_ID");
|
||||||
request.setSelectAll(false);
|
request.setSelectAll(false);
|
||||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
||||||
request.setSelectIds(Arrays.asList("TEST"));
|
|
||||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
|
||||||
request.setSelectIds(new ArrayList<>());
|
request.setSelectIds(new ArrayList<>());
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_BATCH_COPY_URL, request);
|
||||||
|
|
Loading…
Reference in New Issue