This commit is contained in:
shiziyuan9527 2020-06-02 16:48:35 +08:00
commit 1a15ebae4e
5 changed files with 51 additions and 22 deletions

View File

@ -1,8 +1,12 @@
package io.metersphere.api.dto; package io.metersphere.api.dto;
import io.metersphere.controller.request.OrderRequest;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List;
import java.util.Map;
@Getter @Getter
@Setter @Setter
public class QueryAPIReportRequest { public class QueryAPIReportRequest {
@ -12,5 +16,6 @@ public class QueryAPIReportRequest {
private String name; private String name;
private String workspaceId; private String workspaceId;
private boolean recent = false; private boolean recent = false;
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
} }

View File

@ -11,12 +11,14 @@ import io.metersphere.base.mapper.ApiTestReportMapper;
import io.metersphere.base.mapper.ext.ExtApiTestReportMapper; import io.metersphere.base.mapper.ext.ExtApiTestReportMapper;
import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.DashboardTestDTO; import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
@ -24,8 +26,6 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.annotation.Resource;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class APIReportService { public class APIReportService {
@ -38,6 +38,7 @@ public class APIReportService {
private ExtApiTestReportMapper extApiTestReportMapper; private ExtApiTestReportMapper extApiTestReportMapper;
public List<APIReportResult> list(QueryAPIReportRequest request) { public List<APIReportResult> list(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extApiTestReportMapper.list(request); return extApiTestReportMapper.list(request);
} }

View File

@ -26,8 +26,23 @@
<if test="request.workspaceId != null"> <if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId,jdbcType=VARCHAR} AND project.workspace_id = #{request.workspaceId,jdbcType=VARCHAR}
</if> </if>
<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">
and r.${key} in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
</foreach>
</if>
</where> </where>
ORDER BY r.update_time DESC <if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
r.${order.name} ${order.type}
</foreach>
</if>
</select> </select>
<select id="listByTestId" resultMap="BaseResultMap"> <select id="listByTestId" resultMap="BaseResultMap">

View File

@ -3,10 +3,12 @@
<ms-main-container> <ms-main-container>
<el-card class="table-card" v-loading="result.loading"> <el-card class="table-card" v-loading="result.loading">
<template v-slot:header> <template v-slot:header>
<ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="search" :title="$t('api_report.title')" <ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="search"
:title="$t('api_report.title')"
:show-create="false"/> :show-create="false"/>
</template> </template>
<el-table :data="tableData" class="table-content"> <el-table :data="tableData" class="table-content" @sort-change="sort"
@filter-change="filter">
<el-table-column :label="$t('commons.name')" width="200" show-overflow-tooltip> <el-table-column :label="$t('commons.name')" width="200" show-overflow-tooltip>
<template v-slot:default="scope"> <template v-slot:default="scope">
<el-link type="info" @click="handleView(scope.row)">{{ scope.row.name }}</el-link> <el-link type="info" @click="handleView(scope.row)">{{ scope.row.name }}</el-link>
@ -22,7 +24,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="status" :label="$t('commons.status')" <el-table-column prop="status" :label="$t('commons.status')"
:filter-method="filter" column-key="status"
:filters="statusFilters"> :filters="statusFilters">
<template v-slot:default="{row}"> <template v-slot:default="{row}">
<ms-api-report-status :row="row"/> <ms-api-report-status :row="row"/>
@ -50,13 +52,14 @@
import MsContainer from "../../common/components/MsContainer"; import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer"; import MsMainContainer from "../../common/components/MsMainContainer";
import MsApiReportStatus from "./ApiReportStatus"; import MsApiReportStatus from "./ApiReportStatus";
import {_filter, _sort} from "../../../../common/js/utils";
export default { export default {
components: {MsApiReportStatus, MsMainContainer, MsContainer, MsTableHeader, MsTablePagination}, components: {MsApiReportStatus, MsMainContainer, MsContainer, MsTableHeader, MsTablePagination},
data() { data() {
return { return {
result: {}, result: {},
condition: {name: ""}, condition: {},
tableData: [], tableData: [],
multipleSelection: [], multipleSelection: [],
currentPage: 1, currentPage: 1,
@ -80,16 +83,14 @@
methods: { methods: {
search() { search() {
let param = {
name: this.condition.name,
};
if (this.testId !== 'all') { if (this.testId !== 'all') {
param.testId = this.testId; this.condition.testId = this.testId;
} }
let url = "/api/report/list/" + this.currentPage + "/" + this.pageSize let url = "/api/report/list/" + this.currentPage + "/" + this.pageSize
this.result = this.$post(url, param, response => { this.result = this.$post(url, this.condition, response => {
let data = response.data; let data = response.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
@ -120,9 +121,18 @@
this.testId = this.$route.params.testId; this.testId = this.$route.params.testId;
this.search(); this.search();
}, },
filter(value, row) { /* filter(value, row) {
return row.status === value; return row.status === value;
} },*/
sort(column) {
_sort(column, this.condition);
this.init();
},
filter(filters) {
_filter(filters, this.condition);
this.init();
},
}, },
created() { created() {

View File

@ -66,7 +66,7 @@
data() { data() {
return { return {
result: {}, result: {},
condition: {name: ""}, condition: {},
projectId: null, projectId: null,
tableData: [], tableData: [],
multipleSelection: [], multipleSelection: [],
@ -106,16 +106,14 @@
this.$router.push('/api/test/create'); this.$router.push('/api/test/create');
}, },
search() { search() {
let param = {
name: this.condition.name,
};
if (this.projectId !== 'all') { if (this.projectId !== 'all') {
param.projectId = this.projectId; this.condition.projectId = this.projectId;
} }
let url = "/api/list/" + this.currentPage + "/" + this.pageSize let url = "/api/list/" + this.currentPage + "/" + this.pageSize
this.result = this.$post(url, param, response => { this.result = this.$post(url, this.condition, response => {
let data = response.data; let data = response.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;