From 1f372ba03286bad268d26237e9847f1847aa5f33 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 13 Mar 2023 11:09:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=EF=BC=8C=E9=99=8D=E4=BD=8E=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E6=8B=A5=E5=A0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../service/ApiExecutionQueueService.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java index 7781fda161..a93d038d3a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiExecutionQueueService.java @@ -67,6 +67,10 @@ public class ApiExecutionQueueService { private ApiCaseSerialService apiCaseSerialService; @Resource private KafkaTemplate kafkaTemplate; + @Resource + private ApiExecutionQueueMapper apiExecutionQueueMapper; + @Resource + private ApiExecutionQueueDetailMapper apiExecutionQueueDetailMapper; @Transactional(propagation = Propagation.REQUIRES_NEW) public DBTestQueue add(Object runObj, String poolId, String type, String reportId, String reportType, String runMode, RunModeConfigDTO config) { @@ -284,7 +288,21 @@ public class ApiExecutionQueueService { this.testPlanCaseTestEnd(testId, runMode); } else { // 由测试计划检查测试计划中其他队列是否结束 - kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_REPORT_TOPIC, testPlanReportId); + ApiExecutionQueueExample executionQueueExample = new ApiExecutionQueueExample(); + executionQueueExample.createCriteria().andReportIdEqualTo(testPlanReportId); + List queues = apiExecutionQueueMapper.selectByExample(executionQueueExample); + if (CollectionUtils.isEmpty(queues)) { + LoggerUtil.info("Normal execution completes, update test plan report status:" + testPlanReportId); + kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_REPORT_TOPIC, testPlanReportId); + } else { + List ids = queues.stream().map(ApiExecutionQueue::getId).collect(Collectors.toList()); + ApiExecutionQueueDetailExample detailExample = new ApiExecutionQueueDetailExample(); + detailExample.createCriteria().andQueueIdIn(ids); + long count = apiExecutionQueueDetailMapper.countByExample(detailExample); + if (count == 0) { + kafkaTemplate.send(KafkaTopicConstants.TEST_PLAN_REPORT_TOPIC, testPlanReportId); + } + } } }