feat: 消息设置

This commit is contained in:
wenyann 2020-10-21 00:09:23 +08:00
parent 736d46c983
commit b38fbf034e
18 changed files with 454 additions and 152 deletions

View File

@ -19,5 +19,7 @@ public class MessageTask implements Serializable {
private String identification;
private Boolean isSet;
private static final long serialVersionUID = 1L;
}

View File

@ -593,6 +593,66 @@ public class MessageTaskExample {
addCriterion("identification not between", value1, value2, "identification");
return (Criteria) this;
}
public Criteria andIsSetIsNull() {
addCriterion("is_Set is null");
return (Criteria) this;
}
public Criteria andIsSetIsNotNull() {
addCriterion("is_Set is not null");
return (Criteria) this;
}
public Criteria andIsSetEqualTo(Boolean value) {
addCriterion("is_Set =", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetNotEqualTo(Boolean value) {
addCriterion("is_Set <>", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetGreaterThan(Boolean value) {
addCriterion("is_Set >", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetGreaterThanOrEqualTo(Boolean value) {
addCriterion("is_Set >=", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetLessThan(Boolean value) {
addCriterion("is_Set <", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetLessThanOrEqualTo(Boolean value) {
addCriterion("is_Set <=", value, "isSet");
return (Criteria) this;
}
public Criteria andIsSetIn(List<Boolean> values) {
addCriterion("is_Set in", values, "isSet");
return (Criteria) this;
}
public Criteria andIsSetNotIn(List<Boolean> values) {
addCriterion("is_Set not in", values, "isSet");
return (Criteria) this;
}
public Criteria andIsSetBetween(Boolean value1, Boolean value2) {
addCriterion("is_Set between", value1, value2, "isSet");
return (Criteria) this;
}
public Criteria andIsSetNotBetween(Boolean value1, Boolean value2) {
addCriterion("is_Set not between", value1, value2, "isSet");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -9,6 +9,7 @@
<result column="task_type" jdbcType="VARCHAR" property="taskType" />
<result column="webhook" jdbcType="VARCHAR" property="webhook" />
<result column="identification" jdbcType="VARCHAR" property="identification" />
<result column="is_Set" jdbcType="BIT" property="isSet" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -69,7 +70,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, `type`, event, user_id, task_type, webhook, identification
id, `type`, event, user_id, task_type, webhook, identification, is_Set
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.MessageTaskExample" resultMap="BaseResultMap">
select
@ -104,10 +105,10 @@
<insert id="insert" parameterType="io.metersphere.base.domain.MessageTask">
insert into message_task (id, `type`, event,
user_id, task_type, webhook,
identification)
identification, is_Set)
values (#{id,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{event,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, #{webhook,jdbcType=VARCHAR},
#{identification,jdbcType=VARCHAR})
#{identification,jdbcType=VARCHAR}, #{isSet,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.MessageTask">
insert into message_task
@ -133,6 +134,9 @@
<if test="identification != null">
identification,
</if>
<if test="isSet != null">
is_Set,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -156,6 +160,9 @@
<if test="identification != null">
#{identification,jdbcType=VARCHAR},
</if>
<if test="isSet != null">
#{isSet,jdbcType=BIT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.MessageTaskExample" resultType="java.lang.Long">
@ -188,6 +195,9 @@
<if test="record.identification != null">
identification = #{record.identification,jdbcType=VARCHAR},
</if>
<if test="record.isSet != null">
is_Set = #{record.isSet,jdbcType=BIT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -201,7 +211,8 @@
user_id = #{record.userId,jdbcType=VARCHAR},
task_type = #{record.taskType,jdbcType=VARCHAR},
webhook = #{record.webhook,jdbcType=VARCHAR},
identification = #{record.identification,jdbcType=VARCHAR}
identification = #{record.identification,jdbcType=VARCHAR},
is_Set = #{record.isSet,jdbcType=BIT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -227,6 +238,9 @@
<if test="identification != null">
identification = #{identification,jdbcType=VARCHAR},
</if>
<if test="isSet != null">
is_Set = #{isSet,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -237,7 +251,8 @@
user_id = #{userId,jdbcType=VARCHAR},
task_type = #{taskType,jdbcType=VARCHAR},
webhook = #{webhook,jdbcType=VARCHAR},
identification = #{identification,jdbcType=VARCHAR}
identification = #{identification,jdbcType=VARCHAR},
is_Set = #{isSet,jdbcType=BIT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -2,6 +2,7 @@ package io.metersphere.base.mapper.ext;
import io.metersphere.base.domain.User;
import io.metersphere.controller.request.UserRequest;
import io.metersphere.notice.domain.UserDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -16,6 +17,6 @@ public interface ExtUserMapper {
List<User> searchUser(String condition);
List<String> queryEmailByIds(List<String> userIds);
List<UserDetail> queryTypeByIds(List<String> userIds);
}

View File

@ -33,9 +33,9 @@
</where>
order by u.update_time desc
</select>
<select id="queryEmailByIds" parameterType="java.lang.String" resultType="java.lang.String">
<select id="queryTypeByIds" parameterType="java.lang.String" resultType="io.metersphere.notice.domain.UserDetail">
SELECT
email
email,phone
from user
WHERE id IN
<foreach collection="list" item="id" index="index"

View File

@ -9,9 +9,13 @@ public interface NoticeConstants {
String CREATE = "CREATE";
String UPDATE = "CREATE";
String DELETE = "DELETE";
String JENKINS_TASK = "jenkinsTask";
String TEST_PLAN_TASK = "testPlanTask";
String REVIEW_TASK = "reviewTask";
String DEFECT_TASK = "defectTask";
String JENKINS_TASK = "JENKINS_TASK";
String TEST_PLAN_TASK = "TEST_PLAN_TASK";
String REVIEW_TASK = "REVIEW_TASK";
String DEFECT_TASK = "DEFECT_TASK";
String FOUNDER="FOUNDER";
String EXECUTOR="EXECUTOR";
String MAINTAINER="MAINTAINER";
}

View File

@ -36,9 +36,9 @@ public class NoticeController {
return noticeService.searchMessage();
}
@GetMapping("/delete/message")
public void deleteMessage() {
@GetMapping("/delete/message/{identification}")
public int deleteMessage(@PathVariable String identification) {
return noticeService.delMessage(identification);
}
}

View File

@ -7,10 +7,12 @@ import java.util.ArrayList;
import java.util.List;
@Data
public class MessageDetail extends MessageTask {
public class MessageDetail {
private List<String> userIds = new ArrayList<>();
private List<String> events = new ArrayList<>();
private String taskType;
private String webhook;
private String type;
private String identification;
private Boolean isSet;
}

View File

@ -0,0 +1,9 @@
package io.metersphere.notice.domain;
import lombok.Data;
@Data
public class UserDetail {
private String email;
private String phone;
}

View File

@ -5,22 +5,53 @@ import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.taobao.api.ApiException;
import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class DingTaskService {
public void sendDingTask(String context, List<String> userIds) {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=5129dc4c073d28f67c7452e0de6536c3ca496728d8c014d0a209b88a8814307a");
@Resource
private UserService userService;
public void sendNailRobot(MessageDetail messageDetail, List<String> userIds, String context, String eventType){
List<String> addresseeIdList=new ArrayList<>();
messageDetail.getEvents().forEach(e->{
if(StringUtils.equals(eventType,e)){
messageDetail.getUserIds().forEach(u->{
if(StringUtils.equals(NoticeConstants.FOUNDER,u)){
addresseeIdList.addAll(userIds);
}else{
addresseeIdList.add(u);
}
});
sendDingTask(context, addresseeIdList,messageDetail.getWebhook());
}
});
}
public void sendDingTask(String context, List<String> userIds,String Webhook) {
DingTalkClient client = new DefaultDingTalkClient(Webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent(context);
request.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(Arrays.asList("15135125273"));
List<UserDetail> list=userService.queryTypeByIds(userIds);
List<String> phoneList=new ArrayList<>();
list.forEach(u->{
phoneList.add(u.getPhone());
});
/* at.setAtMobiles(phoneList);*/
at.setAtMobiles(Arrays.asList("15135125273","13718506428"));
request.setAt(at);
OapiRobotSendResponse response = null;
try {

View File

@ -12,7 +12,9 @@ import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.service.SystemParameterService;
import io.metersphere.service.UserService;
import io.metersphere.track.request.testreview.SaveCommentRequest;
@ -100,17 +102,17 @@ public class MailService {
}
}
public void sendEndNotice(List<String> userIds, SaveTestCaseReviewRequest reviewRequest) {
public void sendEndNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
Map<String, String> context = getReviewContext(reviewRequest);
try {
String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8);
sendReviewNotice(userIds, context, endTemplate);
sendReviewNotice(addresseeIdList(messageDetail,userIds,eventType), context, endTemplate);
} catch (Exception e) {
LogUtil.error(e);
}
}
public void sendCommentNotice(List<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) {
public void sendCommentNotice(MessageDetail messageDetail, List<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> context = new HashMap<>();
context.put("maintainer", testCaseWithBLOBs.getMaintainer());
@ -126,11 +128,11 @@ public class MailService {
}
}
public void sendReviewerNotice(List<String> userIds, SaveTestCaseReviewRequest reviewRequest) {
public void sendReviewerNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
Map<String, String> context = getReviewContext(reviewRequest);
try {
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8);
sendReviewNotice(userIds, context, reviewerTemplate);
sendReviewNotice(addresseeIdList(messageDetail,userIds,eventType), context, reviewerTemplate);
} catch (Exception e) {
LogUtil.error(e);
}
@ -171,7 +173,10 @@ public class MailService {
String[] users;
List<String> emails = new ArrayList<>();
try {
emails = userService.queryEmailByIds(userIds);
List<UserDetail> list=userService.queryTypeByIds(userIds);
list.forEach(u->{
emails.add(u.getEmail());
});
} catch (Exception e) {
LogUtil.error("Recipient information is empty");
}
@ -232,10 +237,16 @@ public class MailService {
if (noticeList.size() > 0) {
for (NoticeDetail n : noticeList) {
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_SUCCESSFUL)) {
successEmailList = userService.queryEmail(n.getUserIds());
List<UserDetail> list = userService.queryTypeByIds(n.getUserIds());
list.forEach(u -> {
successEmailList.add(u.getEmail());
});
}
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_FAILED)) {
failEmailList = userService.queryEmail(n.getUserIds());
List<UserDetail> list = userService.queryTypeByIds(n.getUserIds());
list.forEach(u -> {
failEmailList.add(u.getEmail());
});
}
}
} else {
@ -250,6 +261,24 @@ public class MailService {
return recipientEmails;
}
private List<String> addresseeIdList(MessageDetail messageDetail, List<String> userIds, String eventType) {
List<String> addresseeIdList = new ArrayList<>();
messageDetail.getEvents().forEach(e -> {
if (StringUtils.equals(eventType, e)) {
messageDetail.getUserIds().forEach(u -> {
if (StringUtils.equals(NoticeConstants.FOUNDER, u)) {
addresseeIdList.addAll(userIds);
} else {
addresseeIdList.add(u);
}
});
}
});
return addresseeIdList;
}
}

View File

@ -1,9 +1,6 @@
package io.metersphere.notice.service;
import io.metersphere.base.domain.MessageTask;
import io.metersphere.base.domain.MessageTaskExample;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeExample;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.MessageTaskMapper;
import io.metersphere.base.mapper.NoticeMapper;
import io.metersphere.commons.constants.NoticeConstants;
@ -13,6 +10,7 @@ import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.MessageSettingDetail;
import io.metersphere.notice.domain.NoticeDetail;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -29,6 +27,9 @@ public class NoticeService {
@Resource
private MessageTaskMapper messageTaskMapper;
@Resource
MailService mailService;
public void saveNotice(NoticeRequest noticeRequest) {
NoticeExample example = new NoticeExample();
example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId());
@ -99,6 +100,7 @@ public class NoticeService {
message.setType(list.getType());
message.setWebhook(list.getWebhook());
message.setIdentification(identification);
message.setIsSet(list.getIsSet());
messageTaskMapper.insert(message);
});
});
@ -126,6 +128,7 @@ public class NoticeService {
messageDetail.setWebhook(m.getWebhook());
messageDetail.setIdentification(m.getIdentification());
messageDetail.setType(m.getType());
messageDetail.setIsSet(m.getIsSet());
}
messageDetail.setEvents(new ArrayList(events));
messageDetail.setUserIds(new ArrayList(userIds));
@ -145,4 +148,92 @@ public class NoticeService {
private static String fetchGroupKey(MessageTask user) {
return user.getTaskType() + "#" + user.getIdentification();
}
public int delMessage(String identification){
MessageTaskExample example = new MessageTaskExample();
example.createCriteria().andIdentificationEqualTo(identification);
return messageTaskMapper.deleteByExample(example);
}
/*
public void sendTask(List<String> userIds,String context,String taskType,String eventType){
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
List<MessageDetail> taskList=new ArrayList<>();
switch (taskType) {
case NoticeConstants.REVIEW_TASK:
taskList=messageSettingDetail.getReviewTask();
break;
case NoticeConstants.JENKINS_TASK:
taskList=messageSettingDetail.getJenkinsTask();
break;
case NoticeConstants.DEFECT_TASK:
taskList=messageSettingDetail.getDefectTask();
break;
case NoticeConstants.TEST_PLAN_TASK:
taskList=messageSettingDetail.getTestCasePlanTask();
break;
}
taskList.forEach(r->{
switch (r.getType()) {
case NoticeConstants.NAIL_ROBOT:
sendNailRobot(r,userIds,context,eventType);
break;
case NoticeConstants.WECHAT_ROBOT:
sendWechatRobot(r,userIds,context,eventType);
break;
case NoticeConstants.EMAIL:
sendEmail(r,userIds,context,eventType);
break;
}
});
}
*/
/*private void sendNailRobot(MessageDetail messageDetail,List<String> userIds,String context,String eventType){
List<String> addresseeIdList=new ArrayList<>();
messageDetail.getEvents().forEach(e->{
if(StringUtils.equals(eventType,e)){
messageDetail.getUserIds().forEach(u->{
if(StringUtils.equals(NoticeConstants.FOUNDER,u)){
addresseeIdList.addAll(userIds);
}else{
addresseeIdList.add(u);
}
});
dingTaskService.sendDingTask(context, addresseeIdList,messageDetail.getWebhook());
}
});
}
private void sendWechatRobot(MessageDetail messageDetail,List<String> userIds,String context,String eventType){
List<String> addresseeIdList=new ArrayList<>();
messageDetail.getEvents().forEach(e->{
if(StringUtils.equals(eventType,e)){
messageDetail.getUserIds().forEach(u->{
if(StringUtils.equals(NoticeConstants.FOUNDER,u)){
addresseeIdList.addAll(userIds);
}else{
addresseeIdList.add(u);
}
});
wxChatTaskService.enterpriseWechatTask(context, addresseeIdList,messageDetail.getWebhook());
}
});
}
private void sendEmail(MessageDetail messageDetail,List<String> userIds,String context,String eventType){
List<String> addresseeIdList=new ArrayList<>();
if(StringUtils.equals(NoticeConstants.EMAIL,messageDetail.getType())){
messageDetail.getEvents().forEach(e->{
if(StringUtils.equals(eventType,e)){
messageDetail.getUserIds().forEach(u->{
if(StringUtils.equals(NoticeConstants.FOUNDER,u)){
addresseeIdList.addAll(userIds);
}else{
addresseeIdList.add(u);
}
});
mailService.sendReviewerNotice(addresseeIdList, context);
}
});
}
}*/
}

View File

@ -1,27 +1,57 @@
package io.metersphere.notice.service;
import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.notice.message.TextMessage;
import io.metersphere.notice.util.SendResult;
import io.metersphere.notice.util.WxChatbotClient;
import io.metersphere.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Service
public class WxChatTaskService {
public void enterpriseWechatTask() {
TextMessage message = new TextMessage("脸给你打歪");
@Resource
private UserService userService;
public void sendWechatRobot(MessageDetail messageDetail, List<String> userIds, String context, String eventType){
List<String> addresseeIdList=new ArrayList<>();
messageDetail.getEvents().forEach(e->{
if(StringUtils.equals(eventType,e)){
messageDetail.getUserIds().forEach(u->{
if(StringUtils.equals(NoticeConstants.FOUNDER,u)){
addresseeIdList.addAll(userIds);
}else{
addresseeIdList.add(u);
}
});
enterpriseWechatTask(context, addresseeIdList,messageDetail.getWebhook());
}
});
}
public void enterpriseWechatTask(String context, List<String> userIds,String Webhook) {
TextMessage message = new TextMessage(context);
List<String> mentionedMobileList = new ArrayList<String>();
mentionedMobileList.add("15135125273");//@群内成员 手机号
List<UserDetail> list=userService.queryTypeByIds(userIds);
List<String> phoneList=new ArrayList<>();
list.forEach(u->{
phoneList.add(u.getPhone());
});
mentionedMobileList.addAll(phoneList);
mentionedMobileList.add("15135125273");
mentionedMobileList.add("18046109770");
message.setMentionedMobileList(mentionedMobileList);
message.setIsAtAll(true);//@所有人
try {
SendResult result = WxChatbotClient.send("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a03acc34-4988-4200-a9c7-7c9b30c5601e", message);
SendResult result = WxChatbotClient.send(Webhook, message);
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -22,6 +22,7 @@ import io.metersphere.controller.request.organization.QueryOrgMemberRequest;
import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.notice.domain.UserDetail;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
@ -61,13 +62,13 @@ public class UserService {
@Resource
private WorkspaceService workspaceService;
public List<String> queryEmail(List<String> userIds) {
return extUserMapper.queryEmailByIds(userIds);
public List<UserDetail> queryTypeByIds(List<String> userIds) {
return extUserMapper.queryTypeByIds(userIds);
}
public List<String> queryEmailByIds(List<String> userIds) {
return extUserMapper.queryEmailByIds(userIds);
}
/* public List<String> queryEmailByIds(List<String> userIds) {
return extUserMapper.queryTypeByIds(userIds);
}*/
public UserDTO insert(UserRequest user) {
checkUserParam(user);

View File

@ -60,13 +60,13 @@ public class TestCaseCommentService {
userIds.add(testCaseWithBLOBs.getMaintainer());
String context = getReviewContext(request, testCaseWithBLOBs);
try {
if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) {
/* if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) {
dingTaskService.sendDingTask(context, userIds);
} else if (StringUtils.equals(NoticeConstants.WECHAT_ROBOT, "WECHAT_ROBOT")) {
wxChatTaskService.enterpriseWechatTask();
} else {
mailService.sendCommentNotice(userIds, request, testCaseWithBLOBs);
}
}*/
} catch (Exception e) {
LogUtil.error(e);
}

View File

@ -73,15 +73,16 @@ public class TestCaseReviewService {
@Resource
TestCaseReviewTestCaseMapper testCaseReviewTestCaseMapper;
@Resource
MailService mailService;
@Resource
ExtTestCaseMapper extTestCaseMapper;
@Resource
NoticeService noticeService;
@Resource
MailService mailService;
@Resource
DingTaskService dingTaskService;
@Resource
WxChatTaskService wxChatTaskService;
@Resource
NoticeService noticeService;
public void saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) {
checkCaseReviewExist(reviewRequest);
@ -109,24 +110,28 @@ public class TestCaseReviewService {
reviewRequest.setCreator(SessionUtils.getUser().getId());
reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name());
testCaseReviewMapper.insert(reviewRequest);
String context = getReviewContext(reviewRequest, "create");
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
List<MessageDetail> reviewTasklist = messageSettingDetail.getReviewTask();
try {
mailService.sendReviewerNotice(userIds, reviewRequest);
/* if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) {
dingTaskService.sendDingTask(context, userIds);
} else if (StringUtils.equals(NoticeConstants.WECHAT_ROBOT, "WECHAT_ROBOT")) {
wxChatTaskService.enterpriseWechatTask();
} else {
mailService.sendReviewerNotice(userIds, reviewRequest);
}*/
String context = getReviewContext(reviewRequest, NoticeConstants.CREATE);
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
List<MessageDetail> taskList=messageSettingDetail.getReviewTask();
taskList.forEach(r->{
switch (r.getType()) {
case NoticeConstants.NAIL_ROBOT:
dingTaskService.sendNailRobot(r,userIds,context,NoticeConstants.CREATE);
break;
case NoticeConstants.WECHAT_ROBOT:
wxChatTaskService.sendWechatRobot(r,userIds,context,NoticeConstants.CREATE);
break;
case NoticeConstants.EMAIL:
mailService.sendReviewerNotice(r,userIds, reviewRequest,NoticeConstants.CREATE);
break;
}
});
} catch (Exception e) {
LogUtil.error(e);
}
}
}
public List<TestCaseReviewDTO> listCaseReview(QueryCaseReviewRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
@ -182,7 +187,22 @@ public class TestCaseReviewService {
checkCaseReviewExist(testCaseReview);
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
try {
mailService.sendReviewerNotice(testCaseReview.getUserIds(), testCaseReview);
String context = getReviewContext(testCaseReview, NoticeConstants.CREATE);
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
List<MessageDetail> taskList=messageSettingDetail.getReviewTask();
taskList.forEach(r->{
switch (r.getType()) {
case NoticeConstants.NAIL_ROBOT:
dingTaskService.sendNailRobot(r,testCaseReview.getUserIds(),context,NoticeConstants.CREATE);
break;
case NoticeConstants.WECHAT_ROBOT:
wxChatTaskService.sendWechatRobot(r,testCaseReview.getUserIds(),context,NoticeConstants.CREATE);
break;
case NoticeConstants.EMAIL:
mailService.sendReviewerNotice(r,testCaseReview.getUserIds(), testCaseReview,NoticeConstants.CREATE);
break;
}
});
} catch (Exception e) {
LogUtil.error(e);
}
@ -395,14 +415,22 @@ public class TestCaseReviewService {
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
try {
BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview);
String context = getReviewContext(testCaseReviewRequest, "create");
if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) {
dingTaskService.sendDingTask(context, userIds);
} else if (StringUtils.equals(NoticeConstants.WECHAT_ROBOT, "WECHAT_ROBOT")) {
wxChatTaskService.enterpriseWechatTask();
} else {
mailService.sendEndNotice(userIds, testCaseReviewRequest);
}
String context = getReviewContext(testCaseReviewRequest, NoticeConstants.UPDATE);
MessageSettingDetail messageSettingDetail = noticeService.searchMessage();
List<MessageDetail> taskList=messageSettingDetail.getReviewTask();
taskList.forEach(r->{
switch (r.getType()) {
case NoticeConstants.NAIL_ROBOT:
dingTaskService.sendNailRobot(r,userIds,context,NoticeConstants.CREATE);
break;
case NoticeConstants.WECHAT_ROBOT:
wxChatTaskService.sendWechatRobot(r,userIds,context,NoticeConstants.CREATE);
break;
case NoticeConstants.EMAIL:
mailService.sendReviewerNotice(r,userIds, testCaseReviewRequest,NoticeConstants.CREATE);
break;
}
});
} catch (Exception e) {
LogUtil.error(e);
}
@ -493,8 +521,8 @@ public class TestCaseReviewService {
request.setProjectIds(projectIds);
return extTestReviewCaseMapper.list(request);
}
private String getReviewContext(SaveTestCaseReviewRequest reviewRequest, String type) {
/*通知内容*/
private static String getReviewContext(SaveTestCaseReviewRequest reviewRequest, String type) {
Long startTime = reviewRequest.getCreateTime();
Long endTime = reviewRequest.getEndTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -509,12 +537,13 @@ public class TestCaseReviewService {
end = sdf.format(new Date(Long.parseLong(eTime)));
}
String context = "";
if (StringUtils.equals("create", type)) {
context = reviewRequest.getCreator() + "发起的" + "'" + reviewRequest.getName() + "'" + "待开始,计划开始时间是" + start + "计划结束时间为" + end + "请跟进";
} else if (StringUtils.equals("end", type)) {
context = reviewRequest.getCreator() + "发起的" + "'" + reviewRequest.getName() + "'" + "已完成,计划开始时间是" + start + "计划结束时间为" + end + "已完成";
if (StringUtils.equals(NoticeConstants.CREATE, type)) {
context = reviewRequest.getCreator() + "发起的任务通知" + "'" + reviewRequest.getName() + "'" + "待开始,计划开始时间是" + start + "计划结束时间为" + end + "请跟进";
} else if (StringUtils.equals(NoticeConstants.UPDATE, type)) {
context = reviewRequest.getCreator() + "发起的任务通知" + "'" + reviewRequest.getName() + "'" + "已完成,计划开始时间是" + start + "计划结束时间为" + end + "已完成";
}
return context;
}
}

View File

@ -1,2 +1,5 @@
alter table message_task
add identification varchar(255) not null;
add identification varchar(255) not null;
alter table message_task
add result boolean not null;
alter table message_task change result is_Set tinyint(1) not null;

View File

@ -74,13 +74,13 @@
<el-button
type="primary"
size="mini"
v-show="scope.row.result.showSave"
v-show="scope.row.isSet"
@click="handleAddTask(scope.$index,scope.row)"
>{{ $t('commons.add') }}
</el-button>
<el-button
size="mini"
v-show="scope.row.result.showCancel"
v-show="scope.row.isSet"
@click.native.prevent="removeRowTask(scope.$index,form.jenkinsTask)"
>{{ $t('commons.cancel') }}
</el-button>
@ -88,8 +88,8 @@
type="danger"
icon="el-icon-delete"
size="mini"
v-show="scope.row.result.showDelete"
@click.native.prevent="deleteRowTask(scope.$index,form.jenkinsTask)"
v-show="!scope.row.isSet"
@click.native.prevent="deleteRowTask(scope.$index,scope.row)"
></el-button>
</template>
</el-table-column>
@ -113,7 +113,7 @@
</el-row>
</div>
<el-table
:data="form.testPlanTask"
:data="form.testCasePlanTask"
class="tb-edit"
border
size="mini"
@ -136,7 +136,7 @@
<template v-slot:default="{row}">
<el-select v-model="row.userIds" filterable multiple
:placeholder="$t('commons.please_select')"
@click.native="defectAndTestPlanUserList()" style="width: 100%;">
@click.native="testPlanUserList()" style="width: 100%;">
<el-option
v-for="item in testPlanReceiverOptions"
:key="item.id"
@ -168,22 +168,22 @@
<el-button
type="primary"
size="mini"
v-show="scope.row.result.showSave"
v-show="scope.row.isSet"
@click="handleAddTask(scope.$index,scope.row)"
>{{ $t('commons.add') }}
</el-button>
<el-button
size="mini"
v-show="scope.row.result.showCancel"
@click.native.prevent="removeRowTask(scope.$index,form.testPlanTask)"
v-show="scope.row.isSet"
@click.native.prevent="removeRowTask(scope.$index,form.testCasePlanTask)"
>{{ $t('commons.cancel') }}
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
v-show="scope.row.result.showDelete"
@click.native.prevent="deleteRowTask(scope.$index,form.testPlanTask)"
v-show="!scope.row.isSet"
@click.native.prevent="deleteRowTask(scope.$index,scope.row)"
></el-button>
</template>
</el-table-column>
@ -260,13 +260,13 @@
<el-button
type="primary"
size="mini"
v-show="scope.row.result.showSave"
v-show="scope.row.isSet"
@click="handleAddTask(scope.$index,scope.row)"
>{{ $t('commons.add') }}
</el-button>
<el-button
size="mini"
v-show="scope.row.result.showCancel"
v-show="scope.row.isSet"
@click.native.prevent="removeRowTask(scope.$index,form.reviewTask)"
>{{ $t('commons.cancel') }}
</el-button>
@ -274,8 +274,8 @@
type="danger"
icon="el-icon-delete"
size="mini"
v-show="scope.row.result.showDelete"
@click.native.prevent="deleteRowTask(scope.$index,form.reviewTask)"
v-show="!scope.row.isSet"
@click.native.prevent="deleteRowTask(scope.$index,scope.row)"
></el-button>
</template>
</el-table-column>
@ -320,7 +320,7 @@
<template v-slot:default="{row}">
<el-select v-model="row.userIds" filterable multiple
:placeholder="$t('commons.please_select')"
@click.native="defectAndTestPlanUserList()" style="width: 100%;">
@click.native="defectUserList()" style="width: 100%;">
<el-option
v-for="item in defectReceiverOptions"
:key="item.id"
@ -352,13 +352,13 @@
<el-button
type="primary"
size="mini"
v-show="scope.row.result.showSave"
v-show="scope.row.isSet"
@click="handleAddTask(scope.$index,scope.row)"
>{{ $t('commons.add') }}
</el-button>
<el-button
size="mini"
v-show="scope.row.result.showCancel"
v-show="scope.row.isSet"
@click.native.prevent="removeRowTask(scope.$index,form.defectTask)"
>{{ $t('commons.cancel') }}
</el-button>
@ -366,8 +366,8 @@
type="danger"
icon="el-icon-delete"
size="mini"
v-show="scope.row.result.showDelete"
@click.native.prevent="deleteRowTask(scope.$index,form.defectTask)"
v-show="!scope.row.isSet"
@click.native.prevent="deleteRowTask(scope.$index,scope.row)"
></el-button>
</template>
</el-table-column>
@ -389,53 +389,37 @@ export default {
taskType: "jenkinsTask",
events: [],
userIds: [],
type:[],
type: [],
webhook: "",
result: {
showSave: true,
showCancel: true,
showDelete: false
},
identification:"",
isSet: true,
identification: "",
}],
testPlanTask: [{
testCasePlanTask: [{
taskType: "testPlanTask",
events: [],
userIds: [],
type:[],
type: [],
webhook: "",
result: {
showSave: true,
showCancel: true,
showDelete: false
},
identification:"",
isSet: true,
identification: "",
}],
reviewTask: [{
taskType: "reviewTask",
events: [],
userIds: [],
type:[],
type: [],
webhook: "",
result: {
showSave: true,
showCancel: true,
showDelete: false
},
identification:"",
isSet: true,
identification: "",
}],
defectTask: [{
taskType: "defectTask",
events: [],
userIds: [],
type:[],
type: [],
webhook: "",
result: {
showSave: true,
showCancel: true,
showDelete: false
},
identification:"",
isSet: true,
identification: "",
}],
},
jenkinsEventOptions: [
@ -467,7 +451,7 @@ export default {
methods: {
initForm() {
this.result = this.$get('/notice/search/message', response => {
/*this.form=response.data*/
this.form = response.data
})
},
userList() {
@ -478,62 +462,73 @@ export default {
reviewUerList() {
this.result = this.$get('user/list', response => {
this.reviewReceiverOptions = response.data
this.reviewReceiverOptions.unshift({id: 'Founder', name: this.$t('api_test.creator')},
this.reviewReceiverOptions.unshift({id: 'FOUNDER', name: this.$t('api_test.creator')},
{id: 'Executor', name: this.$t('test_track.plan_view.executor')},
{id: 'Maintainer', name: this.$t('test_track.case.maintainer')})
{id: 'MAINTAINER', name: this.$t('test_track.case.maintainer')})
})
},
defectAndTestPlanUserList() {
defectUserList() {
this.result = this.$get('user/list', response => {
this.defectReceiverOptions = response.data
this.defectReceiverOptions.unshift({id: 'FOUNDER', name: this.$t('api_test.creator')}, {
id: 'EXECUTOR',
name: this.$t('test_track.plan_view.executor')
})
})
},
testPlanUserList() {
this.result = this.$get('user/list', response => {
this.testPlanReceiverOptions = response.data
this.defectReceiverOptions = response.data
this.testPlanReceiverOptions.unshift({id: 'Founder', name: this.$t('api_test.creator')}, {
id: 'Executor',
this.testPlanReceiverOptions.unshift({id: 'FOUNDER', name: this.$t('api_test.creator')}, {
id: 'EXECUTOR',
name: this.$t('test_track.plan_view.executor')
})
})
},
handleAddTaskModel(type) {
let Task = {};
Task.result = {
showSave: true,
showCancel: true,
showDelete: false,
}
Task.events = [];
Task.userIds = [];
Task.type = "";
Task.webhook = "";
Task.isSet = true;
Task.identification = "";
if (type === 'jenkinsTask') {
Task.taskType = 'jenkinsTask'
Task.taskType = 'JENKINS_TASK'
this.form.jenkinsTask.unshift(Task)
} else if (type === 'testPlanTask') {
Task.taskType = 'testPlanTask'
this.form.testPlanTask.unshift(Task)
} else if (type === 'reviewTask') {
Task.taskType = 'reviewTask'
}
if (type === 'testPlanTask') {
Task.taskType = 'TEST_PLAN_TASK'
this.form.testCasePlanTask.unshift(Task)
}
if (type === 'reviewTask') {
Task.taskType = 'REVIEW_TASK'
this.form.reviewTask.unshift(Task)
} else {
Task.taskType = 'defectTask'
}
if (type === 'defectTask') {
Task.taskType = 'DEFECT_TASK'
this.form.defectTask.unshift(Task)
}
},
handleAddTask(index, data) {
let list = []
data.isSet = false
list.push(data)
let param = {};
param.messageDetail = list
this.result = this.$post("/notice/save/message/task", param, () => {
data.result.showSave = false;
data.result.showCancel = false;
data.result.showDelete = true;
})
},
removeRowTask(index, data) { //
data.splice(index, 1)
},
deleteRowTask(index, data) { //
this.result = this.$get("/delete/message" + index, response => {
this.result = this.$get("/notice/delete/message/" + data.identification, response => {
this.initForm()
})
data.splice(index, 1)
/*data.splice(index, 1)*/
},
}
}