diff --git a/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java b/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java index 3bf7e23..005865c 100644 --- a/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java +++ b/test-test/src/main/java/com/test/test/controller/PerformanceTestController.java @@ -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 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)); diff --git a/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestCaseQO.java b/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestCaseQO.java new file mode 100644 index 0000000..6a3f2f4 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestCaseQO.java @@ -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; +} diff --git a/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestQO.java b/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestQO.java new file mode 100644 index 0000000..786c425 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/qo/PerformanceTestQO.java @@ -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 performanceTestCaseVOList = new ArrayList<>(); +} diff --git a/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestCaseVO.java b/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestCaseVO.java new file mode 100644 index 0000000..4282a32 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestCaseVO.java @@ -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; +} diff --git a/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestVO.java b/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestVO.java new file mode 100644 index 0000000..7248428 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/vo/PerformanceTestVO.java @@ -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 performanceTestCaseVOList = new ArrayList<>(); +} diff --git a/test-test/src/main/java/com/test/test/mapper/TestCaseMapper.java b/test-test/src/main/java/com/test/test/mapper/TestCaseMapper.java index 9b224eb..ddf6d6f 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestCaseMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestCaseMapper.java @@ -20,6 +20,11 @@ public interface TestCaseMapper */ List selectTestCaseList(TestCaseListQO qo); + /** + * 查询用例列表 + */ + List selectTestCaseListNoGroupId(TestCase testCase); + /** * 新增用例 */ diff --git a/test-test/src/main/java/com/test/test/service/IPerformanceTestService.java b/test-test/src/main/java/com/test/test/service/IPerformanceTestService.java index 37d5ab4..56197fb 100644 --- a/test-test/src/main/java/com/test/test/service/IPerformanceTestService.java +++ b/test-test/src/main/java/com/test/test/service/IPerformanceTestService.java @@ -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); /** * 批量删除性能测试 diff --git a/test-test/src/main/java/com/test/test/service/ITestCaseService.java b/test-test/src/main/java/com/test/test/service/ITestCaseService.java index aa6ba98..b698465 100644 --- a/test-test/src/main/java/com/test/test/service/ITestCaseService.java +++ b/test-test/src/main/java/com/test/test/service/ITestCaseService.java @@ -29,6 +29,13 @@ public interface ITestCaseService */ public List selectTestCaseList(TestCaseListQO qo); + /** + * 查询用例列表 + * @param testCase + * @return + */ + List selectTestCaseList(TestCase testCase); + /** * 新增用例 * diff --git a/test-test/src/main/java/com/test/test/service/impl/PerformanceTestServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/PerformanceTestServiceImpl.java index 1f16d9c..0ed7905 100644 --- a/test-test/src/main/java/com/test/test/service/impl/PerformanceTestServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/PerformanceTestServiceImpl.java @@ -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 performanceTestCaseList = performanceTestCaseMapper.selectPerformanceTestCaseList(performanceTestCase); + List 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 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 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 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; } /** diff --git a/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java index 90247ee..efd4c18 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java @@ -76,6 +76,11 @@ public class TestCaseServiceImpl implements ITestCaseService return testCaseMapper.selectTestCaseList(qo); } + @Override + public List selectTestCaseList(TestCase testCase) { + return testCaseMapper.selectTestCaseListNoGroupId(testCase); + } + /** * 新增用例 * diff --git a/test-test/src/main/resources/mapper/test/PerformanceTestCaseMapper.xml b/test-test/src/main/resources/mapper/test/PerformanceTestCaseMapper.xml index e900734..e721499 100644 --- a/test-test/src/main/resources/mapper/test/PerformanceTestCaseMapper.xml +++ b/test-test/src/main/resources/mapper/test/PerformanceTestCaseMapper.xml @@ -56,7 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from performance_test_case where id = #{id} + delete from performance_test_case where performance_id = #{id} diff --git a/test-test/src/main/resources/mapper/test/PerformanceTestMapper.xml b/test-test/src/main/resources/mapper/test/PerformanceTestMapper.xml index 8aa8511..e554cc5 100644 --- a/test-test/src/main/resources/mapper/test/PerformanceTestMapper.xml +++ b/test-test/src/main/resources/mapper/test/PerformanceTestMapper.xml @@ -49,6 +49,7 @@ and rps_limit = #{rpsLimit} and status = #{status} + order by create_time desc - + insert into performance_test id, @@ -131,11 +132,11 @@ - delete from performance_test where id = #{id} + update performance_test set del_flag = '1' where id = #{id} - delete from performance_test where id in + update performance_test set del_flag = '1' where id in #{id} diff --git a/test-test/src/main/resources/mapper/test/TestCaseMapper.xml b/test-test/src/main/resources/mapper/test/TestCaseMapper.xml index 846430e..b73eb76 100644 --- a/test-test/src/main/resources/mapper/test/TestCaseMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestCaseMapper.xml @@ -41,6 +41,14 @@ order by create_time desc + +