From c40b43eda4b2d3839e31a0a5dab64e7c1614b520 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Fri, 1 May 2020 10:43:58 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E6=94=B9=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=9A=E7=94=A8=E6=88=B7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/biz/bo/user/UserAddressBO.java | 46 ++++++ .../biz/convert/user/UserAddressConvert.java | 35 ++++ .../biz/dao/user/UserAddressMapper.java | 40 +++++ .../biz/dataobject/user/UserAddressDO.java | 46 ++++++ .../biz/dto/user/UserAddressAddDTO.java | 45 +++++ .../biz/dto/user/UserAddressUpdateDTO.java | 46 ++++++ .../biz/enums/UserAddressHasDefaultEnum.java | 30 ++++ .../biz/service/user/UserAddressService.java | 28 ++++ .../service/user/UserAddressServiceImpl.java | 155 ++++++++++++++++++ .../system/rpc/api/user/UserAddressRPC.java | 28 ++++ .../request/user/UserAddressAddRequest.java | 45 +++++ .../user/UserAddressUpdateRequest.java | 46 ++++++ .../response/user/UserAddressResponse.java | 46 ++++++ .../convert/user/UserAddressRPCConvert.java | 41 +++++ .../rpc/rpc/user/UserAddressRPCImpl.java | 49 ++++++ 15 files changed, 726 insertions(+) create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserAddressBO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserAddressConvert.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserAddressMapper.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserAddressDO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressAddDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressUpdateDTO.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/enums/UserAddressHasDefaultEnum.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressService.java create mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressServiceImpl.java create mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/user/UserAddressRPC.java create mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressAddRequest.java create mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressUpdateRequest.java create mode 100644 system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/user/UserAddressResponse.java create mode 100644 system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/user/UserAddressRPCConvert.java create mode 100644 system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/user/UserAddressRPCImpl.java diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserAddressBO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserAddressBO.java new file mode 100644 index 000000000..7b1aec9d1 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/bo/user/UserAddressBO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.system.biz.bo.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +public class UserAddressBO implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认 + */ + private Integer hasDefault; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserAddressConvert.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserAddressConvert.java new file mode 100644 index 000000000..c090efd8b --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/convert/user/UserAddressConvert.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.system.biz.convert.user; + +import cn.iocoder.mall.system.biz.bo.user.UserAddressBO; +import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.system.biz.dto.user.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({}) + UserAddressBO convert(UserAddressDO userAddressDO); + + @Mappings({}) + List convertUserAddressBOList(List userAddressDOList); +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserAddressMapper.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserAddressMapper.java new file mode 100644 index 000000000..bc5bd5c4e --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dao/user/UserAddressMapper.java @@ -0,0 +1,40 @@ +package cn.iocoder.mall.system.biz.dao.user; + +import cn.iocoder.mall.system.biz.dataobject.user.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 + ); + + UserAddressDO selectHasDefault( + Integer deleted, + Integer userId, + Integer hasDefault + ); +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserAddressDO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserAddressDO.java new file mode 100644 index 000000000..976d89926 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dataobject/user/UserAddressDO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.system.biz.dataobject.user; + +import cn.iocoder.mall.mybatis.dataobject.DeletableDO; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 用户地址信息 + * + * @author Sin + * @time 2019-04-06 13:22 + */ +@Data +@Accessors(chain = true) +public class UserAddressDO extends DeletableDO { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否为默认 + */ + private Integer hasDefault; + +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressAddDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressAddDTO.java new file mode 100644 index 000000000..b34b7853f --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressAddDTO.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.system.biz.dto.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 13:25 + */ +@Data +@Accessors(chain = true) +public class UserAddressAddDTO implements Serializable { + + /** + * 收件区域编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认 + * + * - 1 不是 + * - 2 是 + */ + private Integer hasDefault; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressUpdateDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressUpdateDTO.java new file mode 100644 index 000000000..34bb51818 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/user/UserAddressUpdateDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.system.biz.dto.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 更新 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +public class UserAddressUpdateDTO implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认地址 + */ + private Integer hasDefault; +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/enums/UserAddressHasDefaultEnum.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/enums/UserAddressHasDefaultEnum.java new file mode 100644 index 000000000..cf682221e --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/enums/UserAddressHasDefaultEnum.java @@ -0,0 +1,30 @@ +package cn.iocoder.mall.system.biz.enums; + +/** + * 用户地址 - 用户默认地址 + * + * @author Sin + * @time 2019-04-10 22:02 + */ +public enum UserAddressHasDefaultEnum { + + DEFAULT_ADDRESS_NO (1, "不是默认地址"), + DEFAULT_ADDRESS_YES (2, "不是默认地址") + ; + + private final int value; + private final String name; + + UserAddressHasDefaultEnum(int value, String name) { + this.value = value; + this.name = name; + } + + public int getValue() { + return value; + } + + public String getName() { + return name; + } +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressService.java new file mode 100644 index 000000000..93aafbb57 --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressService.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.system.biz.service.user; + +import cn.iocoder.mall.system.biz.bo.user.UserAddressBO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO; + +import java.util.List; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:24 + */ +public interface UserAddressService { + + void addAddress(UserAddressAddDTO userAddressAddDTO); + + void updateAddress(UserAddressUpdateDTO userAddressAddDTO); + + void removeAddress(Integer userId, Integer addressId); + + List addressList(Integer userId); + + UserAddressBO getAddress(Integer userId, Integer id); + + UserAddressBO getDefaultAddress(Integer userId); +} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressServiceImpl.java new file mode 100644 index 000000000..70cad2e8c --- /dev/null +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/user/UserAddressServiceImpl.java @@ -0,0 +1,155 @@ +package cn.iocoder.mall.system.biz.service.user; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; +import cn.iocoder.mall.system.biz.bo.user.UserAddressBO; +import cn.iocoder.mall.system.biz.convert.user.UserAddressConvert; +import cn.iocoder.mall.system.biz.dao.user.UserAddressMapper; +import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO; +import cn.iocoder.mall.system.biz.enums.UserAddressHasDefaultEnum; +import cn.iocoder.mall.system.biz.enums.UserErrorCodeEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +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 + @Transactional + public void addAddress(UserAddressAddDTO userAddressAddDTO) { + UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + userAddressDO.setCreateTime(new Date()); + userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()); + + // 检查是否设置为默认地址 + if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) { + UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( + DeletedStatusEnum.DELETED_NO.getValue(), + userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + + if (defaultUserAddress != null) { + userAddressMapper.updateById(defaultUserAddress.getId(), + new UserAddressDO() + .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) + ); + } + } + + userAddressMapper.insert(userAddressDO); + } + + @Override + public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) { + UserAddressDO userAddress = userAddressMapper + .selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId()); + + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); + } + + if (userAddress == null) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); + } + + // 检查是否设置为默认地址 + if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) { + UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( + DeletedStatusEnum.DELETED_NO.getValue(), + userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + + if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) { + userAddressMapper.updateById(defaultUserAddress.getId(), + new UserAddressDO() + .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) + ); + } + } + + UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( + DeletedStatusEnum.DELETED_NO.getValue(), + userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + + if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) { + userAddressMapper.updateById(defaultUserAddress.getId(), + new UserAddressDO() + .setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue()) + ); + } + + UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO); + userAddressDO.setUpdateTime(new Date()); + userAddressMapper.updateById(userAddressDO.getId(), userAddressDO); + } + + @Override + public void removeAddress(Integer userId, Integer addressId) { + UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, addressId); + + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + // skip + return; + } + + if (userAddress == null) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode()); + } + + userAddressMapper.updateById( + addressId, + (UserAddressDO) new UserAddressDO() + .setDeleted(DeletedStatusEnum.DELETED_YES.getValue()) + ); + } + + @Override + public List addressList(Integer userId) { + List userAddressDOList = userAddressMapper + .selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId); + + List userAddressBOList = UserAddressConvert + .INSTANCE.convertUserAddressBOList(userAddressDOList); + + return userAddressBOList; + } + + @Override + public UserAddressBO getAddress(Integer userId, Integer id) { + UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id); + if (userAddress == null) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode()); + } + + if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) { + throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode()); + } + + UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress); + return userAddressBO; + } + + @Override + public UserAddressBO getDefaultAddress(Integer userId) { + + UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( + DeletedStatusEnum.DELETED_NO.getValue(), + userId, + UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); + + return UserAddressConvert.INSTANCE.convert(defaultUserAddress); + } +} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/user/UserAddressRPC.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/user/UserAddressRPC.java new file mode 100644 index 000000000..77c2afc7e --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/api/user/UserAddressRPC.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.system.rpc.api.user; + +import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest; +import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest; +import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse; + +import java.util.List; + +/** + * 用户地址 RPC + * + * author: sin + * time: 2020/5/1 10:26 上午 + */ +public interface UserAddressRPC { + + void addAddress(UserAddressAddRequest userAddressAddRequest); + + void updateAddress(UserAddressUpdateRequest userAddressUpdateRequest); + + void removeAddress(Integer userId, Integer addressId); + + List addressList(Integer userId); + + UserAddressResponse getAddress(Integer userId, Integer id); + + UserAddressResponse getDefaultAddress(Integer userId); +} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressAddRequest.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressAddRequest.java new file mode 100644 index 000000000..50e0d507d --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressAddRequest.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.system.rpc.request.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 add + * + * @author Sin + * @time 2019-04-06 13:25 + */ +@Data +@Accessors(chain = true) +public class UserAddressAddRequest implements Serializable { + + /** + * 收件区域编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认 + * + * - 1 不是 + * - 2 是 + */ + private Integer hasDefault; +} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressUpdateRequest.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressUpdateRequest.java new file mode 100644 index 000000000..ea6cd81af --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/request/user/UserAddressUpdateRequest.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.system.rpc.request.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 更新 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +public class UserAddressUpdateRequest implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认地址 + */ + private Integer hasDefault; +} diff --git a/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/user/UserAddressResponse.java b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/user/UserAddressResponse.java new file mode 100644 index 000000000..567b7799d --- /dev/null +++ b/system/system-rpc-api/src/main/java/cn/iocoder/mall/system/rpc/response/user/UserAddressResponse.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.system.rpc.response.user; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 用户地址 + * + * @author Sin + * @time 2019-04-06 13:28 + */ +@Data +@Accessors(chain = true) +public class UserAddressResponse implements Serializable { + + /** + * 编号 + */ + private Integer id; + /** + * 用户编号 + */ + private Integer userId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 收件详细地址 + */ + private String address; + /** + * 是否默认 + */ + private Integer hasDefault; +} diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/user/UserAddressRPCConvert.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/user/UserAddressRPCConvert.java new file mode 100644 index 000000000..681c974f9 --- /dev/null +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/convert/user/UserAddressRPCConvert.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.system.rpc.convert.user; + +import cn.iocoder.mall.system.biz.bo.user.UserAddressBO; +import cn.iocoder.mall.system.biz.dataobject.user.UserAddressDO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressAddDTO; +import cn.iocoder.mall.system.biz.dto.user.UserAddressUpdateDTO; +import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest; +import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest; +import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * user address convert + * + * author: sin + * time: 2020/5/1 10:30 上午 + */ +@Mapper +public interface UserAddressRPCConvert { + + UserAddressRPCConvert INSTANCE = Mappers.getMapper(UserAddressRPCConvert.class); + + + @Mappings({}) + UserAddressAddDTO convert(UserAddressAddRequest userAddressAddRequest); + + @Mappings({}) + UserAddressUpdateDTO convert(UserAddressUpdateRequest userAddressUpdateRequest); + + @Mappings({}) + UserAddressResponse convert(UserAddressBO userAddressBO); + + @Mappings({}) + List convert(List addressBOS); + + +} diff --git a/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/user/UserAddressRPCImpl.java b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/user/UserAddressRPCImpl.java new file mode 100644 index 000000000..7c275627f --- /dev/null +++ b/system/system-rpc/src/main/java/cn/iocoder/mall/system/rpc/rpc/user/UserAddressRPCImpl.java @@ -0,0 +1,49 @@ +package cn.iocoder.mall.system.rpc.rpc.user; + +import cn.iocoder.mall.system.biz.service.user.UserAddressService; +import cn.iocoder.mall.system.rpc.api.user.UserAddressRPC; +import cn.iocoder.mall.system.rpc.convert.user.UserAddressRPCConvert; +import cn.iocoder.mall.system.rpc.request.user.UserAddressAddRequest; +import cn.iocoder.mall.system.rpc.request.user.UserAddressUpdateRequest; +import cn.iocoder.mall.system.rpc.response.user.UserAddressResponse; +import org.apache.dubbo.config.annotation.Service; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +@Service(version = "${dubbo.provider.UserAddressRPC.version}", validation = "true") +public class UserAddressRPCImpl implements UserAddressRPC { + + @Autowired + private UserAddressService userAddressService; + + @Override + public void addAddress(UserAddressAddRequest userAddressAddRequest) { + userAddressService.addAddress(UserAddressRPCConvert.INSTANCE.convert(userAddressAddRequest)); + } + + @Override + public void updateAddress(UserAddressUpdateRequest userAddressUpdateRequest) { + userAddressService.updateAddress(UserAddressRPCConvert.INSTANCE.convert(userAddressUpdateRequest)); + } + + @Override + public void removeAddress(Integer userId, Integer addressId) { + userAddressService.removeAddress(userId, addressId); + } + + @Override + public List addressList(Integer userId) { + return UserAddressRPCConvert.INSTANCE.convert(userAddressService.addressList(userId)); + } + + @Override + public UserAddressResponse getAddress(Integer userId, Integer id) { + return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(userId, id)); + } + + @Override + public UserAddressResponse getDefaultAddress(Integer userId) { + return UserAddressRPCConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId)); + } +}