refactor: Merge branch 'v1.1'

This commit is contained in:
wangzhen-fit2cloud 2020-07-23 10:31:27 +08:00
commit 57c02609b8
2 changed files with 24 additions and 17 deletions

View File

@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;
@RestController
@ -112,14 +111,6 @@ public class PerformanceReportController {
@GetMapping("log/download/{reportId}/{resourceId}")
public void downloadLog(@PathVariable String reportId, @PathVariable String resourceId, HttpServletResponse response) throws Exception {
try (OutputStream outputStream = response.getOutputStream()) {
List<String> content = reportService.downloadLog(reportId, resourceId);
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=jmeter.log");
for (String log : content) {
outputStream.write(log.getBytes());
}
outputStream.flush();
}
reportService.downloadLog(response, reportId, resourceId);
}
}

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@ -207,17 +208,32 @@ public class ReportService {
public List<LoadTestReportLog> getReportLogs(String reportId, String resourceId) {
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
example.setOrderByClause("part desc");
example.setOrderByClause("part");
return loadTestReportLogMapper.selectByExampleWithBLOBs(example);
}
public List<String> downloadLog(String reportId, String resourceId) {
public void downloadLog(HttpServletResponse response, String reportId, String resourceId) throws Exception {
LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
example.setOrderByClause("part desc");
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
LoadTestReportLogExample.Criteria criteria = example.createCriteria();
criteria.andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
example.setOrderByClause("part");
return loadTestReportLogs.stream().map(LoadTestReportLog::getContent).collect(Collectors.toList());
long count = loadTestReportLogMapper.countByExample(example);
try (OutputStream outputStream = response.getOutputStream()) {
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=jmeter.log");
for (long i = 1; i <= count; i++) {
example.clear();
LoadTestReportLogExample.Criteria innerCriteria = example.createCriteria();
innerCriteria.andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId).andPartEqualTo(i);
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
LoadTestReportLog content = loadTestReportLogs.get(0);
outputStream.write(content.getContent().getBytes());
}
outputStream.flush();
}
}
public LoadTestReport getReport(String reportId) {