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;
@Api(tags = "管理后台 - 邮件账号")
@RestController
@RequestMapping("/system/mail-account")
@ -57,6 +56,9 @@ public class MailAccountController {
return success(true);
}
// TODO @wangjingyigetMailAccount 和 getMailAccountPage 这两个接口,定义一个对应的 Resp 类哈,参考别的模块。主要不要返回 password 字段。
// 一个可以的做法,是 MailAccountBaseVO 不返回 password然后 MailAccountCreateReqVO、MailAccountUpdateReqVO 添加这个字段
@GetMapping("/get")
@ApiOperation("获得邮箱账号")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@ -74,6 +76,8 @@ public class MailAccountController {
return success(MailAccountConvert.INSTANCE.convertPage(pageResult));
}
// TODO @wangjingyigetSimpleMailAccountList 单独定义一个类只返回精简的信息idfrom 即可。像密码之类都是敏感信息,不应该返回
@GetMapping("/list-all-simple")
@ApiOperation(value = "获得邮箱账号精简列表")
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")
public class MailTemplateController {
// TODO @wangjingyiprivate
@Autowired
MailTemplateService mailTempleService;
@ -55,6 +56,8 @@ public class MailTemplateController {
return success(true);
}
// TODO @wangjingyi下面几个 VO 也参考我在 account 给的建议
@GetMapping("/get")
@ApiOperation("获得邮箱模版")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)

View File

@ -12,6 +12,7 @@ import lombok.ToString;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MailAccountPageReqVO extends PageParam {
@ApiModelProperty(value = "邮箱" , required = true , example = "yudaoyuanma@123.com")
private String from;

View File

@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO;
import javax.validation.Valid;
import java.util.List;
/**
* Service
*

View File

@ -1,6 +1,5 @@
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.log.MailLogExportReqVO;
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;
/**
*
*
*
* @author wangjingyi
* @since 2022-03-21
*/
public interface MailLogService {
/**
*
*
* @param pageVO
* @return
*/
@ -26,6 +27,7 @@ public interface MailLogService {
/**
*
*
* @param exportReqVO
* @return
*/
@ -33,13 +35,14 @@ public interface MailLogService {
/**
*
* @param mailAccountDO
*
* @param mailAccountDO
* @param mailTemplateDO
* @param from
* @param content
* @param tos
* @param title
* @param isSend
* @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);

View File

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

View File

@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* Service
* Service
*
* @author wangjingyi
* @since 2022-03-21
@ -39,28 +39,34 @@ public class MailAccountServiceImpl implements MailAccountService {
@Override
public Long create(MailAccountCreateReqVO createReqVO) {
// username 要校验唯一
this.validateMailAccountOnlyByUserName(createReqVO.getUsername());
validateMailAccountOnlyByUserName(createReqVO.getUsername());
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(createReqVO);
mailAccountMapper.insert(mailAccountDO);
// 更新
return mailAccountDO.getId();
}
@Override
public void update(MailAccountUpdateReqVO updateReqVO) {
// username 要校验唯一
this.validateMailAccountExists(updateReqVO.getId());
// username 要校验唯一 TODO @wangjingyi校验唯一的时候需要排除掉自己
validateMailAccountExists(updateReqVO.getId());
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
// 校验是否存在
this.validateMailAccountExists(mailAccountDO.getId());
validateMailAccountExists(mailAccountDO.getId());
// 更新
mailAccountMapper.updateById(mailAccountDO);
}
@Override
public void delete(Long id) {
// 校验是否存在账号
this.validateMailAccountExists(id);
validateMailAccountExists(id);
// 校验是否存在关联模版
this.validateMailTemplateByAccountId(id);
validateMailTemplateByAccountId(id);
// 删除
mailAccountMapper.deleteById(id);
}
@ -95,6 +101,7 @@ public class MailAccountServiceImpl implements MailAccountService {
private void validateMailTemplateByAccountId(Long accountId){
MailTemplateDO mailTemplateDO = mailTemplateMapper.selectOneByAccountId(accountId);
if (mailTemplateDO != null) {
// TODO wangjingyiMAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS
throw exception(MAIL_RELATE_TEMPLATE_EXISTS);
}
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.system.service.mail.impl;
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.MailLogPageReqVO;
@ -62,6 +61,7 @@ public class MailLogServiceImpl implements MailLogService {
return mailLogDO.getId();
}
// TODO @wangjingyi不需要返回 id 呀
@Override
public Long updateSmsSendResult(Long logId, String result) {
MailLogDO.MailLogDOBuilder logDOBuilder = MailLogDO.builder();
@ -72,6 +72,7 @@ public class MailLogServiceImpl implements MailLogService {
return logId;
}
// TODO @wangjingyi无用的方法需要进行删除
public Long create(){
MailLogDO mailLogDO = new MailLogDO();
mailLogMapper.insert(mailLogDO);

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.system.service.mail.impl;
import cn.hutool.extra.mail.MailAccount;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.module.system.convert.mail.MailAccountConvert;
@ -80,6 +79,7 @@ public class MailSendServiceImpl implements MailSendService {
@Override
public void doSendMail(MailSendMessage message) {
// TODO @wangjingyi直接使用 hutool 发送,不要封装 mail client 哈,因为短信的客户端都是比较统一的
MailClient mailClient = mailClientFactory.getMailClient();
String result = mailClient.sendMail(message.getFrom() , message.getContent() , message.getTitle() , message.getTos());
mailLogService.updateSmsSendResult(message.getLogId() , result);

View File

@ -62,6 +62,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
private volatile Date maxUpdateTime;
// TODO @wangjingyi参考下别的模块的 initLocalCache 的实现
@Override
@PostConstruct
public void initLocalCache() {
@ -85,9 +86,11 @@ public class MailTemplateServiceImpl implements MailTemplateService {
@Override
public Long create(MailTemplateCreateReqVO createReqVO) {
// code 要校验唯一
// TODO @wangjingyi参考下我在 account 给的唯一校验的说明。
this.validateMailTemplateOnlyByCode(createReqVO.getCode());
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO);
mailTemplateMapper.insert(mailTemplateDO);
// TODO @wangjingyimq 更新
return mailTemplateDO.getId();
}
@ -97,6 +100,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
this.validateMailTemplateExists(updateReqVO.getId());
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO);
mailTemplateMapper.updateById(mailTemplateDO);
// TODO @wangjingyimq 更新
}
@Override
@ -104,6 +108,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
// 校验是否存在
this.validateMailTemplateExists(id);
mailTemplateMapper.deleteById(id);
// TODO @wangjingyimq 更新
}
@Override
@ -144,6 +149,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
MailUtil.send(account , mailReqVO.getTos() , mailReqVO.getTitle() , content , false);
}
// TODO @@wangjingyi单词拼写错误
@Override
public String formateMailTemplateContent(String content, Map<String, String> params) {
return StrUtil.format(content, params);