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 c2e1902894..88312b9bd5 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -3,12 +3,14 @@ package io.metersphere.notice.service; import io.metersphere.api.dto.APIReportResult; import io.metersphere.base.domain.Notice; import io.metersphere.base.domain.SystemParameter; +import io.metersphere.base.domain.TestCaseWithBLOBs; 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.service.SystemParameterService; import io.metersphere.service.UserService; +import io.metersphere.track.request.testreview.SaveCommentRequest; import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSenderImpl; @@ -138,12 +140,20 @@ public class MailService { } - public void sendHtml(List userIds, String type, SaveTestCaseReviewRequest reviewRequest) { + public void sendHtml(List userIds, String type, SaveTestCaseReviewRequest reviewRequest, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) { Long startTime = reviewRequest.getCreateTime(); Long endTime = reviewRequest.getEndTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String start = sdf.format(new Date(Long.parseLong(String.valueOf(startTime)))); - String end = sdf.format(new Date(Long.parseLong(String.valueOf(endTime)))); + String start = null; + String sTime = String.valueOf(startTime); + String eTime = String.valueOf(endTime); + if (!sTime.equals("null")) { + start = sdf.format(new Date(Long.parseLong(sTime))); + } + String end = null; + if (!eTime.equals("null")) { + end = sdf.format(new Date(Long.parseLong(eTime))); + } JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); List paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue()); javaMailSender.setDefaultEncoding("UTF-8"); @@ -182,8 +192,31 @@ public class MailService { " \n" + "\n" + ""; - String html2 = ""; - String html3 = ""; + String html2 = "\n" + + "\n" + + "\n" + + " \n" + + " MeterSphere\n" + + "\n" + + "\n" + + "
\n" + + "

" + testCaseWithBLOBs.getMaintainer() + "发起的" + testCaseWithBLOBs.getName() + "添加评论:" + request.getDescription() + "

\n" + + "
\n" + + "\n" + + ""; + String html3 = "\n" + + "\n" + + "\n" + + " \n" + + " MeterSphere\n" + + "\n" + + "\n" + + "
\n" + + "

" + reviewRequest.getCreator() + "发起的" + reviewRequest.getName() + "的计划开始时间是" + start + ",计划结束时间为" + end + "已完成" + "

\n" + + "
\n" + + "\n" + + ""; + ; try { MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); helper.setFrom(javaMailSender.getUsername()); @@ -198,6 +231,10 @@ public class MailService { users = emails.toArray(new String[emails.size()]); if (type.equals("reviewer")) { helper.setText(html1, true); + } else if (type.equals("comment")) { + helper.setText(html2, true); + } else if (type.equals("end")) { + helper.setText(html3, true); } helper.setTo(users); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java index 8c42b89389..3634f16c5e 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java @@ -1,16 +1,21 @@ package io.metersphere.track.service; -import io.metersphere.base.domain.TestCaseComment; -import io.metersphere.base.domain.TestCaseCommentExample; -import io.metersphere.base.domain.User; +import io.metersphere.base.domain.*; import io.metersphere.base.mapper.TestCaseCommentMapper; +import io.metersphere.base.mapper.TestCaseMapper; +import io.metersphere.base.mapper.TestCaseReviewMapper; import io.metersphere.base.mapper.UserMapper; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.notice.service.MailService; import io.metersphere.track.request.testreview.SaveCommentRequest; +import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; +import org.apache.commons.beanutils.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -21,7 +26,13 @@ public class TestCaseCommentService { @Resource TestCaseCommentMapper testCaseCommentMapper; @Resource + private TestCaseReviewMapper testCaseReviewMapper; + @Resource UserMapper userMapper; + @Resource + MailService mailService; + @Resource + TestCaseMapper testCaseMapper; public void saveComment(SaveCommentRequest request) { TestCaseComment testCaseComment = new TestCaseComment(); @@ -32,6 +43,13 @@ public class TestCaseCommentService { testCaseComment.setUpdateTime(System.currentTimeMillis()); testCaseComment.setDescription(request.getDescription()); testCaseCommentMapper.insert(testCaseComment); + TestCaseWithBLOBs testCaseWithBLOBs; + testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(request.getCaseId()); + SaveTestCaseReviewRequest caseReviewRequest = new SaveTestCaseReviewRequest(); + List userIds = new ArrayList<>(); + userIds.add(testCaseComment.getAuthor()); + mailService.sendHtml(userIds, "comment", caseReviewRequest, request, testCaseWithBLOBs); + } public List getComments(String caseId) { diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java index a44843a503..f69b5ab1c5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -17,10 +17,8 @@ import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.notice.service.MailService; import io.metersphere.service.UserService; import io.metersphere.track.dto.*; -import io.metersphere.track.request.testreview.QueryTestReviewRequest; -import io.metersphere.track.request.testreview.ReviewRelevanceRequest; -import io.metersphere.track.request.testreview.QueryCaseReviewRequest; -import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; +import io.metersphere.track.request.testreview.*; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -30,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.stream.Collectors; @@ -64,6 +63,7 @@ public class TestCaseReviewService { @Resource MailService mailService; + public void saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) { checkCaseReviewExist(reviewRequest); @@ -91,7 +91,9 @@ public class TestCaseReviewService { reviewRequest.setCreator(SessionUtils.getUser().getId()); reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); testCaseReviewMapper.insert(reviewRequest); - mailService.sendHtml(userIds, "reviewer", reviewRequest); + SaveCommentRequest request = new SaveCommentRequest(); + TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); + mailService.sendHtml(userIds, "reviewer", reviewRequest, request, testCaseWithBLOBs); } @@ -148,7 +150,9 @@ public class TestCaseReviewService { testCaseReview.setUpdateTime(System.currentTimeMillis()); checkCaseReviewExist(testCaseReview); testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); - mailService.sendHtml(testCaseReview.getUserIds(), "reviewer", testCaseReview); + SaveCommentRequest request = new SaveCommentRequest(); + TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); + mailService.sendHtml(testCaseReview.getUserIds(), "reviewer", testCaseReview, request, testCaseWithBLOBs); } private void editCaseReviewer(SaveTestCaseReviewRequest testCaseReview) { @@ -321,6 +325,20 @@ public class TestCaseReviewService { } } testCaseReview.setStatus(TestPlanStatus.Completed.name()); + SaveCommentRequest request = new SaveCommentRequest(); + TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); + SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest(); + TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId); + List userIds = new ArrayList<>(); + userIds.add(_testCaseReview.getCreator()); + try { + BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + mailService.sendHtml(userIds, "end", testCaseReviewRequest, request, testCaseWithBLOBs); testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); } diff --git a/frontend/src/business/components/api/report/ApiReportExport.vue b/frontend/src/business/components/api/report/ApiReportExport.vue index 5e1ace1bcd..c011bf3747 100644 --- a/frontend/src/business/components/api/report/ApiReportExport.vue +++ b/frontend/src/business/components/api/report/ApiReportExport.vue @@ -1,30 +1,35 @@