refactor: 重构邮件通知部分

This commit is contained in:
Captain.B 2020-09-27 14:41:04 +08:00
parent 22b0a423bd
commit 5ae9f9a2df
11 changed files with 146 additions and 41 deletions

View File

@ -16,5 +16,7 @@ public class Notice implements Serializable {
private String enable; private String enable;
private String type;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -453,6 +453,76 @@ public class NoticeExample {
addCriterion("`ENABLE` not between", value1, value2, "enable"); addCriterion("`ENABLE` not between", value1, value2, "enable");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTypeIsNull() {
addCriterion("`type` is null");
return (Criteria) this;
}
public Criteria andTypeIsNotNull() {
addCriterion("`type` is not null");
return (Criteria) this;
}
public Criteria andTypeEqualTo(String value) {
addCriterion("`type` =", value, "type");
return (Criteria) this;
}
public Criteria andTypeNotEqualTo(String value) {
addCriterion("`type` <>", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThan(String value) {
addCriterion("`type` >", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThanOrEqualTo(String value) {
addCriterion("`type` >=", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThan(String value) {
addCriterion("`type` <", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThanOrEqualTo(String value) {
addCriterion("`type` <=", value, "type");
return (Criteria) this;
}
public Criteria andTypeLike(String value) {
addCriterion("`type` like", value, "type");
return (Criteria) this;
}
public Criteria andTypeNotLike(String value) {
addCriterion("`type` not like", value, "type");
return (Criteria) this;
}
public Criteria andTypeIn(List<String> values) {
addCriterion("`type` in", values, "type");
return (Criteria) this;
}
public Criteria andTypeNotIn(List<String> values) {
addCriterion("`type` not in", values, "type");
return (Criteria) this;
}
public Criteria andTypeBetween(String value1, String value2) {
addCriterion("`type` between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andTypeNotBetween(String value1, String value2) {
addCriterion("`type` not between", value1, value2, "type");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -7,6 +7,7 @@
<result column="TEST_ID" jdbcType="VARCHAR" property="testId" /> <result column="TEST_ID" jdbcType="VARCHAR" property="testId" />
<result column="NAME" jdbcType="VARCHAR" property="name" /> <result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="ENABLE" jdbcType="VARCHAR" property="enable" /> <result column="ENABLE" jdbcType="VARCHAR" property="enable" />
<result column="type" jdbcType="VARCHAR" property="type" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -67,7 +68,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, EVENT, TEST_ID, `NAME`, `ENABLE` id, EVENT, TEST_ID, `NAME`, `ENABLE`, `type`
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.NoticeExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.base.domain.NoticeExample" resultMap="BaseResultMap">
select select
@ -84,26 +85,26 @@
</if> </if>
</select> </select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
SELECT select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM notice from notice
WHERE id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
DELETE FROM notice DELETE FROM notice
WHERE id = #{id,jdbcType=VARCHAR} WHERE id = #{id,jdbcType=VARCHAR}
</delete> </delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.NoticeExample"> <delete id="deleteByExample" parameterType="io.metersphere.base.domain.NoticeExample">
DELETE FROM notice delete from notice
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.base.domain.Notice"> <insert id="insert" parameterType="io.metersphere.base.domain.Notice">
INSERT INTO notice (id, EVENT, TEST_ID, INSERT INTO notice (id, EVENT, TEST_ID,
`NAME`, `ENABLE`) `NAME`, `ENABLE`, `type`)
VALUES (#{id,jdbcType=VARCHAR}, #{event,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR}, VALUES (#{id,jdbcType=VARCHAR}, #{event,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{enable,jdbcType=VARCHAR}) #{name,jdbcType=VARCHAR}, #{enable,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.Notice"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.Notice">
insert into notice insert into notice
@ -123,6 +124,9 @@
<if test="enable != null"> <if test="enable != null">
`ENABLE`, `ENABLE`,
</if> </if>
<if test="type != null">
`type`,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -140,6 +144,9 @@
<if test="enable != null"> <if test="enable != null">
#{enable,jdbcType=VARCHAR}, #{enable,jdbcType=VARCHAR},
</if> </if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.NoticeExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.base.domain.NoticeExample" resultType="java.lang.Long">
@ -166,24 +173,28 @@
<if test="record.enable != null"> <if test="record.enable != null">
`ENABLE` = #{record.enable,jdbcType=VARCHAR}, `ENABLE` = #{record.enable,jdbcType=VARCHAR},
</if> </if>
<if test="record.type != null">
`type` = #{record.type,jdbcType=VARCHAR},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map"> <update id="updateByExample" parameterType="map">
UPDATE notice update notice
SET id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
EVENT = #{record.event,jdbcType=VARCHAR}, EVENT = #{record.event,jdbcType=VARCHAR},
TEST_ID = #{record.testId,jdbcType=VARCHAR}, TEST_ID = #{record.testId,jdbcType=VARCHAR},
`NAME` = #{record.name,jdbcType=VARCHAR}, `NAME` = #{record.name,jdbcType=VARCHAR},
`ENABLE` = #{record.enable,jdbcType=VARCHAR} `ENABLE` = #{record.enable,jdbcType=VARCHAR},
`type` = #{record.type,jdbcType=VARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.Notice"> <update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.Notice">
UPDATE notice update notice
<set> <set>
<if test="event != null"> <if test="event != null">
EVENT = #{event,jdbcType=VARCHAR}, EVENT = #{event,jdbcType=VARCHAR},
@ -197,15 +208,19 @@
<if test="enable != null"> <if test="enable != null">
`ENABLE` = #{enable,jdbcType=VARCHAR}, `ENABLE` = #{enable,jdbcType=VARCHAR},
</if> </if>
<if test="type != null">
`type` = #{type,jdbcType=VARCHAR},
</if>
</set> </set>
WHERE id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.Notice"> <update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.Notice">
UPDATE notice UPDATE notice
SET EVENT = #{event,jdbcType=VARCHAR}, SET EVENT = #{event,jdbcType=VARCHAR},
TEST_ID = #{testId,jdbcType=VARCHAR}, TEST_ID = #{testId,jdbcType=VARCHAR},
`NAME` = #{name,jdbcType=VARCHAR}, `NAME` = #{name,jdbcType=VARCHAR},
`ENABLE` = #{enable,jdbcType=VARCHAR} `ENABLE` = #{enable,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR}
WHERE id = #{id,jdbcType=VARCHAR} WHERE id = #{id,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>

View File

@ -222,10 +222,10 @@ public class MailService {
List<String> failEmailList = new ArrayList<>(); List<String> failEmailList = new ArrayList<>();
if (noticeList.size() > 0) { if (noticeList.size() > 0) {
for (NoticeDetail n : noticeList) { for (NoticeDetail n : noticeList) {
if (n.getEnable().equals("true") && n.getEvent().equals("执行成功")) { if (n.getEnable().equals("true") && n.getEvent().equals("EXECUTE_SUCCESSFUL")) {
successEmailList = userService.queryEmail(n.getNames()); successEmailList = userService.queryEmail(n.getNames());
} }
if (n.getEnable().equals("true") && n.getEvent().equals("执行失败")) { if (n.getEnable().equals("true") && n.getEvent().equals("EXECUTE_FAILED")) {
failEmailList = userService.queryEmail(n.getNames()); failEmailList = userService.queryEmail(n.getNames());
} }
} }

View File

@ -18,7 +18,6 @@ public class NoticeService {
private NoticeMapper noticeMapper; private NoticeMapper noticeMapper;
public void saveNotice(NoticeRequest noticeRequest) { public void saveNotice(NoticeRequest noticeRequest) {
Notice notice = new Notice();
NoticeExample example = new NoticeExample(); NoticeExample example = new NoticeExample();
example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId()); example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId());
List<Notice> notices = noticeMapper.selectByExample(example); List<Notice> notices = noticeMapper.selectByExample(example);
@ -28,11 +27,13 @@ public class NoticeService {
noticeRequest.getNotices().forEach(n -> { noticeRequest.getNotices().forEach(n -> {
if (n.getNames().length > 0) { if (n.getNames().length > 0) {
for (String x : n.getNames()) { for (String x : n.getNames()) {
Notice notice = new Notice();
notice.setId(UUID.randomUUID().toString()); notice.setId(UUID.randomUUID().toString());
notice.setEvent(n.getEvent()); notice.setEvent(n.getEvent());
notice.setEnable(n.getEnable()); notice.setEnable(n.getEnable());
notice.setTestId(noticeRequest.getTestId()); notice.setTestId(noticeRequest.getTestId());
notice.setName(x); notice.setName(x);
notice.setType(n.getType());
noticeMapper.insert(notice); noticeMapper.insert(notice);
} }
} }
@ -52,16 +53,18 @@ public class NoticeService {
NoticeDetail notice2 = new NoticeDetail(); NoticeDetail notice2 = new NoticeDetail();
if (notices.size() > 0) { if (notices.size() > 0) {
for (Notice n : notices) { for (Notice n : notices) {
if (n.getEvent().equals("执行成功")) { if (n.getEvent().equals("EXECUTE_SUCCESSFUL")) {
success.add(n.getName()); success.add(n.getName());
notice1.setEnable(n.getEnable()); notice1.setEnable(n.getEnable());
notice1.setTestId(id); notice1.setTestId(id);
notice1.setType(n.getType());
notice1.setEvent(n.getEvent()); notice1.setEvent(n.getEvent());
} }
if (n.getEvent().equals("执行失败")) { if (n.getEvent().equals("EXECUTE_FAILED")) {
fail.add(n.getName()); fail.add(n.getName());
notice2.setEnable(n.getEnable()); notice2.setEnable(n.getEnable());
notice2.setTestId(id); notice2.setTestId(id);
notice2.setType(n.getType());
notice2.setEvent(n.getEvent()); notice2.setEvent(n.getEvent());
} }
} }

View File

@ -6,3 +6,5 @@ ALTER TABLE notice
MODIFY COLUMN id VARCHAR(50) PRIMARY KEY; MODIFY COLUMN id VARCHAR(50) PRIMARY KEY;
ALTER TABLE notice ALTER TABLE notice
DROP COLUMN EMAIL; DROP COLUMN EMAIL;
ALTER TABLE notice
ADD COLUMN type VARCHAR(100) DEFAULT 'EMAIL';

View File

@ -1,5 +1,5 @@
<template> <template>
<el-dialog :close-on-click-modal="false" width="50%" class="schedule-edit" :visible.sync="dialogVisible" <el-dialog :close-on-click-modal="false" width="60%" class="schedule-edit" :visible.sync="dialogVisible"
@close="close"> @close="close">
<template> <template>
<div> <div>
@ -21,7 +21,7 @@
</el-form-item> </el-form-item>
<crontab-result :ex="form.cronValue" ref="crontabResult"/> <crontab-result :ex="form.cronValue" ref="crontabResult"/>
</el-form> </el-form>
<el-dialog :title="$t('schedule.generate_expression')" :visible.sync="showCron" :modal="false"> <el-dialog width="60%" :title="$t('schedule.generate_expression')" :visible.sync="showCron" :modal="false">
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value" ref="crontab"/> <crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value" ref="crontab"/>
</el-dialog> </el-dialog>
</el-tab-pane> </el-tab-pane>
@ -32,9 +32,12 @@
style="width: 100%"> style="width: 100%">
<el-table-column <el-table-column
prop="event" prop="event"
:label="$t('schedule.event')" :label="$t('schedule.event')">
<template v-slot:default="{row}">
> <span v-if="row.event === 'EXECUTE_SUCCESSFUL'"> {{ $t('schedule.event_success') }}</span>
<span v-else-if="row.event === 'EXECUTE_FAILED'"> {{ $t('schedule.event_failed') }}</span>
<span v-else>{{ row.event }}</span>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="name" prop="name"
@ -42,7 +45,8 @@
width="200" width="200"
> >
<template v-slot:default="{row}"> <template v-slot:default="{row}">
<el-select v-model="row.names" filterable multiple placeholder="请选择" @click.native="userList()"> <el-select v-model="row.names" filterable multiple :placeholder="$t('commons.please_select')"
@click.native="userList()">
<el-option <el-option
v-for="item in options" v-for="item in options"
:key="item.id" :key="item.id"
@ -53,7 +57,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
prop="email" prop="type"
:label="$t('schedule.receiving_mode')" :label="$t('schedule.receiving_mode')"
> >
</el-table-column> </el-table-column>
@ -142,19 +146,21 @@ export default {
}, },
tableData: [ tableData: [
{ {
event: "执行成功", event: "EXECUTE_SUCCESSFUL",
type: "EMAIL",
names: [], names: [],
enable: false enable: false
}, },
{ {
event: "执行失败", event: "EXECUTE_FAILED",
type: "EMAIL",
names: [], names: [],
enable: false enable: false
} }
], ],
options: [{}], options: [{}],
enable: true, enable: true,
email: "", type: "",
activeName: 'first', activeName: 'first',
rules: { rules: {
cronValue: [{required: true, validator: validateCron, trigger: 'blur'}], cronValue: [{required: true, validator: validateCron, trigger: 'blur'}],
@ -168,14 +174,15 @@ export default {
}) })
}, },
handleClick() { handleClick() {
if (this.activeName == "second") { if (this.activeName === "second") {
this.result = this.$get('notice/query/' + this.testId, response => { this.result = this.$get('notice/query/' + this.testId, response => {
if (response.data.length > 0) { if (response.data.length > 0) {
this.tableData = response.data this.tableData = response.data
this.tableData[0].email="邮箱"
this.tableData[0].event="执行成功" this.tableData[0].event = "EXECUTE_SUCCESSFUL"
this.tableData[1].email="邮箱" this.tableData[0].type = "EMAIL"
this.tableData[1].event="执行失败" this.tableData[1].event = "EXECUTE_FAILED"
this.tableData[1].type = "EMAIL"
} else { } else {
this.tableData[0].names = [] this.tableData[0].names = []
this.tableData[1].names = [] this.tableData[1].names = []

@ -1 +1 @@
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1 Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9

View File

@ -930,6 +930,8 @@ export default {
schedule: { schedule: {
input_email: "Please input email account", input_email: "Please input email account",
event: "event", event: "event",
event_success: 'EXECUTE SUCCESSFUL',
event_failed: 'EXECUTE FAILED',
receiving_mode: "mailbox", receiving_mode: "mailbox",
receiver: "Receiver", receiver: "Receiver",
operation: "operation", operation: "operation",

View File

@ -935,6 +935,8 @@ export default {
schedule: { schedule: {
input_email: "请输入邮箱账号", input_email: "请输入邮箱账号",
event: "事件", event: "事件",
event_success: '执行成功',
event_failed: '执行失败',
receiving_mode: "接收方式", receiving_mode: "接收方式",
receiver: "接收人", receiver: "接收人",
operation: "操作", operation: "操作",

View File

@ -931,6 +931,8 @@ export default {
schedule: { schedule: {
input_email: "請輸入郵箱賬號", input_email: "請輸入郵箱賬號",
event: "事件", event: "事件",
event_success: '執行成功',
event_failed: '執行失敗',
receiving_mode: "接收方式", receiving_mode: "接收方式",
receiver: "接收人", receiver: "接收人",
operation: "操作", operation: "操作",