- 迁移:UserAddress
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user