Merge branch 'v1.1'

This commit is contained in:
chenjianxing 2020-07-23 10:42:22 +08:00
commit 896594e9d9
3 changed files with 25 additions and 18 deletions

View File

@ -264,7 +264,7 @@ public class APITestService {
ApiImportParser apiImportParser = ApiImportParserFactory.getApiImportParser(request.getPlatform()); ApiImportParser apiImportParser = ApiImportParserFactory.getApiImportParser(request.getPlatform());
ApiImport apiImport = null; ApiImport apiImport = null;
try { try {
apiImport = Objects.requireNonNull(apiImportParser).parse(file.getInputStream(), request); apiImport = Objects.requireNonNull(apiImportParser).parse(file == null ? null : file.getInputStream(), request);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
MSException.throwException(Translator.get("parse_data_error")); MSException.throwException(Translator.get("parse_data_error"));

View File

@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List; import java.util.List;
@RestController @RestController
@ -112,14 +111,6 @@ public class PerformanceReportController {
@GetMapping("log/download/{reportId}/{resourceId}") @GetMapping("log/download/{reportId}/{resourceId}")
public void downloadLog(@PathVariable String reportId, @PathVariable String resourceId, HttpServletResponse response) throws Exception { public void downloadLog(@PathVariable String reportId, @PathVariable String resourceId, HttpServletResponse response) throws Exception {
try (OutputStream outputStream = response.getOutputStream()) { reportService.downloadLog(response, reportId, resourceId);
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();
}
} }
} }

View File

@ -23,9 +23,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -207,17 +208,32 @@ public class ReportService {
public List<LoadTestReportLog> getReportLogs(String reportId, String resourceId) { public List<LoadTestReportLog> getReportLogs(String reportId, String resourceId) {
LoadTestReportLogExample example = new LoadTestReportLogExample(); LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
example.setOrderByClause("part desc"); example.setOrderByClause("part");
return loadTestReportLogMapper.selectByExampleWithBLOBs(example); 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(); LoadTestReportLogExample example = new LoadTestReportLogExample();
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId); LoadTestReportLogExample.Criteria criteria = example.createCriteria();
example.setOrderByClause("part desc"); criteria.andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example); 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) { public LoadTestReport getReport(String reportId) {