显示日志

This commit is contained in:
Captain.B 2020-04-30 16:00:35 +08:00
parent e2e3d799ab
commit 589846cad8
3 changed files with 47 additions and 3 deletions

View File

@ -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<ReportDTO> getRecentReportList(ReportRequest request) {
return extLoadTestReportMapper.getReportList(request);
@ -150,7 +158,34 @@ public class ReportService {
}
public Map<String, String> log(String reportId) {
// todo 查询日志
return null;
Map<String, String> logMap = new HashMap<>();
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId);
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
loadTestReportLogs.stream().map(log -> {
Map<String, String> 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;
}
}

View File

@ -47,4 +47,8 @@ public class TestResourceService {
example.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
return testResourceMapper.selectByExampleWithBLOBs(example);
}
public TestResource getTestResource(String resourceId) {
return testResourceMapper.selectByPrimaryKey(resourceId);
}
}

View File

@ -1,6 +1,10 @@
<template>
<div>
{{logContent}}
<el-tabs type="border-card" :stretch="true">
<el-tab-pane v-for="(item, key) in logContent" :key="key" :label="key" class="logging-content">
{{item}}
</el-tab-pane>
</el-tabs>
</div>
</template>
@ -34,6 +38,7 @@
.logging-content {
white-space: pre-line;
overflow: auto;
height: calc(100vh - 400px);
}
</style>