code review 短信的实现

pull/2/head
YunaiV 2022-05-02 23:21:45 +08:00
parent 0189993a2a
commit 0b0e37a3d5
10 changed files with 44 additions and 19 deletions

View File

@ -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 @wangjingyigetMailAccount 和 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 @wangjingyigetSimpleMailAccountList 单独定义一个类只返回精简的信息idfrom 即可。像密码之类都是敏感信息,不应该返回
@GetMapping("/list-all-simple") @GetMapping("/list-all-simple")
@ApiOperation(value = "获得邮箱账号精简列表") @ApiOperation(value = "获得邮箱账号精简列表")
public CommonResult<List<MailAccountBaseVO>> getSimpleMailAccountList() { public CommonResult<List<MailAccountBaseVO>> getSimpleMailAccountList() {

View File

@ -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 @wangjingyiprivate
@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)

View File

@ -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;

View File

@ -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
* *

View File

@ -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);

View File

@ -20,6 +20,7 @@ import java.util.Map;
public interface MailTemplateService { public interface MailTemplateService {
void initLocalCache(); void initLocalCache();
/** /**
* *
* *

View File

@ -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 wangjingyiMAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS
throw exception(MAIL_RELATE_TEMPLATE_EXISTS); throw exception(MAIL_RELATE_TEMPLATE_EXISTS);
} }
} }

View File

@ -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);

View File

@ -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);

View File

@ -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 @wangjingyimq 更新
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 @wangjingyimq 更新
} }
@Override @Override
@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
// 校验是否存在 // 校验是否存在
this.validateMailTemplateExists(id); this.validateMailTemplateExists(id);
mailTemplateMapper.deleteById(id); mailTemplateMapper.deleteById(id);
// TODO @wangjingyimq 更新
} }
@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);