code review 邮箱的实现代码

This commit is contained in:
YunaiV 2022-05-17 20:07:50 +08:00
parent 63983bbab3
commit 1464f7d399
10 changed files with 54 additions and 46 deletions

View File

@ -79,7 +79,7 @@ public class TestDemoServiceImpl implements TestDemoService {
@Override
public PageResult<TestDemoDO> getTestDemoPage(TestDemoPageReqVO pageReqVO) {
// testDemoMapper.selectList2();
testDemoMapper.selectList2();
return testDemoMapper.selectPage(pageReqVO);
}

View File

@ -17,6 +17,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailLogPageReqVO extends PageParam {
// TODO @wangjingyirequired false 它是默认值所以不用谢
@ApiModelProperty(value = "邮箱" , required = false , example = "yudaoyuanma@123.com")
private String from;

View File

@ -34,5 +34,4 @@ public class MailReqVO { // TODO @wangjingqi1, 不用空格2应该
@ApiModelProperty(value = "附件",example = "附件编码")
private List<String> fileIds;
}

View File

@ -11,6 +11,7 @@ import java.util.List;
@Mapper
public interface MailTemplateConvert {
MailTemplateConvert INSTANCE = Mappers.getMapper(MailTemplateConvert.class);
MailTemplateDO convert(MailTemplateBaseVO baseVO);
@ -20,4 +21,5 @@ public interface MailTemplateConvert {
PageResult<MailTemplateRespVO> convertPage(PageResult<MailTemplateDO> pageResult);
List<MailTemplateRespVO> convertList02(List<MailTemplateDO> list);
}

View File

@ -80,7 +80,6 @@ public class MailLogDO extends BaseDO implements Serializable {
/**
* 发送结果
*
*/
private String sendResult;

View File

@ -20,16 +20,16 @@ public interface MailLogService {
/**
* 邮箱日志分页
*
* @param pageVO
* @return
* @param pageVO 分页参数
* @return 分页结果
*/
PageResult<MailLogDO> getMailLogPage(MailLogPageReqVO pageVO);
/**
* 邮箱日志数组信息
*
* @param exportReqVO
* @return
* @param exportReqVO 导出筛选请求
* @return 导出的日志数据
*/
List<MailLogDO> getMailLogList(MailLogExportReqVO exportReqVO);
@ -37,14 +37,14 @@ public interface MailLogService {
* 创建邮箱日志
*
* @param mailAccountDO 邮箱账号信息
* @param mailTemplateDO 模版信息
* @param template 模版信息
* @param from 邮箱
* @param content 内容
* @param tos 收件人
* @param title 标题
* @param isSend 是否发送成功
*/
Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List<String> tos, String title, Boolean isSend);
Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List<String> tos, String title, Boolean isSend);
/**
* 更新邮件发送结果
@ -53,4 +53,5 @@ public interface MailLogService {
* @param result 发送结果 默认返回messageId
*/
void updateMailSendResult(Long logId, String result);
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.system.service.mail;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
@ -68,6 +67,7 @@ public interface MailTemplateService {
* @return 模版数组
*/
List<MailTemplateDO> getMailTemplateList();
/**
* 从缓存中获取邮箱模版
*
@ -78,9 +78,11 @@ public interface MailTemplateService {
/**
* 邮件模版内容合成
*
* @param content 邮箱模版
* @param params 合成参数
* @return
* @return 格式化后的内容
*/
String formatMailTemplateContent(String content, Map<String, String> params);
}

View File

@ -27,6 +27,7 @@ import java.util.Objects;
@Validated
public class MailLogServiceImpl implements MailLogService {
// TODO @wangjingyiprivate然后使用 @Resource
@Autowired
MailLogMapper mailLogMapper;
@ -41,25 +42,34 @@ public class MailLogServiceImpl implements MailLogService {
}
@Override
public Long createMailLog(MailAccountDO mailAccountDO , MailTemplateDO mailTemplateDO , String from, String content, List<String> tos, String title, Boolean isSend) {
public Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO template, String from, String content, List<String> tos, String title, Boolean isSend) {
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
logDOBuilder.fromAddress(mailAccountDO.getFromAddress());
logDOBuilder.accountId(mailAccountDO.getId());
logDOBuilder.content(content);
logDOBuilder.title(title);
logDOBuilder.templateCode(mailTemplateDO.getCode());
logDOBuilder.templateId(mailTemplateDO.getId());
logDOBuilder.to(tos.toString());
logDOBuilder.sendTime(new Date());
// TODO @wangjingyi使用 builder 的时候不用每个 set 是一行
// 根据是否要发送设置状态
logDOBuilder.sendStatus(Objects.equals(isSend, true) ? MailSendStatusEnum.INIT.getStatus()
: MailSendStatusEnum.IGNORE.getStatus());
// 设置邮箱相关字段
// TODO @wangjingyiuserIduserType
logDOBuilder.fromAddress(mailAccountDO.getFromAddress());
logDOBuilder.accountId(mailAccountDO.getId());
// TODO @wangjingyi每个接收人一条日志发送多个人就调用多次业务方因为某个邮箱有问题会导致所有都发送失败
logDOBuilder.to(tos.toString());
// 设置模板相关字段
// TODO @wangjingyi可以参考下 sms 短信的逻辑templateContenttemplateParams
logDOBuilder.templateId(template.getId());
logDOBuilder.templateCode(template.getCode());
logDOBuilder.title(title);
logDOBuilder.content(content);
// TODO @wangjingyi有结果的时候才是 sendTime
logDOBuilder.sendTime(new Date());
MailLogDO mailLogDO = logDOBuilder.build();
mailLogMapper.insert(mailLogDO);
return mailLogDO.getId();
// 插入数据库
MailLogDO logDO = logDOBuilder.build();
mailLogMapper.insert(logDO);
return logDO.getId();
}
// TODO @wangjingyi不需要返回 id DONE
// TODO @wangjingyi还是加几个字段哈日志上sendStatus成功失败messageId 消息标号sendException 记录发送的异常这样界面才好筛选邮件的发送结果
@Override
public void updateMailSendResult(Long logId, String result) {
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();

View File

@ -3,20 +3,13 @@ package cn.iocoder.yudao.module.system.service.mail.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.send.MailReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert;
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.sms.SmsTemplateDO;
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.mq.producer.mail.MailProducer;
import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
@ -36,7 +29,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPL
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS;
/**
* 邮箱模版 服务实现类
* 邮箱模版 Service 实现类
*
* @author wangjingyi
* @since 2022-03-21
@ -48,6 +41,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
@Resource
private MailTemplateMapper mailTemplateMapper;
@Resource
private MailProducer mailProducer;
@ -61,7 +55,6 @@ public class MailTemplateServiceImpl implements MailTemplateService {
private volatile Date maxUpdateTime;
// TODO @wangjingyi参考下别的模块的 initLocalCache 的实现 DONE
@Override
@PostConstruct
public void initLocalCache() {
@ -79,7 +72,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
@Override
public Long create(MailTemplateCreateReqVO createReqVO) {
// 要校验存在
this.validateMailTemplateExists(createReqVO.getId());
validateMailTemplateExists(createReqVO.getId());
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO);
mailTemplateMapper.insert(mailTemplateDO);
// TODO @wangjingyimq 更新 DONE
@ -123,7 +116,6 @@ public class MailTemplateServiceImpl implements MailTemplateService {
return mailTemplateCache.get(code);
}
// TODO @@wangjingyi单词拼写错误 DONE
@Override
public String formatMailTemplateContent(String content, Map<String, String> params) {
return StrUtil.format(content, params);