From 589846cad8db3e5c5f1f9a93a4cd6085a27efc90 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 30 Apr 2020 16:00:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/service/ReportService.java | 39 ++++++++++++++++++- .../service/TestResourceService.java | 4 ++ .../report/components/LogDetails.vue | 7 +++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 8b304d5457..a77676995b 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -1,8 +1,10 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.LoadTestMapper; +import io.metersphere.base.mapper.LoadTestReportLogMapper; import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.LoadTestReportResultMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; @@ -20,8 +22,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -35,6 +39,10 @@ public class ReportService { private LoadTestMapper loadTestMapper; @Resource private LoadTestReportResultMapper loadTestReportResultMapper; + @Resource + private LoadTestReportLogMapper loadTestReportLogMapper; + @Resource + private TestResourceService testResourceService; public List getRecentReportList(ReportRequest request) { return extLoadTestReportMapper.getReportList(request); @@ -150,7 +158,34 @@ public class ReportService { } public Map log(String reportId) { - // todo 查询日志 - return null; + Map logMap = new HashMap<>(); + LoadTestReportLogExample example = new LoadTestReportLogExample(); + example.createCriteria().andReportIdEqualTo(reportId); + List loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example); + loadTestReportLogs.stream().map(log -> { + Map result = new HashMap<>(); + TestResource testResource = testResourceService.getTestResource(log.getResourceId()); + if (testResource == null) { + result.put(log.getResourceId(), log.getContent()); + return result; + } + String configuration = testResource.getConfiguration(); + JSONObject object = JSON.parseObject(configuration); + if (StringUtils.isNotBlank(object.getString("masterUrl"))) { + result.put(object.getString("masterUrl"), log.getContent()); + return result; + } + if (StringUtils.isNotBlank(object.getString("ip"))) { + result.put(object.getString("ip"), log.getContent()); + return result; + + } + result.put(log.getResourceId(), log.getContent()); + return result; + }).forEach(log -> logMap.putAll(log.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) + ); + + return logMap; } } diff --git a/backend/src/main/java/io/metersphere/service/TestResourceService.java b/backend/src/main/java/io/metersphere/service/TestResourceService.java index f6924503de..c3ef935ffe 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourceService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourceService.java @@ -47,4 +47,8 @@ public class TestResourceService { example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId); return testResourceMapper.selectByExampleWithBLOBs(example); } + + public TestResource getTestResource(String resourceId) { + return testResourceMapper.selectByPrimaryKey(resourceId); + } } diff --git a/frontend/src/business/components/performance/report/components/LogDetails.vue b/frontend/src/business/components/performance/report/components/LogDetails.vue index 6ac7f3fcaf..ac43d66e16 100644 --- a/frontend/src/business/components/performance/report/components/LogDetails.vue +++ b/frontend/src/business/components/performance/report/components/LogDetails.vue @@ -1,6 +1,10 @@ @@ -34,6 +38,7 @@ .logging-content { white-space: pre-line; overflow: auto; + height: calc(100vh - 400px); }