fix: 任务通知设置

This commit is contained in:
wenyann 2020-09-02 16:21:40 +08:00
parent 4fa973eff1
commit 2dbe00bf23
9 changed files with 135 additions and 22 deletions

View File

@ -23,6 +23,7 @@ import io.metersphere.controller.request.QueryScheduleRequest;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.mail.MailService;
import io.metersphere.service.FileService;
import io.metersphere.service.QuotaService;
import io.metersphere.service.ScheduleService;
@ -30,6 +31,7 @@ import io.metersphere.track.service.TestCaseService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.aspectj.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -61,6 +63,8 @@ public class APITestService {
private ScheduleService scheduleService;
@Resource
private TestCaseService testCaseService;
@Resource
private MailService mailService;
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
@ -225,6 +229,7 @@ public class APITestService {
apiTest.setUserId(request.getUserId());
}
String reportId = apiReportService.create(apiTest, request.getTriggerMode());
mailService.sendMail(reportId);
changeStatus(request.getId(), APITestStatus.Running);
jMeterService.run(request.getId(), null, is);

View File

@ -0,0 +1,19 @@
package io.metersphere.mail;
import lombok.Data;
@Data
public class Mail {
// 发送给谁
private String to;
// 发送主题
private String subject;
// 发送内容
private String content;
// 附件地址
private String filePath;
}

View File

@ -0,0 +1,5 @@
package io.metersphere.mail;
public interface MailService {
public void sendMail(String reportId);
}

View File

@ -0,0 +1,32 @@
package io.metersphere.mail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Service
public class MailServiceImpl implements MailService {
@Autowired
private JavaMailSender mailSender;
@Value("${mail.fromMail.addr}")
private String mailFrom;
@Override
public void sendMail(String reportId) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(mailFrom);
message.setTo("15135125273@163.com", "wenyan.yang@fit2cloud.com");
message.setSubject("automatic");
message.setText("自动邮件发布");
try {
mailSender.send(message);
System.out.println("发送简单邮件");
} catch (Exception e) {
e.printStackTrace();
System.out.println("发送简单邮件失败");
}
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE `notice` (
`EVENT` varchar(120) NOT NULL,
`TEST_ID` varchar(120) NOT NULL,
`NAME` varchar(200) NOT NULL,
`EMAIL` varchar(200) NOT NULL,
`ENABLE` varchar(200) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@ -1,5 +1,5 @@
<template>
<el-dialog :close-on-click-modal="false" width="35%" class="schedule-edit" :visible.sync="dialogVisible"
<el-dialog :close-on-click-modal="false" width="50%" class="schedule-edit" :visible.sync="dialogVisible"
@close="close">
<template>
<div>
@ -26,18 +26,20 @@
</el-tab-pane>
<el-tab-pane :label="$t('schedule.task_notification')" name="second">
<template>
<el-select v-model="value" :placeholder="$t('commons.please_select')">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
prop="event"
:label="$t('schedule.event')"
>
</el-table-column>
<el-table-column
prop="receiver"
:label="$t('schedule.receiver')"
width="200"
>
<template v-slot:default="{row}">
<el-input
@ -54,7 +56,8 @@
<el-table-column
prop="email"
:label="$t('schedule.receiving_mode')"
width="300">
width="200"
>
<template v-slot:default="{row}">
<el-input
size="mini"
@ -69,8 +72,9 @@
</el-table-column>
<el-table-column
align="center"
:label="$t('schedule.operation')"
show-overflow-tooltip>
prop="enable"
:label="$t('test_resource_pool.enable_disable')"
>
<template slot-scope="scope">
<el-switch
v-model="scope.row.status"
@ -81,7 +85,22 @@
/>
</template>
</el-table-column>
<el-table-column :label="$t('schedule.operation')">
<template v-slot:default="scope">
<el-button
type="primary"
icon="el-icon-plus"
circle size="mini"
@click="handleAddStep(scope.$index, scope.row)"></el-button>
<el-button
type="danger"
icon="el-icon-delete"
circle size="mini"
@click="handleDeleteStep(scope.$index, scope.row)"></el-button>
</template>
</el-table-column>
</el-table>
<el-button type="primary" @click="saveNotice">{{$t('commons.save')}}</el-button>
</template>
</el-tab-pane>
</el-tabs>
@ -145,17 +164,22 @@
form: {
cronValue: ""
},
options: [{
value: 'success',
label: '执行成功通知'
}, {
value: 'fail',
label: '执行失败通知'
}, {
value: 'all',
label: '全部通知'
}],
value: '',
tableData: [
{
event: '执行成功',
receiver: '',
email: '',
operation: 1
}, {
event: '执行成功',
receiver: '',
email: '',
operation: 2
receiver:"",
mail:"",
enable:""
}
],
email: "",
@ -169,6 +193,27 @@
methods: {
handleClick() {
},
saveNotice(){
let param = this.buildParam();
this.result=this.$post(()=>{
})
},
buildParam() {
let param = {};
return param;
},
handleAddStep(index, data) {
let step = {};
step.num = data.num + 1;
step.desc = null;
step.result = null;
this.tableData.splice(index + 1, 0, step);
},
handleDeleteStep(index, data) {
this.tableData.splice(index, 1);
},
open() {
this.dialogVisible = true;

View File

@ -810,7 +810,7 @@ export default {
schedule: {
input_email: "Please input email account",
event: "event",
receiving_mode: "Receiving mode",
receiving_mode: "mailbox",
receiver: "Receiver",
operation: "operation",
task_notification: "Task notification",

View File

@ -812,7 +812,7 @@ export default {
schedule: {
input_email: "请输入邮箱账号",
event: "事件",
receiving_mode: "接收方式",
receiving_mode: "邮箱",
receiver: "接收人",
operation: "操作",
task_notification: "任务通知",

View File

@ -809,7 +809,7 @@ export default {
schedule: {
input_email: "請輸入郵箱帳號",
event: "事件",
receiving_mode: "接收管道",
receiving_mode: "郵箱",
receiver: "接收人",
operation: "操作",
task_notification: "任務通知",