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; }