feat: 测试评审任务发起通知
This commit is contained in:
parent
1c51bc57e9
commit
629ec87958
|
@ -16,6 +16,8 @@ public interface ExtUserMapper {
|
|||
|
||||
List<User> searchUser(String condition);
|
||||
|
||||
List<String> queryEmails(String[] names);
|
||||
List<String> queryEmails(String[] names);
|
||||
|
||||
List<String> queryEmailByIds(List<String> userIds);
|
||||
|
||||
}
|
||||
|
|
|
@ -38,12 +38,23 @@
|
|||
SELECT
|
||||
email
|
||||
from user
|
||||
WHERE name IN
|
||||
WHERE name IN
|
||||
<foreach collection="array" item="id" index="index"
|
||||
open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
<select id="queryEmailByIds" parameterType="java.lang.String" resultType="java.lang.String">
|
||||
SELECT
|
||||
email
|
||||
from user
|
||||
WHERE id IN
|
||||
<foreach collection="list" item="id" index="index"
|
||||
open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
|
||||
</select>
|
||||
|
||||
<!--修改密码-->
|
||||
|
|
|
@ -9,6 +9,7 @@ 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.SaveTestCaseReviewRequest;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
|
@ -18,7 +19,9 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -135,5 +138,81 @@ public class MailService {
|
|||
}
|
||||
|
||||
|
||||
public void sendHtml(List<String> userIds, String type, SaveTestCaseReviewRequest reviewRequest) {
|
||||
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))));
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
List<SystemParameter> paramList = systemParameterService.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setProtocol("smtps");
|
||||
for (SystemParameter p : paramList) {
|
||||
if (p.getParamKey().equals("smtp.host")) {
|
||||
javaMailSender.setHost(p.getParamValue());
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.port")) {
|
||||
javaMailSender.setPort(Integer.parseInt(p.getParamValue()));
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.account")) {
|
||||
javaMailSender.setUsername(p.getParamValue());
|
||||
}
|
||||
if (p.getParamKey().equals("smtp.password")) {
|
||||
javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString());
|
||||
}
|
||||
}
|
||||
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.timeout", "30000");
|
||||
props.put("mail.smtp.connectiontimeout", "5000");
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
String html1 = "<!DOCTYPE html>\n" +
|
||||
"<html lang=\"en\">\n" +
|
||||
"<head>\n" +
|
||||
" <meta charset=\"UTF-8\">\n" +
|
||||
" <title>MeterSphere</title>\n" +
|
||||
"</head>\n" +
|
||||
"<body style=\"text-align: left\">\n" +
|
||||
" <div>\n" +
|
||||
" <p>" + reviewRequest.getCreator() + "发起的" + reviewRequest.getName() + "的计划开始时间是" + start + ",计划结束时间为" + end + "请跟进" + "</p>\n" +
|
||||
" </div>\n" +
|
||||
"</body>\n" +
|
||||
"</html>";
|
||||
String html2 = "";
|
||||
String html3 = "";
|
||||
try {
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("测试评审任务通知");
|
||||
String users[] = {};
|
||||
List<String> emails = new ArrayList<>();
|
||||
try {
|
||||
emails = userService.queryEmailByIds(userIds);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("Recipient information is empty");
|
||||
}
|
||||
users = emails.toArray(new String[emails.size()]);
|
||||
if (type.equals("reviewer")) {
|
||||
helper.setText(html1, true);
|
||||
} else if (type.equals("reviewer")) {
|
||||
helper.setText(html2, true);
|
||||
} else {
|
||||
helper.setText(html3, true);
|
||||
}
|
||||
helper.setTo(users);
|
||||
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MailException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ public class PerformanceTestService {
|
|||
}
|
||||
|
||||
startEngine(loadTest, engine, request.getTriggerMode());
|
||||
if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
/* if (request.getTriggerMode().equals("SCHEDULE")) {
|
||||
List<Notice> notice = null;
|
||||
try {
|
||||
notice = noticeService.queryNotice(request.getId());
|
||||
|
@ -249,7 +249,7 @@ public class PerformanceTestService {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return engine.getReportId();
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,14 @@ public class UserService {
|
|||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
|
||||
public List<String> queryEmail(String[] names){
|
||||
return extUserMapper.queryEmails(names);
|
||||
public List<String> queryEmail(String[] names) {
|
||||
return extUserMapper.queryEmails(names);
|
||||
}
|
||||
|
||||
public List<String> queryEmailByIds(List<String> userIds) {
|
||||
return extUserMapper.queryEmailByIds(userIds);
|
||||
}
|
||||
|
||||
public UserDTO insert(UserRequest user) {
|
||||
checkUserParam(user);
|
||||
//
|
||||
|
|
|
@ -14,6 +14,7 @@ import io.metersphere.commons.utils.MathUtils;
|
|||
import io.metersphere.commons.utils.ServiceUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
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;
|
||||
|
@ -60,6 +61,8 @@ public class TestCaseReviewService {
|
|||
TestCaseMapper testCaseMapper;
|
||||
@Resource
|
||||
TestCaseReviewTestCaseMapper testCaseReviewTestCaseMapper;
|
||||
@Resource
|
||||
MailService mailService;
|
||||
|
||||
public void saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) {
|
||||
checkCaseReviewExist(reviewRequest);
|
||||
|
@ -88,6 +91,8 @@ public class TestCaseReviewService {
|
|||
reviewRequest.setCreator(SessionUtils.getUser().getId());
|
||||
reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testCaseReviewMapper.insert(reviewRequest);
|
||||
mailService.sendHtml(userIds, "reviewer", reviewRequest);
|
||||
|
||||
}
|
||||
|
||||
public List<TestCaseReviewDTO> listCaseReview(QueryCaseReviewRequest request) {
|
||||
|
@ -143,6 +148,7 @@ public class TestCaseReviewService {
|
|||
testCaseReview.setUpdateTime(System.currentTimeMillis());
|
||||
checkCaseReviewExist(testCaseReview);
|
||||
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
|
||||
mailService.sendHtml(testCaseReview.getUserIds(), "reviewer", testCaseReview);
|
||||
}
|
||||
|
||||
private void editCaseReviewer(SaveTestCaseReviewRequest testCaseReview) {
|
||||
|
|
Loading…
Reference in New Issue