性能测试接口

This commit is contained in:
2025-04-15 13:32:27 +08:00
parent cb7a7c947c
commit 949322600d
13 changed files with 322 additions and 29 deletions

View File

@@ -3,8 +3,13 @@ package com.test.test.controller;
import java.util.List;
import com.test.test.domain.PerformanceTest;
import com.test.test.domain.TestCase;
import com.test.test.domain.qo.PerformanceTestQO;
import com.test.test.domain.vo.PerformanceTestVO;
import com.test.test.service.IPerformanceTestService;
import com.test.test.service.ITestCaseService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,11 +34,15 @@ import com.test.common.core.page.TableDataInfo;
* @date 2025-04-14
*/
@RestController
@RequestMapping("/test/PerformanceTest")
@RequestMapping("/test/performanceTest")
@Slf4j
public class PerformanceTestController extends BaseController
{
@Autowired
private IPerformanceTestService performanceTestService;
@Autowired
private ITestCaseService testCaseService;
/**
* 查询性能测试列表
@@ -47,6 +56,14 @@ public class PerformanceTestController extends BaseController
return getDataTable(list);
}
@GetMapping("/testCaseList")
public TableDataInfo testCaseList(TestCase testCase)
{
startPage();
List<TestCase> testCaseList = testCaseService.selectTestCaseList(testCase);
return getDataTable(testCaseList);
}
/**
* 导出性能测试列表
*/
@@ -71,33 +88,75 @@ public class PerformanceTestController extends BaseController
}
/**
* 新增性能测试
* 新增保存性能测试
*/
// @PreAuthorize("@ss.hasPermi('system:test:add')")
@Log(title = "性能测试", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody PerformanceTest performanceTest)
@PostMapping("/add")
public AjaxResult add(@RequestBody PerformanceTestQO performanceTestQO)
{
return toAjax(performanceTestService.insertPerformanceTest(performanceTest));
try {
Long l = performanceTestService.insertPerformanceTest(performanceTestQO);
if (l > 0){
return success(l);
}
return error("新增失败!");
} catch (Exception e) {
log.info("新增失败!",e);
return error("新增失败!");
}
}
/**
* 新增保存性能测试
*/
// @PreAuthorize("@ss.hasPermi('system:test:add')")
@Log(title = "性能测试", businessType = BusinessType.INSERT)
@PostMapping("/addAndExecute")
public AjaxResult addAndExecute(@RequestBody PerformanceTestQO performanceTestQO)
{
try {
Long l = performanceTestService.insertPerformanceTest(performanceTestQO);
if (l > 0){
//todo 执行逻辑
return success(l);
}
return error("新增失败!");
} catch (Exception e) {
log.info("新增失败!",e);
return error("新增失败!");
}
}
/**
* 修改性能测试
* ·
*/
// @PreAuthorize("@ss.hasPermi('system:test:edit')")
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody PerformanceTest performanceTest)
public AjaxResult edit(@RequestBody PerformanceTestQO performanceTestQO)
{
return toAjax(performanceTestService.updatePerformanceTest(performanceTest));
try {
Long l = performanceTestService.updatePerformanceTest(performanceTestQO);
if (l > 0){
return success(l);
}
return error("修改失败!");
} catch (Exception e) {
log.info("修改失败!",e);
return error("修改失败!");
}
}
/**
* 删除性能测试
*/
// @PreAuthorize("@ss.hasPermi('system:test:remove')")
@Log(title = "性能测试", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
@Log(title = "性能测试", businessType = BusinessType.UPDATE)
@PutMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(performanceTestService.deletePerformanceTestByIds(ids));

View File

@@ -0,0 +1,13 @@
package com.test.test.domain.qo;
import lombok.Data;
@Data
public class PerformanceTestCaseQO {
/** 性能测试id逻辑外键 */
private Long performanceId;
/** 性能测试关联测试用例的id逻辑外键 */
private Long testCaseId;
/** 状态0关闭1开启默认1 */
private Integer status;
}

View File

@@ -0,0 +1,47 @@
package com.test.test.domain.qo;
import com.test.common.core.domain.BaseEntity;
import com.test.test.domain.vo.PerformanceTestCaseVO;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class PerformanceTestQO extends BaseEntity {
/** 主键 */
private Long id;
/** 性能测试名称 */
private String performanceName;
/** crontab表达式 */
private String crontab;
/** 定时任务状态0关闭1开启默认0 */
private Integer crontabStatus;
/** 并发线程数 */
private Integer concurrentThreads;
/** 在取样器错误后要执行的动作1继续2开始下一个线程轮询3停止线程4停止测试5立即停止测试 */
private Integer errorOperType;
/** 执行方式1按持续时间2按迭代次数 */
private Integer executeType;
/** 多少秒内线程建立完成默认0 */
private Integer rampUpSeconds;
/** 压测时长默认0 */
private Integer pressureHour;
/** 压测时长默认0 */
private Integer pressureMinute;
/** 压测时长默认0 */
private Integer pressureSecond;
/** 迭代次数默认0 */
private Integer loopCount;
/** rps状态0关闭1开启默认0 */
private Integer rpsStatus;
/** 每分钟rps上限数默认0 */
private Integer rpsLimit;
/** 是否已执行完成状态0否1是默认0 */
private String status;
/** 0,正常,1,删除 */
private String delFlag;
private List<PerformanceTestCaseQO> performanceTestCaseVOList = new ArrayList<>();
}

View File

@@ -0,0 +1,18 @@
package com.test.test.domain.vo;
import com.test.common.annotation.Excel;
import lombok.Data;
@Data
public class PerformanceTestCaseVO {
/** 主键 */
private Long id;
/** 性能测试id逻辑外键 */
private Long performanceId;
/** 性能测试关联测试用例的id逻辑外键 */
private Long testCaseId;
/** 性能测试关联测试用例的名称 */
private String testCaseName;
/** 状态0关闭1开启默认1 */
private Integer status;
}

View File

@@ -0,0 +1,47 @@
package com.test.test.domain.vo;
import com.test.common.annotation.Excel;
import com.test.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class PerformanceTestVO extends BaseEntity {
/** 主键 */
private Long id;
/** 性能测试名称 */
private String performanceName;
/** crontab表达式 */
private String crontab;
/** 定时任务状态0关闭1开启默认0 */
private Integer crontabStatus;
/** 并发线程数 */
private Integer concurrentThreads;
/** 在取样器错误后要执行的动作1继续2开始下一个线程轮询3停止线程4停止测试5立即停止测试 */
private Integer errorOperType;
/** 执行方式1按持续时间2按迭代次数 */
private Integer executeType;
/** 多少秒内线程建立完成默认0 */
private Integer rampUpSeconds;
/** 压测时长默认0 */
private Integer pressureHour;
/** 压测时长默认0 */
private Integer pressureMinute;
/** 压测时长默认0 */
private Integer pressureSecond;
/** 迭代次数默认0 */
private Integer loopCount;
/** rps状态0关闭1开启默认0 */
private Integer rpsStatus;
/** 每分钟rps上限数默认0 */
private Integer rpsLimit;
/** 是否已执行完成状态0否1是默认0 */
private String status;
/** 0,正常,1,删除 */
private String delFlag;
private List<PerformanceTestCaseVO> performanceTestCaseVOList = new ArrayList<>();
}

View File

@@ -20,6 +20,11 @@ public interface TestCaseMapper
*/
List<TestCase> selectTestCaseList(TestCaseListQO qo);
/**
* 查询用例列表
*/
List<TestCase> selectTestCaseListNoGroupId(TestCase testCase);
/**
* 新增用例
*/

View File

@@ -1,6 +1,9 @@
package com.test.test.service;
import com.test.test.domain.PerformanceTest;
import com.test.test.domain.qo.PerformanceTestQO;
import com.test.test.domain.vo.PerformanceTestCaseVO;
import com.test.test.domain.vo.PerformanceTestVO;
import java.util.List;
@@ -18,7 +21,7 @@ public interface IPerformanceTestService
* @param id 性能测试主键
* @return 性能测试
*/
public PerformanceTest selectPerformanceTestById(Long id);
public PerformanceTestVO selectPerformanceTestById(Long id);
/**
* 查询性能测试列表
@@ -31,10 +34,10 @@ public interface IPerformanceTestService
/**
* 新增性能测试
*
* @param performanceTest 性能测试
* @param performanceTestQO 性能测试
* @return 结果
*/
public int insertPerformanceTest(PerformanceTest performanceTest);
public Long insertPerformanceTest(PerformanceTestQO performanceTestQO);
/**
* 修改性能测试
@@ -42,7 +45,7 @@ public interface IPerformanceTestService
* @param performanceTest 性能测试
* @return 结果
*/
public int updatePerformanceTest(PerformanceTest performanceTest);
public Long updatePerformanceTest(PerformanceTestQO performanceTest);
/**
* 批量删除性能测试

View File

@@ -29,6 +29,13 @@ public interface ITestCaseService
*/
public List<TestCase> selectTestCaseList(TestCaseListQO qo);
/**
* 查询用例列表
* @param testCase
* @return
*/
List<TestCase> selectTestCaseList(TestCase testCase);
/**
* 新增用例
*

View File

@@ -1,12 +1,26 @@
package com.test.test.service.impl;
import java.util.Collections;
import java.util.List;
import com.test.common.utils.DateUtils;
import com.test.common.utils.SecurityUtils;
import com.test.test.domain.PerformanceTest;
import com.test.test.domain.PerformanceTestCase;
import com.test.test.domain.TestCase;
import com.test.test.domain.qo.PerformanceTestCaseQO;
import com.test.test.domain.qo.PerformanceTestQO;
import com.test.test.domain.vo.PerformanceTestCaseVO;
import com.test.test.domain.vo.PerformanceTestVO;
import com.test.test.mapper.PerformanceTestCaseMapper;
import com.test.test.mapper.PerformanceTestMapper;
import com.test.test.mapper.TestCaseMapper;
import com.test.test.service.IPerformanceTestService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
/**
@@ -18,8 +32,12 @@ import org.springframework.stereotype.Service;
@Service
public class PerformanceTestServiceImpl implements IPerformanceTestService
{
@Autowired
@Resource
private PerformanceTestMapper performanceTestMapper;
@Resource
private PerformanceTestCaseMapper performanceTestCaseMapper;
@Resource
private TestCaseMapper testCaseMapper;
/**
* 查询性能测试
@@ -28,9 +46,26 @@ public class PerformanceTestServiceImpl implements IPerformanceTestService
* @return 性能测试
*/
@Override
public PerformanceTest selectPerformanceTestById(Long id)
public PerformanceTestVO selectPerformanceTestById(Long id)
{
return performanceTestMapper.selectPerformanceTestById(id);
PerformanceTestVO performanceTestVO = new PerformanceTestVO();
PerformanceTest performanceTest = performanceTestMapper.selectPerformanceTestById(id);
BeanUtils.copyProperties(performanceTest, performanceTestVO);
//通过id查询performance_test_case信息
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
performanceTestCase.setPerformanceId(performanceTest.getId());
List<PerformanceTestCase> performanceTestCaseList = performanceTestCaseMapper.selectPerformanceTestCaseList(performanceTestCase);
List<PerformanceTestCaseVO> performanceTestCaseVOList = performanceTestVO.getPerformanceTestCaseVOList();
for (PerformanceTestCase testCase : performanceTestCaseList) {
PerformanceTestCaseVO performanceTestCaseVO = new PerformanceTestCaseVO();
BeanUtils.copyProperties(testCase, performanceTestCaseVO);
performanceTestCaseVOList.add(performanceTestCaseVO);
}
for (PerformanceTestCaseVO performanceTestCaseVO : performanceTestCaseVOList) {
TestCase caseEntity = testCaseMapper.selectTestCaseById(performanceTestCaseVO.getId());
performanceTestCaseVO.setTestCaseName(caseEntity.getName());
}
return performanceTestVO;
}
/**
@@ -42,33 +77,78 @@ public class PerformanceTestServiceImpl implements IPerformanceTestService
@Override
public List<PerformanceTest> selectPerformanceTestList(PerformanceTest performanceTest)
{
//默认显示未删除
performanceTest.setDelFlag("0");
return performanceTestMapper.selectPerformanceTestList(performanceTest);
}
/**
* 新增性能测试
*
* @param performanceTest 性能测试
* @param performanceTestQO 性能测试
* @return 结果
*/
@Override
public int insertPerformanceTest(PerformanceTest performanceTest)
@Transactional
public Long insertPerformanceTest(PerformanceTestQO performanceTestQO)
{
performanceTest.setCreateTime(DateUtils.getNowDate());
return performanceTestMapper.insertPerformanceTest(performanceTest);
PerformanceTest performanceTest = new PerformanceTest();
//默认未删除
performanceTestQO.setDelFlag("0");
performanceTestQO.setCreateTime(DateUtils.getNowDate());
performanceTestQO.setCreateBy(SecurityUtils.getUsername());
performanceTestQO.setUpdateBy(SecurityUtils.getUsername());
BeanUtils.copyProperties(performanceTestQO,performanceTest);
//新增performance_test
performanceTestMapper.insertPerformanceTest(performanceTest);
//新增后的主键
Long id = performanceTest.getId();
List<PerformanceTestCaseQO> performanceTestCaseQOList = performanceTestQO.getPerformanceTestCaseVOList();
if (CollectionUtils.isEmpty(performanceTestCaseQOList)){
return 0L;
}
for (PerformanceTestCaseQO performanceTestCaseQO : performanceTestCaseQOList) {
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
performanceTestCaseQO.setPerformanceId(id);
performanceTestCaseQO.setStatus(performanceTestCaseQO.getStatus());
BeanUtils.copyProperties(performanceTestCaseQO,performanceTestCase);
performanceTestCaseMapper.insertPerformanceTestCase(performanceTestCase);
}
return id;
}
/**
* 修改性能测试
*
* @param performanceTest 性能测试
* @param performanceTestQO 性能测试
* @return 结果
*/
@Override
public int updatePerformanceTest(PerformanceTest performanceTest)
@Transactional
public Long updatePerformanceTest(PerformanceTestQO performanceTestQO)
{
performanceTest.setUpdateTime(DateUtils.getNowDate());
return performanceTestMapper.updatePerformanceTest(performanceTest);
Long id = performanceTestQO.getId();
PerformanceTest performanceTest = new PerformanceTest();
performanceTestQO.setUpdateTime(DateUtils.getNowDate());
performanceTestQO.setUpdateBy(SecurityUtils.getUsername());
BeanUtils.copyProperties(performanceTestQO,performanceTest);
performanceTestMapper.updatePerformanceTest(performanceTest);
//先删除 performance_test_case
performanceTestCaseMapper.deletePerformanceTestCaseById(id);
//再新增
List<PerformanceTestCaseQO> performanceTestCaseQOList = performanceTestQO.getPerformanceTestCaseVOList();
if (CollectionUtils.isEmpty(performanceTestCaseQOList)){
return 0L;
}
for (PerformanceTestCaseQO performanceTestCaseQO : performanceTestCaseQOList) {
PerformanceTestCase performanceTestCase = new PerformanceTestCase();
performanceTestCaseQO.setPerformanceId(id);
performanceTestCaseQO.setStatus(performanceTestCaseQO.getStatus());
BeanUtils.copyProperties(performanceTestCaseQO,performanceTestCase);
performanceTestCaseMapper.insertPerformanceTestCase(performanceTestCase);
}
return id;
}
/**

View File

@@ -76,6 +76,11 @@ public class TestCaseServiceImpl implements ITestCaseService
return testCaseMapper.selectTestCaseList(qo);
}
@Override
public List<TestCase> selectTestCaseList(TestCase testCase) {
return testCaseMapper.selectTestCaseListNoGroupId(testCase);
}
/**
* 新增用例
*

View File

@@ -56,7 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deletePerformanceTestCaseById" parameterType="Long">
delete from performance_test_case where id = #{id}
delete from performance_test_case where performance_id = #{id}
</delete>
<delete id="deletePerformanceTestCaseByIds" parameterType="String">

View File

@@ -49,6 +49,7 @@
<if test="rpsLimit != null "> and rps_limit = #{rpsLimit}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
</where>
order by create_time desc
</select>
<select id="selectPerformanceTestById" parameterType="Long" resultMap="PerformanceTestResult">
@@ -56,7 +57,7 @@
where id = #{id}
</select>
<insert id="insertPerformanceTest" parameterType="PerformanceTest">
<insert id="insertPerformanceTest" parameterType="PerformanceTest" useGeneratedKeys="true" keyProperty="id">
insert into performance_test
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
@@ -131,11 +132,11 @@
</update>
<delete id="deletePerformanceTestById" parameterType="Long">
delete from performance_test where id = #{id}
update performance_test set del_flag = '1' where id = #{id}
</delete>
<delete id="deletePerformanceTestByIds" parameterType="String">
delete from performance_test where id in
update performance_test set del_flag = '1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>

View File

@@ -41,6 +41,14 @@
order by create_time desc
</select>
<select id="selectTestCaseListNoGroupId" parameterType="TestCase" resultMap="TestCaseResult">
<include refid="selectTestCaseVo"/>
<where>
del_flag = '0'
</where>
order by create_time desc
</select>
<select id="selectTestCaseById" parameterType="Long" resultMap="TestCaseResult">
<include refid="selectTestCaseVo"/>
where id = #{id}