- 迁移:UserAddress
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
<module>user-rest</module>
|
||||
<module>user-rpc</module>
|
||||
<module>user-rpc-api</module>
|
||||
<module>user-biz-api</module>
|
||||
<module>user-biz</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
15
user/user-biz-api/pom.xml
Normal file
15
user/user-biz-api/pom.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>user</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>user-biz-api</artifactId>
|
||||
|
||||
|
||||
</project>
|
||||
89
user/user-biz/pom.xml
Normal file
89
user/user-biz/pom.xml
Normal file
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>user</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>user-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>system-biz-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring 核心 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>mall-spring-boot-starter-mybatis</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 短信平台 阿里云、云片 -->
|
||||
<dependency>
|
||||
<groupId>com.yunpian.sdk</groupId>
|
||||
<artifactId>yunpian-java-sdk</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 文件服务商 -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-jdk8</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:31 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.bo;
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:31 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.convert;
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.user.biz.convert.user;
|
||||
|
||||
import cn.iocoder.mall.user.biz.bo.user.UserAddressBO;
|
||||
import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.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<UserAddressBO> convertUserAddressBOList(List<UserAddressDO> userAddressDOList);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:28 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.dao;
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.mall.user.biz.dao.user;
|
||||
|
||||
import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO;
|
||||
import cn.iocoder.mall.user.biz.enums.user.UserAddressHasDefaultEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户 地址
|
||||
*
|
||||
* @author Sin
|
||||
* @time 2019-04-06 13:29
|
||||
*/
|
||||
@Repository
|
||||
// TODO FROM 芋艿 to 小范:替换成 Mybatis Plus
|
||||
public interface UserAddressMapper extends BaseMapper<UserAddressDO> {
|
||||
|
||||
default List<UserAddressDO> selectByUserId(Integer userId) {
|
||||
LambdaQueryWrapper<UserAddressDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(UserAddressDO::getUserId, userId);
|
||||
return selectList(wrapper);
|
||||
}
|
||||
|
||||
default UserAddressDO selectHasDefault(Integer userId) {
|
||||
LambdaQueryWrapper<UserAddressDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(UserAddressDO::getUserId, userId);
|
||||
wrapper.eq(UserAddressDO::getHasDefault, UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
|
||||
return selectOne(wrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:27 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.dataobject;
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.mall.user.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)
|
||||
// TODO FROM 芋艿 to 小范:还是放在 user 服务,哈哈哈,我表述错了。
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:29 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.dto;
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:29 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.enums;
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.mall.user.biz.enums.user;
|
||||
|
||||
/**
|
||||
* 用户地址 - 用户默认地址
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:27 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz;
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:30 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.biz.service;
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.user.biz.service.user;
|
||||
|
||||
import cn.iocoder.mall.user.biz.bo.user.UserAddressBO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.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<UserAddressBO> addressList(Integer userId);
|
||||
|
||||
UserAddressBO getAddress(Integer userId, Integer id);
|
||||
|
||||
UserAddressBO getDefaultAddress(Integer userId);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package cn.iocoder.mall.user.biz.service.user;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum;
|
||||
import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum;
|
||||
import cn.iocoder.mall.user.biz.bo.user.UserAddressBO;
|
||||
import cn.iocoder.mall.user.biz.convert.user.UserAddressConvert;
|
||||
import cn.iocoder.mall.user.biz.dao.user.UserAddressMapper;
|
||||
import cn.iocoder.mall.user.biz.dataobject.user.UserAddressDO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO;
|
||||
import cn.iocoder.mall.user.biz.enums.user.UserAddressHasDefaultEnum;
|
||||
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(userAddressAddDTO.getUserId());
|
||||
|
||||
if (defaultUserAddress != null) {
|
||||
userAddressMapper.updateById(
|
||||
new UserAddressDO()
|
||||
.setId(defaultUserAddress.getId())
|
||||
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
userAddressMapper.insert(userAddressDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) {
|
||||
UserAddressDO userAddress = userAddressMapper.selectById(userAddressAddDTO.getId());
|
||||
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
|
||||
}
|
||||
|
||||
if (userAddress == null) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
|
||||
}
|
||||
|
||||
// 检查是否设置为默认地址
|
||||
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
|
||||
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
|
||||
|
||||
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
|
||||
userAddressMapper.updateById(
|
||||
new UserAddressDO()
|
||||
.setId(defaultUserAddress.getId())
|
||||
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
|
||||
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
|
||||
userAddressMapper.updateById(
|
||||
new UserAddressDO()
|
||||
.setId(defaultUserAddress.getId())
|
||||
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
|
||||
);
|
||||
}
|
||||
|
||||
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
|
||||
userAddressDO.setUpdateTime(new Date());
|
||||
userAddressMapper.updateById(userAddressDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAddress(Integer userId, Integer addressId) {
|
||||
UserAddressDO userAddress = userAddressMapper.selectById(addressId);
|
||||
|
||||
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
|
||||
// skip
|
||||
return;
|
||||
}
|
||||
|
||||
if (userAddress == null) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
|
||||
}
|
||||
|
||||
userAddressMapper.updateById(
|
||||
(UserAddressDO) new UserAddressDO()
|
||||
.setId(addressId)
|
||||
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserAddressBO> addressList(Integer userId) {
|
||||
List<UserAddressDO> userAddressDOList = userAddressMapper.selectByUserId(userId);
|
||||
|
||||
List<UserAddressBO> userAddressBOList = UserAddressConvert
|
||||
.INSTANCE.convertUserAddressBOList(userAddressDOList);
|
||||
|
||||
return userAddressBOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserAddressBO getAddress(Integer userId, Integer id) {
|
||||
UserAddressDO userAddress = userAddressMapper.selectById(id);
|
||||
if (userAddress == null) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode());
|
||||
}
|
||||
|
||||
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
|
||||
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
|
||||
}
|
||||
|
||||
UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress);
|
||||
return userAddressBO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserAddressBO getDefaultAddress(Integer userId) {
|
||||
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userId);
|
||||
return UserAddressConvert.INSTANCE.convert(defaultUserAddress);
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,19 @@
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>common-framework</artifactId>
|
||||
<artifactId>system-biz-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类 -->
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.mall.user.rpc.api;
|
||||
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressAddRequest;
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressUpdateRequest;
|
||||
import cn.iocoder.mall.user.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<UserAddressResponse> addressList(Integer userId);
|
||||
|
||||
UserAddressResponse getAddress(Integer userId, Integer id);
|
||||
|
||||
UserAddressResponse getDefaultAddress(Integer userId);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:39 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc;
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:41 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc.request;
|
||||
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:42 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc.response;
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.user.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;
|
||||
}
|
||||
@@ -13,21 +13,16 @@
|
||||
|
||||
<dependencies>
|
||||
<!-- Mall 相关 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.iocoder.mall</groupId>-->
|
||||
<!-- <artifactId>system-rpc-api</artifactId>-->
|
||||
<!-- <version>1.0-SNAPSHOT</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>user-rpc-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.iocoder.mall</groupId>-->
|
||||
<!-- <artifactId>user-biz</artifactId>-->
|
||||
<!-- <version>1.0-SNAPSHOT</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>user-biz</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RPC 相关 -->
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:43 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc.convert;
|
||||
@@ -0,0 +1,40 @@
|
||||
package cn.iocoder.mall.user.rpc.convert.user;
|
||||
|
||||
import cn.iocoder.mall.user.biz.bo.user.UserAddressBO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressAddDTO;
|
||||
import cn.iocoder.mall.user.biz.dto.user.UserAddressUpdateDTO;
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressAddRequest;
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressUpdateRequest;
|
||||
import cn.iocoder.mall.user.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<UserAddressResponse> convert(List<UserAddressBO> addressBOS);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:36 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc;
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* author: sin
|
||||
* time: 2020/5/3 8:37 下午
|
||||
*/
|
||||
package cn.iocoder.mall.user.rpc.rpc;
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.iocoder.mall.user.rpc.rpc.user;
|
||||
|
||||
import cn.iocoder.mall.user.biz.service.user.UserAddressService;
|
||||
import cn.iocoder.mall.user.rpc.api.UserAddressRPC;
|
||||
import cn.iocoder.mall.user.rpc.convert.user.UserAddressRPCConvert;
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressAddRequest;
|
||||
import cn.iocoder.mall.user.rpc.request.user.UserAddressUpdateRequest;
|
||||
import cn.iocoder.mall.user.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<UserAddressResponse> 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));
|
||||
}
|
||||
}
|
||||
@@ -15,3 +15,5 @@ dubbo:
|
||||
filter: -exception
|
||||
SystemLogRPC:
|
||||
version: 1.0.0
|
||||
UserAddressRPC:
|
||||
version: 1.0.0
|
||||
|
||||
Reference in New Issue
Block a user