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

View File

@ -57,8 +57,37 @@
<when test='${object}.operator == "le"'>
&lt;= #{${object}.value}
</when>
<when test='${object}.operator == "current user"'>
= '${@io.metersphere.commons.utils.SessionUtils@getUserId()}'
<otherwise>
= #{${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>
<otherwise>
= #{${object}.value}

View File

@ -181,7 +181,7 @@ public class ApiDefinitionService {
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
request = this.initRequest(request, true, true);
setCustomFieldsOrder(request);
ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
buildUserInfo(resList);
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.api.ModuleReference;
import io.metersphere.service.NodeTreeService;
import io.metersphere.service.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
@ -161,6 +162,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
request.setVersionId(versionId);
}
apiDefinitionService.checkFilterHasCoverage(request);
ServiceUtils.setBaseQueryRequestCustomMultipleFields(request);
List<ApiModuleDTO> countMNodes;
if (isCaseRelevance) {
countMNodes = extApiDefinitionMapper.moduleCaseCountByCollection(request);

View File

@ -3,3 +3,7 @@ import { get } from 'metersphere-frontend/src/plugins/request';
export function getCurrentByResourceId(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 MsTipButton from 'metersphere-frontend/src/components/MsTipButton';
import CaseBatchMove from '@/business/definition/components/basis/BatchMove';
import {getProjectMember} from "@/api/user";
import {
buildBatchParam,
deepClone,
@ -507,6 +508,7 @@ export default {
versionEnable: false,
isFirstInitTable: true,
visibleSearch: true,
members: [],
};
},
props: {
@ -606,10 +608,7 @@ export default {
}
}
this.setAdvSearchParam();
getApiTemplate(this.projectId).then((template) => {
let comp = getAdvSearchCustomField(this.condition, template.customFields);
this.condition.components.push(...comp)
});
this.getTemplateField();
},
watch: {
selectNodeIds() {
@ -653,6 +652,36 @@ export default {
},
},
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() {
let comp = this.condition.components.find((c) => c.key === 'moduleIds');
if (comp) {

View File

@ -203,7 +203,8 @@ export default {
})
this.newCustomFiled = newConfig.components.filter(co => co.custom);
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};
},

View File

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

View File

@ -9,6 +9,7 @@ import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.request.BaseQueryRequest;
import io.metersphere.request.OrderRequest;
import io.metersphere.request.ResetOrderRequest;
@ -387,18 +388,16 @@ public class ServiceUtils {
if (MapUtils.isNotEmpty(request.getCombine()) && ObjectUtils.isNotEmpty((request.getCombine().get("customs")))) {
List<Map<String, Object>> customs = (List<Map<String, Object>>) request.getCombine().get("customs");
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(),
CustomFieldType.CHECKBOX.getValue(), CustomFieldType.MULTIPLE_SELECT.getValue())
&& StringUtils.isNotEmpty(custom.get("value").toString())) {
List<String> customValues = JSON.parseArray(custom.get("value").toString(), String.class);
List<String> jsonValues;
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(")"));
}
List<String> jsonValues = customValues.stream().map(item -> "JSON_CONTAINS(`value`, '[\"".concat(item).concat("\"]')")).collect(Collectors.toList());
custom.put("value", "(".concat(StringUtils.join(jsonValues, " OR ")).concat(")"));
}
});