Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Captain.B 2020-05-18 15:51:29 +08:00
commit 17d627afe9
11 changed files with 85 additions and 18 deletions

View File

@ -10,11 +10,13 @@ import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.DashboardTestDTO;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@ -34,6 +36,11 @@ public class APIReportController {
return apiReportService.recentTest(request);
}
@GetMapping("/list/{testId}")
public List<APIReportResult> listByTestId(@PathVariable String testId) {
return apiReportService.listByTestId(testId);
}
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<APIReportResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPIReportRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
@ -51,4 +58,10 @@ public class APIReportController {
apiReportService.delete(request);
}
@GetMapping("dashboard/tests")
public List<DashboardTestDTO> dashboardTests() {
return apiReportService.dashboardTests(SessionUtils.getCurrentWorkspaceId());
}
}

View File

@ -10,9 +10,12 @@ import io.metersphere.base.domain.ApiTestWithBLOBs;
import io.metersphere.base.mapper.ApiTestReportMapper;
import io.metersphere.base.mapper.ext.ExtApiTestReportMapper;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.dto.DashboardTestDTO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;
@ -62,4 +65,11 @@ public class APIReportService {
report.setStatus(APITestStatus.Completed.name());
apiTestReportMapper.insert(report);
}
public List<DashboardTestDTO> dashboardTests(String workspaceId) {
Instant oneYearAgo = Instant.now().plus(-365, ChronoUnit.DAYS);
long startTimestamp = oneYearAgo.toEpochMilli();
return extApiTestReportMapper.selectDashboardTests(workspaceId, startTimestamp);
}
}

View File

@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.api.dto.QueryAPIReportRequest;
import io.metersphere.dto.ApiReportDTO;
import io.metersphere.dto.DashboardTestDTO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -15,4 +16,6 @@ public interface ExtApiTestReportMapper {
APIReportResult get(@Param("id") String id);
List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp);
}

View File

@ -29,7 +29,7 @@
</select>
<select id="listByTestId" resultMap="BaseResultMap">
SELECT c,
SELECT t.name AS test_name,
r.name, r.description, r.id, r.test_id, r.create_time, r.update_time, r.status,
project.name AS project_name
FROM api_test_report r JOIN api_test t ON r.test_id = t.id
@ -50,4 +50,16 @@
ORDER BY r.update_time DESC
</select>
<select id="selectDashboardTests" resultType="io.metersphere.dto.DashboardTestDTO">
SELECT create_time AS date, count(api_test_report.id) AS count,
date_format(from_unixtime(create_time / 1000), '%Y-%m-%d') AS x
FROM api_test_report
WHERE test_id IN (SELECT api_test.id
FROM api_test
JOIN project ON api_test.project_id = project.id
WHERE workspace_id = #{workspaceId,jdbcType=VARCHAR})
AND create_time > #{startTimestamp}
GROUP BY x
</select>
</mapper>

View File

@ -73,7 +73,7 @@
return '/api/' + item.id;
},
router: function (item) {
return {name: 'fucPlan', params: {projectId: item.id, projectName: item.name}}
return {name: 'ApiTestList', params: {projectId: item.id, projectName: item.name}}
}
},
testRecent: {

View File

@ -1,6 +1,6 @@
<template>
<ms-container>
<ms-main-container>
<ms-main-container v-loading="result.loading">
<el-row :gutter="20">
<el-col :span="12">
<ms-api-test-recent-list/>
@ -9,6 +9,9 @@
<ms-api-report-recent-list/>
</el-col>
</el-row>
<el-row>
<ms-test-heatmap :values="values"></ms-test-heatmap>
</el-row>
</ms-main-container>
</ms-container>
@ -19,13 +22,34 @@
import MsMainContainer from "../../common/components/MsMainContainer";
import MsApiTestRecentList from "./ApiTestRecentList";
import MsApiReportRecentList from "./ApiReportRecentList";
import MsTestHeatmap from "../../common/components/MsTestHeatmap";
export default {
name: "ApiTestHome",
components: {MsApiReportRecentList, MsApiTestRecentList, MsMainContainer, MsContainer}
components: {MsTestHeatmap, MsApiReportRecentList, MsApiTestRecentList, MsMainContainer, MsContainer},
data() {
return {
values: [],
result: {},
}
},
mounted() {
this.result = this.$get('/api/report/dashboard/tests', response => {
this.values = response.data;
});
},
}
</script>
<style scoped>
.el-row {
margin-bottom: 20px;
}
.el-row:last-child {
margin-bottom: 0;
}
</style>

View File

@ -59,11 +59,11 @@
}
},
beforeRouteEnter(to, from, next) {
next(self => {
self.testId = to.params.testId;
self.search();
});
watch: {
'$route'(to) {
this.testId = to.params.testId;
this.search();
}
},
methods: {

View File

@ -3,7 +3,7 @@
<el-button type="success" plain @click="search">{{$t('api_report.title')}}</el-button>
<el-dialog :title="$t('api_report.title')" :visible.sync="reportVisible">
<el-table :data="tableData">
<el-table :data="tableData" v-loading="result.loading">
<el-table-column :label="$t('commons.name')" width="150" show-overflow-tooltip>
<template v-slot:default="scope">
<el-link type="info" @click="link(scope.row)">{{ scope.row.name }}</el-link>
@ -37,6 +37,8 @@
components: {MsApiReportStatus},
props: ["testId"],
data() {
return {
reportVisible: false,
@ -50,7 +52,8 @@
search() {
this.reportVisible = true;
this.result = this.$get("/api/report/recent/99", response => {
let url = "/api/report/list/" + this.testId;
this.result = this.$get(url, response => {
this.tableData = response.data;
});
},

View File

@ -26,7 +26,7 @@
<el-button type="warning" plain @click="cancel">{{$t('commons.cancel')}}</el-button>
<ms-api-report-dialog/>
<ms-api-report-dialog :test-id="id" v-if="id"/>
</el-row>
</el-header>
<ms-api-scenario-config :scenarios="test.scenarioDefinition" ref="config"/>

View File

@ -63,11 +63,11 @@
}
},
beforeRouteEnter(to, from, next) {
next(self => {
self.projectId = to.params.projectId;
self.search();
});
watch: {
'$route'(to) {
this.projectId = to.params.projectId;
this.search();
}
},
methods: {

View File

@ -34,7 +34,9 @@
},
watch: {
'$route'(to) {
if (to.matched.length > 0) {
this.activeIndex = to.matched[0].path;
}
this.handleSelect(this.activeIndex);
}
},