forked from github/dataease
feat: 消息订阅增加邮件渠道
This commit is contained in:
parent
75a22aabdb
commit
5ce64f0d09
@ -1,20 +1,15 @@
|
||||
package io.dataease.base.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("消息渠道")
|
||||
public class SysMsgChannel implements Serializable {
|
||||
|
||||
@ApiModelProperty("消息渠道ID")
|
||||
private Long msgChannelId;
|
||||
|
||||
@ApiModelProperty("消息渠道名称")
|
||||
private String channelName;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
@ -233,6 +233,76 @@ public class SysMsgChannelExample {
|
||||
addCriterion("channel_name not between", value1, value2, "channelName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameIsNull() {
|
||||
addCriterion("service_name is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameIsNotNull() {
|
||||
addCriterion("service_name is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameEqualTo(String value) {
|
||||
addCriterion("service_name =", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameNotEqualTo(String value) {
|
||||
addCriterion("service_name <>", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameGreaterThan(String value) {
|
||||
addCriterion("service_name >", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("service_name >=", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameLessThan(String value) {
|
||||
addCriterion("service_name <", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameLessThanOrEqualTo(String value) {
|
||||
addCriterion("service_name <=", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameLike(String value) {
|
||||
addCriterion("service_name like", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameNotLike(String value) {
|
||||
addCriterion("service_name not like", value, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameIn(List<String> values) {
|
||||
addCriterion("service_name in", values, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameNotIn(List<String> values) {
|
||||
addCriterion("service_name not in", values, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameBetween(String value1, String value2) {
|
||||
addCriterion("service_name between", value1, value2, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andServiceNameNotBetween(String value1, String value2) {
|
||||
addCriterion("service_name not between", value1, value2, "serviceName");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
@ -4,6 +4,7 @@
|
||||
<resultMap id="BaseResultMap" type="io.dataease.base.domain.SysMsgChannel">
|
||||
<id column="msg_channel_id" jdbcType="BIGINT" property="msgChannelId" />
|
||||
<result column="channel_name" jdbcType="VARCHAR" property="channelName" />
|
||||
<result column="service_name" jdbcType="VARCHAR" property="serviceName" />
|
||||
</resultMap>
|
||||
<sql id="Example_Where_Clause">
|
||||
<where>
|
||||
@ -64,7 +65,7 @@
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
msg_channel_id, channel_name
|
||||
msg_channel_id, channel_name, service_name
|
||||
</sql>
|
||||
<select id="selectByExample" parameterType="io.dataease.base.domain.SysMsgChannelExample" resultMap="BaseResultMap">
|
||||
select
|
||||
@ -97,8 +98,10 @@
|
||||
</if>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="io.dataease.base.domain.SysMsgChannel">
|
||||
insert into sys_msg_channel (msg_channel_id, channel_name)
|
||||
values (#{msgChannelId,jdbcType=BIGINT}, #{channelName,jdbcType=VARCHAR})
|
||||
insert into sys_msg_channel (msg_channel_id, channel_name, service_name
|
||||
)
|
||||
values (#{msgChannelId,jdbcType=BIGINT}, #{channelName,jdbcType=VARCHAR}, #{serviceName,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.dataease.base.domain.SysMsgChannel">
|
||||
insert into sys_msg_channel
|
||||
@ -109,6 +112,9 @@
|
||||
<if test="channelName != null">
|
||||
channel_name,
|
||||
</if>
|
||||
<if test="serviceName != null">
|
||||
service_name,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="msgChannelId != null">
|
||||
@ -117,6 +123,9 @@
|
||||
<if test="channelName != null">
|
||||
#{channelName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="serviceName != null">
|
||||
#{serviceName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<select id="countByExample" parameterType="io.dataease.base.domain.SysMsgChannelExample" resultType="java.lang.Long">
|
||||
@ -134,6 +143,9 @@
|
||||
<if test="record.channelName != null">
|
||||
channel_name = #{record.channelName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.serviceName != null">
|
||||
service_name = #{record.serviceName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
@ -142,7 +154,8 @@
|
||||
<update id="updateByExample" parameterType="map">
|
||||
update sys_msg_channel
|
||||
set msg_channel_id = #{record.msgChannelId,jdbcType=BIGINT},
|
||||
channel_name = #{record.channelName,jdbcType=VARCHAR}
|
||||
channel_name = #{record.channelName,jdbcType=VARCHAR},
|
||||
service_name = #{record.serviceName,jdbcType=VARCHAR}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
@ -153,12 +166,16 @@
|
||||
<if test="channelName != null">
|
||||
channel_name = #{channelName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="serviceName != null">
|
||||
service_name = #{serviceName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where msg_channel_id = #{msgChannelId,jdbcType=BIGINT}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.SysMsgChannel">
|
||||
update sys_msg_channel
|
||||
set channel_name = #{channelName,jdbcType=VARCHAR}
|
||||
set channel_name = #{channelName,jdbcType=VARCHAR},
|
||||
service_name = #{serviceName,jdbcType=VARCHAR}
|
||||
where msg_channel_id = #{msgChannelId,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
@ -6,8 +6,8 @@ import io.dataease.controller.sys.response.BasicInfo;
|
||||
import io.dataease.controller.sys.response.MailInfo;
|
||||
import io.dataease.dto.SystemParameterDTO;
|
||||
import io.dataease.service.FileService;
|
||||
import io.dataease.service.system.EmailService;
|
||||
import io.dataease.service.system.SystemParameterService;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -16,12 +16,12 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApiIgnore
|
||||
@RestController
|
||||
@RequestMapping(value = "/system")
|
||||
@ -32,10 +32,13 @@ public class SystemParameterController {
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
|
||||
@Resource
|
||||
private EmailService emailService;
|
||||
|
||||
|
||||
@GetMapping("/mail/info")
|
||||
public MailInfo mailInfo() {
|
||||
return systemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
|
||||
return emailService.mailInfo();
|
||||
}
|
||||
|
||||
@GetMapping("/basic/info")
|
||||
@ -51,7 +54,7 @@ public class SystemParameterController {
|
||||
|
||||
@PostMapping("/edit/email")
|
||||
public void editMail(@RequestBody List<SystemParameter> systemParameter) {
|
||||
systemParameterService.editMail(systemParameter);
|
||||
emailService.editMail(systemParameter);
|
||||
}
|
||||
|
||||
@PostMapping("/edit/basic")
|
||||
@ -61,7 +64,7 @@ public class SystemParameterController {
|
||||
|
||||
@PostMapping("/testConnection")
|
||||
public void testConnection(@RequestBody HashMap<String, String> hashMap) {
|
||||
systemParameterService.testConnection(hashMap);
|
||||
emailService.testConnection(hashMap);
|
||||
}
|
||||
|
||||
@GetMapping("/version")
|
||||
|
@ -413,7 +413,7 @@ public class ExtractDataService {
|
||||
if (ObjectUtils.isNotEmpty(datasetTableTask) && ObjectUtils.isNotEmpty(datasetTableTask.getName())) {
|
||||
content += " 任务名称【" + datasetTableTask.getName() + "】";
|
||||
}
|
||||
DeMsgutil.sendMsg(userId, typeId, 1L, content, gson.toJson(param));
|
||||
DeMsgutil.sendMsg(userId, typeId, content, gson.toJson(param));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ public class DatasourceService {
|
||||
|
||||
String content = "数据源【" + datasource.getName() + "】无效";
|
||||
|
||||
DeMsgutil.sendMsg(userId, typeId, 1L, content, gson.toJson(param));
|
||||
DeMsgutil.sendMsg(userId, typeId, content, gson.toJson(param));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,9 @@ public class DeMsgutil {
|
||||
|
||||
|
||||
|
||||
public static void sendMsg(Long userId, Long typeId, Long channelId, String content, String param) {
|
||||
// SysMsg sysMsg = new SysMsg();
|
||||
// sysMsg.setUserId(userId);
|
||||
// sysMsg.setTypeId(typeId);
|
||||
// sysMsg.setContent(content);
|
||||
// sysMsg.setStatus(false);
|
||||
// sysMsg.setCreateTime(System.currentTimeMillis());
|
||||
// sysMsg.setParam(param);
|
||||
sysMsgService.sendMsg(userId, typeId, channelId, content, param);
|
||||
public static void sendMsg(Long userId, Long typeId, String content, String param) {
|
||||
|
||||
sysMsgService.sendMsg(userId, typeId, content, param);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
package io.dataease.service.message;
|
||||
|
||||
|
||||
import io.dataease.controller.sys.response.SubscribeNode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class MsgAop {
|
||||
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private SysMsgService sysMsgService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 对sendMsg 切面拦截
|
||||
* @param point
|
||||
*/
|
||||
@Around("(execution(* io.dataease.service.message.SysMsgService.sendMsg(..)))")
|
||||
public Object cutPoint(ProceedingJoinPoint point) {
|
||||
|
||||
Object[] args = point.getArgs();
|
||||
Object arg0 = args[0];
|
||||
Object arg1 = args[1];
|
||||
Object arg2 = args[2];
|
||||
|
||||
if (ObjectUtils.isEmpty(arg0) || ObjectUtils.isEmpty(arg1) || ObjectUtils.isEmpty(arg2)) {
|
||||
return null;
|
||||
}
|
||||
Long userId = (Long) arg0;
|
||||
Long typeId = (Long) arg1;
|
||||
Long channelId = (Long) arg2;
|
||||
|
||||
List<SubscribeNode> subscribes = sysMsgService.subscribes(userId);
|
||||
|
||||
try {
|
||||
// 如果已经订阅了这种类型的消息 直接发送 否则直接返回
|
||||
if (CollectionUtils.isNotEmpty(subscribes) && subscribes.stream().anyMatch(item -> item.match(typeId, channelId)))
|
||||
return point.proceed(args);
|
||||
return null;
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import io.dataease.controller.sys.request.MsgSettingRequest;
|
||||
import io.dataease.controller.sys.response.MsgGridDto;
|
||||
import io.dataease.controller.sys.response.SettingTreeNode;
|
||||
import io.dataease.controller.sys.response.SubscribeNode;
|
||||
import io.dataease.service.message.service.SendService;
|
||||
import io.dataease.service.system.SystemParameterService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@ -280,15 +281,22 @@ public class SysMsgService {
|
||||
extSysMsgMapper.batchInsert(settings);
|
||||
}
|
||||
|
||||
public void sendMsg(Long userId, Long typeId, Long channelId, String content, String param) {
|
||||
SysMsg sysMsg = new SysMsg();
|
||||
sysMsg.setUserId(userId);
|
||||
sysMsg.setTypeId(typeId);
|
||||
sysMsg.setContent(content);
|
||||
sysMsg.setStatus(false);
|
||||
sysMsg.setCreateTime(System.currentTimeMillis());
|
||||
sysMsg.setParam(param);
|
||||
save(sysMsg);
|
||||
public void sendMsg(Long userId, Long typeId, String content, String param) {
|
||||
List<SubscribeNode> subscribes = subscribes(userId);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(subscribes)) {
|
||||
subscribes.stream().filter(item -> item.getTypeId() == typeId).forEach(sub -> {
|
||||
SendService sendService = serviceByChannel(sub.getChannelId());
|
||||
sendService.sendMsg(userId, typeId, content, param);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private SendService serviceByChannel(Long channelId){
|
||||
String beanName = sysMsgChannelMapper.selectByPrimaryKey(channelId).getServiceName();
|
||||
return (SendService)CommonBeanFactory.getBean(beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,7 @@
|
||||
package io.dataease.service.message.service;
|
||||
|
||||
public interface SendService {
|
||||
|
||||
|
||||
void sendMsg(Long userId, Long typeId, String content, String param);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.dataease.service.message.service.strategy;
|
||||
|
||||
import io.dataease.auth.service.AuthUserService;
|
||||
import io.dataease.service.message.service.SendService;
|
||||
import io.dataease.service.system.EmailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service("sendEmail")
|
||||
public class SendEmail implements SendService {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
@Autowired
|
||||
private AuthUserService authUserService;
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void sendMsg(Long userId, Long typeId, String content, String param) {
|
||||
String email = authUserService.getUserById(userId).getEmail();
|
||||
|
||||
emailService.send(email, content, content);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.dataease.service.message.service.strategy;
|
||||
|
||||
import io.dataease.base.domain.SysMsg;
|
||||
import io.dataease.base.mapper.SysMsgMapper;
|
||||
import io.dataease.service.message.service.SendService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service("sendStation")
|
||||
public class SendStation implements SendService {
|
||||
|
||||
@Resource
|
||||
private SysMsgMapper sysMsgMapper;
|
||||
|
||||
@Override
|
||||
public void sendMsg(Long userId, Long typeId, String content, String param) {
|
||||
|
||||
SysMsg sysMsg = new SysMsg();
|
||||
sysMsg.setUserId(userId);
|
||||
sysMsg.setTypeId(typeId);
|
||||
sysMsg.setContent(content);
|
||||
sysMsg.setStatus(false);
|
||||
sysMsg.setCreateTime(System.currentTimeMillis());
|
||||
sysMsg.setParam(param);
|
||||
|
||||
sysMsgMapper.insert(sysMsg);
|
||||
|
||||
}
|
||||
}
|
@ -136,13 +136,13 @@ public class ShareService {
|
||||
msgParam.add(panelGroupId);
|
||||
addUserIdSet.forEach(userId -> {
|
||||
if (!redUserIdSet.contains(userId) && user.getUserId() != userId){
|
||||
DeMsgutil.sendMsg(userId, 2L, 1L,user.getNickName()+" 分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
DeMsgutil.sendMsg(userId, 2L,user.getNickName()+" 分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
}
|
||||
});
|
||||
|
||||
redUserIdSet.forEach(userId -> {
|
||||
if (!addUserIdSet.contains(userId) && user.getUserId() != userId){
|
||||
DeMsgutil.sendMsg(userId, 3L, 1L,user.getNickName()+" 取消分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
DeMsgutil.sendMsg(userId, 3L, user.getNickName()+" 取消分享了仪表板【"+msg+"】,请查收!", gson.toJson(msgParam));
|
||||
}
|
||||
});
|
||||
|
||||
@ -265,7 +265,7 @@ public class ShareService {
|
||||
Gson gson = new Gson();
|
||||
userIdSet.forEach(userId -> {
|
||||
// DeMsgutil.sendMsg(userId, 0, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!");
|
||||
DeMsgutil.sendMsg(userId, 2L,1L, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!", gson.toJson(panelIds));
|
||||
DeMsgutil.sendMsg(userId, 2L, user.getNickName()+" 分享了仪表板【"+msg+"】给您,请查收!", gson.toJson(panelIds));
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,199 @@
|
||||
package io.dataease.service.system;
|
||||
|
||||
import io.dataease.base.domain.SystemParameter;
|
||||
import io.dataease.base.domain.SystemParameterExample;
|
||||
import io.dataease.base.mapper.SystemParameterMapper;
|
||||
import io.dataease.commons.constants.ParamConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.EncryptUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.controller.sys.response.MailInfo;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
@Service
|
||||
public class EmailService {
|
||||
|
||||
private static final String SSL_CLASS_KEY = "mail.smtp.socketFactory.class";
|
||||
|
||||
private static final String SSL_CLASS_VAL = "javax.net.ssl.SSLSocketFactory";
|
||||
|
||||
private static final String TLS_PROP_KEY = "mail.smtp.starttls.enable";
|
||||
|
||||
private static final String SMTP_TIMEOUT_KEY = "mail.smtp.timeout";
|
||||
|
||||
private static final String SMTP_TIMEOUT_VAL = "30000";
|
||||
|
||||
private static final String SMTP_CONNECTIONTIMEOUT_KEY = "mail.smtp.connectiontimeout";
|
||||
|
||||
private static final String SMTP_CONNECTIONTIMEOUT_VAL = "5000";
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private SystemParameterMapper systemParameterMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param to 收件人
|
||||
* @param title 标题
|
||||
* @param content 内容
|
||||
*/
|
||||
public void send(String to, String title, String content) {
|
||||
if (StringUtils.isBlank(to)) return ;
|
||||
MailInfo mailInfo = proxy().mailInfo();
|
||||
JavaMailSenderImpl driver = driver(mailInfo);
|
||||
|
||||
MimeMessage mimeMessage = driver.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(driver.getUsername());
|
||||
helper.setSubject(title );
|
||||
helper.setText(content, true);
|
||||
helper.setTo(to);
|
||||
driver.send(mimeMessage);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
}
|
||||
|
||||
public JavaMailSenderImpl driver(MailInfo mailInfo) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setHost(mailInfo.getHost());
|
||||
javaMailSender.setPort(Integer.valueOf(mailInfo.getPort()));
|
||||
javaMailSender.setUsername(mailInfo.getAccount());
|
||||
javaMailSender.setPassword(mailInfo.getPassword());
|
||||
Properties props = new Properties();
|
||||
if (BooleanUtils.toBoolean(mailInfo.getSsl())) {
|
||||
props.put(SSL_CLASS_KEY, SSL_CLASS_VAL);
|
||||
}
|
||||
if (BooleanUtils.toBoolean(mailInfo.getTls())) {
|
||||
props.put(TLS_PROP_KEY, "true");
|
||||
}
|
||||
props.put(SMTP_TIMEOUT_KEY, SMTP_TIMEOUT_VAL);
|
||||
props.put(SMTP_CONNECTIONTIMEOUT_KEY, SMTP_CONNECTIONTIMEOUT_VAL);
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
return javaMailSender;
|
||||
}
|
||||
|
||||
private EmailService proxy() {
|
||||
return CommonBeanFactory.getBean(EmailService.class);
|
||||
}
|
||||
|
||||
|
||||
public MailInfo mailInfo() {
|
||||
String type = ParamConstants.Classify.MAIL.getValue();
|
||||
List<SystemParameter> paramList = getParamList(type);
|
||||
MailInfo mailInfo = new MailInfo();
|
||||
if (!CollectionUtils.isEmpty(paramList)) {
|
||||
for (SystemParameter param : paramList) {
|
||||
if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SERVER.getValue())) {
|
||||
mailInfo.setHost(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PORT.getValue())) {
|
||||
mailInfo.setPort(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.ACCOUNT.getValue())) {
|
||||
mailInfo.setAccount(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
String password = EncryptUtils.aesDecrypt(param.getParamValue()).toString();
|
||||
mailInfo.setPassword(password);
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SSL.getValue())) {
|
||||
mailInfo.setSsl(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.TLS.getValue())) {
|
||||
mailInfo.setTls(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.RECIPIENTS.getValue())) {
|
||||
mailInfo.setRecipient(param.getParamValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return mailInfo;
|
||||
}
|
||||
|
||||
|
||||
public List<SystemParameter> getParamList(String type) {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
example.createCriteria().andParamKeyLike(type + "%");
|
||||
return systemParameterMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
|
||||
public void editMail(List<SystemParameter> parameters) {
|
||||
/*List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
boolean empty = paramList.size() <= 0;*/
|
||||
parameters.forEach(parameter -> {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
if (parameter.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
if (!StringUtils.isBlank(parameter.getParamValue())) {
|
||||
String string = EncryptUtils.aesEncrypt(parameter.getParamValue()).toString();
|
||||
parameter.setParamValue(string);
|
||||
}
|
||||
}
|
||||
example.createCriteria().andParamKeyEqualTo(parameter.getParamKey());
|
||||
if (systemParameterMapper.countByExample(example) > 0) {
|
||||
systemParameterMapper.updateByPrimaryKey(parameter);
|
||||
} else {
|
||||
systemParameterMapper.insert(parameter);
|
||||
}
|
||||
example.clear();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void testConnection(HashMap<String, String> hashMap) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.SERVER.getValue()));
|
||||
javaMailSender.setPort(Integer.valueOf(hashMap.get(ParamConstants.MAIL.PORT.getValue())));
|
||||
javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getValue()));
|
||||
javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getValue()));
|
||||
Properties props = new Properties();
|
||||
String recipients = hashMap.get(ParamConstants.MAIL.RECIPIENTS.getValue());
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.SSL.getValue()))) {
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
}
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getValue()))) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
props.put("mail.smtp.timeout", "30000");
|
||||
props.put("mail.smtp.connectiontimeout", "5000");
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
try {
|
||||
javaMailSender.testConnection();
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
if(!StringUtils.isBlank(recipients)){
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("DataEase测试邮件 " );
|
||||
helper.setText("这是一封测试邮件,邮件发送成功", true);
|
||||
helper.setTo(recipients);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -9,24 +9,16 @@ import io.dataease.commons.constants.ParamConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.EncryptUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.controller.sys.response.BasicInfo;
|
||||
import io.dataease.controller.sys.response.MailInfo;
|
||||
import io.dataease.dto.SystemParameterDTO;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.service.FileService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
@ -44,6 +36,7 @@ public class SystemParameterService {
|
||||
private FileService fileService;
|
||||
|
||||
|
||||
|
||||
public String searchEmail() {
|
||||
return extSystemParameterMapper.email();
|
||||
}
|
||||
@ -67,31 +60,7 @@ public class SystemParameterService {
|
||||
}
|
||||
|
||||
|
||||
public MailInfo mailInfo(String type) {
|
||||
List<SystemParameter> paramList = this.getParamList(type);
|
||||
MailInfo mailInfo = new MailInfo();
|
||||
if (!CollectionUtils.isEmpty(paramList)) {
|
||||
for (SystemParameter param : paramList) {
|
||||
if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SERVER.getValue())) {
|
||||
mailInfo.setHost(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PORT.getValue())) {
|
||||
mailInfo.setPort(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.ACCOUNT.getValue())) {
|
||||
mailInfo.setAccount(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
String password = EncryptUtils.aesDecrypt(param.getParamValue()).toString();
|
||||
mailInfo.setPassword(password);
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SSL.getValue())) {
|
||||
mailInfo.setSsl(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.TLS.getValue())) {
|
||||
mailInfo.setTls(param.getParamValue());
|
||||
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.RECIPIENTS.getValue())) {
|
||||
mailInfo.setRecipient(param.getParamValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return mailInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getSystemLanguage() {
|
||||
@ -110,28 +79,7 @@ public class SystemParameterService {
|
||||
|
||||
|
||||
|
||||
public void editMail(List<SystemParameter> parameters) {
|
||||
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue());
|
||||
boolean empty = paramList.size() <= 0;
|
||||
|
||||
parameters.forEach(parameter -> {
|
||||
SystemParameterExample example = new SystemParameterExample();
|
||||
if (parameter.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getValue())) {
|
||||
if (!StringUtils.isBlank(parameter.getParamValue())) {
|
||||
String string = EncryptUtils.aesEncrypt(parameter.getParamValue()).toString();
|
||||
parameter.setParamValue(string);
|
||||
}
|
||||
}
|
||||
example.createCriteria().andParamKeyEqualTo(parameter.getParamKey());
|
||||
if (systemParameterMapper.countByExample(example) > 0) {
|
||||
systemParameterMapper.updateByPrimaryKey(parameter);
|
||||
} else {
|
||||
systemParameterMapper.insert(parameter);
|
||||
}
|
||||
example.clear();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void editBasic(List<SystemParameter> parameters) {
|
||||
parameters.forEach(parameter -> {
|
||||
@ -154,49 +102,8 @@ public class SystemParameterService {
|
||||
return systemParameterMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public void testConnection(HashMap<String, String> hashMap) {
|
||||
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
|
||||
javaMailSender.setDefaultEncoding("UTF-8");
|
||||
javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.SERVER.getValue()));
|
||||
javaMailSender.setPort(Integer.valueOf(hashMap.get(ParamConstants.MAIL.PORT.getValue())));
|
||||
javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getValue()));
|
||||
javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getValue()));
|
||||
Properties props = new Properties();
|
||||
String recipients = hashMap.get(ParamConstants.MAIL.RECIPIENTS.getValue());
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.SSL.getValue()))) {
|
||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||
}
|
||||
if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getValue()))) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
props.put("mail.smtp.timeout", "30000");
|
||||
props.put("mail.smtp.connectiontimeout", "5000");
|
||||
javaMailSender.setJavaMailProperties(props);
|
||||
try {
|
||||
javaMailSender.testConnection();
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
if(!StringUtils.isBlank(recipients)){
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
try {
|
||||
helper = new MimeMessageHelper(mimeMessage, true);
|
||||
helper.setFrom(javaMailSender.getUsername());
|
||||
helper.setSubject("DataEase测试邮件 " );
|
||||
helper.setText("这是一封测试邮件,邮件发送成功", true);
|
||||
helper.setTo(recipients);
|
||||
javaMailSender.send(mimeMessage);
|
||||
} catch (MessagingException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
DEException.throwException(Translator.get("connection_failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return System.getenv("MS_VERSION");
|
||||
}
|
||||
|
@ -16,3 +16,14 @@ CREATE TABLE `panel_link_mapping` (
|
||||
`resource_id` varchar(255) DEFAULT NULL COMMENT '仪表板ID',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- 策略模式优化发送消息
|
||||
-- ----------------------------
|
||||
ALTER TABLE `dataease`.`sys_msg_channel`
|
||||
ADD COLUMN `service_name` varchar(255) NULL COMMENT '策略名称' AFTER `channel_name`;
|
||||
|
||||
|
||||
UPDATE `dataease`.`sys_msg_channel` SET `service_name` = 'sendStation' WHERE `msg_channel_id` = 1;
|
||||
INSERT INTO `dataease`.`sys_msg_channel`(`msg_channel_id`, `channel_name`, `service_name`) VALUES (2, 'webmsg.channel_email_msg', 'sendEmail');
|
||||
|
@ -65,22 +65,7 @@
|
||||
<!--要生成的数据库表 -->
|
||||
|
||||
|
||||
<!-- <table tableName="panel_link_jump"/>-->
|
||||
<!-- <table tableName="panel_link_jump_info"/>-->
|
||||
<!-- <table tableName="panel_link_jump_target_view_info"/>-->
|
||||
<table tableName="v_auth_model"/>
|
||||
<table tableName="panel_link_mapping"/>
|
||||
<!-- <table tableName="sys_dict_item"/>-->
|
||||
<!-- <table tableName="dataset_table_field"/>-->
|
||||
<!-- <table tableName="v_chart">-->
|
||||
<!-- </table>-->
|
||||
<!-- <table tableName="v_auth_model">-->
|
||||
<!-- </table>-->
|
||||
<!-- <table tableName="v_dataset"/>-->
|
||||
<!-- <table tableName="sys_auth_detail"/>-->
|
||||
<!-- <table tableName="dataset_table_task">-->
|
||||
<!-- <columnOverride column="extra_data" javaType="java.lang.String" jdbcType="VARCHAR" />-->
|
||||
<!-- </table>-->
|
||||
<table tableName="sys_msg_channel"/>
|
||||
|
||||
|
||||
</context>
|
||||
|
@ -65,9 +65,15 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
beforeCreate() {
|
||||
// this.loadChannelData()
|
||||
|
||||
channelList().then(res => {
|
||||
this.msg_channels = res.data
|
||||
})
|
||||
},
|
||||
created() {
|
||||
this.loadChannelData()
|
||||
this.loadSettingData(this.loadTreeData)
|
||||
},
|
||||
|
||||
@ -129,7 +135,7 @@ export default {
|
||||
settingList().then(res => {
|
||||
const lists = res.data
|
||||
lists.forEach(item => {
|
||||
const key = item.typeId
|
||||
const key = item.typeId + ''
|
||||
if (!Object.keys(temp_setting_data).includes(key)) {
|
||||
temp_setting_data[key] = []
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
<basic-setting />
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- <el-tab-pane :lazy="true" :label="$t('system_parameter_setting.mailbox_service_settings')" name="first">
|
||||
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.mailbox_service_settings')" name="first">
|
||||
<email-setting />
|
||||
</el-tab-pane> -->
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane v-if="isPluginLoaded" :lazy="true" :label="$t('sysParams.display')" name="second">
|
||||
<plugin-com v-if="isPluginLoaded" ref="DisplaySetting" component-name="DisplaySetting" />
|
||||
|
Loading…
Reference in New Issue
Block a user