测试任务执行前端功能

This commit is contained in:
liangdaliang
2025-03-19 15:48:00 +08:00
parent ad3e95bd73
commit ef2dcdac1f
7 changed files with 81 additions and 13 deletions

View File

@@ -6,16 +6,18 @@ import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.common.utils.DateUtils;
import com.test.test.domain.TestCase;
import com.test.common.utils.SecurityUtils;
import com.test.test.domain.TestTask;
import com.test.test.domain.qo.GroupIdQO;
import com.test.test.domain.qo.IDQO;
import com.test.test.service.ITestTaskService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 定时任务Controller
@@ -23,6 +25,10 @@ import java.util.List;
@RestController
@RequestMapping("/test/task")
public class TestTaskController extends BaseController {
@Value("${test.jmeterHomePath:/opt/apache-jmeter}")
private String jmeterHomePath;
@Resource
private ITestTaskService testTaskService;
@@ -73,5 +79,18 @@ public class TestTaskController extends BaseController {
return toAjax(testTaskService.deleteTestTaskById(qo.getId()));
}
/**
* 执行任务
*/
@Log(title = "任务", businessType = BusinessType.OTHER)
@PostMapping("/run")
public AjaxResult run(@RequestBody IDQO qo) {
// 异步执行任务
CompletableFuture.runAsync(() -> {
testTaskService.executeTestTaskById(qo.getId(), 2, null, jmeterHomePath, SecurityUtils.getUsername());
});
return toAjax(true);
}
}

View File

@@ -63,7 +63,7 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService {
int i = 1;
for (TestCaseResult testCaseResult : testCaseResultList) {
String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, testCaseResult.getExecuteTime());
testCaseResult.setTitle("结果" + i + "" + dateStr + "),状态:" + testCaseResult.getStatus());
testCaseResult.setTitle("结果" + i + "" + dateStr + "),状态:" + testCaseResult.getStatus() + "耗时ms" + testCaseResult.getUseTime());
i ++;
}
}

View File

@@ -110,9 +110,8 @@ public class TestTaskServiceImpl implements ITestTaskService {
@Override
public boolean executeTestTaskById(Long id, Integer triggerType, String environment, String jmeterHomePath, String operUser) {
TestTask testTask = testTaskMapper.selectTestTaskById(id);
if (testTask == null || testTask.getStatus() == null
|| testTask.getStatus() > 0 || "2".equals(testTask.getDelFlag())) {
log.error("定时任务已删除或未启用,不能执行!");
if (testTask == null || "2".equals(testTask.getDelFlag())) {
log.error("定时任务已删除,不能执行!");
return false;
}
TestTaskLog testTaskLog = new TestTaskLog();