refactor(测试计划): 重构测试计划执行报告状态处理
This commit is contained in:
parent
6b0337cc74
commit
5edf97a356
|
@ -14,8 +14,10 @@ import io.metersphere.base.mapper.ext.ExtApiExecutionQueueMapper;
|
||||||
import io.metersphere.commons.constants.ApiRunMode;
|
import io.metersphere.commons.constants.ApiRunMode;
|
||||||
import io.metersphere.commons.constants.TestPlanReportStatus;
|
import io.metersphere.commons.constants.TestPlanReportStatus;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.constants.RunModeConstants;
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.dto.ResultDTO;
|
import io.metersphere.dto.ResultDTO;
|
||||||
|
import io.metersphere.track.service.TestPlanReportService;
|
||||||
import io.metersphere.utils.LoggerUtil;
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -159,6 +161,10 @@ public class ApiExecutionQueueService {
|
||||||
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
if (StringUtils.equals(dto.getReportType(), RunModeConstants.SET_REPORT.toString())) {
|
||||||
apiScenarioReportService.margeReport(dto.getReportId());
|
apiScenarioReportService.margeReport(dto.getReportId());
|
||||||
}
|
}
|
||||||
|
// 更新测试计划报告
|
||||||
|
if (StringUtils.isNotEmpty(dto.getTestPlanReportId())) {
|
||||||
|
CommonBeanFactory.getBean(TestPlanReportService.class).finishedTestPlanReport(dto.getTestPlanReportId());
|
||||||
|
}
|
||||||
queueMapper.deleteByPrimaryKey(executionQueue.getId());
|
queueMapper.deleteByPrimaryKey(executionQueue.getId());
|
||||||
LoggerUtil.info("队列:" + dto.getQueueId() + " 执行结束");
|
LoggerUtil.info("队列:" + dto.getQueueId() + " 执行结束");
|
||||||
}
|
}
|
||||||
|
@ -210,6 +216,16 @@ public class ApiExecutionQueueService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 处理测试计划报告
|
||||||
|
List<ApiExecutionQueue> queues = extApiExecutionQueueMapper.findTestPlanReportQueue();
|
||||||
|
if (CollectionUtils.isNotEmpty(queues)) {
|
||||||
|
queues.forEach(item -> {
|
||||||
|
// 更新测试计划报告
|
||||||
|
if (StringUtils.isNotEmpty(item.getReportId())) {
|
||||||
|
CommonBeanFactory.getBean(TestPlanReportService.class).finishedTestPlanReport(item.getReportId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
// 清除异常队列/一般是服务突然停止产生
|
// 清除异常队列/一般是服务突然停止产生
|
||||||
extApiExecutionQueueMapper.delete();
|
extApiExecutionQueueMapper.delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package io.metersphere.base.mapper.ext;
|
package io.metersphere.base.mapper.ext;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.ApiExecutionQueue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface ExtApiExecutionQueueMapper {
|
public interface ExtApiExecutionQueueMapper {
|
||||||
void delete();
|
void delete();
|
||||||
|
|
||||||
|
List<ApiExecutionQueue> findTestPlanReportQueue();
|
||||||
}
|
}
|
|
@ -4,4 +4,7 @@
|
||||||
<delete id="delete">
|
<delete id="delete">
|
||||||
DELETE from api_execution_queue where id not IN (SELECT t1.queue_id from api_execution_queue_detail t1);
|
DELETE from api_execution_queue where id not IN (SELECT t1.queue_id from api_execution_queue_detail t1);
|
||||||
</delete>
|
</delete>
|
||||||
|
<select id="findTestPlanReportQueue" resultType="io.metersphere.base.domain.ApiExecutionQueue">
|
||||||
|
select * from api_execution_queue where report_id !=null and run_mode='API_PLAN' and id not IN (SELECT t1.queue_id from api_execution_queue_detail t1) ;
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
|
@ -319,29 +319,30 @@ public class TestPlanReportService {
|
||||||
|
|
||||||
public TestPlanReport finishedTestPlanReport(String testPlanReportId) {
|
public TestPlanReport finishedTestPlanReport(String testPlanReportId) {
|
||||||
TestPlanReport testPlanReport = this.getTestPlanReport(testPlanReportId);
|
TestPlanReport testPlanReport = this.getTestPlanReport(testPlanReportId);
|
||||||
//初始化测试计划包含组件信息
|
if (testPlanReport != null) {
|
||||||
int[] componentIndexArr = new int[]{1, 3, 4};
|
//初始化测试计划包含组件信息
|
||||||
testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr));
|
int[] componentIndexArr = new int[]{1, 3, 4};
|
||||||
//计算测试计划状态
|
testPlanReport.setComponents(JSONArray.toJSONString(componentIndexArr));
|
||||||
String testPlanStatus = this.getTestPlanReportStatus(testPlanReport, null);
|
//计算测试计划状态
|
||||||
testPlanReport.setStatus(testPlanStatus);
|
testPlanReport.setStatus(TestPlanReportStatus.COMPLETED.name());
|
||||||
//如果测试案例没有未结束的功能用例,则更新最后结束日期。
|
//如果测试案例没有未结束的功能用例,则更新最后结束日期。
|
||||||
TestPlanTestCaseMapper testPlanTestCaseMapper = CommonBeanFactory.getBean(TestPlanTestCaseMapper.class);
|
TestPlanTestCaseMapper testPlanTestCaseMapper = CommonBeanFactory.getBean(TestPlanTestCaseMapper.class);
|
||||||
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||||
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanReport.getTestPlanId()).andStatusNotEqualTo("Prepare");
|
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanReport.getTestPlanId()).andStatusNotEqualTo("Prepare");
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
long testCaseCount = testPlanTestCaseMapper.countByExample(testPlanTestCaseExample);
|
long testCaseCount = testPlanTestCaseMapper.countByExample(testPlanTestCaseExample);
|
||||||
boolean updateTestPlanTime = testCaseCount > 0;
|
boolean updateTestPlanTime = testCaseCount > 0;
|
||||||
if (updateTestPlanTime) {
|
if (updateTestPlanTime) {
|
||||||
testPlanReport.setEndTime(endTime);
|
testPlanReport.setEndTime(endTime);
|
||||||
testPlanReport.setUpdateTime(endTime);
|
testPlanReport.setUpdateTime(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
//更新测试计划并发送通知
|
//更新测试计划并发送通知
|
||||||
testPlanReport.setIsApiCaseExecuting(false);
|
testPlanReport.setIsApiCaseExecuting(false);
|
||||||
testPlanReport.setIsScenarioExecuting(false);
|
testPlanReport.setIsScenarioExecuting(false);
|
||||||
testPlanReport.setIsPerformanceExecuting(false);
|
testPlanReport.setIsPerformanceExecuting(false);
|
||||||
testPlanReport = this.update(testPlanReport);
|
testPlanReport = this.update(testPlanReport);
|
||||||
|
}
|
||||||
return testPlanReport;
|
return testPlanReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue