diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java new file mode 100644 index 000000000..bb28e6c1d --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java @@ -0,0 +1,62 @@ +package cn.iocoder.mall.user.application.controller.users; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.application.convert.UserAddressConvert; +import cn.iocoder.mall.user.application.po.UserAddressAddPO; +import cn.iocoder.mall.user.application.po.UserAddressUpdatePO; +import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; +import cn.iocoder.mall.user.service.api.UserAddressService; +import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO; +import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 14:11 + */ +@RestController +@RequestMapping("user/address") +@Api(description = "用户地址API") +public class UserAddressController { + + @Autowired + private UserAddressService userAddressService; + + @PostMapping("add") + @ApiOperation(value = "用户地址-添加") + public CommonResult addAddress(@RequestBody @Validated UserAddressAddPO userAddressAddPO) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + UserAddressAddDTO userAddressAddDTO = UserAddressConvert.INSTANCE.convert(userAddressAddPO); + userAddressAddDTO.setUserId(userId); + return userAddressService.addAddress(userAddressAddDTO); + } + + @PostMapping("update") + @ApiOperation(value = "用户地址-更新") + public CommonResult updateAddress(@RequestBody @Validated UserAddressUpdatePO userAddressUpdatePO) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + UserAddressUpdateDTO userAddressUpdateDTO = UserAddressConvert.INSTANCE.convert(userAddressUpdatePO); + userAddressUpdateDTO.setUserId(userId); + return userAddressService.updateAddress(userAddressUpdateDTO); + } + + @DeleteMapping("remove") + @ApiOperation(value = "用户地址-删除") + public CommonResult removeAddress(@RequestParam("id") Integer id) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + return userAddressService.removeAddress(userId, id); + } + + @GetMapping("list") + @ApiOperation(value = "用户地址列表") + public CommonResult addressList() { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + return userAddressService.addressList(userId); + } +} diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserAddressConvert.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserAddressConvert.java new file mode 100644 index 000000000..430773355 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserAddressConvert.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.user.application.convert; + +import cn.iocoder.mall.user.application.po.UserAddressAddPO; +import cn.iocoder.mall.user.application.po.UserAddressUpdatePO; +import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO; +import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Sin + * @time 2019-04-06 14:19 + */ +@Mapper +public interface UserAddressConvert { + + UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class); + + @Mappings({}) + UserAddressAddDTO convert(UserAddressAddPO userAddressAddPO); + + @Mappings({}) + UserAddressUpdateDTO convert(UserAddressUpdatePO userAddressUpdatePO); +} diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressAddPO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressAddPO.java new file mode 100644 index 000000000..bc31804ee --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressAddPO.java @@ -0,0 +1,91 @@ +package cn.iocoder.mall.user.application.po; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 14:13 + */ +@ApiModel("用户地址") +public class UserAddressAddPO implements Serializable { + + /** + * 收件区域编号 + */ + @ApiModelProperty("区域编号") + @NotNull(message = "区域编号不能为空!") + private String areaNo; + /** + * 收件人名称 + */ + @ApiModelProperty("收件人名称") + @NotNull(message = "请填写收人信息!") + private String name; + /** + * 收件手机号 + */ + @ApiModelProperty("收件手机号") + @NotNull(message = "手机号为不能为空!") + @Size(min = 11, max = 11, message = "手机号为 11 位!") + private String mobile; + /** + * 收件详细地址 + */ + @ApiModelProperty("收件详细地址") + @NotNull(message = "详细地址不能为空") + @Size(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!") + private String address; + + @Override + public String toString() { + return "UserAddressAddPO{" + + "areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public String getAreaNo() { + return areaNo; + } + + public UserAddressAddPO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public UserAddressAddPO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public UserAddressAddPO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public UserAddressAddPO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressUpdatePO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressUpdatePO.java new file mode 100644 index 000000000..551607482 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressUpdatePO.java @@ -0,0 +1,108 @@ +package cn.iocoder.mall.user.application.po; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 14:13 + */ +@ApiModel("用户地址-更新") +public class UserAddressUpdatePO implements Serializable { + + + /** + * 收件区域编号 + */ + @ApiModelProperty("地址编号") + @NotNull(message = "地址编号为空!") + private Integer id; + /** + * 收件区域编号 + */ + @ApiModelProperty("区域编号") + @NotNull(message = "区域编号不能为空!") + private String areaNo; + /** + * 收件人名称 + */ + @ApiModelProperty("收件人名称") + @NotNull(message = "请填写收人信息!") + private String name; + /** + * 收件手机号 + */ + @ApiModelProperty("收件手机号") + @NotNull(message = "手机号为不能为空!") + @Size(min = 11, max = 11, message = "手机号为 11 位!") + private String mobile; + /** + * 收件详细地址 + */ + @ApiModelProperty("收件详细地址") + @NotNull(message = "详细地址不能为空") + @Size(min = 10, max = 100, message = "地址在 10 ~ 100 字之间!") + private String address; + + @Override + public String toString() { + return "UserAddressUpdatePO{" + + "id=" + id + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public UserAddressUpdatePO setId(Integer id) { + this.id = id; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public UserAddressUpdatePO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public UserAddressUpdatePO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public UserAddressUpdatePO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public UserAddressUpdatePO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserAddressService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserAddressService.java new file mode 100644 index 000000000..5b783fd2b --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserAddressService.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.user.service.api; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.service.api.bo.UserAddressBO; +import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO; +import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO; + +import java.util.List; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:24 + */ +public interface UserAddressService { + + CommonResult addAddress(UserAddressAddDTO userAddressAddDTO); + + CommonResult updateAddress(UserAddressUpdateDTO userAddressAddDTO); + + CommonResult removeAddress(Integer userId, Integer addressId); + + CommonResult> addressList(Integer userId); +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressBO.java new file mode 100644 index 000000000..e6d21dc45 --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressBO.java @@ -0,0 +1,8 @@ +package cn.iocoder.mall.user.service.api.bo; + +/** + * @author Sin + * @time 2019-04-06 13:28 + */ +public class UserAddressBO { +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressPageBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressPageBO.java new file mode 100644 index 000000000..ca57a6e53 --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserAddressPageBO.java @@ -0,0 +1,48 @@ +package cn.iocoder.mall.user.service.api.bo; + +import java.io.Serializable; +import java.util.List; + +/** + * 用户地址 page + * + * @author Sin + * @time 2019-04-06 13:56 + */ +public class UserAddressPageBO implements Serializable { + + /** + * 总量 + */ + private Integer total; + /** + * 地址 + */ + private List list; + + @Override + public String toString() { + return "UserAddressPageBO{" + + "total=" + total + + ", list=" + list + + '}'; + } + + public Integer getTotal() { + return total; + } + + public UserAddressPageBO setTotal(Integer total) { + this.total = total; + return this; + } + + public List getList() { + return list; + } + + public UserAddressPageBO setList(List list) { + this.list = list; + return this; + } +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java index 47a338ec6..85d00966d 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java @@ -30,7 +30,11 @@ public enum UserErrorCodeEnum { MOBILE_CODE_USED(1001003002, "验证码已使用"), MOBILE_CODE_NOT_CORRECT(1001003003, "验证码不正确"), MOBILE_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY(1001003004, "超过每日短信发送数量"), - MOBILE_CODE_SEND_TOO_FAST(1001003005, "短信发送过于频率") + MOBILE_CODE_SEND_TOO_FAST(1001003005, "短信发送过于频率"), + + // ========== 用户地址 ========== + USER_ADDRESS_NOT_EXISTENT(1001004000, "用户地址不存在!"), + USER_ADDRESS_IS_DELETED(1001004000, "用户地址已被删除!"), ; private final int code; diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressAddDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressAddDTO.java new file mode 100644 index 000000000..3807fbacb --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressAddDTO.java @@ -0,0 +1,89 @@ +package cn.iocoder.mall.user.service.api.dto; + +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 13:25 + */ +public class UserAddressAddDTO implements Serializable { + + /** + * 收件区域编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + + @Override + public String toString() { + return "UserAddressAddDTO{" + + "userId=" + userId + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getUserId() { + return userId; + } + + public UserAddressAddDTO setUserId(Integer userId) { + this.userId = userId; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public UserAddressAddDTO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public UserAddressAddDTO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public UserAddressAddDTO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public UserAddressAddDTO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressUpdateDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressUpdateDTO.java new file mode 100644 index 000000000..8552b4d5c --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserAddressUpdateDTO.java @@ -0,0 +1,103 @@ +package cn.iocoder.mall.user.service.api.dto; + +import java.io.Serializable; + +/** + * 用户地址 更新 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +public class UserAddressUpdateDTO implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + + @Override + public String toString() { + return "UserAddressUpdateDTO{" + + "id=" + id + + ", userId=" + userId + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public UserAddressUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getUserId() { + return userId; + } + + public UserAddressUpdateDTO setUserId(Integer userId) { + this.userId = userId; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public UserAddressUpdateDTO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public UserAddressUpdateDTO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public UserAddressUpdateDTO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public UserAddressUpdateDTO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserAddressConvert.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserAddressConvert.java new file mode 100644 index 000000000..71be6fad3 --- /dev/null +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserAddressConvert.java @@ -0,0 +1,32 @@ +package cn.iocoder.mall.user.convert; + +import cn.iocoder.mall.user.dataobject.UserAddressDO; +import cn.iocoder.mall.user.service.api.bo.UserAddressBO; +import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO; +import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 用户地址 convert + * + * @author Sin + * @time 2019-04-06 13:38 + */ +@Mapper +public interface UserAddressConvert { + + UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class); + + @Mappings({}) + UserAddressDO convert(UserAddressAddDTO userAddressAddDTO); + + @Mappings({}) + UserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO); + + @Mappings({}) + List convertUserAddressBOList(List userAddressDOList); +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserAddressMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserAddressMapper.java new file mode 100644 index 000000000..0e9fb93dc --- /dev/null +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserAddressMapper.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.user.dao; + +import cn.iocoder.mall.user.dataobject.UserAddressDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * 用户 地址 + * + * @author Sin + * @time 2019-04-06 13:29 + */ +@Repository +public interface UserAddressMapper { + + int insert(UserAddressDO userAddressDO); + + int updateById( + @Param("id") Integer id, + @Param("userAddressDO") UserAddressDO userAddressDO + ); + + List selectByUserIdAndDeleted( + Integer deleted, + Integer userId + ); + + UserAddressDO selectByUserIdAndId( + Integer userId, + Integer id + ); +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserAddressDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserAddressDO.java new file mode 100644 index 000000000..f76823339 --- /dev/null +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserAddressDO.java @@ -0,0 +1,103 @@ +package cn.iocoder.mall.user.dataobject; + +import cn.iocoder.common.framework.dataobject.DeletableDO; + +/** + * 用户地址信息 + * + * @author Sin + * @time 2019-04-06 13:22 + */ +public class UserAddressDO extends DeletableDO { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + + @Override + public String toString() { + return "UserAddressDO{" + + "id=" + id + + ", userId=" + userId + + ", areaNo='" + areaNo + '\'' + + ", name='" + name + '\'' + + ", mobile='" + mobile + '\'' + + ", address='" + address + '\'' + + '}'; + } + + public Integer getId() { + return id; + } + + public UserAddressDO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getUserId() { + return userId; + } + + public UserAddressDO setUserId(Integer userId) { + this.userId = userId; + return this; + } + + public String getAreaNo() { + return areaNo; + } + + public UserAddressDO setAreaNo(String areaNo) { + this.areaNo = areaNo; + return this; + } + + public String getName() { + return name; + } + + public UserAddressDO setName(String name) { + this.name = name; + return this; + } + + public String getMobile() { + return mobile; + } + + public UserAddressDO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getAddress() { + return address; + } + + public UserAddressDO setAddress(String address) { + this.address = address; + return this; + } +} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserAddressServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserAddressServiceImpl.java new file mode 100644 index 000000000..bf22e4b6b --- /dev/null +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserAddressServiceImpl.java @@ -0,0 +1,92 @@ +package cn.iocoder.mall.user.service; + +import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.convert.UserAddressConvert; +import cn.iocoder.mall.user.dao.UserAddressMapper; +import cn.iocoder.mall.user.dataobject.UserAddressDO; +import cn.iocoder.mall.user.service.api.UserAddressService; +import cn.iocoder.mall.user.service.api.bo.UserAddressBO; +import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum; +import cn.iocoder.mall.user.service.api.dto.UserAddressAddDTO; +import cn.iocoder.mall.user.service.api.dto.UserAddressUpdateDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:26 + */ +@Service +public class UserAddressServiceImpl implements UserAddressService { + + @Autowired + private UserAddressMapper userAddressMapper; + + @Override + public CommonResult addAddress(UserAddressAddDTO userAddressAddDTO) { + UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + userAddressDO.setCreateTime(new Date()); + userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); + userAddressMapper.insert(userAddressDO); + return CommonResult.success(null); + } + + @Override + public CommonResult updateAddress(UserAddressUpdateDTO userAddressAddDTO) { + UserAddressDO userAddress = userAddressMapper + .selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId()); + + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + return CommonResult.success(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); + } + + if (userAddress == null) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); + } + + UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + userAddressDO.setUpdateTime(new Date()); + userAddressMapper.updateById(userAddressDO.getId(), userAddressDO); + return CommonResult.success(null); + } + + @Override + public CommonResult removeAddress(Integer userId, Integer addressId) { + UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, addressId); + + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + // skip + return CommonResult.success(null); + } + + if (userAddress == null) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); + } + + userAddressMapper.updateById( + addressId, + (UserAddressDO) new UserAddressDO() + .setDeleted(DeletedStatusEnum.DELETED_YES.getValue()) + ); + return CommonResult.success(null); + } + + @Override + public CommonResult> addressList(Integer userId) { + + List userAddressDOList = userAddressMapper + .selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId); + + List userAddressBOList = UserAddressConvert + .INSTANCE.convertUserAddressBOList(userAddressDOList); + + return CommonResult.success(userAddressBOList); + } +} diff --git a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml new file mode 100644 index 000000000..4297e5617 --- /dev/null +++ b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml @@ -0,0 +1,59 @@ + + + + + + id, user_id, areaNo, `name`, mobile, address, + create_time, update_time, deleted + + + + INSERT INTO user_address ( + user_id, areaNo, `name`, mobile, address + ) VALUES ( + #{userId}, #{areaNo}, #{name}, #{mobile}, #{address}, + #{createTime}, #{updateTime}, #{deleted} + ) + + + + UPDATE user_address + + + , area_no = #{areaNo} + + + , `name` = #{name} + + + , mobile = #{mobile} + + + , address = #{address} + + + , update_time = #{updateTime} + + + , deleted = #{deleted} + + + WHERE id = #{id} + + + + + + \ No newline at end of file