code review 短信的实现
parent
0189993a2a
commit
0b0e37a3d5
|
@ -24,7 +24,6 @@ import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
|
||||||
@Api(tags = "管理后台 - 邮件账号")
|
@Api(tags = "管理后台 - 邮件账号")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/mail-account")
|
@RequestMapping("/system/mail-account")
|
||||||
|
@ -57,6 +56,9 @@ public class MailAccountController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @wangjingyi:getMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。
|
||||||
|
// 一个可以的做法,是 MailAccountBaseVO 不返回 password,然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@ApiOperation("获得邮箱账号")
|
@ApiOperation("获得邮箱账号")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
|
@ -74,6 +76,8 @@ public class MailAccountController {
|
||||||
return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
|
return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @wangjingyi:getSimpleMailAccountList 单独定义一个类,只返回精简的信息,id,from 即可。像密码之类都是敏感信息,不应该返回
|
||||||
|
|
||||||
@GetMapping("/list-all-simple")
|
@GetMapping("/list-all-simple")
|
||||||
@ApiOperation(value = "获得邮箱账号精简列表")
|
@ApiOperation(value = "获得邮箱账号精简列表")
|
||||||
public CommonResult<List<MailAccountBaseVO>> getSimpleMailAccountList() {
|
public CommonResult<List<MailAccountBaseVO>> getSimpleMailAccountList() {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@RequestMapping("/system/mail-template")
|
@RequestMapping("/system/mail-template")
|
||||||
public class MailTemplateController {
|
public class MailTemplateController {
|
||||||
|
|
||||||
|
// TODO @wangjingyi:private
|
||||||
@Autowired
|
@Autowired
|
||||||
MailTemplateService mailTempleService;
|
MailTemplateService mailTempleService;
|
||||||
|
|
||||||
|
@ -55,6 +56,8 @@ public class MailTemplateController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @wangjingyi:下面几个 VO 也参考我在 account 给的建议
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@ApiOperation("获得邮箱模版")
|
@ApiOperation("获得邮箱模版")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import lombok.ToString;
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class MailAccountPageReqVO extends PageParam {
|
public class MailAccountPageReqVO extends PageParam {
|
||||||
|
|
||||||
@ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com")
|
@ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com")
|
||||||
private String from;
|
private String from;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱账号 Service 接口
|
* 邮箱账号 Service 接口
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.iocoder.yudao.module.system.service.mail;
|
package cn.iocoder.yudao.module.system.service.mail;
|
||||||
|
|
||||||
|
|
||||||
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.log.MailLogExportReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
|
||||||
|
@ -11,14 +10,16 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailTemplateDO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱日志服务类
|
* 邮箱日志服务类
|
||||||
*
|
*
|
||||||
* @author wangjingyi
|
* @author wangjingyi
|
||||||
* @since 2022-03-21
|
* @since 2022-03-21
|
||||||
*/
|
*/
|
||||||
public interface MailLogService {
|
public interface MailLogService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱日志分页
|
* 邮箱日志分页
|
||||||
|
*
|
||||||
* @param pageVO
|
* @param pageVO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +27,7 @@ public interface MailLogService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱日志数组信息
|
* 邮箱日志数组信息
|
||||||
|
*
|
||||||
* @param exportReqVO
|
* @param exportReqVO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -33,13 +35,14 @@ public interface MailLogService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建邮箱日志
|
* 创建邮箱日志
|
||||||
* @param mailAccountDO 邮箱账号信息
|
*
|
||||||
|
* @param mailAccountDO 邮箱账号信息
|
||||||
* @param mailTemplateDO 模版信息
|
* @param mailTemplateDO 模版信息
|
||||||
* @param from 邮箱
|
* @param from 邮箱
|
||||||
* @param content 内容
|
* @param content 内容
|
||||||
* @param tos 收件人
|
* @param tos 收件人
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @param isSend 是否发送成功
|
* @param isSend 是否发送成功
|
||||||
*/
|
*/
|
||||||
Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List<String> tos, String title, Boolean isSend);
|
Long createMailLog(MailAccountDO mailAccountDO, MailTemplateDO mailTemplateDO, String from, String content, List<String> tos, String title, Boolean isSend);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
public interface MailTemplateService {
|
public interface MailTemplateService {
|
||||||
|
|
||||||
void initLocalCache();
|
void initLocalCache();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱模版创建
|
* 邮箱模版创建
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱账号 Service 实现类
|
* 邮箱账号 Service 实现类
|
||||||
*
|
*
|
||||||
* @author wangjingyi
|
* @author wangjingyi
|
||||||
* @since 2022-03-21
|
* @since 2022-03-21
|
||||||
|
@ -39,28 +39,34 @@ public class MailAccountServiceImpl implements MailAccountService {
|
||||||
@Override
|
@Override
|
||||||
public Long create(MailAccountCreateReqVO createReqVO) {
|
public Long create(MailAccountCreateReqVO createReqVO) {
|
||||||
// username 要校验唯一
|
// username 要校验唯一
|
||||||
this.validateMailAccountOnlyByUserName(createReqVO.getUsername());
|
validateMailAccountOnlyByUserName(createReqVO.getUsername());
|
||||||
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO);
|
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO);
|
||||||
mailAccountMapper.insert(mailAccountDO);
|
mailAccountMapper.insert(mailAccountDO);
|
||||||
|
|
||||||
|
// 更新
|
||||||
return mailAccountDO.getId();
|
return mailAccountDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(MailAccountUpdateReqVO updateReqVO) {
|
public void update(MailAccountUpdateReqVO updateReqVO) {
|
||||||
// username 要校验唯一
|
// username 要校验唯一 TODO @wangjingyi:校验唯一的时候,需要排除掉自己
|
||||||
this.validateMailAccountExists(updateReqVO.getId());
|
validateMailAccountExists(updateReqVO.getId());
|
||||||
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
|
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
|
||||||
// 校验是否存在
|
// 校验是否存在
|
||||||
this.validateMailAccountExists(mailAccountDO.getId());
|
validateMailAccountExists(mailAccountDO.getId());
|
||||||
|
|
||||||
|
// 更新
|
||||||
mailAccountMapper.updateById(mailAccountDO);
|
mailAccountMapper.updateById(mailAccountDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
// 校验是否存在账号
|
// 校验是否存在账号
|
||||||
this.validateMailAccountExists(id);
|
validateMailAccountExists(id);
|
||||||
// 校验是否存在关联模版
|
// 校验是否存在关联模版
|
||||||
this.validateMailTemplateByAccountId(id);
|
validateMailTemplateByAccountId(id);
|
||||||
|
|
||||||
|
// 删除
|
||||||
mailAccountMapper.deleteById(id);
|
mailAccountMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService {
|
||||||
private void validateMailTemplateByAccountId(Long accountId){
|
private void validateMailTemplateByAccountId(Long accountId){
|
||||||
MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId);
|
MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId);
|
||||||
if (mailTemplateDO != null) {
|
if (mailTemplateDO != null) {
|
||||||
|
// TODO wangjingyi:MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS
|
||||||
throw exception(MAIL_RELATE_TEMPLATE_EXISTS);
|
throw exception(MAIL_RELATE_TEMPLATE_EXISTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.iocoder.yudao.module.system.service.mail.impl;
|
package cn.iocoder.yudao.module.system.service.mail.impl;
|
||||||
|
|
||||||
|
|
||||||
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.log.MailLogExportReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogExportReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.log.MailLogPageReqVO;
|
||||||
|
@ -62,6 +61,7 @@ public class MailLogServiceImpl implements MailLogService {
|
||||||
return mailLogDO.getId();
|
return mailLogDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @wangjingyi:不需要返回 id 呀
|
||||||
@Override
|
@Override
|
||||||
public Long updateSmsSendResult(Long logId, String result) {
|
public Long updateSmsSendResult(Long logId, String result) {
|
||||||
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
|
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
|
||||||
|
@ -72,6 +72,7 @@ public class MailLogServiceImpl implements MailLogService {
|
||||||
return logId;
|
return logId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @wangjingyi:无用的方法,需要进行删除
|
||||||
public Long create(){
|
public Long create(){
|
||||||
MailLogDO mailLogDO = new MailLogDO();
|
MailLogDO mailLogDO = new MailLogDO();
|
||||||
mailLogMapper.insert(mailLogDO);
|
mailLogMapper.insert(mailLogDO);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cn.iocoder.yudao.module.system.service.mail.impl;
|
package cn.iocoder.yudao.module.system.service.mail.impl;
|
||||||
|
|
||||||
|
|
||||||
import cn.hutool.extra.mail.MailAccount;
|
import cn.hutool.extra.mail.MailAccount;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
|
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
|
||||||
|
@ -80,6 +79,7 @@ public class MailSendServiceImpl implements MailSendService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doSendMail(MailSendMessage message) {
|
public void doSendMail(MailSendMessage message) {
|
||||||
|
// TODO @wangjingyi:直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的
|
||||||
MailClient mailClient = mailClientFactory.getMailClient();
|
MailClient mailClient = mailClientFactory.getMailClient();
|
||||||
String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos());
|
String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos());
|
||||||
mailLogService.updateSmsSendResult(message.getLogId() , result);
|
mailLogService.updateSmsSendResult(message.getLogId() , result);
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
|
||||||
|
|
||||||
private volatile Date maxUpdateTime;
|
private volatile Date maxUpdateTime;
|
||||||
|
|
||||||
|
// TODO @wangjingyi:参考下别的模块的 initLocalCache 的实现
|
||||||
@Override
|
@Override
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initLocalCache() {
|
public void initLocalCache() {
|
||||||
|
@ -85,9 +86,11 @@ public class MailTemplateServiceImpl implements MailTemplateService {
|
||||||
@Override
|
@Override
|
||||||
public Long create(MailTemplateCreateReqVO createReqVO) {
|
public Long create(MailTemplateCreateReqVO createReqVO) {
|
||||||
// code 要校验唯一
|
// code 要校验唯一
|
||||||
|
// TODO @wangjingyi:参考下我在 account 给的唯一校验的说明。
|
||||||
this.validateMailTemplateOnlyByCode(createReqVO.getCode());
|
this.validateMailTemplateOnlyByCode(createReqVO.getCode());
|
||||||
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO);
|
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO);
|
||||||
mailTemplateMapper.insert(mailTemplateDO);
|
mailTemplateMapper.insert(mailTemplateDO);
|
||||||
|
// TODO @wangjingyi:mq 更新
|
||||||
return mailTemplateDO.getId();
|
return mailTemplateDO.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +100,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
|
||||||
this.validateMailTemplateExists(updateReqVO.getId());
|
this.validateMailTemplateExists(updateReqVO.getId());
|
||||||
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO);
|
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||||
mailTemplateMapper.updateById(mailTemplateDO);
|
mailTemplateMapper.updateById(mailTemplateDO);
|
||||||
|
// TODO @wangjingyi:mq 更新
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
|
||||||
// 校验是否存在
|
// 校验是否存在
|
||||||
this.validateMailTemplateExists(id);
|
this.validateMailTemplateExists(id);
|
||||||
mailTemplateMapper.deleteById(id);
|
mailTemplateMapper.deleteById(id);
|
||||||
|
// TODO @wangjingyi:mq 更新
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -144,6 +149,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
|
||||||
MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false);
|
MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @@wangjingyi:单词拼写错误
|
||||||
@Override
|
@Override
|
||||||
public String formateMailTemplateContent(String content, Map<String, String> params) {
|
public String formateMailTemplateContent(String content, Map<String, String> params) {
|
||||||
return StrUtil.format(content, params);
|
return StrUtil.format(content, params);
|
||||||
|
|
Loading…
Reference in New Issue