From 20546a37cc89fbdf530dbc4f7a9bc3598869311c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 15 Apr 2022 21:34:14 +0800 Subject: [PATCH] =?UTF-8?q?mall=EF=BC=9Acode=20review=20=E6=94=B6=E4=BB=B6?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/address/AppAddressController.java | 6 --- .../app/address/vo/AppAddressBaseVO.java | 4 +- .../app/address/vo/AppAddressExportReqVO.java | 41 ------------------ .../app/address/vo/AppAddressPageReqVO.java | 43 ------------------- .../dal/dataobject/address/AddressDO.java | 4 +- .../dal/mysql/address/AddressMapper.java | 12 ------ .../module/member/enums/AddressTypeEnum.java | 4 +- .../service/address/AddressService.java | 18 +------- .../service/address/AddressServiceImpl.java | 26 +++++------ 9 files changed, 18 insertions(+), 140 deletions(-) delete mode 100644 yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressExportReqVO.java delete mode 100644 yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressPageReqVO.java diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.java index 74e9f8acd..ed7c157d2 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/AppAddressController.java @@ -34,14 +34,12 @@ public class AppAddressController { @PostMapping("/create") @ApiOperation("创建用户收件地址") - public CommonResult createAddress(@Valid @RequestBody AppAddressCreateReqVO createReqVO) { return success(addressService.createAddress(getLoginUserId(), createReqVO)); } @PutMapping("/update") @ApiOperation("更新用户收件地址") - public CommonResult updateAddress(@Valid @RequestBody AppAddressUpdateReqVO updateReqVO) { addressService.updateAddress(getLoginUserId(), updateReqVO); return success(true); @@ -50,7 +48,6 @@ public class AppAddressController { @DeleteMapping("/delete") @ApiOperation("删除用户收件地址") @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) - public CommonResult deleteAddress(@RequestParam("id") Long id) { addressService.deleteAddress(getLoginUserId(), id); return success(true); @@ -59,7 +56,6 @@ public class AppAddressController { @GetMapping("/get") @ApiOperation("获得用户收件地址") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) - public CommonResult getAddress(@RequestParam("id") Long id) { AddressDO address = addressService.getAddress(getLoginUserId(), id); return success(AddressConvert.INSTANCE.convert(address)); @@ -67,7 +63,6 @@ public class AppAddressController { @GetMapping("/get-default") @ApiOperation("获得默认的用户收件地址") - public CommonResult getDefaultUserAddress() { AddressDO address = addressService.getDefaultUserAddress(getLoginUserId()); return success(AddressConvert.INSTANCE.convert(address)); @@ -75,7 +70,6 @@ public class AppAddressController { @GetMapping("/list") @ApiOperation("获得用户收件地址列表") - public CommonResult> getAddressList() { List list = addressService.getAddressList(getLoginUserId()); return success(AddressConvert.INSTANCE.convertList(list)); diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java index b66248996..a1439f8bc 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressBaseVO.java @@ -12,6 +12,8 @@ import javax.validation.constraints.*; @Data public class AppAddressBaseVO { + // TODO @shuaidawang:swagger 注解的 example;其它 VO 类也要补充下 + @ApiModelProperty(value = "收件人名称", required = true) @NotNull(message = "收件人名称不能为空") private String name; @@ -28,7 +30,7 @@ public class AppAddressBaseVO { @NotNull(message = "收件详细地址不能为空") private String detailAddress; - @ApiModelProperty(value = "地址类型", required = true) + @ApiModelProperty(value = "地址类型", required = true) // TODO @shuaidawang:这个是枚举字段,最好说明下对应的枚举类 @NotNull(message = "地址类型不能为空") private Integer type; diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressExportReqVO.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressExportReqVO.java deleted file mode 100644 index e0982b6c4..000000000 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressExportReqVO.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.app.address.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel(value = "用户 APP - 用户收件地址 Excel 导出 Request VO", description = "参数和 AddressPageReqVO 是一致的") -@Data -public class AppAddressExportReqVO { - - @ApiModelProperty(value = "用户编号") - private Long userId; - - @ApiModelProperty(value = "收件人名称") - private String name; - - @ApiModelProperty(value = "手机号") - private String mobile; - - @ApiModelProperty(value = "地区编码") - private Integer areaCode; - - @ApiModelProperty(value = "收件详细地址") - private String detailAddress; - - @ApiModelProperty(value = "地址类型") - private Integer type; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "开始创建时间") - private Date beginCreateTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "结束创建时间") - private Date endCreateTime; - -} diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressPageReqVO.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressPageReqVO.java deleted file mode 100644 index 402e52296..000000000 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/vo/AppAddressPageReqVO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.module.member.controller.app.address.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@ApiModel("用户 APP - 用户收件地址分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class AppAddressPageReqVO extends PageParam { - - @ApiModelProperty(value = "用户编号") - private Long userId; - - @ApiModelProperty(value = "收件人名称") - private String name; - - @ApiModelProperty(value = "手机号") - private String mobile; - - @ApiModelProperty(value = "地区编码") - private Integer areaCode; - - @ApiModelProperty(value = "收件详细地址") - private String detailAddress; - - @ApiModelProperty(value = "地址类型") - private Integer type; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "开始创建时间") - private Date beginCreateTime; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @ApiModelProperty(value = "结束创建时间") - private Date endCreateTime; - -} diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java index fe02a1e47..546df00c6 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/address/AddressDO.java @@ -46,9 +46,9 @@ public class AddressDO extends BaseDO { */ private String detailAddress; /** - * 地址类型,主要分为默认地址,和普通地址 + * 地址类型 * - * 外键 {@link AddressTypeEnum} + * 枚举 {@link AddressTypeEnum} */ private Integer type; diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java index 81de47665..2925ada1f 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/address/AddressMapper.java @@ -29,16 +29,4 @@ public interface AddressMapper extends BaseMapperX { .orderByDesc(AddressDO::getId)); } - default List selectList(AppAddressExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(AddressDO::getUserId, reqVO.getUserId()) - .likeIfPresent(AddressDO::getName, reqVO.getName()) - .eqIfPresent(AddressDO::getMobile, reqVO.getMobile()) - .eqIfPresent(AddressDO::getAreaCode, reqVO.getAreaCode()) - .eqIfPresent(AddressDO::getDetailAddress, reqVO.getDetailAddress()) - .eqIfPresent(AddressDO::getType, reqVO.getType()) - .betweenIfPresent(AddressDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc(AddressDO::getId)); - } - } diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/enums/AddressTypeEnum.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/enums/AddressTypeEnum.java index f5eeb8382..c7d199241 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/enums/AddressTypeEnum.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/enums/AddressTypeEnum.java @@ -11,11 +11,11 @@ import lombok.Getter; public enum AddressTypeEnum { DEFAULT(1, "默认收件地址"), - NORMAL(2, "普通收件地址"), // 即非默认收件笛之爱 + NORMAL(2, "普通收件地址"), // 即非默认收件地址 ; private final Integer type; private final String desc; -} \ No newline at end of file +} diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java index d446e128f..0a0f3c8d0 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressService.java @@ -54,23 +54,7 @@ public interface AddressService { * @return 用户收件地址列表 */ List getAddressList(Long userId); - - /** - * 获得用户收件地址分页 - * - * @param pageReqVO 分页查询 - * @return 用户收件地址分页 - */ - PageResult getAddressPage(AppAddressPageReqVO pageReqVO); - - /** - * 获得用户收件地址列表, 用于 Excel 导出 - * - * @param exportReqVO 查询条件 - * @return 用户收件地址列表 - */ - List getAddressList(AppAddressExportReqVO exportReqVO); - + /** * 获得用户收件地址 * diff --git a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java index bdc094f3a..37ecc503b 100644 --- a/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java +++ b/yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/address/AddressServiceImpl.java @@ -34,10 +34,11 @@ public class AddressServiceImpl implements AddressService { @Resource private AddressMapper addressMapper; - @Override + @Override // TODO @shuaidawang:事务要加下哈 public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) { // 如果添加的是默认收件地址,则将原默认地址修改为非默认 if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) { + // TODO @shuaidawang:查询到一个,然后进行 update List addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); if (!CollectionUtils.isEmpty(addressDOs)) { addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO() @@ -52,12 +53,13 @@ public class AddressServiceImpl implements AddressService { return address.getId(); } - @Override + @Override // TODO @shuaidawang:事务要加下哈 public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) { - // 校验存在,校验是否能够操作 + // 校验存在,校验是否能够操作 TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好; check(userId, updateReqVO.getId()); // 如果修改的是默认收件地址,则将原默认地址修改为非默认 if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) { + // TODO @shuaidawang:查询到一个,然后进行 update,需要排除自己哈 List addressDOs = selectListByUserIdAndType( userId, AddressTypeEnum.DEFAULT.getType()); if (!CollectionUtils.isEmpty(addressDOs)) { @@ -68,13 +70,13 @@ public class AddressServiceImpl implements AddressService { } // 更新 AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO); - updateObj.setUserId(userId); + updateObj.setUserId(userId); // TODO @shuaidawang:不用加 userId addressMapper.updateById(updateObj); } @Override public void deleteAddress(Long userId, Long id) { - // 校验存在,校验是否能够操作 + // 校验存在,校验是否能够操作 TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好; check(userId, id); // 删除 addressMapper.deleteById(id); @@ -106,19 +108,9 @@ public class AddressServiceImpl implements AddressService { return selectListByUserIdAndType(userId, null); } - @Override - public PageResult getAddressPage(AppAddressPageReqVO pageReqVO) { - return addressMapper.selectPage(pageReqVO); - } - - @Override - public List getAddressList(AppAddressExportReqVO exportReqVO) { - return addressMapper.selectList(exportReqVO); - } - @Override public AddressDO getAddress(Long userId, Long id) { - AddressDO address = getAddress(id); + AddressDO address = getAddress(id); // TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好; check(userId, id); return address; } @@ -130,10 +122,12 @@ public class AddressServiceImpl implements AddressService { */ @Override public AddressDO getDefaultUserAddress(Long userId) { + // TODO @shuaidawang:查询,都抽到 mapper 中 List addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType()); return addressDOList.stream().findFirst().orElse(null); } + // TODO @shuaidawang:查询,都抽到 mapper 中 /** * 根据类型获取地址列表 * @param userId