From bf69e72c585f73692c5d7d0f58c224bf79a8b1cd Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 23 Feb 2024 19:00:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=AC=AC=E4=B8=89=E6=96=B9=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/DemandPageRequest.java | 10 +++++ .../bug/controller/BugController.java | 4 +- .../bug/controller/BugControllerTests.java | 44 ++++++++++++------- .../components/bugDetailTab.vue | 2 +- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java index b3f7f5fb99..4e55f1ff0a 100644 --- a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java +++ b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java @@ -32,4 +32,14 @@ public class DemandPageRequest { * 每页条数 */ private int pageSize; + + /** + * 是否查询所有(关联全选需求时传参) + */ + private boolean selectAll; + + /** + * 取消勾选的需求ID(关联全选需求时传参) + */ + private List excludeIds; } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java index c24f7ac116..475eb2d7a0 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java @@ -100,7 +100,7 @@ public class BugController { @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request, #files)", msClass = BugLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getNoticeByRequest(#request)", targetClass = BugNoticeService.class) public Bug add(@Validated({Created.class}) @RequestPart(value = "request") BugEditRequest request, - @RequestPart(value = "file", required = false) List files) { + @RequestPart(value = "files", required = false) List files) { return bugService.addOrUpdate(request, files, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), false); } @@ -111,7 +111,7 @@ public class BugController { @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request, #files)", msClass = BugLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.UPDATE, target = "#targetClass.getNoticeByRequest(#request)", targetClass = BugNoticeService.class) public Bug update(@Validated({Updated.class}) @RequestPart(value = "request") BugEditRequest request, - @RequestPart(value = "file", required = false) List files) { + @RequestPart(value = "files", required = false) List files) { return bugService.addOrUpdate(request, files, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), true); } 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 2c9f5a1fb2..088580796f 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 @@ -236,7 +236,7 @@ public class BugControllerTests extends BaseTest { request.setDescription(null); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); File file = new File(filePath); - MultiValueMap paramMap = getDefaultMultiPartParam(request, file); + MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipartWithOkAndReturn(BUG_ADD, paramMap); request.setCaseId("test"); @@ -253,24 +253,24 @@ public class BugControllerTests extends BaseTest { File file = new File(filePath); // 项目ID为空 request.setProjectId(null); - MultiValueMap paramMap = getDefaultMultiPartParam(request, file); + MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); request.setProjectId("default-project-for-bug"); // 处理人为空 request.setTitle("default-bug-title"); List noHandleUser = request.getCustomFields().stream().filter(field -> !StringUtils.equals(field.getId(), "handleUser")).toList(); request.setCustomFields(noHandleUser); - paramMap = getDefaultMultiPartParam(request, file); + paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is5xxServerError()); // 模板为空 request.setTemplateId(null); - paramMap = getDefaultMultiPartParam(request, file); + paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); // 状态为空 request.setTemplateId("default-bug-template"); List noStatus = request.getCustomFields().stream().filter(field -> !StringUtils.equals(field.getId(), "status")).toList(); request.setCustomFields(noStatus); - paramMap = getDefaultMultiPartParam(request, file); + paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is5xxServerError()); } @@ -280,7 +280,7 @@ public class BugControllerTests extends BaseTest { BugEditRequest request = buildRequest(true); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); File file = new File(filePath); - MultiValueMap paramMap = getDefaultMultiPartParam(request, file); + MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipartWithOkAndReturn(BUG_UPDATE, paramMap); // 第二次更新, no-file MultiValueMap noFileParamMap = new LinkedMultiValueMap<>(); @@ -300,7 +300,7 @@ public class BugControllerTests extends BaseTest { request.setId("default-bug-id-not-exist"); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); File file = new File(filePath); - MultiValueMap paramMap = getDefaultMultiPartParam(request, file); + MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_UPDATE, paramMap).andExpect(status().is5xxServerError()); } @@ -315,7 +315,7 @@ public class BugControllerTests extends BaseTest { request.setLinkFileIds(null); request.setUnLinkRefIds(null); request.setDeleteLocalFileIds(null); - MultiValueMap paramMap = getDefaultMultiPartParam(request, file); + MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipartWithOkAndReturn(BUG_UPDATE, paramMap); } @@ -562,14 +562,14 @@ public class BugControllerTests extends BaseTest { BugEditRequest addRequest = buildJiraBugRequest(false); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); File file = new File(filePath); - MultiValueMap addParam = getDefaultMultiPartParam(addRequest, file); + MultiValueMap addParam = getMultiPartParam(addRequest, file); this.requestMultipartWithOkAndReturn(BUG_ADD, addParam); // 更新Jira缺陷 BugEditRequest updateRequest = buildJiraBugRequest(true); updateRequest.setUnLinkRefIds(List.of(getAddJiraAssociateFile().getId())); updateRequest.setDeleteLocalFileIds(List.of(getAddJiraLocalFile().getFileId())); - MultiValueMap updateParma = getDefaultMultiPartParam(updateRequest, null); + MultiValueMap updateParma = getMultiPartParam(updateRequest, null); this.requestMultipartWithOkAndReturn(BUG_UPDATE, updateParma); // 删除Jira缺陷 this.requestGet(BUG_DELETE + "/" + updateRequest.getId(), status().isOk()); @@ -582,7 +582,7 @@ public class BugControllerTests extends BaseTest { summary.setType("input"); summary.setValue("这是一个系统Jira模板创建的缺陷"); addRequest.getCustomFields().add(summary); - MultiValueMap addParam3 = getDefaultMultiPartParam(addRequest, null); + MultiValueMap addParam3 = getMultiPartParam(addRequest, null); this.requestMultipart(BUG_ADD, addParam3).andExpect(status().is5xxServerError()); // 同步Jira存量缺陷(存量数据为空) @@ -591,7 +591,7 @@ public class BugControllerTests extends BaseTest { // 添加没有附件的Jira缺陷 addRequest.setLinkFileIds(null); addRequest.setTemplateId("default-bug-template-id"); - MultiValueMap addParam2 = getDefaultMultiPartParam(addRequest, null); + MultiValueMap addParam2 = getMultiPartParam(addRequest, null); this.requestMultipartWithOkAndReturn(BUG_ADD, addParam2); this.requestGetWithOk(BUG_SYNC + "/default-project-for-bug"); // 覆盖Redis-Key还未删除的情况 @@ -601,7 +601,7 @@ public class BugControllerTests extends BaseTest { // 更新没有附件的缺陷 BugEditRequest updateRequest2 = buildJiraBugRequest(true); updateRequest2.setLinkFileIds(List.of("default-bug-file-id-1")); - MultiValueMap updateParam2 = getDefaultMultiPartParam(updateRequest2, file); + MultiValueMap updateParam2 = getMultiPartParam(updateRequest2, file); this.requestMultipartWithOkAndReturn(BUG_UPDATE, updateParam2); // 同步方法为异步, 所以换成手动调用 BugExample example = new BugExample(); @@ -625,7 +625,7 @@ public class BugControllerTests extends BaseTest { // 集成配置为空 addRequest.setProjectId("default-project-for-not-integration"); - MultiValueMap notIntegrationParam = getDefaultMultiPartParam(addRequest, file); + MultiValueMap notIntegrationParam = getMultiPartParam(addRequest, file); this.requestMultipart(BUG_ADD, notIntegrationParam).andExpect(status().is5xxServerError()); // 执行同步全部 @@ -681,7 +681,7 @@ public class BugControllerTests extends BaseTest { BugEditRequest addRequest = buildRequest(false); String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.xlsx")).getPath(); File file = new File(filePath); - MultiValueMap addParam = getDefaultMultiPartParam(addRequest, file); + MultiValueMap addParam = getMultiPartParam(addRequest, file); this.requestMultipart(BUG_ADD, addParam).andExpect(status().is5xxServerError()); // 获取禅道模板(删除默认项目模板) bugService.attachTemplateStatusField(null, null, null, null); @@ -966,4 +966,18 @@ public class BugControllerTests extends BaseTest { example.createCriteria().andSourceIdEqualTo(bugId).andSourceTypeEqualTo(FileAssociationSourceUtil.SOURCE_TYPE_BUG); fileAssociationMapper.deleteByExample(example); } + + /** + * 获取默认的 MultiValue 参数 + * + * @param param 参数 + * @param file 文件 + * @return 文件参数 + */ + protected MultiValueMap getMultiPartParam(Object param, File file) { + MultiValueMap paramMap = new LinkedMultiValueMap<>(); + paramMap.add("files", file); + paramMap.add("request", JSON.toJSONString(param)); + return paramMap; + } } diff --git a/frontend/src/views/bug-management/components/bugDetailTab.vue b/frontend/src/views/bug-management/components/bugDetailTab.vue index b8a7eebc2f..9a76a17c6f 100644 --- a/frontend/src/views/bug-management/components/bugDetailTab.vue +++ b/frontend/src/views/bug-management/components/bugDetailTab.vue @@ -276,7 +276,7 @@ defineOptions({ async function deleteFileHandler(item: MsFileItem) { try { const params = { - refId: item.uid, + refId: item.associateId, associated: !item.local, bugId: bugId.value, projectId: currentProjectId.value,