编辑测试时回显一部分数据
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;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
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.dto.LoadTestDTO;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.LoadTestService;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -18,44 +20,20 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/testplan")
|
||||
public class TestPlanController {
|
||||
private static List<LoadTestDTO> loadTests = Collections.synchronizedList(new ArrayList<LoadTestDTO>());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public class LoadTestController {
|
||||
@Resource
|
||||
private LoadTestService loadTestService;
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
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.setTotal(loadTests.size());
|
||||
return PageUtils.setPageInfo(
|
||||
page,
|
||||
loadTests.stream().skip((goPage - 1) * pageSize).limit(pageSize).collect(Collectors.toList())
|
||||
);
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, loadTestService.list(request));
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
|
@ -65,13 +43,7 @@ public class TestPlanController {
|
|||
|
||||
@PostMapping("/delete")
|
||||
public void delete(@RequestBody DeleteTestPlanRequest request) {
|
||||
final Iterator<LoadTestDTO> iterator = loadTests.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (iterator.next().getId().equals(request.getId())) {
|
||||
iterator.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
loadTestService.delete(request);
|
||||
}
|
||||
|
||||
@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: {
|
||||
content: (route) => {
|
||||
window.console.log("route.params: " + route.params);
|
||||
return {
|
||||
...route.params
|
||||
}
|
||||
|
|
|
@ -125,8 +125,10 @@
|
|||
handleDelete(testPlan) {
|
||||
this.$alert('确认删除测试: ' + testPlan.name + "?", '', {
|
||||
confirmButtonText: '确定',
|
||||
callback: () => {
|
||||
this._handleDelete(testPlan);
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
this._handleDelete(testPlan);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<el-row>
|
||||
<el-col :span="10">
|
||||
<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
|
||||
v-for="item in projects"
|
||||
:key="item.id"
|
||||
|
@ -48,23 +48,9 @@
|
|||
data() {
|
||||
return {
|
||||
testPlan: {},
|
||||
listProjectPath: "/project/listAll",
|
||||
savePath: "/testplan/save",
|
||||
projects: [{
|
||||
id: '选项1',
|
||||
name: '黄金糕'
|
||||
}, {
|
||||
id: '选项2',
|
||||
name: '双皮奶'
|
||||
}, {
|
||||
id: '选项3',
|
||||
name: '蚵仔煎'
|
||||
}, {
|
||||
id: '选项4',
|
||||
name: '龙须面'
|
||||
}, {
|
||||
id: '选项5',
|
||||
name: '北京烤鸭'
|
||||
}],
|
||||
projects: [],
|
||||
active: '0',
|
||||
tabs: [{
|
||||
title: '场景配置',
|
||||
|
@ -82,12 +68,19 @@
|
|||
}
|
||||
},
|
||||
created() {
|
||||
window.console.log("testPlanObj: " + this.testPlanObj);
|
||||
if (this.testPlanObj) {
|
||||
this.testPlan = this.testPlanObj;
|
||||
}
|
||||
this.listProjects();
|
||||
},
|
||||
methods: {
|
||||
listProjects() {
|
||||
this.$get(this.listProjectPath).then(response => {
|
||||
this.projects = response.data.data;
|
||||
}).catch((response) => {
|
||||
this.$message.error(response.message);
|
||||
});
|
||||
},
|
||||
save() {
|
||||
if (!this.validTestPlan()) {
|
||||
return;
|
||||
|
|
|
@ -115,8 +115,10 @@
|
|||
handleDelete(file, index) {
|
||||
this.$alert('确认删除文件: ' + file.name + "?", '', {
|
||||
confirmButtonText: '确定',
|
||||
callback: () => {
|
||||
this._handleDelete(file, index);
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
this._handleDelete(file, index);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue