fix(接口测试):接口测试高级搜索自定义字段,不同字段类型处理

--bug=1026609 --user=王旭 【接口测试】高级搜索-自定义字段搜索-搜索显示数量问题 https://www.tapd.cn/55049933/s/1377932

--bug=1026610 --user=王旭 【接口测试】高级搜索-自定义字段-富文本框-不包含条件-未搜索出所有不包含条件的接口 https://www.tapd.cn/55049933/s/1377934

--bug=1026612 --user=王旭 【接口测试】高级搜索-自定义字段搜索-列表显示问题 https://www.tapd.cn/55049933/s/1377935

--bug=1026625 --user=王旭 【接口测试】api-高级搜索自定义字段-输入框类型-未返回符合结果 https://www.tapd.cn/55049933/s/1377936

--bug=1026627 --user=王旭 【接口测试】api列表-高级搜索-自定义字段-输入框类型-输入关键字-不包含/包含-返回结果同一个api显示好多个 https://www.tapd.cn/55049933/s/1377937

--bug=1026629 --user=王旭 【接口测试】api列表-高级搜索-自定义字段-输入框类型-搜索结果模块树显示1条-列表显示1000多条且页面无法继续操作 https://www.tapd.cn/55049933/s/1377938

--bug=1026648 --user=王旭 【接口测试】api列表-高级搜索-自定义字段多选框类型-下拉选择-属于/不属于-查询报sql异常 https://www.tapd.cn/55049933/s/1377939
This commit is contained in:
WangXu10 2023-06-01 17:44:53 +08:00 committed by 建国
parent ed10bfbfca
commit b7462e1b9b
9 changed files with 90 additions and 30 deletions

View File

