- 迁移:UserAddress

This commit is contained in:
cherishsince 2020-05-03 20:49:20 +08:00
parent 3c5486c80a
commit 174b19723a
35 changed files with 282 additions and 85 deletions

View File

@ -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
View 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
View 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>

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:31 下午
*/
package cn.iocoder.mall.user.biz.bo;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.biz.bo.user;
package cn.iocoder.mall.user.biz.bo.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:31 下午
*/
package cn.iocoder.mall.user.biz.convert;

View File

@ -1,9 +1,9 @@
package cn.iocoder.mall.system.biz.convert.user;
package cn.iocoder.mall.user.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 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;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:28 下午
*/
package cn.iocoder.mall.user.biz.dao;

View File

@ -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);
}
}

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:27 下午
*/
package cn.iocoder.mall.user.biz.dataobject;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.biz.dataobject.user;
package cn.iocoder.mall.user.biz.dataobject.user;
import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
import lombok.Data;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:29 下午
*/
package cn.iocoder.mall.user.biz.dto;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.biz.dto.user;
package cn.iocoder.mall.user.biz.dto.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.biz.dto.user;
package cn.iocoder.mall.user.biz.dto.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:29 下午
*/
package cn.iocoder.mall.user.biz.enums;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.biz.enums.userAddress;
package cn.iocoder.mall.user.biz.enums.user;
/**
* 用户地址 - 用户默认地址
@ -9,7 +9,7 @@ package cn.iocoder.mall.system.biz.enums.userAddress;
public enum UserAddressHasDefaultEnum {
DEFAULT_ADDRESS_NO (1, "不是默认地址"),
DEFAULT_ADDRESS_YES (2, "是默认地址")
DEFAULT_ADDRESS_YES (2, "是默认地址")
;
private final int value;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:27 下午
*/
package cn.iocoder.mall.user.biz;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:30 下午
*/
package cn.iocoder.mall.user.biz.service;

View File

@ -1,8 +1,8 @@
package cn.iocoder.mall.system.biz.service.user;
package cn.iocoder.mall.user.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 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;

View File

@ -1,15 +1,15 @@
package cn.iocoder.mall.system.biz.service.user;
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.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.userAddress.UserAddressHasDefaultEnum;
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;
@ -38,13 +38,12 @@ public class UserAddressServiceImpl implements UserAddressService {
// 检查是否设置为默认地址
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
if (defaultUserAddress != null) {
userAddressMapper.updateById(defaultUserAddress.getId(),
userAddressMapper.updateById(
new UserAddressDO()
.setId(defaultUserAddress.getId())
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
@ -55,9 +54,7 @@ public class UserAddressServiceImpl implements UserAddressService {
@Override
public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) {
UserAddressDO userAddress = userAddressMapper
.selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId());
UserAddressDO userAddress = userAddressMapper.selectById(userAddressAddDTO.getId());
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
@ -68,37 +65,34 @@ public class UserAddressServiceImpl implements UserAddressService {
// 检查是否设置为默认地址
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
userAddressMapper.updateById(defaultUserAddress.getId(),
userAddressMapper.updateById(
new UserAddressDO()
.setId(defaultUserAddress.getId())
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
}
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userAddressAddDTO.getUserId(), UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
userAddressMapper.updateById(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.getId(), userAddressDO);
userAddressMapper.updateById(userAddressDO);
}
@Override
public void removeAddress(Integer userId, Integer addressId) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, addressId);
UserAddressDO userAddress = userAddressMapper.selectById(addressId);
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
// skip
@ -110,16 +104,15 @@ public class UserAddressServiceImpl implements UserAddressService {
}
userAddressMapper.updateById(
addressId,
(UserAddressDO) new UserAddressDO()
.setId(addressId)
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue())
);
}
@Override
public List<UserAddressBO> addressList(Integer userId) {
List<UserAddressDO> userAddressDOList = userAddressMapper
.selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId);
List<UserAddressDO> userAddressDOList = userAddressMapper.selectByUserId(userId);
List<UserAddressBO> userAddressBOList = UserAddressConvert
.INSTANCE.convertUserAddressBOList(userAddressDOList);
@ -129,7 +122,7 @@ public class UserAddressServiceImpl implements UserAddressService {
@Override
public UserAddressBO getAddress(Integer userId, Integer id) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id);
UserAddressDO userAddress = userAddressMapper.selectById(id);
if (userAddress == null) {
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode());
}
@ -144,12 +137,7 @@ public class UserAddressServiceImpl implements UserAddressService {
@Override
public UserAddressBO getDefaultAddress(Integer userId) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userId,
UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userId);
return UserAddressConvert.INSTANCE.convert(defaultUserAddress);
}
}

View File

@ -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>

View File

@ -1,8 +1,8 @@
package cn.iocoder.mall.system.rpc.api.user;
package cn.iocoder.mall.user.rpc.api;
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 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;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:39 下午
*/
package cn.iocoder.mall.user.rpc;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:41 下午
*/
package cn.iocoder.mall.user.rpc.request;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.rpc.request.user;
package cn.iocoder.mall.user.rpc.request.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.rpc.request.user;
package cn.iocoder.mall.user.rpc.request.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:42 下午
*/
package cn.iocoder.mall.user.rpc.response;

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.system.rpc.response.user;
package cn.iocoder.mall.user.rpc.response.user;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -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>

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:43 下午
*/
package cn.iocoder.mall.user.rpc.convert;

View File

@ -1,12 +1,11 @@
package cn.iocoder.mall.system.rpc.convert.user;
package cn.iocoder.mall.user.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 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;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:36 下午
*/
package cn.iocoder.mall.user.rpc;

View File

@ -0,0 +1,5 @@
/**
* author: sin
* time: 2020/5/3 8:37 下午
*/
package cn.iocoder.mall.user.rpc.rpc;

View File

@ -1,11 +1,11 @@
package cn.iocoder.mall.system.rpc.rpc.user;
package cn.iocoder.mall.user.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 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;

View File

@ -15,3 +15,5 @@ dubbo:
filter: -exception
SystemLogRPC:
version: 1.0.0
UserAddressRPC:
version: 1.0.0