refactor: 测试用例模块树加载优化

This commit is contained in:
chenjianxing 2021-05-25 19:01:57 +08:00 committed by jianxing
parent 6c329d3f1e
commit 8f43deaf41
3 changed files with 57 additions and 51 deletions

View File

@ -93,16 +93,11 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
moduleIds = this.nodeList(apiModules, node.getId(), moduleIds); moduleIds = this.nodeList(apiModules, node.getId(), moduleIds);
moduleIds.add(node.getId()); moduleIds.add(node.getId());
request.setModuleIds(moduleIds); request.setModuleIds(moduleIds);
int num = this.getCaseNum(request); node.setCaseNum(extApiDefinitionMapper.moduleCount(request));
node.setCaseNum(num);
}); });
return getNodeTrees(apiModules); return getNodeTrees(apiModules);
} }
private int getCaseNum(ApiDefinitionRequest request) {
return extApiDefinitionMapper.list(request).size();
}
public static List<String> nodeList(List<ApiModuleDTO> apiNodes, String pid, List<String> list) { public static List<String> nodeList(List<ApiModuleDTO> apiNodes, String pid, List<String> list) {
for (ApiModuleDTO node : apiNodes) { for (ApiModuleDTO node : apiNodes) {
//遍历出父id等于参数的idadd进子节点集合 //遍历出父id等于参数的idadd进子节点集合

View File

@ -17,6 +17,8 @@ public interface ExtApiDefinitionMapper {
List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request); List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request);
int moduleCount(@Param("request") ApiDefinitionRequest request);
//List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids); //List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids);
List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids, @Param("projectId") String projectId); List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids, @Param("projectId") String projectId);
@ -46,4 +48,4 @@ public interface ExtApiDefinitionMapper {
List<ApiDefinition> selectEffectiveIdByProjectId(String projectId); List<ApiDefinition> selectEffectiveIdByProjectId(String projectId);
List<ApiDefinitionResult> listByIds(@Param("ids") List<String> ids); List<ApiDefinitionResult> listByIds(@Param("ids") List<String> ids);
} }

View File

@ -487,6 +487,40 @@
WHERE project_id = #{0} AND status != 'Trash' AND protocol = 'HTTP' WHERE project_id = #{0} AND status != 'Trash' AND protocol = 'HTTP'
</select> </select>
<select id="moduleCount" resultType="java.lang.Integer">
select count(id) from api_definition
<include refid="queryWhereCondition"/>
</select>
<sql id="filter">
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
<choose>
<when test="key=='status'">
and api_definition.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='method'">
and api_definition.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_definition.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
</sql>
<sql id="queryWhereCondition"> <sql id="queryWhereCondition">
<where> <where>
<if test="request.combine != null"> <if test="request.combine != null">
@ -504,12 +538,6 @@
<if test="request.protocol != null"> <if test="request.protocol != null">
AND api_definition.protocol = #{request.protocol} AND api_definition.protocol = #{request.protocol}
</if> </if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
</if>
<if test="request.projectId != null">
AND project.id = #{request.projectId}
</if>
<if test="request.id != null"> <if test="request.id != null">
AND api_definition.id = #{request.id} AND api_definition.id = #{request.id}
</if> </if>
@ -522,41 +550,24 @@
<if test="request.moduleId != null"> <if test="request.moduleId != null">
AND api_definition.module_id = #{request.moduleId} AND api_definition.module_id = #{request.moduleId}
</if> </if>
<if test="request.projectId != null"> <choose>
AND api_definition.project_id = #{request.projectId} <when test="request.moduleIds != null and request.moduleIds.size() > 0">
</if> AND api_definition.module_id in
<if test="request.moduleIds != null and request.moduleIds.size() > 0"> <foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
AND api_definition.module_id in #{nodeId}
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")"> </foreach>
#{nodeId} </when>
</foreach> <when test="request.projectId != null">
</if> AND api_definition.project_id = #{request.projectId}
<if test="request.filters != null and request.filters.size() > 0"> </when>
<foreach collection="request.filters.entrySet()" index="key" item="values"> <when test="request.projectId != null">
<if test="values != null and values.size() > 0"> AND project.id = #{request.projectId}
<choose> </when>
<when test="key=='status'"> <when test="request.workspaceId != null">
and api_definition.status in AND project.workspace_id = #{request.workspaceId}
<foreach collection="values" item="value" separator="," open="(" close=")"> </when>
#{value} </choose>
</foreach> <include refid="filter"/>
</when>
<when test="key=='method'">
and api_definition.method in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
<when test="key=='user_id'">
and api_definition.user_id in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</when>
</choose>
</if>
</foreach>
</if>
<if test="request.apiCaseCoverage == 'uncoverage' "> <if test="request.apiCaseCoverage == 'uncoverage' ">
and api_definition.id not in and api_definition.id not in
(SELECT api_definition_id FROM api_test_case) (SELECT api_definition_id FROM api_test_case)
@ -565,8 +576,6 @@
and api_definition.id in and api_definition.id in
(SELECT api_definition_id FROM api_test_case) (SELECT api_definition_id FROM api_test_case)
</if> </if>
</where> </where>
</sql> </sql>
</mapper> </mapper>