邮件发送功能修改

This commit is contained in:
wangjingyi 2022-03-30 14:21:03 +08:00
parent f349fbf84a
commit 1bf1d3ee6a
2 changed files with 25 additions and 23 deletions

View File

@ -5,8 +5,14 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOUNT_EXISTS;
@Mapper @Mapper
public interface MailAccountMapper extends BaseMapperX<MailAccountDO> { public interface MailAccountMapper extends BaseMapperX<MailAccountDO> {
@ -20,4 +26,11 @@ public interface MailAccountMapper extends BaseMapperX<MailAccountDO> {
); );
} }
default MailAccountDO selectByParams(Map params){
QueryWrapperX queryWrapperX = new QueryWrapperX<MailAccountDO>();
params.forEach((k , v)->{
queryWrapperX.eqIfPresent((String) k, v);
});
return this.selectOne(queryWrapperX);
};
} }

View File

@ -1,19 +1,19 @@
package cn.iocoder.yudao.module.system.service.mail.impl; package cn.iocoder.yudao.module.system.service.mail.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil; import cn.hutool.extra.mail.MailUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailSendVO; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO;
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert; import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper;
import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.dal.mysql.mail.MailTemplateMapper;
import cn.iocoder.yudao.module.system.service.mail.MailAccountService; import cn.iocoder.yudao.module.system.service.mail.MailAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -27,9 +27,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU
/** /**
* <p>
* 邮箱账号 Service 实现类 * 邮箱账号 Service 实现类
* </p>
* *
* @author wangjingyi * @author wangjingyi
* @since 2022-03-21 * @since 2022-03-21
@ -66,7 +64,6 @@ public class MailAccountServiceImpl implements MailAccountService {
mailAccountMapper.updateById(mailAccountDO); mailAccountMapper.updateById(mailAccountDO);
} }
@Override @Override
public void delete(Long id) { public void delete(Long id) {
// 校验是否存在 // 校验是否存在
@ -90,20 +87,16 @@ public class MailAccountServiceImpl implements MailAccountService {
} }
@Override @Override
public void sendMail(MailSendVO mailSendVO) { public void sendMail(MailReqVO mailReqVO) {
// FIXME 查询模版信息 查询模版多条时 使用规则是什么 MailTemplateDO mailTemplateDO = mailTemplateMapper.selectById(mailReqVO.getTemplateId());
// 回复选择某一条模板进行发送邮件
List<MailTemplateDO> mailTemplateDOList = mailTemplateMapper.selectList(
"username",mailSendVO.getFrom()
);
//查询账号信息 //查询账号信息
MailAccountDO mailAccountDO = mailAccountMapper.selectOne( MailAccountDO mailAccountDO = mailAccountMapper.selectOne(
"from",mailSendVO.getFrom() "from", mailReqVO.getFrom()
); );
// FIXME 模版和邮件内容合成方式未知 String content = mailReqVO.getContent();
// 回复参考短信的方式通过 {name} {mobile} 这样的占位符 formatSmsTemplateContent 方法 Map<String , String> params = MailAccountConvert.INSTANCE.convertToMap(mailAccountDO , content);
String content = mailSendVO.getContent(); content = StrUtil.format(mailTemplateDO.getContent(), params);
String templateContent = "";
// 后续功能 TODO 附件查询 // 后续功能 TODO 附件查询
//List<String> fileIds = mailSendVO.getFileIds(); //List<String> fileIds = mailSendVO.getFileIds();
@ -111,7 +104,7 @@ public class MailAccountServiceImpl implements MailAccountService {
MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO); MailAccount account = MailAccountConvert.INSTANCE.convertAccount(mailAccountDO);
//发送 //发送
MailUtil.send(account , mailSendVO.getTos() , mailSendVO.getTitle() , mailSendVO.getContent() , false); MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false);
} }
private void validateMailAccountExists(Long id) { private void validateMailAccountExists(Long id) {
@ -121,12 +114,8 @@ public class MailAccountServiceImpl implements MailAccountService {
} }
private void validateMailAccountOnly(Map params){ private void validateMailAccountOnly(Map params){
// TODO wangjingyiService 不允许出现 MyBatis 操作而是 Mapper 提供对应查询方法 MailAccountDO mailAccountDO = mailAccountMapper.selectByParams(params);
QueryWrapper queryWrapper = new QueryWrapper<MailAccountDO>(); if (mailAccountDO != null) {
params.forEach((k , v)->{
queryWrapper.like(k , v); // TODO wangjingyi账号应该是 equlas不能是 like
});
if (mailAccountMapper.selectOne(queryWrapper) != null) {
throw exception(MAIL_ACCOUNT_EXISTS); throw exception(MAIL_ACCOUNT_EXISTS);
} }
} }