From 58359cb409c79ec04477c44a0eca0f7d0fee762e Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 25 Aug 2022 17:49:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B,=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E7=AB=99,=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E5=A4=9A=E9=80=89=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=AD=9B=E9=80=89=E5=8F=8A=E9=AB=98=E7=BA=A7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016257 --user=宋昌昌 【测试跟踪】功能用例,回收站列表,高级搜索,“多选下拉列表”不属于,筛选无效 https://www.tapd.cn/55049933/s/1234070 --- .../base/mapper/ext/ExtIssuesMapper.xml | 21 ++---- .../base/mapper/ext/ExtTestCaseMapper.xml | 65 +++++++++---------- .../commons/utils/ServiceUtils.java | 31 +++++++++ .../track/service/IssuesService.java | 1 + .../track/service/TestCaseNodeService.java | 4 ++ .../track/service/TestCaseService.java | 3 + 6 files changed, 75 insertions(+), 50 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml index d4a8aed3e3..afc89b1fd7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml @@ -261,10 +261,10 @@ and issues.id in ( select resource_id from custom_field_issues where concat('custom_multiple-',field_id) = #{key} - and JSON_CONTAINS(value, - - #{value} - ) + and + + JSON_CONTAINS(value, #{value}) + ) @@ -309,18 +309,11 @@ - and issues.id in ( + and issues.id ${custom.operator} ( select resource_id from custom_field_issues where field_id = #{custom.id} - - - and JSON_CONTAINS(`value`, #{custom.value}) - - - and NOT JSON_CONTAINS(`value`, #{custom.value}) - - + and ${custom.value} and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13) @@ -341,7 +334,7 @@ - ) + ) 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 361f22ec7c..4e7124cf1a 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 @@ -108,38 +108,31 @@ - and test_case.id in ( - select resource_id from custom_field_test_case where field_id = #{custom.id} - - - - - and JSON_CONTAINS(`value`, #{custom.value}) - - - and NOT JSON_CONTAINS(`value`, #{custom.value}) - - - - - and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13) - - - - - - and text_value - - - - - - and trim(both '"' from value) - - - - - + and test_case.id ${custom.operator} ( + select resource_id from custom_field_test_case where field_id = #{custom.id} + + + and ${custom.value} + + + and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13) + + + + + + and text_value + + + + + + and trim(both '"' from value) + + + + + ) @@ -605,10 +598,10 @@ and test_case.id in ( select resource_id from custom_field_test_case where concat('custom_multiple-',field_id) = #{key} - and JSON_CONTAINS(value, - - #{value} - ) + and + + JSON_CONTAINS(value, #{value}) + ) diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 7a9cb658e8..c82b101b82 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -1,9 +1,11 @@ package io.metersphere.commons.utils; +import com.alibaba.fastjson.JSONArray; import io.metersphere.base.domain.Project; import io.metersphere.base.domain.ProjectVersion; import io.metersphere.base.domain.User; import io.metersphere.base.domain.Workspace; +import io.metersphere.commons.constants.CustomFieldType; import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.controller.request.OrderRequest; @@ -13,6 +15,8 @@ import io.metersphere.service.ProjectService; import io.metersphere.service.ProjectVersionService; import io.metersphere.service.UserService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -419,4 +423,31 @@ public class ServiceUtils { .distinct() .collect(Collectors.toList()); } + + @SuppressWarnings("unchecked") + public static void setBaseQueryRequestCustomMultipleFields(BaseQueryRequest request) { + // filter中自定义多选字段 + if (MapUtils.isNotEmpty(request.getFilters())) { + request.getFilters().entrySet().forEach(entry -> { + if (entry.getKey().startsWith("custom_multiple") && CollectionUtils.isNotEmpty(entry.getValue())) { + List customValues = JSONArray.parseArray(entry.getValue().get(0), String.class); + List jsonValues = customValues.stream().map(item -> "[\"".concat(item).concat("\"]")).collect(Collectors.toList()); + entry.setValue(jsonValues); + } + }); + } + // 高级搜索中自定义多选字段 + if (MapUtils.isNotEmpty(request.getCombine()) && ObjectUtils.isNotEmpty((request.getCombine().get("customs")))) { + List> customs = (List>) request.getCombine().get("customs"); + customs.forEach(custom -> { + if (StringUtils.equalsAny(custom.get("type").toString(), CustomFieldType.MULTIPLE_MEMBER.getValue(), + CustomFieldType.CHECKBOX.getValue(), CustomFieldType.MULTIPLE_SELECT.getValue()) + && StringUtils.isNotEmpty(custom.get("value").toString())) { + List customValues = JSONArray.parseArray(custom.get("value").toString(), String.class); + List jsonValues = customValues.stream().map(item -> "JSON_CONTAINS(`value`, '[\"".concat(item).concat("\"]')")).collect(Collectors.toList()); + custom.put("value", "(".concat(StringUtils.join(jsonValues, " OR ")).concat(")")); + } + }); + } + } } diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index c1d732729e..2f2ddbecfe 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -397,6 +397,7 @@ public class IssuesService { order.setName("value"); } }); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); List issues = extIssuesMapper.getIssues(request); Map> caseSetMap = getCaseSetMap(issues); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java index 3d60c7fbee..ffc68ee1ed 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -15,6 +15,7 @@ import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.NodeNumDTO; import io.metersphere.exception.ExcelException; @@ -250,6 +251,7 @@ public class TestCaseNodeService extends NodeTreeService { request.setProjectId(projectId); request.setUserId(SessionUtils.getUserId()); request.setNodeIds(null); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); List countMNodes = extTestCaseMapper.getCountNodes(request); List testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId); return getNodeTrees(testCaseNodes, getCountMap(countMNodes)); @@ -275,6 +277,7 @@ public class TestCaseNodeService extends NodeTreeService { request.setWorkspaceId(workspaceId); request.setProjectId(null); request.setNodeIds(null); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); List countModules = extTestCaseMapper.getWorkspaceCountNodes(request); return getNodeTreeWithPruningTree(countModules); } @@ -285,6 +288,7 @@ public class TestCaseNodeService extends NodeTreeService { extTestCaseMapper.updateNoModuleTrashNodeToDefault(projectId, defaultNode.getId(), defaultNode.getName()); request.setProjectId(projectId); request.setNodeIds(null); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); List countModules = extTestCaseMapper.getCountNodes(request); countModules.forEach(item -> item.setProjectId(projectId)); return getNodeTreeWithPruningTree(countModules); 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 a9ed2494db..386826dbc0 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -725,6 +725,7 @@ public class TestCaseService { public List listTestCase(QueryTestCaseRequest request, boolean isSampleInfo) { this.initRequest(request, true); setDefaultOrder(request); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); if (request.getFilters() != null && !request.getFilters().containsKey("status")) { request.getFilters().put("status", new ArrayList<>(0)); } @@ -782,10 +783,12 @@ public class TestCaseService { MSException.throwException("workspaceId could not be null!"); } request.setProjectId(null); + ServiceUtils.setBaseQueryRequestCustomMultipleFields(request); List returnList = extTestCaseMapper.publicList(request); ServiceUtils.buildVersionInfo(returnList); ServiceUtils.buildProjectInfo(returnList); buildUserInfo(returnList); + buildCustomField(returnList); return returnList; }