mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
mall:code review 收件地址
This commit is contained in:
parent
8dd83f4a1c
commit
20546a37cc
@ -34,14 +34,12 @@ public class AppAddressController {
|
|||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ApiOperation("创建用户收件地址")
|
@ApiOperation("创建用户收件地址")
|
||||||
|
|
||||||
public CommonResult<Long> createAddress(@Valid @RequestBody AppAddressCreateReqVO createReqVO) {
|
public CommonResult<Long> createAddress(@Valid @RequestBody AppAddressCreateReqVO createReqVO) {
|
||||||
return success(addressService.createAddress(getLoginUserId(), createReqVO));
|
return success(addressService.createAddress(getLoginUserId(), createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@ApiOperation("更新用户收件地址")
|
@ApiOperation("更新用户收件地址")
|
||||||
|
|
||||||
public CommonResult<Boolean> updateAddress(@Valid @RequestBody AppAddressUpdateReqVO updateReqVO) {
|
public CommonResult<Boolean> updateAddress(@Valid @RequestBody AppAddressUpdateReqVO updateReqVO) {
|
||||||
addressService.updateAddress(getLoginUserId(), updateReqVO);
|
addressService.updateAddress(getLoginUserId(), updateReqVO);
|
||||||
return success(true);
|
return success(true);
|
||||||
@ -50,7 +48,6 @@ public class AppAddressController {
|
|||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@ApiOperation("删除用户收件地址")
|
@ApiOperation("删除用户收件地址")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||||
|
|
||||||
public CommonResult<Boolean> deleteAddress(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> deleteAddress(@RequestParam("id") Long id) {
|
||||||
addressService.deleteAddress(getLoginUserId(), id);
|
addressService.deleteAddress(getLoginUserId(), id);
|
||||||
return success(true);
|
return success(true);
|
||||||
@ -59,7 +56,6 @@ public class AppAddressController {
|
|||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@ApiOperation("获得用户收件地址")
|
@ApiOperation("获得用户收件地址")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
|
|
||||||
public CommonResult<AppAddressRespVO> getAddress(@RequestParam("id") Long id) {
|
public CommonResult<AppAddressRespVO> getAddress(@RequestParam("id") Long id) {
|
||||||
AddressDO address = addressService.getAddress(getLoginUserId(), id);
|
AddressDO address = addressService.getAddress(getLoginUserId(), id);
|
||||||
return success(AddressConvert.INSTANCE.convert(address));
|
return success(AddressConvert.INSTANCE.convert(address));
|
||||||
@ -67,7 +63,6 @@ public class AppAddressController {
|
|||||||
|
|
||||||
@GetMapping("/get-default")
|
@GetMapping("/get-default")
|
||||||
@ApiOperation("获得默认的用户收件地址")
|
@ApiOperation("获得默认的用户收件地址")
|
||||||
|
|
||||||
public CommonResult<AppAddressRespVO> getDefaultUserAddress() {
|
public CommonResult<AppAddressRespVO> getDefaultUserAddress() {
|
||||||
AddressDO address = addressService.getDefaultUserAddress(getLoginUserId());
|
AddressDO address = addressService.getDefaultUserAddress(getLoginUserId());
|
||||||
return success(AddressConvert.INSTANCE.convert(address));
|
return success(AddressConvert.INSTANCE.convert(address));
|
||||||
@ -75,7 +70,6 @@ public class AppAddressController {
|
|||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("获得用户收件地址列表")
|
@ApiOperation("获得用户收件地址列表")
|
||||||
|
|
||||||
public CommonResult<List<AppAddressRespVO>> getAddressList() {
|
public CommonResult<List<AppAddressRespVO>> getAddressList() {
|
||||||
List<AddressDO> list = addressService.getAddressList(getLoginUserId());
|
List<AddressDO> list = addressService.getAddressList(getLoginUserId());
|
||||||
return success(AddressConvert.INSTANCE.convertList(list));
|
return success(AddressConvert.INSTANCE.convertList(list));
|
||||||
|
@ -12,6 +12,8 @@ import javax.validation.constraints.*;
|
|||||||
@Data
|
@Data
|
||||||
public class AppAddressBaseVO {
|
public class AppAddressBaseVO {
|
||||||
|
|
||||||
|
// TODO @shuaidawang:swagger 注解的 example;其它 VO 类也要补充下
|
||||||
|
|
||||||
@ApiModelProperty(value = "收件人名称", required = true)
|
@ApiModelProperty(value = "收件人名称", required = true)
|
||||||
@NotNull(message = "收件人名称不能为空")
|
@NotNull(message = "收件人名称不能为空")
|
||||||
private String name;
|
private String name;
|
||||||
@ -28,7 +30,7 @@ public class AppAddressBaseVO {
|
|||||||
@NotNull(message = "收件详细地址不能为空")
|
@NotNull(message = "收件详细地址不能为空")
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
|
|
||||||
@ApiModelProperty(value = "地址类型", required = true)
|
@ApiModelProperty(value = "地址类型", required = true) // TODO @shuaidawang:这个是枚举字段,最好说明下对应的枚举类
|
||||||
@NotNull(message = "地址类型不能为空")
|
@NotNull(message = "地址类型不能为空")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
@ -46,9 +46,9 @@ public class AddressDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private String detailAddress;
|
private String detailAddress;
|
||||||
/**
|
/**
|
||||||
* 地址类型,主要分为默认地址,和普通地址
|
* 地址类型
|
||||||
*
|
*
|
||||||
* 外键 {@link AddressTypeEnum}
|
* 枚举 {@link AddressTypeEnum}
|
||||||
*/
|
*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@ -29,16 +29,4 @@ public interface AddressMapper extends BaseMapperX<AddressDO> {
|
|||||||
.orderByDesc(AddressDO::getId));
|
.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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import lombok.Getter;
|
|||||||
public enum AddressTypeEnum {
|
public enum AddressTypeEnum {
|
||||||
|
|
||||||
DEFAULT(1, "默认收件地址"),
|
DEFAULT(1, "默认收件地址"),
|
||||||
NORMAL(2, "普通收件地址"), // 即非默认收件笛之爱
|
NORMAL(2, "普通收件地址"), // 即非默认收件地址
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -55,22 +55,6 @@ public interface AddressService {
|
|||||||
*/
|
*/
|
||||||
List<AddressDO> getAddressList(Long userId);
|
List<AddressDO> getAddressList(Long userId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得用户收件地址分页
|
|
||||||
*
|
|
||||||
* @param pageReqVO 分页查询
|
|
||||||
* @return 用户收件地址分页
|
|
||||||
*/
|
|
||||||
PageResult<AddressDO> getAddressPage(AppAddressPageReqVO pageReqVO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得用户收件地址列表, 用于 Excel 导出
|
|
||||||
*
|
|
||||||
* @param exportReqVO 查询条件
|
|
||||||
* @return 用户收件地址列表
|
|
||||||
*/
|
|
||||||
List<AddressDO> getAddressList(AppAddressExportReqVO exportReqVO);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得用户收件地址
|
* 获得用户收件地址
|
||||||
*
|
*
|
||||||
|
@ -34,10 +34,11 @@ public class AddressServiceImpl implements AddressService {
|
|||||||
@Resource
|
@Resource
|
||||||
private AddressMapper addressMapper;
|
private AddressMapper addressMapper;
|
||||||
|
|
||||||
@Override
|
@Override // TODO @shuaidawang:事务要加下哈
|
||||||
public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) {
|
public Long createAddress(Long userId, AppAddressCreateReqVO createReqVO) {
|
||||||
// 如果添加的是默认收件地址,则将原默认地址修改为非默认
|
// 如果添加的是默认收件地址,则将原默认地址修改为非默认
|
||||||
if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) {
|
if (AddressTypeEnum.DEFAULT.getType().equals(createReqVO.getType())) {
|
||||||
|
// TODO @shuaidawang:查询到一个,然后进行 update
|
||||||
List<AddressDO> addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
|
List<AddressDO> addressDOs = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
|
||||||
if (!CollectionUtils.isEmpty(addressDOs)) {
|
if (!CollectionUtils.isEmpty(addressDOs)) {
|
||||||
addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO()
|
addressDOs.forEach(userAddressDO -> addressMapper.updateById(new AddressDO()
|
||||||
@ -52,12 +53,13 @@ public class AddressServiceImpl implements AddressService {
|
|||||||
return address.getId();
|
return address.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override // TODO @shuaidawang:事务要加下哈
|
||||||
public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) {
|
public void updateAddress(Long userId, AppAddressUpdateReqVO updateReqVO) {
|
||||||
// 校验存在,校验是否能够操作
|
// 校验存在,校验是否能够操作 TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好;
|
||||||
check(userId, updateReqVO.getId());
|
check(userId, updateReqVO.getId());
|
||||||
// 如果修改的是默认收件地址,则将原默认地址修改为非默认
|
// 如果修改的是默认收件地址,则将原默认地址修改为非默认
|
||||||
if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) {
|
if (AddressTypeEnum.DEFAULT.getType().equals(updateReqVO.getType())) {
|
||||||
|
// TODO @shuaidawang:查询到一个,然后进行 update,需要排除自己哈
|
||||||
List<AddressDO> addressDOs = selectListByUserIdAndType(
|
List<AddressDO> addressDOs = selectListByUserIdAndType(
|
||||||
userId, AddressTypeEnum.DEFAULT.getType());
|
userId, AddressTypeEnum.DEFAULT.getType());
|
||||||
if (!CollectionUtils.isEmpty(addressDOs)) {
|
if (!CollectionUtils.isEmpty(addressDOs)) {
|
||||||
@ -68,13 +70,13 @@ public class AddressServiceImpl implements AddressService {
|
|||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO);
|
AddressDO updateObj = AddressConvert.INSTANCE.convert(updateReqVO);
|
||||||
updateObj.setUserId(userId);
|
updateObj.setUserId(userId); // TODO @shuaidawang:不用加 userId
|
||||||
addressMapper.updateById(updateObj);
|
addressMapper.updateById(updateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAddress(Long userId, Long id) {
|
public void deleteAddress(Long userId, Long id) {
|
||||||
// 校验存在,校验是否能够操作
|
// 校验存在,校验是否能够操作 TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好;
|
||||||
check(userId, id);
|
check(userId, id);
|
||||||
// 删除
|
// 删除
|
||||||
addressMapper.deleteById(id);
|
addressMapper.deleteById(id);
|
||||||
@ -106,19 +108,9 @@ public class AddressServiceImpl implements AddressService {
|
|||||||
return selectListByUserIdAndType(userId, null);
|
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
|
@Override
|
||||||
public AddressDO getAddress(Long userId, Long id) {
|
public AddressDO getAddress(Long userId, Long id) {
|
||||||
AddressDO address = getAddress(id);
|
AddressDO address = getAddress(id); // TODO shuaidawang:改成基于 id + userId 查询,以前的做法不太好;
|
||||||
check(userId, id);
|
check(userId, id);
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
@ -130,10 +122,12 @@ public class AddressServiceImpl implements AddressService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public AddressDO getDefaultUserAddress(Long userId) {
|
public AddressDO getDefaultUserAddress(Long userId) {
|
||||||
|
// TODO @shuaidawang:查询,都抽到 mapper 中
|
||||||
List<AddressDO> addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
|
List<AddressDO> addressDOList = selectListByUserIdAndType(userId, AddressTypeEnum.DEFAULT.getType());
|
||||||
return addressDOList.stream().findFirst().orElse(null);
|
return addressDOList.stream().findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @shuaidawang:查询,都抽到 mapper 中
|
||||||
/**
|
/**
|
||||||
* 根据类型获取地址列表
|
* 根据类型获取地址列表
|
||||||
* @param userId
|
* @param userId
|
||||||
|
Loading…
Reference in New Issue
Block a user