编辑测试时回显一部分数据
This commit is contained in:
parent
c9f185366c
commit
6f70ceea9a
|
@ -0,0 +1,10 @@
|
||||||
|
package io.metersphere.base.mapper.ext;
|
||||||
|
|
||||||
|
import io.metersphere.dto.LoadTestDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface ExtLoadTestMapper {
|
||||||
|
List<LoadTestDTO> list(Map<String, Object> params);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="io.metersphere.base.mapper.ext.ExtLoadTestMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="io.metersphere.dto.LoadTestDTO"
|
||||||
|
extends="io.metersphere.base.mapper.LoadTestMapper.BaseResultMap">
|
||||||
|
<result column="project_name" property="projectName"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="list" resultMap="BaseResultMap">
|
||||||
|
select load_test.*, project.name as project_name
|
||||||
|
from load_test
|
||||||
|
left join project on load_test.project_id = project.id
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.controller;
|
package io.metersphere.controller;
|
||||||
|
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
import io.metersphere.controller.request.testplan.DeleteTestPlanRequest;
|
import io.metersphere.controller.request.testplan.DeleteTestPlanRequest;
|
||||||
|
@ -9,6 +10,7 @@ import io.metersphere.controller.request.testplan.QueryTestPlanRequest;
|
||||||
import io.metersphere.controller.request.testplan.SaveTestPlanRequest;
|
import io.metersphere.controller.request.testplan.SaveTestPlanRequest;
|
||||||
import io.metersphere.dto.LoadTestDTO;
|
import io.metersphere.dto.LoadTestDTO;
|
||||||
import io.metersphere.service.FileService;
|
import io.metersphere.service.FileService;
|
||||||
|
import io.metersphere.service.LoadTestService;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
@ -18,44 +20,20 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "/testplan")
|
@RequestMapping(value = "/testplan")
|
||||||
public class TestPlanController {
|
public class LoadTestController {
|
||||||
private static List<LoadTestDTO> loadTests = Collections.synchronizedList(new ArrayList<LoadTestDTO>());
|
@Resource
|
||||||
|
private LoadTestService loadTestService;
|
||||||
static {
|
|
||||||
// 模拟数据
|
|
||||||
for (int i = 0; i < 100; i++) {
|
|
||||||
final LoadTestDTO loadTest = new LoadTestDTO();
|
|
||||||
loadTest.setId(String.valueOf(i));
|
|
||||||
loadTest.setName("load test " + i);
|
|
||||||
loadTest.setDescription("no description");
|
|
||||||
loadTest.setScenarioDefinition("no scenario description");
|
|
||||||
loadTest.setCreateTime(System.currentTimeMillis());
|
|
||||||
loadTest.setUpdateTime(System.currentTimeMillis());
|
|
||||||
loadTest.setProjectId(String.valueOf(i));
|
|
||||||
loadTest.setProjectName("project " + i);
|
|
||||||
loadTests.add(loadTest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
|
||||||
@PostMapping("/list/{goPage}/{pageSize}")
|
@PostMapping("/list/{goPage}/{pageSize}")
|
||||||
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
|
public Pager<List<LoadTestDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
|
||||||
final Page page = new Page((int) Math.ceil(loadTests.size() * 1.0 / pageSize), pageSize);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
page.setTotal(loadTests.size());
|
return PageUtils.setPageInfo(page, loadTestService.list(request));
|
||||||
return PageUtils.setPageInfo(
|
|
||||||
page,
|
|
||||||
loadTests.stream().skip((goPage - 1) * pageSize).limit(pageSize).collect(Collectors.toList())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/save")
|
@PostMapping("/save")
|
||||||
|
@ -65,13 +43,7 @@ public class TestPlanController {
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public void delete(@RequestBody DeleteTestPlanRequest request) {
|
public void delete(@RequestBody DeleteTestPlanRequest request) {
|
||||||
final Iterator<LoadTestDTO> iterator = loadTests.iterator();
|
loadTestService.delete(request);
|
||||||
while (iterator.hasNext()) {
|
|
||||||
if (iterator.next().getId().equals(request.getId())) {
|
|
||||||
iterator.remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/file/upload")
|
@PostMapping("/file/upload")
|
|
@ -0,0 +1,23 @@
|
||||||
|
package io.metersphere.controller;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.Project;
|
||||||
|
import io.metersphere.service.ProjectService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/project")
|
||||||
|
public class ProjectController {
|
||||||
|
@Resource
|
||||||
|
private ProjectService projectService;
|
||||||
|
|
||||||
|
@GetMapping("/listAll")
|
||||||
|
public List<Project> listAll() {
|
||||||
|
/// todo: 限制workspace和org
|
||||||
|
return projectService.listAll();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package io.metersphere.service;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.*;
|
||||||
|
import io.metersphere.base.mapper.LoadTestMapper;
|
||||||
|
import io.metersphere.base.mapper.OrganizationMapper;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
|
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
|
||||||
|
import io.metersphere.controller.request.testplan.DeleteTestPlanRequest;
|
||||||
|
import io.metersphere.controller.request.testplan.QueryTestPlanRequest;
|
||||||
|
import io.metersphere.dto.LoadTestDTO;
|
||||||
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class LoadTestService {
|
||||||
|
@Resource
|
||||||
|
private LoadTestMapper loadTestMapper;
|
||||||
|
@Resource
|
||||||
|
private ExtLoadTestMapper extLoadTestMapper;
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
// 测试,模拟数据
|
||||||
|
@PostConstruct
|
||||||
|
public void initData() {
|
||||||
|
if (!CollectionUtils.isEmpty(loadTestMapper.selectByExample(null))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<Project> projects = projectMapper.selectByExample(null);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs();
|
||||||
|
loadTest.setId(UUID.randomUUID().toString());
|
||||||
|
loadTest.setName("load test " + i);
|
||||||
|
loadTest.setProjectId(projects.get(RandomUtils.nextInt(0, projects.size())).getId());
|
||||||
|
loadTest.setCreateTime(System.currentTimeMillis());
|
||||||
|
loadTest.setUpdateTime(System.currentTimeMillis());
|
||||||
|
loadTest.setScenarioDefinition(UUID.randomUUID().toString());
|
||||||
|
loadTest.setDescription(UUID.randomUUID().toString());
|
||||||
|
loadTestMapper.insert(loadTest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
|
||||||
|
return extLoadTestMapper.list(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(DeleteTestPlanRequest request) {
|
||||||
|
LoadTestExample loadTestExample = new LoadTestExample();
|
||||||
|
loadTestExample.createCriteria().andIdEqualTo(request.getId());
|
||||||
|
|
||||||
|
loadTestMapper.deleteByExample(loadTestExample);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package io.metersphere.service;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.Project;
|
||||||
|
import io.metersphere.base.mapper.ProjectMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ProjectService {
|
||||||
|
@Resource
|
||||||
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
public List<Project> listAll() {
|
||||||
|
return projectMapper.selectByExample(null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -63,7 +63,6 @@ const router = new VueRouter({
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
content: (route) => {
|
content: (route) => {
|
||||||
window.console.log("route.params: " + route.params);
|
|
||||||
return {
|
return {
|
||||||
...route.params
|
...route.params
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,9 +125,11 @@
|
||||||
handleDelete(testPlan) {
|
handleDelete(testPlan) {
|
||||||
this.$alert('确认删除测试: ' + testPlan.name + "?", '', {
|
this.$alert('确认删除测试: ' + testPlan.name + "?", '', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
callback: () => {
|
callback: (action) => {
|
||||||
|
if (action === 'confirm') {
|
||||||
this._handleDelete(testPlan);
|
this._handleDelete(testPlan);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
_handleDelete(testPlan) {
|
_handleDelete(testPlan) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="10">
|
<el-col :span="10">
|
||||||
<el-input placeholder="请输入名称" v-model="testPlan.name" class="input-with-select">
|
<el-input placeholder="请输入名称" v-model="testPlan.name" class="input-with-select">
|
||||||
<el-select v-model="testPlan.project" slot="prepend" placeholder="请选择项目">
|
<el-select v-model="testPlan.projectId" slot="prepend" placeholder="请选择项目">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in projects"
|
v-for="item in projects"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
|
@ -48,23 +48,9 @@
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
testPlan: {},
|
testPlan: {},
|
||||||
|
listProjectPath: "/project/listAll",
|
||||||
savePath: "/testplan/save",
|
savePath: "/testplan/save",
|
||||||
projects: [{
|
projects: [],
|
||||||
id: '选项1',
|
|
||||||
name: '黄金糕'
|
|
||||||
}, {
|
|
||||||
id: '选项2',
|
|
||||||
name: '双皮奶'
|
|
||||||
}, {
|
|
||||||
id: '选项3',
|
|
||||||
name: '蚵仔煎'
|
|
||||||
}, {
|
|
||||||
id: '选项4',
|
|
||||||
name: '龙须面'
|
|
||||||
}, {
|
|
||||||
id: '选项5',
|
|
||||||
name: '北京烤鸭'
|
|
||||||
}],
|
|
||||||
active: '0',
|
active: '0',
|
||||||
tabs: [{
|
tabs: [{
|
||||||
title: '场景配置',
|
title: '场景配置',
|
||||||
|
@ -82,12 +68,19 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
window.console.log("testPlanObj: " + this.testPlanObj);
|
|
||||||
if (this.testPlanObj) {
|
if (this.testPlanObj) {
|
||||||
this.testPlan = this.testPlanObj;
|
this.testPlan = this.testPlanObj;
|
||||||
}
|
}
|
||||||
|
this.listProjects();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
listProjects() {
|
||||||
|
this.$get(this.listProjectPath).then(response => {
|
||||||
|
this.projects = response.data.data;
|
||||||
|
}).catch((response) => {
|
||||||
|
this.$message.error(response.message);
|
||||||
|
});
|
||||||
|
},
|
||||||
save() {
|
save() {
|
||||||
if (!this.validTestPlan()) {
|
if (!this.validTestPlan()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -115,9 +115,11 @@
|
||||||
handleDelete(file, index) {
|
handleDelete(file, index) {
|
||||||
this.$alert('确认删除文件: ' + file.name + "?", '', {
|
this.$alert('确认删除文件: ' + file.name + "?", '', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
callback: () => {
|
callback: (action) => {
|
||||||
|
if (action === 'confirm') {
|
||||||
this._handleDelete(file, index);
|
this._handleDelete(file, index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
_handleDelete(file, index) {
|
_handleDelete(file, index) {
|
||||||
|
|
Loading…
Reference in New Issue