refactor(性能测试): 重构部分接口,projectID, workspaceID使用接口传入的值

This commit is contained in:
Captain.B 2021-04-26 12:42:03 +08:00 committed by 刘瑞斌
parent 82026932c8
commit e5dbdcb83a
11 changed files with 204 additions and 199 deletions

View File

@ -29,12 +29,9 @@ public class PerformanceReportController {
@Resource
private ReportService reportService;
@GetMapping("/recent/{count}")
@PostMapping("/recent/{count}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public List<ReportDTO> recentProjects(@PathVariable int count) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
ReportRequest request = new ReportRequest();
request.setWorkspaceId(currentWorkspaceId);
public List<ReportDTO> recentProjects(@PathVariable int count, @RequestBody ReportRequest request) {
request.setUserId(SessionUtils.getUserId());
// 最近 `count` 个项目
PageHelper.startPage(1, count);
@ -43,8 +40,6 @@ public class PerformanceReportController {
@PostMapping("/list/all/{goPage}/{pageSize}")
public Pager<List<ReportDTO>> getReportList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ReportRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, reportService.getReportList(request));
}

View File

@ -55,8 +55,6 @@ public class PerformanceTestController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setProjectId(SessionUtils.getCurrentProjectId());
return PageUtils.setPageInfo(page, performanceTestService.list(request));
}

View File

@ -524,8 +524,8 @@ public class PerformanceTestService {
if (!resourceIds.isEmpty()) {
LoadTestExample example = new LoadTestExample();
LoadTestExample.Criteria criteria = example.createCriteria();
if (StringUtils.isNotBlank(SessionUtils.getCurrentProjectId())) {
criteria.andProjectIdEqualTo(SessionUtils.getCurrentProjectId());
if (StringUtils.isNotBlank(request.getProjectId())) {
criteria.andProjectIdEqualTo(request.getProjectId());
}
criteria.andIdIn(resourceIds);
List<LoadTest> loadTests = loadTestMapper.selectByExample(example);

View File

@ -69,13 +69,11 @@ public class ReportService {
orderRequest.setType("desc");
orders.add(orderRequest);
request.setOrders(orders);
request.setProjectId(SessionUtils.getCurrentProjectId());
return extLoadTestReportMapper.getReportList(request);
}
public List<ReportDTO> getReportList(ReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request.setProjectId(SessionUtils.getCurrentProjectId());
return extLoadTestReportMapper.getReportList(request);
}

View File

@ -1,7 +1,7 @@
<template>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<span class="title">{{$t('schedule.running_task')}}</span>
<span class="title">{{ $t('schedule.running_task') }}</span>
</template>
<el-table height="289" border :data="tableData" class="adjust-table table-content" @row-click="link">
<el-table-column prop="resourceName" :label="$t('schedule.test_name')" width="150" show-overflow-tooltip/>
@ -27,80 +27,81 @@
</template>
<script>
import {getCurrentWorkspaceId} from "../../../../common/js/utils";
import CrontabResult from "../../common/cron/CrontabResult";
import {SCHEDULE_TYPE} from "../../../../common/js/constants";
import {getCurrentProjectID, getCurrentWorkspaceId} from "../../../../common/js/utils";
import CrontabResult from "../../common/cron/CrontabResult";
import {SCHEDULE_TYPE} from "../../../../common/js/constants";
export default {
name: "MsScheduleList",
components: {CrontabResult},
data() {
return {
result: {},
tableData: [],
loading: false,
operators: {}
}
},
props: {
group: String
},
watch: {
group() {
this.init();
}
},
methods: {
search() {
if (this.operators.listUrl) {
this.result = this.$post(this.operators.listUrl, {
workspaceId: getCurrentWorkspaceId(),
group: this.group
}, response => {
this.tableData = response.data;
});
}
},
link(row) {
this.$router.push({
path: this.operators.linkUrl + row.resourceId,
})
},
update(schedule) {
this.result = this.$post(this.operators.updateUrl, schedule, response => {
this.search();
});
},
init() {
switch (this.group) {
case SCHEDULE_TYPE.API_TEST:
this.operators.listUrl = '/api/list/schedule';
this.operators.updateUrl = '/api/schedule/update';
this.operators.linkUrl = '/api/test/edit?id=';
break;
case SCHEDULE_TYPE.PERFORMANCE_TEST:
this.operators.listUrl = '/performance/list/schedule';
this.operators.updateUrl = '/performance/schedule/update';
this.operators.linkUrl = '/performance/test/edit/';
break;
default:
break;
}
this.search();
}
},
created() {
this.init();
},
activated() {
export default {
name: "MsScheduleList",
components: {CrontabResult},
data() {
return {
result: {},
tableData: [],
loading: false,
operators: {}
};
},
props: {
group: String
},
watch: {
group() {
this.init();
}
},
methods: {
search() {
if (this.operators.listUrl) {
this.result = this.$post(this.operators.listUrl, {
workspaceId: getCurrentWorkspaceId(),
projectId: getCurrentProjectID(),
group: this.group
}, response => {
this.tableData = response.data;
});
}
},
link(row) {
this.$router.push({
path: this.operators.linkUrl + row.resourceId,
});
},
update(schedule) {
this.result = this.$post(this.operators.updateUrl, schedule, response => {
this.search();
});
},
init() {
switch (this.group) {
case SCHEDULE_TYPE.API_TEST:
this.operators.listUrl = '/api/list/schedule';
this.operators.updateUrl = '/api/schedule/update';
this.operators.linkUrl = '/api/test/edit?id=';
break;
case SCHEDULE_TYPE.PERFORMANCE_TEST:
this.operators.listUrl = '/performance/list/schedule';
this.operators.updateUrl = '/performance/schedule/update';
this.operators.linkUrl = '/performance/test/edit/';
break;
default:
break;
}
this.search();
}
},
created() {
this.init();
},
activated() {
this.init();
}
};
</script>
<style scoped>
.el-table {
cursor: pointer;
}
.el-table {
cursor: pointer;
}
</style>

View File

@ -2,54 +2,59 @@
<div v-loading="result.loading">
<div class="recent-text">
<i class="el-icon-time"/>
<span>{{options.title}}</span>
<span>{{ options.title }}</span>
<i class="el-icon-refresh" @click="recent"/>
</div>
<el-menu-item :key="i.id" v-for="i in items" :index="getIndex(i)" :route="getRouter(i)">
<template slot="title">
<div class="title">{{ i.name }}</div>
<div class="time" v-if="options.showTime && i.updateTime">{{ i.updateTime | timestampFormatDate}}</div>
<div class="time" v-if="options.showTime && i.updateTime">{{ i.updateTime | timestampFormatDate }}</div>
</template>
</el-menu-item>
</div>
</template>
<script>
import {hasRoles} from "../../../../common/js/utils";
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "../../../../common/js/constants";
import {hasRoles} from "@/common/js/utils";
import {ROLE_TEST_MANAGER, ROLE_TEST_USER, ROLE_TEST_VIEWER} from "@/common/js/constants";
export default {
name: "MsRecentList",
props: {
options: Object
export default {
name: "MsRecentList",
props: {
options: Object
},
mounted() {
this.recent();
},
data() {
return {
result: {},
items: []
};
},
computed: {
getIndex: function () {
return function (item) {
return this.options.index(item);
};
},
mounted() {
this.recent();
},
data() {
return {
result: {},
items: []
}
},
computed: {
getIndex: function () {
return function (item) {
return this.options.index(item);
getRouter: function () {
return function (item) {
if (this.options.router) {
return this.options.router(item);
}
},
getRouter: function () {
return function (item) {
if (this.options.router) {
return this.options.router(item);
}
}
}
},
};
}
},
methods: {
recent: function () {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
methods: {
recent() {
if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
if (this.options.condition) {
this.result = this.$post(this.options.url, this.options.condition, (response) => {
this.items = response.data;
});
} else {
this.result = this.$get(this.options.url, (response) => {
this.items = response.data;
});
@ -57,45 +62,46 @@
}
}
}
};
</script>
<style scoped>
.recent-text {
padding: 0 10px;
margin-top: -5px;
line-height: 36px;
color: #777777;
background-color: #F5F5F5;
}
.recent-text {
padding: 0 10px;
margin-top: -5px;
line-height: 36px;
color: #777777;
background-color: #F5F5F5;
}
.recent-text span {
padding-left: 6px;
line-height: 36px;
}
.recent-text span {
padding-left: 6px;
line-height: 36px;
}
.recent-text .el-icon-refresh {
cursor: pointer;
float: right;
line-height: 36px;
}
.recent-text .el-icon-refresh {
cursor: pointer;
float: right;
line-height: 36px;
}
.recent-text .el-icon-refresh:hover {
color: #BBBBBB;
}
.recent-text .el-icon-refresh:hover {
color: #BBBBBB;
}
.title {
display: inline-block;
padding-left: 20px;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.title {
display: inline-block;
padding-left: 20px;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.time {
color: #C0C4CC;
display: inline-block;
padding-left: 20px;
float: right;
}
.time {
color: #C0C4CC;
display: inline-block;
padding-left: 20px;
float: right;
}
</style>

View File

@ -27,7 +27,7 @@
</el-submenu>
</el-menu>
</el-col>
<el-col :span="4" >
<el-col :span="4">
<el-row type="flex" justify="center">
<ms-create-test :to="'/performance/test/create'"/>
</el-row>
@ -46,6 +46,7 @@ import MsShowAll from "../../common/head/ShowAll";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
import SearchList from "@/business/components/common/head/SearchList";
import ProjectChange from "@/business/components/common/head/ProjectSwitch";
import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
export default {
name: "PerformanceHeaderMenus",
@ -71,6 +72,10 @@ export default {
reportRecent: {
title: this.$t('report.recent'),
url: "/performance/report/recent/5",
condition: {
workspaceId: getCurrentWorkspaceId(),
projectId: getCurrentProjectID(),
},
showTime: true,
index(item) {
return '/performance/report/view/' + item.id;
@ -79,7 +84,7 @@ export default {
}
},
currentProject: ''
}
};
},
methods: {
registerEvents() {
@ -95,7 +100,7 @@ export default {
beforeDestroy() {
PerformanceEvent.$off(LIST_CHANGE);
}
}
};
</script>

View File

@ -1,7 +1,7 @@
<template>
<el-card class="table-card" v-loading="result.loading">
<template v-slot:header>
<span class="title">{{$t('api_report.title')}}</span>
<span class="title">{{ $t('api_report.title') }}</span>
</template>
<el-table border :data="tableData" class="adjust-table table-content" @row-click="link" height="300px">
<el-table-column prop="name" :label="$t('commons.name')" width="150" show-overflow-tooltip/>
@ -20,7 +20,7 @@
<report-trigger-mode-item :trigger-mode="scope.row.triggerMode"/>
</template>
</el-table-column>
<el-table-column prop="status" :label="$t('commons.status')">
<el-table-column prop="status" :label="$t('commons.status')">
<template v-slot:default="{row}">
<ms-performance-report-status :row="row"/>
</template>
@ -31,45 +31,50 @@
<script>
import MsPerformanceReportStatus from "../report/PerformanceReportStatus";
import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem";
import MsPerformanceReportStatus from "../report/PerformanceReportStatus";
import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem";
import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
export default {
name: "MsPerformanceReportRecentList",
components: {ReportTriggerModeItem, MsPerformanceReportStatus},
data() {
return {
result: {},
tableData: []
}
},
export default {
name: "MsPerformanceReportRecentList",
components: {ReportTriggerModeItem, MsPerformanceReportStatus},
data() {
return {
result: {},
tableData: []
};
},
methods: {
search() {
this.result = this.$get("/performance/report/recent/5", response => {
this.tableData = response.data;
});
},
link(row) {
this.$router.push({
path: '/performance/report/view/' + row.id,
})
}
methods: {
search() {
let condition = {
workspaceId: getCurrentWorkspaceId(),
projectId: getCurrentProjectID(),
};
this.result = this.$post("/performance/report/recent/5", condition, response => {
this.tableData = response.data;
});
},
created() {
this.search();
},
activated() {
this.search();
link(row) {
this.$router.push({
path: '/performance/report/view/' + row.id,
});
}
},
created() {
this.search();
},
activated() {
this.search();
}
};
</script>
<style scoped>
.el-table {
cursor:pointer;
}
.el-table {
cursor: pointer;
}
</style>

View File

@ -98,7 +98,7 @@ import MsTablePagination from "../../common/pagination/TablePagination";
import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsPerformanceReportStatus from "./PerformanceReportStatus";
import {getCurrentProjectID} from "@/common/js/utils";
import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
import MsTableOperatorButton from "../../common/components/MsTableOperatorButton";
import ReportTriggerModeItem from "../../common/tableItem/ReportTriggerModeItem";
import {REPORT_CONFIGS} from "../../common/components/search/search-components";
@ -130,7 +130,6 @@ export default {
data() {
return {
result: {},
queryPath: "/performance/report/list/all",
deletePath: "/performance/report/delete/",
condition: {
components: REPORT_CONFIGS
@ -184,7 +183,9 @@ export default {
if (!getCurrentProjectID()) {
return;
}
this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => {
this.condition.workspaceId = getCurrentWorkspaceId();
this.condition.projectId = getCurrentProjectID();
this.result = this.$post(this.buildPagePath('/performance/report/list/all'), this.condition, response => {
let data = response.data;
this.total = data.itemCount;
this.tableData = data.listObject;

View File

@ -50,6 +50,7 @@
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
import ReportTriggerModeItem from "@/business/components/common/tableItem/ReportTriggerModeItem";
import {WORKSPACE_ID} from "@/common/js/constants";
export default {
name: "SameTestReports",

View File

@ -94,11 +94,11 @@ import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer";
import MsPerformanceTestStatus from "./PerformanceTestStatus";
import MsTableOperators from "../../common/components/MsTableOperators";
import {getCurrentProjectID} from "@/common/js/utils";
import {getCurrentProjectID, getCurrentWorkspaceId} from "@/common/js/utils";
import MsTableHeader from "../../common/components/MsTableHeader";
import {TEST_CONFIGS} from "../../common/components/search/search-components";
import {LIST_CHANGE, PerformanceEvent} from "@/business/components/common/head/ListEvent";
import {WORKSPACE_ID} from "@/common/js/constants";
import {PROJECT_ID, WORKSPACE_ID} from "@/common/js/constants";
import {_filter, _sort} from "@/common/js/tableUtils";
export default {
@ -114,7 +114,6 @@ export default {
data() {
return {
result: {},
queryPath: "/performance/list",
deletePath: "/performance/delete",
condition: {
components: TEST_CONFIGS
@ -163,7 +162,7 @@ export default {
},
methods: {
getMaintainerOptions() {
let workspaceId = localStorage.getItem(WORKSPACE_ID);
let workspaceId = getCurrentWorkspaceId();
this.$post('/user/ws/member/tester/list', {workspaceId: workspaceId}, response => {
this.userFilters = response.data.map(u => {
return {text: u.name, value: u.id};
@ -171,13 +170,9 @@ export default {
});
},
initTableData() {
if (this.projectId !== 'all') {
this.condition.projectId = this.projectId;
if (!this.condition.projectId) {
return;
}
}
this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => {
this.condition.projectId = getCurrentProjectID();
this.condition.workspaceId = getCurrentWorkspaceId();
this.result = this.$post(this.buildPagePath('/performance/list'), this.condition, response => {
let data = response.data;
this.total = data.itemCount;
this.tableData = data.listObject;