mall:code review 收件地址

This commit is contained in:
YunaiV 2022-04-15 21:34:14 +08:00
parent 8dd83f4a1c
commit 20546a37cc
9 changed files with 18 additions and 140 deletions

View File

@ -34,14 +34,12 @@ public class AppAddressController {
@PostMapping("/create")
@ApiOperation("创建用户收件地址")
public CommonResult<Long> createAddress(@Valid @RequestBody AppAddressCreateReqVO createReqVO) {
return success(addressService.createAddress(getLoginUserId(), createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新用户收件地址")
public CommonResult<Boolean> 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<Boolean> 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<AppAddressRespVO> 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<AppAddressRespVO> getDefaultUserAddress() {
AddressDO address = addressService.getDefaultUserAddress(getLoginUserId());
return success(AddressConvert.INSTANCE.convert(address));
@ -75,7 +70,6 @@ public class AppAddressController {
@GetMapping("/list")
@ApiOperation("获得用户收件地址列表")
public CommonResult<List<AppAddressRespVO>> getAddressList() {
List<AddressDO> list = addressService.getAddressList(getLoginUserId());
return success(AddressConvert.INSTANCE.convertList(list));

View File

@ -12,6 +12,8 @@ import javax.validation.constraints.*;
@Data
public class AppAddressBaseVO {
// TODO @shuaidawangswagger 注解的 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;

View File

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

View File

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

View File

@ -46,9 +46,9 @@ public class AddressDO extends BaseDO {
*/
private String detailAddress;
/**
* 地址类型主要分为默认地址和普通地址
* 地址类型
*
* 外键 {@link AddressTypeEnum}
* 枚举 {@link AddressTypeEnum}
*/
private Integer type;

View File

@ -29,16 +29,4 @@ public interface AddressMapper extends BaseMapperX<AddressDO> {
.orderByDesc(AddressDO::getId));
}
default List<AddressDO> selectList(AppAddressExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<AddressDO>()
.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));
}
}

View File

@ -11,11 +11,11 @@ import lombok.Getter;
public enum AddressTypeEnum {
DEFAULT(1, "默认收件地址"),
NORMAL(2, "普通收件地址"), // 即非默认收件笛之爱
NORMAL(2, "普通收件地址"), // 即非默认收件地址
;
private final Integer type;
private final String desc;
}
}

View File

@ -54,23 +54,7 @@ public interface AddressService {
* @return 用户收件地址列表
*/
List<AddressDO> getAddressList(Long userId);
/**
* 获得用户收件地址分页
*
* @param pageReqVO 分页查询
* @return 用户收件地址分页
*/
PageResult<AddressDO> getAddressPage(AppAddressPageReqVO pageReqVO);
/**
* 获得用户收件地址列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 用户收件地址列表
*/
List<AddressDO> getAddressList(AppAddressExportReqVO exportReqVO);
/**
* 获得用户收件地址
*

View File

@ -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<AddressDO> 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<AddressDO> 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<AddressDO> getAddressPage(AppAddressPageReqVO pageReqVO) {
return addressMapper.selectPage(pageReqVO);
}
@Override
public List<AddressDO> 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<AddressDO> addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
return addressDOList.stream().findFirst().orElse(null);
}
// TODO @shuaidawang查询都抽到 mapper
/**
* 根据类型获取地址列表
* @param userId