From e48c01a8aa3a8ea81e6467bdc1447a26c81aa121 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Sun, 29 Sep 2024 17:34:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=80=9A=E7=94=A8=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E6=B8=85=E7=A9=BA=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiCaseBatchEditRequest.java | 2 + .../ApiDefinitionBatchUpdateRequest.java | 3 + .../definition/ApiMockBatchEditRequest.java | 2 + .../scenario/ApiScenarioBatchEditRequest.java | 2 + .../definition/ApiDefinitionMockService.java | 2 +- .../definition/ApiDefinitionService.java | 2 +- .../definition/ApiTestCaseService.java | 2 +- .../service/scenario/ApiScenarioService.java | 3 +- .../ApiDefinitionControllerTests.java | 11 +++ .../ApiDefinitionMockControllerTests.java | 7 ++ .../ApiScenarioControllerTests.java | 8 +++ .../ApiTestCaseControllerTests.java | 7 ++ .../dto/request/BugBatchUpdateRequest.java | 3 + .../metersphere/bug/service/BugService.java | 69 ++++++++++--------- .../bug/controller/BugControllerTests.java | 14 ++++ .../mapper/ExtFunctionalCaseMapper.xml | 2 - .../service/FunctionalCaseMinderService.java | 9 ++- .../service/FunctionalCaseService.java | 14 +--- .../dto/request/TestPlanBatchEditRequest.java | 3 + .../plan/service/TestPlanService.java | 4 +- .../plan/controller/TestPlanTests.java | 8 +++ 21 files changed, 121 insertions(+), 56 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseBatchEditRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseBatchEditRequest.java index 7b2a463793..c2bee4bbea 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseBatchEditRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiCaseBatchEditRequest.java @@ -27,6 +27,8 @@ public class ApiCaseBatchEditRequest extends ApiTestCaseBatchRequest implements private String type; @Schema(description = "是否追加标签") private boolean append = false; + @Schema(description = "默认不清空所有标签") + private boolean clear = false; @Schema(description = "环境id") @Size(max = 50, message = "{api_test_case.env_id.length_range}") private String environmentId; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchUpdateRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchUpdateRequest.java index ba5c734b47..9a2d5cbec4 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchUpdateRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDefinitionBatchUpdateRequest.java @@ -47,6 +47,9 @@ public class ApiDefinitionBatchUpdateRequest extends ApiDefinitionBatchRequest { @Schema(description = "是否追加", requiredMode = Schema.RequiredMode.REQUIRED) private boolean append = false; + @Schema(description = "是否清空") + private boolean clear = false; + public List getTags() { if (tags == null) { return new ArrayList<>(0); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiMockBatchEditRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiMockBatchEditRequest.java index 5d4c103f23..5c8170fa03 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiMockBatchEditRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiMockBatchEditRequest.java @@ -27,6 +27,8 @@ public class ApiMockBatchEditRequest extends ApiTestCaseBatchRequest implements private String type; @Schema(description = "是否追加标签") private boolean append = false; + @Schema(description = "默认不清空所有标签") + private boolean clear = false; @Schema(description = "状态 开启/关闭") private boolean enable; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioBatchEditRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioBatchEditRequest.java index 6debdcb096..4f9067998c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioBatchEditRequest.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioBatchEditRequest.java @@ -27,6 +27,8 @@ public class ApiScenarioBatchEditRequest extends ApiScenarioBatchRequest impleme private String type; @Schema(description = "默认覆盖原标签") private boolean append = false; + @Schema(description = "默认不清空所有标签") + private boolean clear = false; @Schema(description = "环境id") @Size(max = 50, message = "{api_test_case.environment_id.length_range}") private String envId; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java index 9027f0408a..a2d4bc6e86 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionMockService.java @@ -449,7 +449,7 @@ public class ApiDefinitionMockService { }); } } else { - updateMock.setTags(ServiceUtils.parseTags(request.getTags())); + updateMock.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); mapper.updateByExampleSelective(updateMock, example); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index ef9240bc4e..5218762339 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -651,7 +651,7 @@ public class ApiDefinitionService extends MoveNodeService { } else { //替换标签 ApiDefinition apiDefinition = new ApiDefinition(); - apiDefinition.setTags(ServiceUtils.parseTags(request.getTags())); + apiDefinition.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); apiDefinition.setProjectId(request.getProjectId()); apiDefinition.setUpdateTime(System.currentTimeMillis()); apiDefinition.setUpdateUser(userId); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index 3e81787c03..5a28a3d1ed 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -535,7 +535,7 @@ public class ApiTestCaseService extends MoveNodeService { }); } } else { - updateCase.setTags(ServiceUtils.parseTags(request.getTags())); + updateCase.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); mapper.updateByExampleSelective(updateCase, example); } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 06159197f3..f54f4da2b2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -331,7 +331,7 @@ public class ApiScenarioService extends MoveNodeService { }); } } else { - updateScenario.setTags(ServiceUtils.parseTags(request.getTags().stream().distinct().toList())); + updateScenario.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags().stream().distinct().toList())); mapper.updateByExampleSelective(updateScenario, example); } } @@ -583,6 +583,7 @@ public class ApiScenarioService extends MoveNodeService { /** * 当文件管理更新了关联资源的 csv 文件版本时 * 前端文件并未更新,这里使用时,进行对比,使用较新的文件版本 + * * @param csvVariables * @param dbCsv */ diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index 25fa8ccf15..95e6fd1fa9 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -750,14 +750,24 @@ public class ApiDefinitionControllerTests extends BaseTest { apiDefinitionBatchUpdateRequest.setSelectIds(List.of("1001", "1002")); apiDefinitionBatchUpdateRequest.setTags(new LinkedHashSet<>(List.of("tag-append", "tag-append1"))); apiDefinitionBatchUpdateRequest.setAppend(true); + apiDefinitionBatchUpdateRequest.setClear(false); this.requestPostWithOk(BATCH_UPDATE, apiDefinitionBatchUpdateRequest); assertBatchUpdateApiDefinition(apiDefinitionBatchUpdateRequest, List.of("1001", "1002")); // 修改标签,覆盖 apiDefinitionBatchUpdateRequest.setSelectIds(List.of("1003", "1004")); apiDefinitionBatchUpdateRequest.setTags(new LinkedHashSet<>(List.of("tag-append", "tag-append1"))); apiDefinitionBatchUpdateRequest.setAppend(false); + apiDefinitionBatchUpdateRequest.setClear(false); this.requestPostWithOk(BATCH_UPDATE, apiDefinitionBatchUpdateRequest); assertBatchUpdateApiDefinition(apiDefinitionBatchUpdateRequest, List.of("1003", "1004")); + apiDefinitionBatchUpdateRequest.setClear(true); + this.requestPostWithOk(BATCH_UPDATE, apiDefinitionBatchUpdateRequest); + ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample(); + apiDefinitionExample.createCriteria().andIdIn(List.of("1003", "1004")); + List apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample); + for (ApiDefinition definition : apiDefinitions) { + Assertions.assertTrue(CollectionUtils.isEmpty(definition.getTags())); + } // 自定义字段覆盖 apiDefinitionBatchUpdateRequest.setType("customs"); apiDefinitionBatchUpdateRequest.setSelectIds(List.of("1002", "1003", "1004")); @@ -766,6 +776,7 @@ public class ApiDefinitionControllerTests extends BaseTest { field.setValue(JSON.toJSONString(List.of("test1-batch"))); apiDefinitionBatchUpdateRequest.setCustomField(field); apiDefinitionBatchUpdateRequest.setAppend(false); + apiDefinitionBatchUpdateRequest.setClear(false); this.requestPostWithOk(BATCH_UPDATE, apiDefinitionBatchUpdateRequest); // 修改协议类型 apiDefinitionBatchUpdateRequest.setType("method"); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java index 440750319b..75e7ec37ef 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionMockControllerTests.java @@ -607,6 +607,7 @@ public class ApiDefinitionMockControllerTests extends BaseTest { request.setProjectId(DEFAULT_PROJECT_ID); request.setType("Tags"); request.setAppend(true); + request.setClear(false); request.setSelectAll(true); request.setTags(new LinkedHashSet<>(List.of("tag1", "tag3", "tag4"))); requestPostWithOkAndReturn(BATCH_EDIT, request); @@ -623,10 +624,16 @@ public class ApiDefinitionMockControllerTests extends BaseTest { //覆盖标签 request.setTags(new LinkedHashSet<>(List.of("tag1"))); request.setAppend(false); + request.setClear(false); requestPostWithOkAndReturn(BATCH_EDIT, request); apiDefinitionMockMapper.selectByExample(example).forEach(apiTestCase -> { Assertions.assertEquals(apiTestCase.getTags(), List.of("tag1")); }); + request.setClear(true); + requestPostWithOkAndReturn(BATCH_EDIT, request); + apiDefinitionMockMapper.selectByExample(example).forEach(apiTestCase -> { + Assertions.assertTrue(CollectionUtils.isEmpty(apiTestCase.getTags())); + }); //标签为空 报错 request.setTags(new LinkedHashSet<>()); this.requestPost(BATCH_EDIT, request, status().is4xxClientError()); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index ee42e80fc1..346feae09b 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -1621,6 +1621,7 @@ public class ApiScenarioControllerTests extends BaseTest { request.setProjectId(DEFAULT_PROJECT_ID); request.setType("Tags"); request.setAppend(true); + request.setClear(false); request.setSelectAll(true); request.setTags(new LinkedHashSet<>(List.of("tag1", "tag3", "tag4"))); requestPostAndReturn(BATCH_EDIT, request); @@ -1654,10 +1655,17 @@ public class ApiScenarioControllerTests extends BaseTest { //覆盖标签 request.setTags(new LinkedHashSet<>(List.of("tag1"))); request.setAppend(false); + request.setClear(false); requestPostAndReturn(BATCH_EDIT, request); apiScenarioMapper.selectByExample(example).forEach(scenario -> { Assertions.assertEquals(scenario.getTags(), List.of("tag1")); }); + request.setAppend(false); + request.setClear(true); + requestPostAndReturn(BATCH_EDIT, request); + apiScenarioMapper.selectByExample(example).forEach(scenario -> { + Assertions.assertTrue(CollectionUtils.isEmpty(scenario.getTags())); + }); //标签为空 报错 request.setTags(new LinkedHashSet<>()); this.requestPost(BATCH_EDIT, request, ERROR_REQUEST_MATCHER); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java index 7e26a3fa30..ab204874c3 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestCaseControllerTests.java @@ -1101,6 +1101,7 @@ public class ApiTestCaseControllerTests extends BaseTest { request.setProjectId(DEFAULT_PROJECT_ID); request.setType("Tags"); request.setAppend(true); + request.setClear(false); request.setSelectAll(true); request.setTags(new LinkedHashSet<>(List.of("tag1", "tag3", "tag4"))); requestPostWithOkAndReturn(BATCH_EDIT, request); @@ -1117,10 +1118,16 @@ public class ApiTestCaseControllerTests extends BaseTest { //覆盖标签 request.setTags(new LinkedHashSet<>(List.of("tag1"))); request.setAppend(false); + request.setClear(false); requestPostWithOkAndReturn(BATCH_EDIT, request); apiTestCaseMapper.selectByExample(example).forEach(apiTestCase -> { Assertions.assertEquals(apiTestCase.getTags(), List.of("tag1")); }); + request.setClear(true); + requestPostWithOkAndReturn(BATCH_EDIT, request); + apiTestCaseMapper.selectByExample(example).forEach(apiTestCase -> { + Assertions.assertTrue(CollectionUtils.isEmpty(apiTestCase.getTags())); + }); //标签为空 报错 request.setTags(new LinkedHashSet<>()); this.requestPost(BATCH_EDIT, request, ERROR_REQUEST_MATCHER); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugBatchUpdateRequest.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugBatchUpdateRequest.java index 4bdf6adcd8..fdf7074a7c 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugBatchUpdateRequest.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/dto/request/BugBatchUpdateRequest.java @@ -16,6 +16,9 @@ public class BugBatchUpdateRequest extends BugBatchRequest{ @Schema(description = "是否追加", requiredMode = Schema.RequiredMode.REQUIRED) private boolean append; + @Schema(description = "是否清空") + private boolean clear; + @Schema(description = "更新人") private String updateUser; 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 26089c320e..60f77f2e63 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 @@ -410,7 +410,7 @@ public class BugService { example.createCriteria().andIdIn(batchIds); List bugs = bugMapper.selectByExample(example); String currentPlatform = projectApplicationService.getPlatformName(bugs.getFirst().getProjectId()); - List platformBugIds = new ArrayList<>(); + List platformBugIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(bugs)) { Map> groupBugs = bugs.stream().collect(Collectors.groupingBy(Bug::getPlatform)); // 根据不同平台, 删除缺陷 @@ -492,7 +492,7 @@ public class BugService { List batchIds = getBatchIdsByRequest(request); // 批量日志{修改之前} List logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-update", - request.getProjectId(), true, request.isAppend(), request.getTags(), currentUser); + request.getProjectId(), true, request.isAppend(), request.isClear() ? new ArrayList<>() : request.getTags(), currentUser); operationLogService.batchAdd(logs); // 目前只做标签的批量编辑 if (request.isAppend()) { @@ -513,8 +513,8 @@ public class BugService { sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } else { - request.setTags(ServiceUtils.parseTags(request.getTags())); - // 标签(覆盖) + // 标签(清空/覆盖) + request.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); request.setUpdateUser(currentUser); request.setUpdateTime(System.currentTimeMillis()); extBugMapper.batchUpdate(request, batchIds); @@ -721,10 +721,11 @@ public class BugService { /** * 处理平台全量缺陷 - * @param project 项目 - * @param request 同步请求参数 + * + * @param project 项目 + * @param request 同步请求参数 * @param currentUser 当前用户 - * @param language 语言 + * @param language 语言 * @param triggerMode 触发方式 */ private void doSyncAllPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode) { @@ -1455,7 +1456,8 @@ public class BugService { /** * 是否插件默认模板 - * @param templateId 模板ID + * + * @param templateId 模板ID * @param pluginTemplate 插件模板 * @return 是否插件默认模板 */ @@ -1969,9 +1971,8 @@ public class BugService { } /** - * - * @param atomicPos 位置 - * @param batchBugMapper 批量操作缺陷 + * @param atomicPos 位置 + * @param batchBugMapper 批量操作缺陷 * @param batchBugContentMapper 批量操作缺陷内容 */ private void handleSaveBug(BugSyncSaveModel saveModel, AtomicLong atomicPos, BugMapper batchBugMapper, BugContentMapper batchBugContentMapper) { @@ -1995,7 +1996,7 @@ public class BugService { // 非平台默认模板时, 设置需要处理的字段 if (!platformBug.getPlatformDefaultTemplate()) { List defaultTemplateCustomFields = saveModel.getMsDefaultTemplate().getCustomFields(); - needSyncApiFieldMap = defaultTemplateCustomFields.stream().filter(field -> StringUtils.isNotBlank(field.getApiFieldId())) + needSyncApiFieldMap = defaultTemplateCustomFields.stream().filter(field -> StringUtils.isNotBlank(field.getApiFieldId())) .collect(Collectors.toMap(TemplateCustomFieldDTO::getApiFieldId, TemplateCustomFieldDTO::getFieldId)); } } else { @@ -2015,7 +2016,7 @@ public class BugService { // 非平台默认模板时, 设置需要处理的字段 if (!platformBug.getPlatformDefaultTemplate()) { List templateCustomFields = saveModel.getTemplateFieldMap().get(platformBug.getTemplateId()); - needSyncApiFieldMap = templateCustomFields.stream().filter(field -> StringUtils.isNotBlank(field.getApiFieldId())) + needSyncApiFieldMap = templateCustomFields.stream().filter(field -> StringUtils.isNotBlank(field.getApiFieldId())) .collect(Collectors.toMap(TemplateCustomField::getApiFieldId, TemplateCustomField::getFieldId)); } } @@ -2084,30 +2085,30 @@ public class BugService { List platformCustomFields = platformBug.getCustomFieldList(); // 过滤出需要同步的自定义字段{默认模板时, 需要同步所有字段; 非默认模板时, 需要同步模板中映射的字段} final Map needSyncApiFieldFilterMap = needSyncApiFieldMap; - List bugCustomFieldDTOList; - if (platformBug.getPlatformDefaultTemplate()) { + List bugCustomFieldDTOList; + if (platformBug.getPlatformDefaultTemplate()) { // 平台默认模板创建的缺陷 - bugCustomFieldDTOList = platformCustomFields.stream() - .map(platformField -> { - BugCustomFieldDTO bugCustomFieldDTO = new BugCustomFieldDTO(); - bugCustomFieldDTO.setId(platformField.getId()); - bugCustomFieldDTO.setValue(platformField.getValue() == null ? null : platformField.getValue().toString()); - return bugCustomFieldDTO; - }).collect(Collectors.toList()); - } else { + bugCustomFieldDTOList = platformCustomFields.stream() + .map(platformField -> { + BugCustomFieldDTO bugCustomFieldDTO = new BugCustomFieldDTO(); + bugCustomFieldDTO.setId(platformField.getId()); + bugCustomFieldDTO.setValue(platformField.getValue() == null ? null : platformField.getValue().toString()); + return bugCustomFieldDTO; + }).collect(Collectors.toList()); + } else { // 非平台默认模板创建的缺陷(使用模板API映射字段) - bugCustomFieldDTOList = platformCustomFields.stream() - .filter(field -> needSyncApiFieldFilterMap.containsKey(field.getId())) - .map(platformField -> { - BugCustomFieldDTO bugCustomFieldDTO = new BugCustomFieldDTO(); - bugCustomFieldDTO.setId(needSyncApiFieldFilterMap.get(platformField.getId())); - bugCustomFieldDTO.setValue(platformField.getValue() == null ? null : platformField.getValue().toString()); - return bugCustomFieldDTO; - }).collect(Collectors.toList()); - } - customEditRequest.setCustomFields(bugCustomFieldDTOList); + bugCustomFieldDTOList = platformCustomFields.stream() + .filter(field -> needSyncApiFieldFilterMap.containsKey(field.getId())) + .map(platformField -> { + BugCustomFieldDTO bugCustomFieldDTO = new BugCustomFieldDTO(); + bugCustomFieldDTO.setId(needSyncApiFieldFilterMap.get(platformField.getId())); + bugCustomFieldDTO.setValue(platformField.getValue() == null ? null : platformField.getValue().toString()); + return bugCustomFieldDTO; + }).collect(Collectors.toList()); + } + customEditRequest.setCustomFields(bugCustomFieldDTOList); - // 保存缺陷 + // 保存缺陷 if (originalBug == null) { // 新增 batchBugMapper.insertSelective(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 501ef91026..00364cff58 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 @@ -51,6 +51,7 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -380,16 +381,29 @@ public class BugControllerTests extends BaseTest { // TAG追加 request.setTags(List.of("TAG", "TEST_TAG")); request.setAppend(true); + request.setClear(false); this.requestPost(BUG_BATCH_UPDATE, request, status().isOk()); // TAG覆盖 request.setExcludeIds(List.of("default-bug-id-tapd1")); request.setTags(List.of("A", "B")); request.setAppend(false); + request.setClear(false); this.requestPost(BUG_BATCH_UPDATE, request, status().isOk()); // 勾选部分 request.setSelectAll(false); request.setSelectIds(List.of("default-bug-id")); this.requestPost(BUG_BATCH_UPDATE, request, status().isOk()); + //TAG追加 清空 + Bug bug = bugMapper.selectByPrimaryKey("default-bug-id"); + Assertions.assertEquals(2, bug.getTags().size()); + request.setAppend(false); + request.setClear(true); + this.requestPost(BUG_BATCH_UPDATE, request, status().isOk()); + bug = bugMapper.selectByPrimaryKey("default-bug-id"); + Assertions.assertTrue(CollectionUtils.isEmpty(bug.getTags())); + + + } @Test diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml index 17d55b1f92..f3992c2ab1 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml @@ -808,8 +808,6 @@ WHERE tpfc.test_plan_id = #{request.planId} AND fc.deleted = #{deleted} - AND - fc.project_Id = #{request.projectId} AND tpfc.test_plan_collection_id = #{request.collectionId} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index 7ff408bc0b..1d6d08d0c9 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -1348,8 +1348,13 @@ public class FunctionalCaseMinderService { public List getCollectionMindFunctionalCase(FunctionalCaseCollectionMindRequest request, boolean deleted) { List list = new ArrayList<>(); List functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCollectionList(request, deleted); - List fieldIds = getFieldIds(request.getProjectId()); - List caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldListByCollection(request, deleted, fieldIds); + List projectIds = functionalCaseMindDTOList.stream().map(FunctionalCaseMindDTO::getProjectId).distinct().toList(); + List caseCustomFieldList = new ArrayList<>(); + for (String projectId : projectIds) { + List fieldIds = getFieldIds(projectId); + List caseCustomFieldListByProjectId = extFunctionalCaseMapper.getCaseCustomFieldListByCollection(request, deleted, fieldIds); + caseCustomFieldList.addAll(caseCustomFieldListByProjectId); + } Map priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); //构造父子级数据 buildList(functionalCaseMindDTOList, list, priorityMap, "TEST_PLAN"); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 6eb685c81e..6d82df6073 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -138,8 +138,6 @@ public class FunctionalCaseService { @Resource private FunctionalCaseDemandMapper functionalCaseDemandMapper; @Resource - private FunctionalCaseTestMapper functionalCaseTestMapper; - @Resource private ExtFunctionalCaseTestMapper extFunctionalCaseTestMapper; @Resource private BugRelationCaseMapper bugRelationCaseMapper; @@ -1026,18 +1024,10 @@ public class FunctionalCaseService { }); sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } else if (request.isClear()) { - //清空标签 - FunctionalCase functionalCase = new FunctionalCase(); - functionalCase.setTags(new ArrayList<>()); - functionalCase.setProjectId(request.getProjectId()); - functionalCase.setUpdateTime(System.currentTimeMillis()); - functionalCase.setUpdateUser(userId); - extFunctionalCaseMapper.batchUpdate(functionalCase, ids); - }else { + } else { //替换标签 FunctionalCase functionalCase = new FunctionalCase(); - functionalCase.setTags(request.getTags()); + functionalCase.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); functionalCase.setProjectId(request.getProjectId()); functionalCase.setUpdateTime(System.currentTimeMillis()); functionalCase.setUpdateUser(userId); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java index 44ec6b306f..fc2b6857d8 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanBatchEditRequest.java @@ -14,6 +14,9 @@ public class TestPlanBatchEditRequest extends TestPlanBatchProcessRequest { @Schema(description = "是否追加") private boolean append = true; + @Schema(description = "是否清空") + private boolean clear; + @Schema(description = "标签") private List tags; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index e7160268e4..b1f1d971b5 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -791,10 +791,10 @@ public class TestPlanService extends TestPlanBaseUtilsService { }); sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } else { + } else { //替换标签 TestPlan testPlan = new TestPlan(); - testPlan.setTags(ServiceUtils.parseTags(request.getTags())); + testPlan.setTags(request.isClear() ? new ArrayList<>() : ServiceUtils.parseTags(request.getTags())); testPlan.setProjectId(request.getProjectId()); testPlan.setUpdateTime(System.currentTimeMillis()); testPlan.setUpdateUser(userId); diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index fa951fb536..0bd031ebbb 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -2384,6 +2384,7 @@ public class TestPlanTests extends BaseTest { request.setProjectId("songtianyang-fix-wx"); request.setSelectIds(Arrays.asList("wx_test_plan_id_1")); request.setAppend(false); + request.setClear(false); request.setTags(Arrays.asList("tag3", "tag4")); this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); //检查标签是否覆盖 @@ -2393,6 +2394,7 @@ public class TestPlanTests extends BaseTest { Assertions.assertTrue(testPlan.getTags().contains("tag4")); request.setAppend(true); + request.setClear(false); request.setTags(Arrays.asList("tag1", "tag2")); this.requestPostWithOk(URL_TEST_PLAN_BATCH_EDIT, request); testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1"); @@ -2417,6 +2419,12 @@ public class TestPlanTests extends BaseTest { Assertions.assertTrue(testPlan.getTags().contains("tag8")); Assertions.assertTrue(testPlan.getTags().contains("tag9")); Assertions.assertTrue(testPlan.getTags().contains("tag0")); + request.setAppend(false); + request.setClear(true); + request.setSelectAll(true); + this.requestPostWithOkAndReturn(URL_TEST_PLAN_BATCH_EDIT, request); + testPlan = testPlanMapper.selectByPrimaryKey("wx_test_plan_id_1"); + Assertions.assertTrue(CollectionUtils.isEmpty(testPlan.getTags())); } @Test