diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugEditRequest.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugEditRequest.java index 1d8162f372..63f4ab81e7 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugEditRequest.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugEditRequest.java @@ -54,4 +54,7 @@ public class BugEditRequest { @Schema(description = "关联附件集合, 文件ID") private List linkFileIds; + + @Schema(description = "用例ID") + private String caseId; } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugMapper.xml b/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugMapper.xml index fe13a514ba..be181191df 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugMapper.xml +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugMapper.xml @@ -378,18 +378,20 @@ - + and b.project_id = #{request.projectId} - + and ( b.title like concat('%', #{request.keyword},'%') or b.num like concat('%', #{request.keyword},'%') + or b.tags like concat('%', #{request.keyword},'%') ) + diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugRelateCaseMapper.xml b/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugRelateCaseMapper.xml index 94a2e41836..815aabdd26 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugRelateCaseMapper.xml +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/mapper/ExtBugRelateCaseMapper.xml @@ -91,10 +91,10 @@ - + and brc.case_id = #{request.caseId} - + and b.title like concat('%', #{request.keyword},'%') 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 4ed925fec9..3ae9e20679 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 @@ -224,6 +224,20 @@ public class BugService { handleAndSaveCustomFields(request, isUpdate); // 处理附件 handleAndSaveAttachments(request, files, currentUser, platformName, platformBug); + + if (!isUpdate && StringUtils.isNotBlank(request.getCaseId())) { + //用例创建缺陷并关联 + BugRelationCase bugRelationCase = new BugRelationCase(); + bugRelationCase.setId(IDGenerator.nextStr()); + bugRelationCase.setCaseId(request.getCaseId()); + bugRelationCase.setBugId(bug.getId()); + bugRelationCase.setCaseType(CaseType.FUNCTIONAL_CASE.getKey()); + bugRelationCase.setCreateUser(currentUser); + bugRelationCase.setCreateTime(System.currentTimeMillis()); + bugRelationCase.setUpdateTime(System.currentTimeMillis()); + bugRelationCaseMapper.insertSelective(bugRelationCase); + } + return bug; } diff --git a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java index 4f4f248b7f..5f37e0f213 100644 --- a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java +++ b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java @@ -239,6 +239,10 @@ public class BugControllerTests extends BaseTest { MultiValueMap paramMap = getDefaultMultiPartParam(request, file); this.requestMultipartWithOkAndReturn(BUG_ADD, paramMap); + request.setCaseId("test"); + paramMap = new LinkedMultiValueMap<>(); + paramMap.add("request", JSON.toJSONString(request)); + this.requestMultipartWithOkAndReturn(BUG_ADD, paramMap); } @Test