diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml
index 5031bfc3de..a8488b27fb 100644
--- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml
+++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml
@@ -94,7 +94,7 @@
project_version.id as versionId
from test_case
left join test_case_review_test_case as T2 on test_case.id=T2.case_id and T2.review_id =#{request.reviewId}
- left join project_version on test_case.version_id = project_version.id and test_casel.project_id = project_version.project_id
+ left join project_version on test_case.version_id = project_version.id and test_case.project_id = project_version.project_id
and T2.case_id is null
diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java
index 901f5506f4..dab4f58ed3 100644
--- a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java
+++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java
@@ -34,6 +34,7 @@ import io.metersphere.track.request.testcase.TestCaseMinderEditRequest;
import io.metersphere.track.request.testplan.FileOperationRequest;
import io.metersphere.track.request.testplan.LoadCaseRequest;
import io.metersphere.track.service.TestCaseService;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -210,6 +211,12 @@ public class TestCaseController {
@SendNotice(taskType = NoticeConstants.TaskType.TRACK_TEST_CASE_TASK, targetClass = TestCaseMapper.class,
event = NoticeConstants.Event.CREATE, mailTemplate = "track/TestCaseCreate", subject = "测试用例通知")
public TestCase addTestCase(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file", required = false) List files) {
+ if(StringUtils.isBlank(request.getId())){
+ //新增 后端生成 id
+ request.setId(UUID.randomUUID().toString());
+ }else{
+ //复制,前端生成 id
+ }
return testCaseService.save(request, files);
}
diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java
index d711a1b48c..f8cba8d58d 100644
--- a/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java
+++ b/backend/src/main/java/io/metersphere/track/request/testcase/EditTestCaseRequest.java
@@ -14,6 +14,7 @@ public class EditTestCaseRequest extends TestCaseWithBLOBs {
private List updatedFileList;
private List follows;
private OtherInfoConfig otherInfoConfig;
+ private String oldDataId;
/**
* 复制测试用例后,要进行复制的文件Id list
*/
@@ -38,5 +39,16 @@ public class EditTestCaseRequest extends TestCaseWithBLOBs {
private boolean archive;
//是否复制依赖
private boolean dependency;
+
+ public static OtherInfoConfig createDefault() {
+ OtherInfoConfig o = new OtherInfoConfig();
+ o.setArchive(true);
+ o.setRemark(true);
+ o.setRelateTest(true);
+ o.setDependency(true);
+ o.setRelateDemand(true);
+ o.setRelateIssue(true);
+ return o;
+ }
}
}
diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java
index 090f1bd54c..2428f5fd42 100644
--- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java
+++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java
@@ -194,18 +194,11 @@ public class TestCaseService {
request.setCreateUser(SessionUtils.getUserId());
this.setNode(request);
request.setOrder(ServiceUtils.getNextOrder(request.getProjectId(), extTestCaseMapper::getLastOrder));
- //直接点保存
+ //直接点保存 || 复制走的逻辑
if (StringUtils.isAllBlank(request.getRefId(), request.getVersionId())) {
//新创建测试用例,默认使用最新版本
request.setRefId(request.getId());
- ProjectVersionRequest pvr = new ProjectVersionRequest();
- pvr.setProjectId(request.getProjectId());
- pvr.setLatest(true);
- List pvs = projectVersionService.getVersionList(pvr);
- if (pvs.size() == 0) {
- MSException.throwException(Translator.get("no_version_exists"));
- }
- request.setVersionId(pvs.get(0).getId());
+ request.setVersionId(extProjectVersionMapper.getDefaultVersion(request.getProjectId()));
} else if (StringUtils.isBlank(request.getRefId()) && StringUtils.isNotBlank(request.getVersionId())) {
//从版本选择直接创建
request.setRefId(request.getId());
@@ -216,6 +209,14 @@ public class TestCaseService {
return request;
}
+ private void dealWithCopyOtherInfo(TestCaseWithBLOBs testCase, String oldTestCaseId) {
+ EditTestCaseRequest request = new EditTestCaseRequest();
+ BeanUtils.copyBean(request, testCase);
+ EditTestCaseRequest.OtherInfoConfig otherInfoConfig = EditTestCaseRequest.OtherInfoConfig.createDefault();
+ request.setOtherInfoConfig(otherInfoConfig);
+ DealWithOtherInfo(request, oldTestCaseId);
+ }
+
public void saveFollows(String caseId, List follows) {
TestCaseFollowExample example = new TestCaseFollowExample();
example.createCriteria().andCaseIdEqualTo(caseId);
@@ -302,7 +303,7 @@ public class TestCaseService {
testCase.setCreateUser(SessionUtils.getUserId());
testCase.setOrder(oldTestCase.getOrder());
testCase.setRefId(oldTestCase.getRefId());
- DealWithOtherInfo(testCase, oldTestCase);
+ DealWithOtherInfo(testCase, oldTestCase.getId());
testCaseMapper.insertSelective(testCase);
}
}
@@ -311,9 +312,9 @@ public class TestCaseService {
* 处理其他信息的复制问题
*
* @param testCase
- * @param oldTestCase
+ * @param oldTestCaseId
*/
- private void DealWithOtherInfo(EditTestCaseRequest testCase, TestCaseWithBLOBs oldTestCase) {
+ private void DealWithOtherInfo(EditTestCaseRequest testCase, String oldTestCaseId) {
EditTestCaseRequest.OtherInfoConfig otherInfoConfig = testCase.getOtherInfoConfig();
if (otherInfoConfig != null) {
if (!otherInfoConfig.isRemark()) {
@@ -324,7 +325,7 @@ public class TestCaseService {
testCase.setDemandName(null);
}
if (otherInfoConfig.isRelateIssue()) {
- List issuesDaos = issuesService.getIssues(oldTestCase.getId());
+ List issuesDaos = issuesService.getIssues(oldTestCaseId);
if (CollectionUtils.isNotEmpty(issuesDaos)) {
issuesDaos.forEach(issue -> {
TestCaseIssues t = new TestCaseIssues();
@@ -336,7 +337,7 @@ public class TestCaseService {
}
}
if (otherInfoConfig.isRelateTest()) {
- List testCaseTestDaos = getRelateTest(oldTestCase.getId());
+ List testCaseTestDaos = getRelateTest(oldTestCaseId);
if (CollectionUtils.isNotEmpty(testCaseTestDaos)) {
testCaseTestDaos.forEach(test -> {
test.setTestCaseId(testCase.getId());
@@ -345,7 +346,7 @@ public class TestCaseService {
}
}
if (otherInfoConfig.isArchive()) {
- List files = fileService.getFileMetadataByCaseId(oldTestCase.getId());
+ List files = fileService.getFileMetadataByCaseId(oldTestCaseId);
if (CollectionUtils.isNotEmpty(files)) {
files.forEach(file -> {
TestCaseFile testCaseFile = new TestCaseFile();
@@ -356,8 +357,8 @@ public class TestCaseService {
}
}
if (otherInfoConfig.isDependency()) {
- List preRelations = relationshipEdgeService.getRelationshipEdgeByType(testCase.getId(), "PRE");
- List postRelations = relationshipEdgeService.getRelationshipEdgeByType(testCase.getId(), "POST");
+ List preRelations = relationshipEdgeService.getRelationshipEdgeByType(oldTestCaseId, "PRE");
+ List postRelations = relationshipEdgeService.getRelationshipEdgeByType(oldTestCaseId, "POST");
if (CollectionUtils.isNotEmpty(preRelations)) {
preRelations.forEach(relation -> {
relation.setSourceId(testCase.getId());
@@ -2351,6 +2352,7 @@ public class TestCaseService {
for (int i = 0; i < testCases.size(); i++) {
TestCaseWithBLOBs testCase = testCases.get(i);
String id = UUID.randomUUID().toString();
+ String oldTestCaseId = testCase.getId();
testCase.setId(id);
testCase.setName(ServiceUtils.getCopyName(testCase.getName()));
testCase.setNodeId(request.getNodeId());
@@ -2361,6 +2363,8 @@ public class TestCaseService {
testCase.setCasePublic(false);
testCase.setRefId(id);
mapper.insert(testCase);
+
+ dealWithCopyOtherInfo(testCase, oldTestCaseId);
if (i % 50 == 0)
sqlSession.flushStatements();
}
diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack
index 738eec25a0..b35dfb7f45 160000
--- a/backend/src/main/java/io/metersphere/xpack
+++ b/backend/src/main/java/io/metersphere/xpack
@@ -1 +1 @@
-Subproject commit 738eec25a070bbd75ba1bc343756ad62163e89ef
+Subproject commit b35dfb7f4571ed9e9496ff67339b9118232b4bbd
diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack
index b556a5ad31..8b60bbae96 160000
--- a/frontend/src/business/components/xpack
+++ b/frontend/src/business/components/xpack
@@ -1 +1 @@
-Subproject commit b556a5ad3171ae92050b8f85c50c5a3735ab6efc
+Subproject commit 8b60bbae9617eed3903ffc847a20ecd9b22c4fe8