code review 邮件模块

This commit is contained in:
YunaiV 2022-03-30 21:46:54 +08:00
parent 1bf1d3ee6a
commit 7d9a6cb2ef
8 changed files with 30 additions and 28 deletions

View File

@ -48,12 +48,11 @@ public class MailAccountController {
return success(true); return success(true);
} }
@DeleteMapping("/delete") @DeleteMapping("/delete")
@ApiOperation("删除邮箱账号") @ApiOperation("删除邮箱账号")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:mail-account:delete')") @PreAuthorize("@ss.hasPermission('system:mail-account:delete')")
public CommonResult<Boolean> deleteMailAccount(@Valid @RequestParam Long id) { public CommonResult<Boolean> deleteMailAccount(@Valid @RequestParam Long id) { // TODO @wangjingyi不需要 @Valid 这里了解下 Validator
mailAccountService.delete(id); mailAccountService.delete(id);
return success(true); return success(true);
} }
@ -87,7 +86,7 @@ public class MailAccountController {
@PostMapping("/send") @PostMapping("/send")
@ApiOperation("发送邮件") @ApiOperation("发送邮件")
@PreAuthorize("@ss.hasPermission('system:mail-account:send')") @PreAuthorize("@ss.hasPermission('system:mail-account:send')")
public CommonResult<Boolean> sendMail(MailReqVO mailReqVO){ public CommonResult<Boolean> sendMail(MailReqVO mailReqVO){ // TODO @wangjingyi应该是测试短信模板做到 MailTemplateController 参考下短信那的做法哈
mailAccountService.sendMail(mailReqVO); mailAccountService.sendMail(mailReqVO);
return success(true); return success(true);
} }

View File

@ -28,7 +28,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 {
@Autowired @Autowired
MailTemplateService mailTempleService; MailTemplateService mailTempleService; // TODO @wangjingyiprivate和上面要空一行
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建邮箱模版") @ApiOperation("创建邮箱模版")
@ -62,7 +62,6 @@ public class MailTemplateController {
return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO));
} }
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得邮箱模版分页") @ApiOperation("获得邮箱模版分页")
@PreAuthorize("@ss.hasPermission('system:mail-account:query')") @PreAuthorize("@ss.hasPermission('system:mail-account:query')")

View File

@ -1,26 +1,25 @@
package cn.iocoder.yudao.module.system.dal.dataobject.mail; package cn.iocoder.yudao.module.system.dal.dataobject.mail;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Accessors(chain = true) @Accessors(chain = true)
@ApiModel(value="MailAccount对象", description="邮箱账号") @ApiModel(value="MailAccount对象", description="邮箱账号") // TODO @wangjingyi不需要 swagger 注解
@TableName(value = "system_mail_account", autoResultMap = true) @TableName(value = "system_mail_account", autoResultMap = true) // TODO @wangjingyi这个放在最上面关键字段
public class MailAccountDO extends BaseDO implements Serializable { public class MailAccountDO extends BaseDO implements Serializable {
private static final long serialVersionUID = 1L; // TODO @wangjingyi每个字段的注释字段名如果一直不用 @TableField
@TableId @TableId
private Long id; private Long id;

View File

@ -5,14 +5,10 @@ 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 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> {
@ -26,11 +22,12 @@ public interface MailAccountMapper extends BaseMapperX<MailAccountDO> {
); );
} }
// TODO @wangjingyi不要提供这样的泛的方法而是明确的查询方法
default MailAccountDO selectByParams(Map params){ default MailAccountDO selectByParams(Map params){
QueryWrapperX queryWrapperX = new QueryWrapperX<MailAccountDO>(); QueryWrapperX queryWrapperX = new QueryWrapperX<MailAccountDO>();
params.forEach((k , v)->{ params.forEach((k , v)->{
queryWrapperX.eqIfPresent((String) k, v); queryWrapperX.eqIfPresent((String) k, v);
}); });
return this.selectOne(queryWrapperX); return this.selecOne(queryWrapperX);
}; };
} }

View File

