From 7d9a6cb2ef1c49afdff4166782be4174d8137053 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 30 Mar 2022 21:46:54 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=20=E9=82=AE=E4=BB=B6=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail/MailAccountController.java | 5 ++--- .../admin/mail/MailTemplateController.java | 3 +-- .../system/dal/dataobject/mail/MailAccountDO.java | 15 +++++++-------- .../system/dal/mysql/mail/MailAccountMapper.java | 7 ++----- .../system/service/mail/MailAccountService.java | 7 +++++-- .../system/service/mail/MailTemplateService.java | 3 +++ .../service/mail/impl/MailAccountServiceImpl.java | 7 ++++--- .../mail/impl/MailTemplateServiceImpl.java | 11 ++++++----- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java index 2d2eb959b..660ea4ab4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java @@ -48,12 +48,11 @@ public class MailAccountController { return success(true); } - @DeleteMapping("/delete") @ApiOperation("删除邮箱账号") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") - public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { + public CommonResult deleteMailAccount(@Valid @RequestParam Long id) { // TODO @wangjingyi:不需要 @Valid 这里。了解下 Validator mailAccountService.delete(id); return success(true); } @@ -87,7 +86,7 @@ public class MailAccountController { @PostMapping("/send") @ApiOperation("发送邮件") @PreAuthorize("@ss.hasPermission('system:mail-account:send')") - public CommonResult sendMail(MailReqVO mailReqVO){ + public CommonResult sendMail(MailReqVO mailReqVO){ // TODO @wangjingyi:应该是测试短信模板,做到 MailTemplateController 里。参考下短信那的做法哈 mailAccountService.sendMail(mailReqVO); return success(true); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java index 988882d83..258dc3856 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailTemplateController.java @@ -28,7 +28,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RequestMapping("/system/mail-template") public class MailTemplateController { @Autowired - MailTemplateService mailTempleService; + MailTemplateService mailTempleService; // TODO @wangjingyi:private;和上面要空一行; @PostMapping("/create") @ApiOperation("创建邮箱模版") @@ -62,7 +62,6 @@ public class MailTemplateController { return success(MailTemplateConvert.INSTANCE.convert(mailTemplateDO)); } - @GetMapping("/page") @ApiOperation("获得邮箱模版分页") @PreAuthorize("@ss.hasPermission('system:mail-account:query')") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java index 2147af7fe..a7db81860 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,26 +1,25 @@ package cn.iocoder.yudao.module.system.dal.dataobject.mail; 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 java.io.Serializable; - +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.io.Serializable; + @Data @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -@ApiModel(value="MailAccount对象", description="邮箱账号") -@TableName(value = "system_mail_account", autoResultMap = true) +@ApiModel(value="MailAccount对象", description="邮箱账号") // TODO @wangjingyi:不需要 swagger 注解 +@TableName(value = "system_mail_account", autoResultMap = true) // TODO @wangjingyi:这个放在最上面,关键字段 public class MailAccountDO extends BaseDO implements Serializable { - private static final long serialVersionUID = 1L; + // TODO @wangjingyi:每个字段的注释;字段名,如果一直,不用 @TableField + @TableId private Long id; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java index effeed1b9..6785e33ec 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/mail/MailAccountMapper.java @@ -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.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; 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 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 public interface MailAccountMapper extends BaseMapperX { @@ -26,11 +22,12 @@ public interface MailAccountMapper extends BaseMapperX { ); } + // TODO @wangjingyi:不要提供这样的泛的方法,而是明确的查询方法 default MailAccountDO selectByParams(Map params){ QueryWrapperX queryWrapperX = new QueryWrapperX(); params.forEach((k , v)->{ queryWrapperX.eqIfPresent((String) k, v); }); - return this.selectOne(queryWrapperX); + return this.selecOne(queryWrapperX); }; } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java index 5b8a07b34..572aa3ffb 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java @@ -11,14 +11,17 @@ import java.util.List; /** - * 邮箱账号 Service 接口 + * 邮箱账号 Service 接口 * * @author wangjingyi * @since 2022-03-21 */ public interface MailAccountService { + + // TODO @wangjingyi:注释,完整;参数校验还是要做的; + /** - * 创建邮箱账号 + * 创建邮箱账号 // TODO @wangjingyi:方法描述,和参数要空行 * @param createReqVO * @return */ diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java index da68a43d0..98fe87ef9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateService.java @@ -15,6 +15,9 @@ import java.util.List; * @since 2022-03-21 */ public interface MailTemplateService { + + // TODO @wangjingyi:注释,完整;参数校验还是要做的; + /** * 邮箱模版创建 * @param createReqVO diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java index 8c8900dcf..4cb5ed0e2 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailAccountServiceImpl.java @@ -33,6 +33,7 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.MAIL_ACCOU * @since 2022-03-21 */ @Service +// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 public class MailAccountServiceImpl implements MailAccountService { @Resource @@ -54,13 +55,13 @@ public class MailAccountServiceImpl implements MailAccountService { @Override public void update(MailAccountUpdateReqVO updateReqVO) { - // username 要校验唯一 + // username 要校验唯一 TODO @wangjingyi:不要用 map 参数 Map map = new HashMap<>(); map.put("username" , updateReqVO.getUsername()); - this.validateMailAccountOnly(map); + this.validateMailAccountOnly(map); // TODO @wangjingyi:如果 username 是自己用呢,要排除下自己呀 MailAccountDO mailAccountDO = MailAccountConvert.INSTANCE.convert(updateReqVO); // 校验是否存在 - this.validateMailAccountExists(mailAccountDO.getId()); // TODO wangjingyi:没有传递 id 噢 + this.validateMailAccountExists(mailAccountDO.getId()); mailAccountMapper.updateById(mailAccountDO); } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java index 92db1d83c..9fd80bdfe 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/mail/impl/MailTemplateServiceImpl.java @@ -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.MailTemplateUpdateReqVO; 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.mysql.mail.MailTemplateMapper; import cn.iocoder.yudao.module.system.service.mail.MailTemplateService; @@ -19,15 +18,17 @@ import java.util.List; import java.util.Map; 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; /** - * 邮箱模版 服务实现类 + * 邮箱模版 服务实现类 * * @author wangjingyi * @since 2022-03-21 */ @Service +// TODO @wangjingyi:需要 @Validated 注解,开启参数校验 public class MailTemplateServiceImpl implements MailTemplateService { @Resource @@ -37,7 +38,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { public Long create(MailTemplateCreateReqVO createReqVO) { // name 要校验唯一 Map map = new HashMap<>(); - map.put("name" , createReqVO.getName()); + map.put("name" , createReqVO.getName()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 this.validateMailTemplateOnly(map); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(createReqVO); mailTemplateMapper.insert(mailTemplateDO); @@ -48,7 +49,7 @@ public class MailTemplateServiceImpl implements MailTemplateService { public void update(MailTemplateUpdateReqVO updateReqVO) { // username 要校验唯一 Map map = new HashMap<>(); - map.put("username" , updateReqVO.getUsername()); + map.put("username" , updateReqVO.getUsername()); // TODO @wangjingyi:模板名重复没关系的;code 不能重复 this.validateMailTemplateOnly(map); MailTemplateDO mailTemplateDO = MailTemplateConvert.INSTANCE.convert(updateReqVO); // 校验是否存在