refactor: 测试计划获取关联接口列表

This commit is contained in:
chenjianxing 2020-12-29 15:32:57 +08:00
parent 8d8292227f
commit 9ce507d201
8 changed files with 95 additions and 37 deletions

View File

@ -41,6 +41,13 @@ public class ApiDefinitionController {
return PageUtils.setPageInfo(page, apiDefinitionService.list(request)); return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
} }
@PostMapping("/list/relevance/{goPage}/{pageSize}")
public Pager<List<ApiDefinitionResult>> listRelevance(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
return PageUtils.setPageInfo(page, apiDefinitionService.listRelevance(request));
}
@PostMapping("/list/all") @PostMapping("/list/all")
public List<ApiDefinitionResult> list(@RequestBody ApiDefinitionRequest request) { public List<ApiDefinitionResult> list(@RequestBody ApiDefinitionRequest request) {
return apiDefinitionService.list(request); return apiDefinitionService.list(request);

View File

@ -20,6 +20,7 @@ public class ApiDefinitionRequest {
private String name; private String name;
private String workspaceId; private String workspaceId;
private String userId; private String userId;
private String planId;
private boolean recent = false; private boolean recent = false;
private List<OrderRequest> orders; private List<OrderRequest> orders;
private List<String> filters; private List<String> filters;

View File

@ -78,23 +78,7 @@ public class ApiDefinitionService {
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) { public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request); List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
if (!resList.isEmpty()) { calculateResult(resList);
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIds(ids);
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
for (ApiDefinitionResult res : resList) {
ApiComputeResult compRes = resultMap.get(res.getId());
if (compRes != null) {
res.setCaseTotal(compRes.getCaseTotal());
res.setCasePassingRate(compRes.getPassRate());
res.setCaseStatus(compRes.getStatus());
} else {
res.setCaseTotal("-");
res.setCasePassingRate("-");
res.setCaseStatus("-");
}
}
}
return resList; return resList;
} }
@ -466,4 +450,31 @@ public class ApiDefinitionService {
example.createCriteria().andIdIn(ids); example.createCriteria().andIdIn(ids);
return apiDefinitionMapper.selectByExample(example); return apiDefinitionMapper.selectByExample(example);
} }
public List<ApiDefinitionResult> listRelevance(ApiDefinitionRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiDefinitionResult> resList = extApiDefinitionMapper.listRelevance(request);
calculateResult(resList);
return resList;
}
public void calculateResult(List<ApiDefinitionResult> resList) {
if (!resList.isEmpty()) {
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
List<ApiComputeResult> results = extApiDefinitionMapper.selectByIds(ids);
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
for (ApiDefinitionResult res : resList) {
ApiComputeResult compRes = resultMap.get(res.getId());
if (compRes != null) {
res.setCaseTotal(compRes.getCaseTotal());
res.setCasePassingRate(compRes.getPassRate());
res.setCaseStatus(compRes.getStatus());
} else {
res.setCaseTotal("-");
res.setCasePassingRate("-");
res.setCaseStatus("-");
}
}
}
}
} }

View File

@ -28,4 +28,6 @@ public interface ExtApiDefinitionMapper {
List<ApiDataCountResult> countApiCoverageByProjectID(String projectId); List<ApiDataCountResult> countApiCoverageByProjectID(String projectId);
ApiDefinition getNextNum(@Param("projectId") String projectId); ApiDefinition getNextNum(@Param("projectId") String projectId);
List<ApiDefinitionResult> listRelevance(@Param("request")ApiDefinitionRequest request);
} }

View File

@ -295,4 +295,52 @@
<select id="getNextNum" resultType="io.metersphere.base.domain.ApiDefinition"> <select id="getNextNum" resultType="io.metersphere.base.domain.ApiDefinition">
SELECT * FROM api_definition WHERE api_definition.project_id = #{projectId} ORDER BY num DESC LIMIT 1; SELECT * FROM api_definition WHERE api_definition.project_id = #{projectId} ORDER BY num DESC LIMIT 1;
</select> </select>
<select id="listRelevance" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
select
<include refid="io.metersphere.base.mapper.ApiDefinitionMapper.Base_Column_List"/>
from api_definition
<where>
<if test="request.combine != null">
<include refid="combine">
<property name="condition" value="request.combine"/>
<property name="name" value="request.name"/>
</include>
</if>
<if test="request.name != null">
and api_definition.name like CONCAT('%', #{request.name},'%')
</if>
<if test="request.protocol != null">
AND api_definition.protocol = #{request.protocol}
</if>
<if test="request.id != null">
AND api_definition.id = #{request.id}
</if>
<if test="request.moduleId != null">
AND api_definition.module_id = #{request.moduleId}
</if>
<if test="request.projectId != null">
AND api_definition.project_id = #{request.projectId}
</if>
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
AND api_definition.module_id in
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
#{nodeId}
</foreach>
</if>
<if test="request.filters != null and request.filters.size() > 0">
and api_definition.status in
<foreach collection="request.filters" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
</where>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
api_definition.${order.name} ${order.type}
</foreach>
</if>
</select>
</mapper> </mapper>

View File

@ -19,7 +19,7 @@
select select
t.id, t.environment_id, t.create_time, t.update_time, t.id, t.environment_id, t.create_time, t.update_time,
c.id as case_id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, c.update_user_id, c.id as case_id, c.project_id, c.name, c.api_definition_id, c.priority, c.description, c.create_user_id, c.update_user_id,
a.module_id, a.path, a.protocol, ader.status execResult a.module_id, a.path, a.protocol, t.status execResult
from from
test_plan_api_case t test_plan_api_case t
inner join inner join
@ -32,24 +32,6 @@
api_definition a api_definition a
on on
c.api_definition_id = a.id c.api_definition_id = a.id
left join (
select
e.status, e.id, e.resource_id
from
api_definition_exec_result e
left join (
select
max(start_time) start_time , resource_id
from
api_definition_exec_result
group by
resource_id
) as b
on e.resource_id = b.resource_id
where
e.start_time = b.start_time and e.type = 'API_PLAN'
) as ader
on t.id = ader.resource_id
<if test="request.protocol != null and request.protocol!=''"> <if test="request.protocol != null and request.protocol!=''">
and a.protocol = #{request.protocol} and a.protocol = #{request.protocol}
</if> </if>

View File

@ -156,6 +156,7 @@
default: false, default: false,
}, },
projectId: String, projectId: String,
planId: String,
isTestPlan: Boolean isTestPlan: Boolean
}, },
created: function () { created: function () {
@ -194,7 +195,12 @@
if (this.currentProtocol != null) { if (this.currentProtocol != null) {
this.condition.protocol = this.currentProtocol; this.condition.protocol = this.currentProtocol;
} }
this.result = this.$post("/api/definition/list/" + this.currentPage + "/" + this.pageSize, this.condition, response => { let url = '/api/definition/list/';
if (this.isTestPlan) {
url = '/api/definition/list/relevance/';
this.condition.planId = this.planId;
}
this.result = this.$post(url + this.currentPage + "/" + this.pageSize, this.condition, response => {
this.total = response.data.itemCount; this.total = response.data.itemCount;
this.tableData = response.data.listObject; this.tableData = response.data.listObject;
}); });

View File

@ -23,6 +23,7 @@
:is-api-list-enable="isApiListEnable" :is-api-list-enable="isApiListEnable"
:project-id="projectId" :project-id="projectId"
:is-test-plan="true" :is-test-plan="true"
:plan-id="planId"
@isApiListEnableChange="isApiListEnableChange" @isApiListEnableChange="isApiListEnableChange"
ref="apiList"/> ref="apiList"/>