refactor(接口测试):接口列表高级搜索支持自定义字段作为查询条件

--story=1011955 --user=王旭 【接口测试】接口列表高级搜索支持添加“自定义字段”搜索 https://www.tapd.cn/55049933/s/1371850
This commit is contained in:
WangXu10 2023-05-17 10:56:30 +08:00 committed by fit2-zhao
parent a0bae09c1b
commit bbfd7e09b6
4 changed files with 58 additions and 1 deletions

View File

@ -51,4 +51,10 @@ public class ApiDefinitionRequest extends BaseQueryRequest {
private Long deleteTime; private Long deleteTime;
private String deleteUserId; private String deleteUserId;
/**
* 是否根据自定义字段进行排序
*/
private Boolean isCustomSorted = false;
} }

View File

@ -236,7 +236,36 @@
<property name="object" value="${condition}.caseCount"/> <property name="object" value="${condition}.caseCount"/>
</include> </include>
</if> </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 (
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'">
and ${custom.value}
</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">
<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">
<property name="object" value="custom"/>
</include>
</when>
<otherwise>
and trim(both '"' from value)
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.condition">
<property name="object" value="custom"/>
</include>
</otherwise>
</choose>
)
</foreach>
</if>
</sql> </sql>
<sql id="condition"> <sql id="condition">
@ -296,6 +325,9 @@
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

@ -181,6 +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);
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())) {
@ -193,6 +194,12 @@ public class ApiDefinitionService {
return resList; return resList;
} }
private void setCustomFieldsOrder(ApiDefinitionRequest request) {
if (request.getCombine() != null && !request.getCombine().isEmpty()) {
request.setIsCustomSorted(true);
}
}
/** /**
* 工作台获取待应用管理设置的更新的条件 * 工作台获取待应用管理设置的更新的条件
* *

View File

@ -305,6 +305,8 @@ import {buildNodePath} from 'metersphere-frontend/src/model/NodeTree';
import VersionSelector from '@/business/definition/components/version/VersionSelector'; import VersionSelector from '@/business/definition/components/version/VersionSelector';
import TableExtendBtns from "@/business/definition/components/complete/table/TableExtendBtns"; import TableExtendBtns from "@/business/definition/components/complete/table/TableExtendBtns";
import MsShowReference from "@/business/definition/components/reference/ShowReference"; import MsShowReference from "@/business/definition/components/reference/ShowReference";
import {getApiTemplate} from "@/api/api-template";
import {getAdvSearchCustomField} from "metersphere-frontend/src/components/search/custom-component";
export default { export default {
name: 'ApiList', name: 'ApiList',
@ -597,7 +599,17 @@ export default {
this.editApi(response.data); this.editApi(response.data);
}); });
} }
for (let i = 0; i < this.condition.components.length; i++) {
if (this.condition.components[i].custom) {
this.condition.components.splice(i, 1);
break;
}
}
this.setAdvSearchParam(); this.setAdvSearchParam();
getApiTemplate(this.projectId).then((template) => {
let comp = getAdvSearchCustomField(this.condition, template.customFields);
this.condition.components.push(...comp)
});
}, },
watch: { watch: {
selectNodeIds() { selectNodeIds() {