diff --git a/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java b/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java new file mode 100644 index 0000000000..f74f04bc49 --- /dev/null +++ b/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java @@ -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 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; + } +} + diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index 8ccf658075..efee1a4519 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -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="\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 = "\n" + "\n" + "\n" + " \n" + @@ -134,5 +130,7 @@ public class MailService { e.printStackTrace(); } } + + }