fix:修改互相调用

This commit is contained in:
wenyann 2020-09-16 12:05:02 +08:00
parent 64a731bb57
commit 8dca4bce9a
2 changed files with 72 additions and 20 deletions

View File

@ -0,0 +1,54 @@
package io.metersphere.notice.service;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.base.domain.ApiTestReportDetail;
import io.metersphere.base.domain.Schedule;
import io.metersphere.base.mapper.ApiTestReportDetailMapper;
import io.metersphere.base.mapper.ext.ExtApiTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.commons.constants.ScheduleGroup;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.service.ScheduleService;
import io.metersphere.track.request.testplan.QueryTestPlanRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Service
public class ApiAndPerformanceHelper {
@Resource
private ExtLoadTestMapper extLoadTestMapper;
@Resource
private ExtApiTestReportMapper extApiTestReportMapper;
@Resource
private ApiTestReportDetailMapper apiTestReportDetailMapper;
@Resource
private ScheduleService scheduleService;
public APIReportResult getApi(String reportId) {
APIReportResult result = extApiTestReportMapper.get(reportId);
ApiTestReportDetail detail = apiTestReportDetailMapper.selectByPrimaryKey(reportId);
if (detail != null) {
result.setContent(new String(detail.getContent(), StandardCharsets.UTF_8));
}
return result;
}
public LoadTestDTO getPerformance(String testId) {
QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setId(testId);
List<LoadTestDTO> testDTOS = extLoadTestMapper.list(request);
if (!CollectionUtils.isEmpty(testDTOS)) {
LoadTestDTO loadTestDTO = testDTOS.get(0);
Schedule schedule = scheduleService.getScheduleByResource(loadTestDTO.getId(), ScheduleGroup.PERFORMANCE_TEST.name());
loadTestDTO.setSchedule(schedule);
return loadTestDTO;
}
return null;
}
}

View File

@ -1,21 +1,19 @@
package io.metersphere.notice.service;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.api.service.APIReportService;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.performance.service.PerformanceTestService;
import io.metersphere.service.SystemParameterService;
import io.metersphere.service.UserService;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
@ -25,10 +23,8 @@ import java.util.Properties;
@Service
public class MailService {
/* @Resource
private APIReportService apiReportService;
@Resource
private PerformanceTestService performanceTestService;*/
private ApiAndPerformanceHelper apiAndPerformanceHelper;
@Resource
private UserService userService;
@Resource
@ -55,24 +51,24 @@ public class MailService {
}
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.starttls.required","true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.timeout", "30000");
props.put("mail.smtp.connectiontimeout", "5000");
javaMailSender.setJavaMailProperties(props);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
String testName="";
String state="";
/* if(type.equals("api")){
APIReportResult reportResult=apiReportService.get(id);
testName=reportResult.getTestName();
state=reportResult.getStatus();
}else if(type.equals("performance")){
LoadTestDTO performanceResult=performanceTestService.get(id);
testName=performanceResult.getName();
state=performanceResult.getStatus();
}*/
String html1="<!DOCTYPE html>\n" +
String testName = "";
String state = "";
if (type.equals("api")) {
APIReportResult reportResult = apiAndPerformanceHelper.getApi(id);
testName = reportResult.getTestName();
state = reportResult.getStatus();
} else if (type.equals("performance")) {
LoadTestDTO performanceResult = apiAndPerformanceHelper.getPerformance(id);
testName = performanceResult.getName();
state = performanceResult.getStatus();
}
String html1 = "<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <meta charset=\"UTF-8\">\n" +
@ -134,5 +130,7 @@ public class MailService {
e.printStackTrace();
}
}
}