@ -17,8 +17,11 @@ import java.util.List;
* @since 2022-03-21 * @since 2022-03-21
*/ */
public interface MailAccountService { public interface MailAccountService {
// TODO @wangjingyi注释完整参数校验还是要做的
/** /**
* 创建邮箱账号 * 创建邮箱账号 // TODO @wangjingyi方法描述和参数要空行
* @param createReqVO * @param createReqVO
* @return * @return
*/ */

View File

@ -15,6 +15,9 @@ import java.util.List;
* @since 2022-03-21 * @since 2022-03-21
*/ */
public interface MailTemplateService { public interface MailTemplateService {
// TODO @wangjingyi注释完整参数校验还是要做的
/** /**
* 邮箱模版创建 * 邮箱模版创建
* @param createReqVO * @param createReqVO

View File

@ -33,6 +33,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU
* @since 2022-03-21 * @since 2022-03-21
*/ */
@Service @Service
// TODO @wangjingyi需要 @Validated 注解开启参数校验
public class MailAccountServiceImpl implements MailAccountService { public class MailAccountServiceImpl implements MailAccountService {
@Resource @Resource
@ -54,13 +55,13 @@ public class MailAccountServiceImpl implements MailAccountService {
@Override @Override
public void update(MailAccountUpdateReqVO updateReqVO) { public void update(MailAccountUpdateReqVO updateReqVO) {
// username 要校验唯一 // username 要校验唯一 TODO @wangjingyi不要用 map 参数
Map<String , String> map = new HashMap<>(); Map<String , String> map = new HashMap<>();
map.put("username" , updateReqVO.getUsername()); map.put("username" , updateReqVO.getUsername());
this.validateMailAccountOnly(map); this.validateMailAccountOnly(map); // TODO @wangjingyi如果 username 是自己用呢要排除下自己呀
MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO);
// 校验是否存在 // 校验是否存在
this.validateMailAccountExists(mailAccountDO.getId()); // TODO wangjingyi没有传递 id this.validateMailAccountExists(mailAccountDO.getId());
mailAccountMapper.updateById(mailAccountDO); mailAccountMapper.updateById(mailAccountDO);
} }

View File

@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemp
import cn.iocoder.yudao.module.system.controller.admin.mail.vo.template.MailTemplatePageReqVO; 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.controller.admin.mail.vo.template.MailTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.mail.MailTemplateConvert; 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.mail.MailTemplateDO;
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.MailTemplateService; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService;
@ -19,7 +18,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_EXISTS;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_TEMPLATE_NOT_EXISTS;
/** /**
* 邮箱模版 服务实现类 * 邮箱模版 服务实现类
@ -28,6 +28,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
* @since 2022-03-21 * @since 2022-03-21
*/ */
@Service @Service
// TODO @wangjingyi需要 @Validated 注解开启参数校验
public class MailTemplateServiceImpl implements MailTemplateService { public class MailTemplateServiceImpl implements MailTemplateService {
@Resource @Resource
@ -37,7 +38,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
public Long create(MailTemplateCreateReqVO createReqVO) { public Long create(MailTemplateCreateReqVO createReqVO) {
// name 要校验唯一 // name 要校验唯一
Map<String , String> map = new HashMap<>(); Map<String , String> map = new HashMap<>();
map.put("name" , createReqVO.getName()); map.put("name" , createReqVO.getName()); // TODO @wangjingyi模板名重复没关系的code 不能重复
this.validateMailTemplateOnly(map); this.validateMailTemplateOnly(map);
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO);
mailTemplateMapper.insert(mailTemplateDO); mailTemplateMapper.insert(mailTemplateDO);
@ -48,7 +49,7 @@ public class MailTemplateServiceImpl implements MailTemplateService {
public void update(MailTemplateUpdateReqVO updateReqVO) { public void update(MailTemplateUpdateReqVO updateReqVO) {
// username 要校验唯一 // username 要校验唯一
Map<String , String> map = new HashMap<>(); Map<String , String> map = new HashMap<>();
map.put("username" , updateReqVO.getUsername()); map.put("username" , updateReqVO.getUsername()); // TODO @wangjingyi模板名重复没关系的code 不能重复
this.validateMailTemplateOnly(map); this.validateMailTemplateOnly(map);
MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO);
// 校验是否存在 // 校验是否存在