@ -238,7 +238,12 @@
</if> </if>
<if test="${condition}.customs != null and ${condition}.customs.size() > 0"> <if test="${condition}.customs != null and ${condition}.customs.size() > 0">
<foreach collection="${condition}.customs" item="custom" separator="" open="" close=""> <foreach collection="${condition}.customs" item="custom" separator="" open="" close="">
<if test='custom.operator == "not like" or custom.operator == "not in"'>
and api_definition.id not in (
</if>
<if test='custom.operator != "not like" and custom.operator != "not in"'>
and api_definition.id in ( and api_definition.id in (
</if>
select resource_id from custom_field_api where field_id = #{custom.id} select resource_id from custom_field_api where field_id = #{custom.id}
<choose> <choose>
<when test="custom.type == 'multipleMember' or custom.type == 'checkbox' or custom.type == 'multipleSelect'"> <when test="custom.type == 'multipleMember' or custom.type == 'checkbox' or custom.type == 'multipleSelect'">
@ -246,19 +251,19 @@
</when> </when>
<when test="custom.type == 'date' or custom.type == 'datetime'"> <when test="custom.type == 'date' or custom.type == 'datetime'">
and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13) and left(replace(unix_timestamp(trim(both '"' from `value`)), '.', ''), 13)
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition"> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.includeCondition">
<property name="object" value="custom"/> <property name="object" value="custom"/>
</include> </include>
</when> </when>
<when test="custom.type == 'richText' or custom.type == 'textarea'"> <when test="custom.type == 'richText' or custom.type == 'textarea'">
and text_value and text_value
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition"> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.includeCondition">
<property name="object" value="custom"/> <property name="object" value="custom"/>
</include> </include>
</when> </when>
<otherwise> <otherwise>
and trim(both '"' from value) and REPLACE(trim( BOTH '"' FROM VALUE ), '\\', '')
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition"> <include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.includeCondition">
<property name="object" value="custom"/> <property name="object" value="custom"/>
</include> </include>
</otherwise> </otherwise>
@ -325,9 +330,6 @@
from api_definition from api_definition
left join user on api_definition.user_id = user.id left join user on api_definition.user_id = user.id
LEFT JOIN project_version ON project_version.id = api_definition.version_id LEFT JOIN project_version ON project_version.id = api_definition.version_id
<if test="request.isCustomSorted">
left join custom_field_api on api_definition.id = custom_field_api.resource_id
</if>
<include refid="queryWhereCondition"/> <include refid="queryWhereCondition"/>
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by

View File

@ -57,8 +57,37 @@
<when test='${object}.operator == "le"'> <when test='${object}.operator == "le"'>
&lt;= #{${object}.value} &lt;= #{${object}.value}
</when> </when>
<when test='${object}.operator == "current user"'> <otherwise>
= '${@io.metersphere.commons.utils.SessionUtils@getUserId()}' = #{${object}.value}
</otherwise>
</choose>
</sql>
<sql id="includeCondition">
<choose>
<when test='${object}.operator == "like" or ${object}.operator == "not like"'>
like CONCAT('%', #{${object}.value},'%')
</when>
<when test='${object}.operator == "in" or ${object}.operator == "not in"'>
in
<foreach collection="${object}.value" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</when>
<when test='${object}.operator == "between"'>
between #{${object}.value[0]} and #{${object}.value[1]}
</when>
<when test='${object}.operator == "gt"'>
&gt; #{${object}.value}
</when>
<when test='${object}.operator == "lt"'>
&lt; #{${object}.value}
</when>
<when test='${object}.operator == "ge"'>
&gt;= #{${object}.value}
</when>
<when test='${object}.operator == "le"'>
&lt;= #{${object}.value}
</when> </when>
<otherwise> <otherwise>
= #{${object}.value} = #{${object}.value}

View File

@ -181,7 +181,7 @@ public class ApiDefinitionService {
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) { public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
request = this.initRequest(request, true, true); request = this.initRequest(request, true, true);
setCustomFieldsOrder(request); ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request); List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
buildUserInfo(resList); buildUserInfo(resList);
if (StringUtils.isNotBlank(request.getProjectId())) { if (StringUtils.isNotBlank(request.getProjectId())) {

View File

@ -22,6 +22,7 @@ import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.api.ModuleReference; import io.metersphere.log.vo.api.ModuleReference;
import io.metersphere.service.NodeTreeService; import io.metersphere.service.NodeTreeService;
import io.metersphere.service.ServiceUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
@ -161,6 +162,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
request.setVersionId(versionId); request.setVersionId(versionId);
} }
apiDefinitionService.checkFilterHasCoverage(request); apiDefinitionService.checkFilterHasCoverage(request);
ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<ApiModuleDTO> countMNodes; List<ApiModuleDTO> countMNodes;
if (isCaseRelevance) { if (isCaseRelevance) {
countMNodes = extApiDefinitionMapper.moduleCaseCountByCollection(request); countMNodes = extApiDefinitionMapper.moduleCaseCountByCollection(request);

View File

@ -3,3 +3,7 @@ import { get } from 'metersphere-frontend/src/plugins/request';
export function getCurrentByResourceId(id) { export function getCurrentByResourceId(id) {
return get('/api/current/user/' + id, () => {}); return get('/api/current/user/' + id, () => {});
} }
export function getProjectMember() {
return get('/user/project/member/list');
}

View File

@ -287,6 +287,7 @@ import {API_DEFINITION_CONFIGS} from 'metersphere-frontend/src/components/search
import {API_DEFINITION_CONFIGS_TRASH, getProtocolFilter} from '@/business/definition/api-definition'; import {API_DEFINITION_CONFIGS_TRASH, getProtocolFilter} from '@/business/definition/api-definition';
import MsTipButton from 'metersphere-frontend/src/components/MsTipButton'; import MsTipButton from 'metersphere-frontend/src/components/MsTipButton';
import CaseBatchMove from '@/business/definition/components/basis/BatchMove'; import CaseBatchMove from '@/business/definition/components/basis/BatchMove';
import {getProjectMember} from "@/api/user";
import { import {
buildBatchParam, buildBatchParam,
deepClone, deepClone,
@ -507,6 +508,7 @@ export default {
versionEnable: false, versionEnable: false,
isFirstInitTable: true, isFirstInitTable: true,
visibleSearch: true, visibleSearch: true,
members: [],
}; };
}, },
props: { props: {
@ -606,10 +608,7 @@ export default {
} }
} }
this.setAdvSearchParam(); this.setAdvSearchParam();
getApiTemplate(this.projectId).then((template) => { this.getTemplateField();
let comp = getAdvSearchCustomField(this.condition, template.customFields);
this.condition.components.push(...comp)
});
}, },
watch: { watch: {
selectNodeIds() { selectNodeIds() {
@ -653,6 +652,36 @@ export default {
}, },
}, },
methods: { methods: {
async getTemplateField() {
this.loading = true;
//
let p1 = getProjectMember()
.then((response) => {
this.members = response.data;
});
let p2 = getApiTemplate(this.projectId);
Promise.all([p1, p2]).then((data) => {
this.loading = false;
let template = data[1];
this.getCustomFields(template.customFields, this.members);
let comp = getAdvSearchCustomField(this.condition, template.customFields);
this.condition.components.push(...comp)
});
},
getCustomFields(customFields, projectMembers = []) {
projectMembers.forEach(member => {
member['text'] = member.name;
// 使
member['label'] = member.name;
member['value'] = member.id;
member['showLabel'] = member.name + "(" + member.id + ")";
})
customFields.forEach(item => {
if ((item.type === 'member' || item.type === 'multipleMember') && projectMembers && projectMembers.length > 0) {
item.options = projectMembers;
}
});
},
setAdvSearchParam() { setAdvSearchParam() {
let comp = this.condition.components.find((c) => c.key === 'moduleIds'); let comp = this.condition.components.find((c) => c.key === 'moduleIds');
if (comp) { if (comp) {

View File

@ -203,7 +203,8 @@ export default {
}) })
this.newCustomFiled = newConfig.components.filter(co => co.custom); this.newCustomFiled = newConfig.components.filter(co => co.custom);
for (let customField of this.newCustomFiled) { for (let customField of this.newCustomFiled) {
this.$set(customField, 'disable', false) let co = _findByKey(this.optional.components, customField.key);
co ? this.$set(co, 'disable', true) : this.$set(customField, 'disable', false);
} }
this.config.components[1] = {label: this.$t('custom_field.name'), child: this.newCustomFiled}; this.config.components[1] = {label: this.$t('custom_field.name'), child: this.newCustomFiled};
}, },

View File

@ -48,9 +48,6 @@
<when test='${object}.operator == "le"'> <when test='${object}.operator == "le"'>
&lt;= #{${object}.value} &lt;= #{${object}.value}
</when> </when>
<when test='${object}.operator == "current user"'>
= '${@io.metersphere.commons.utils.SessionUtils@getUserId()}'
</when>
<otherwise> <otherwise>
= #{${object}.value} = #{${object}.value}
</otherwise> </otherwise>
@ -92,9 +89,6 @@
<when test='${object}.operator == "le"'> <when test='${object}.operator == "le"'>
&lt;= #{${object}.value} &lt;= #{${object}.value}
</when> </when>
<when test='${object}.operator == "current user"'>
= '${@io.metersphere.commons.utils.SessionUtils@getUserId()}'
</when>
<otherwise> <otherwise>
= #{${object}.value} = #{${object}.value}
</otherwise> </otherwise>

View File

@ -9,6 +9,7 @@ import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.request.BaseQueryRequest; import io.metersphere.request.BaseQueryRequest;
import io.metersphere.request.OrderRequest; import io.metersphere.request.OrderRequest;
import io.metersphere.request.ResetOrderRequest; import io.metersphere.request.ResetOrderRequest;
@ -387,18 +388,16 @@ public class ServiceUtils {
if (MapUtils.isNotEmpty(request.getCombine()) && ObjectUtils.isNotEmpty((request.getCombine().get("customs")))) { if (MapUtils.isNotEmpty(request.getCombine()) && ObjectUtils.isNotEmpty((request.getCombine().get("customs")))) {
List<Map<String, Object>> customs = (List<Map<String, Object>>) request.getCombine().get("customs"); List<Map<String, Object>> customs = (List<Map<String, Object>>) request.getCombine().get("customs");
customs.forEach(custom -> { customs.forEach(custom -> {
if(StringUtils.equalsIgnoreCase(custom.get("operator").toString(), "current user")){
String userId = SessionUtils.getUserId();
custom.put("value", userId);
}
if (StringUtils.equalsAny(custom.get("type").toString(), CustomFieldType.MULTIPLE_MEMBER.getValue(), if (StringUtils.equalsAny(custom.get("type").toString(), CustomFieldType.MULTIPLE_MEMBER.getValue(),
CustomFieldType.CHECKBOX.getValue(), CustomFieldType.MULTIPLE_SELECT.getValue()) CustomFieldType.CHECKBOX.getValue(), CustomFieldType.MULTIPLE_SELECT.getValue())
&& StringUtils.isNotEmpty(custom.get("value").toString())) { && StringUtils.isNotEmpty(custom.get("value").toString())) {
List<String> customValues = JSON.parseArray(custom.get("value").toString(), String.class); List<String> customValues = JSON.parseArray(custom.get("value").toString(), String.class);
List<String> jsonValues; List<String> jsonValues = customValues.stream().map(item -> "JSON_CONTAINS(`value`, '[\"".concat(item).concat("\"]')")).collect(Collectors.toList());
if (StringUtils.equalsIgnoreCase(custom.get("operator").toString(), OperatorTypeConstants.NOT_IN)) {
jsonValues = customValues.stream().map(item -> "locate('"+item+"',`value`) = 0").collect(Collectors.toList());
custom.put("value", "(".concat(StringUtils.join(jsonValues, " and ")).concat(")"));
} else {
jsonValues = customValues.stream().map(item -> "JSON_CONTAINS(`value`, '[\"".concat(item).concat("\"]')")).collect(Collectors.toList());
custom.put("value", "(".concat(StringUtils.join(jsonValues, " OR ")).concat(")")); custom.put("value", "(".concat(StringUtils.join(jsonValues, " OR ")).concat(")"));
}
} }
}); });