继续迁移用户收件地址的代码

This commit is contained in:
YunaiV 2020-07-23 19:02:33 +08:00
parent 6ae48b6543
commit 84d4e604b1
82 changed files with 1242 additions and 1875 deletions

View File

@ -15,7 +15,7 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Constraint( @Constraint(
validatedBy = InEnumValidator.class validatedBy = MobileValidator.class
) )
public @interface Mobile { public @interface Mobile {

View File

@ -97,7 +97,7 @@ public class DubboProviderExceptionFilter implements Filter, Filter.Listener {
*/ */
private GlobalException defaultExceptionHandler(Throwable exception, Invocation invocation) { private GlobalException defaultExceptionHandler(Throwable exception, Invocation invocation) {
logger.error("[defaultExceptionHandler][service({}) method({}) params({}) 执行异常]", logger.error("[defaultExceptionHandler][service({}) method({}) params({}) 执行异常]",
invocation.getServiceName(), invocation.getServiceName(), invocation.getArguments(), exception); invocation.getTargetServiceUniqueName(), invocation.getMethodName(), invocation.getArguments(), exception);
// 如果已经是 GlobalException 全局异常直接返回即可 // 如果已经是 GlobalException 全局异常直接返回即可
if (exception instanceof GlobalException) { if (exception instanceof GlobalException) {
return (GlobalException) exception; return (GlobalException) exception;
@ -108,7 +108,7 @@ public class DubboProviderExceptionFilter implements Filter, Filter.Listener {
private String buildDetailMessage(Throwable exception, Invocation invocation) { private String buildDetailMessage(Throwable exception, Invocation invocation) {
return String.format("Service(%s) Method(%s) 发生异常(%s)", return String.format("Service(%s) Method(%s) 发生异常(%s)",
invocation.getServiceName(), invocation.getMethodName(), ExceptionUtil.getRootCauseMessage(exception)); invocation.getTargetServiceUniqueName(), invocation.getMethodName(), ExceptionUtil.getRootCauseMessage(exception));
} }
} }

12
http-client.env.json Normal file
View File

@ -0,0 +1,12 @@
{
"local": {
"baseUrl": "http://127.0.0.1:18083/management-api/",
"management-api-base-url": "http://127.0.0.1:18083/management-api/",
"accessToken": "yudaoyuanma",
"user-api-base-url": "http://127.0.0.1:18082/user-api/",
"user-access-token": "yunai",
"dubboTag": "${HOSTNAME}"
}
}

View File

@ -82,17 +82,6 @@
<artifactId>mapstruct-jdk8</artifactId> <artifactId>mapstruct-jdk8</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.1-b06</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
</project> </project>

View File

@ -1,7 +0,0 @@
{
"local": {
"baseUrl": "http://127.0.0.1:18083/management-api/",
"accessToken": "yudaoyuanma",
"dubboTag": "${HOSTNAME}"
}
}

View File

@ -18,9 +18,8 @@ public interface UserErrorCodeConstants {
ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1001001205, "短信发送过于频率"); ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1001001205, "短信发送过于频率");
// ========== 用户地址 ========== // ========== 用户地址 ==========
ErrorCode USER_ADDRESS_NOT_EXISTENT = new ErrorCode(1001004000, "用户地址不存在!"); ErrorCode USER_ADDRESS_NOT_FOUND = new ErrorCode(1001004000, "用户地址不存在!");
ErrorCode USER_ADDRESS_IS_DELETED = new ErrorCode(1001004001, "用户地址已被删除!"); ErrorCode USER_GET_ADDRESS_NOT_EXISTS = new ErrorCode(1001004001, "获取的地址不存在!");
ErrorCode USER_GET_ADDRESS_NOT_EXISTS = new ErrorCode(1001004002, "获取的地址不存在!");
// ========== 用户信息模块 1004004100 ========== // ========== 用户信息模块 1004004100 ==========
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004004100, "用户不存在"); ErrorCode USER_NOT_EXISTS = new ErrorCode(1004004100, "用户不存在");

View File

@ -0,0 +1,62 @@
package cn.iocoder.mall.userservice.rpc.address;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import java.util.List;
/**
* 用户收件地址 Rpc 接口
*/
public interface UserAddressRpc {
/**
* 创建用户收件地址
*
* @param createDTO 创建用户收件地址 DTO
* @return 用户收件地址编号
*/
CommonResult<Integer> createUserAddress(UserAddressCreateReqDTO createDTO);
/**
* 更新用户收件地址
*
* @param updateDTO 更新用户收件地址 DTO
*/
CommonResult<Boolean> updateUserAddress(UserAddressUpdateReqDTO updateDTO);
/**
* 删除用户收件地址
*
* @param userAddressId 用户收件地址编号
*/
CommonResult<Boolean> deleteUserAddress(Integer userAddressId);
/**
* 获得用户收件地址
*
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
CommonResult<UserAddressRespDTO> getUserAddress(Integer userAddressId);
/**
* 获得用户收件地址列表
*
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
CommonResult<List<UserAddressRespDTO>> listUserAddresses(List<Integer> userAddressIds);
/**
* 获取指定用户的收件地址列表
*
* @param userId 用户编号
* @param type 地址类型
* @return 收件地址列表
*/
CommonResult<List<UserAddressRespDTO>> listUserAddresses(Integer userId, Integer type);
}

View File

@ -0,0 +1,58 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 用户收件地址创建 Request DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressCreateReqDTO implements Serializable {
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
* 省份编号
*/
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
/**
* 城市编号
*/
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
/**
* 区域编号
*/
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -0,0 +1,57 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* 用户收件地址 Response DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressRespDTO implements Serializable {
/**
* 收件地址编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件人名称
*/
private String name;
/**
* 手机号
*/
private String mobile;
/**
* 省份编号
*/
private Integer provinceCode;
/**
* 城市编号
*/
private Integer cityCode;
/**
* 区域编号
*/
private Integer countyCode;
/**
* 收件详细地址
*/
private String detailAddress;
/**
* 地址类型
*/
private Integer type;
/**
* 创建时间
*/
private Date createTime;
}

View File

@ -0,0 +1,70 @@
package cn.iocoder.mall.userservice.rpc.address.dto;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.validator.Mobile;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 用户收件地址更新 Request DTO
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateReqDTO implements Serializable {
/**
* 收件地址编号
*/
@NotNull(message = "收件地址编号不能为空")
private Integer id;
/**
* 用户编号
*
* TODO 正在讨论
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
@Mobile
private String mobile;
/**
* 省份编号
*/
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
/**
* 城市编号
*/
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
/**
* 区域编号
*/
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
@InEnum(value = UserAddressType.class, message = "地址类型必须是 {value}")
private Integer type;
}

View File

@ -64,6 +64,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
@ -78,18 +79,6 @@
<artifactId>mapstruct-jdk8</artifactId> <artifactId>mapstruct-jdk8</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.1-b06</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,36 @@
package cn.iocoder.mall.userservice.convert.address;
import cn.iocoder.mall.userservice.dal.mysql.dataobject.address.UserAddressDO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressCreateBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressUpdateBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface UserAddressConvert {
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
UserAddressDO convert(UserAddressCreateBO bean);
UserAddressBO convert(UserAddressDO bean);
UserAddressDO convert(UserAddressUpdateBO bean);
List<UserAddressBO> convertList(List<UserAddressDO> list);
UserAddressCreateBO convert(UserAddressCreateReqDTO bean);
UserAddressUpdateBO convert(UserAddressUpdateReqDTO bean);
UserAddressRespDTO convert(UserAddressBO bean);
List<UserAddressRespDTO> convertList02(List<UserAddressBO> list);
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.userservice.dal.mysql.dataobject.address;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO; import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import cn.iocoder.mall.userservice.enums.address.UserAddressType; import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -9,13 +10,16 @@ import lombok.experimental.Accessors;
/** /**
* 用户收件地址 * 用户收件地址
* *
* idx_userId 索引基于 {@link #userId} 字段
*
* @author Sin * @author Sin
* @time 2019-04-06 13:22 * @time 2019-04-06 13:22
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class UsersUserAddressDO extends DeletableDO { @TableName("user_address")
public class UserAddressDO extends DeletableDO {
/** /**
* 编号 * 编号

View File

@ -0,0 +1,19 @@
package cn.iocoder.mall.userservice.dal.mysql.mapper.address;
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
import cn.iocoder.mall.userservice.dal.mysql.dataobject.address.UserAddressDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import javax.annotation.Nullable;
import java.util.List;
@Repository
public interface UserAddressMapper extends BaseMapper<UserAddressDO> {
default List<UserAddressDO> selectListByUserIdAndType(Integer userId, @Nullable Integer type) {
return selectList(new QueryWrapperX<UserAddressDO>().eq("userId", userId)
.eqIfPresent("type", type));
}
}

View File

@ -0,0 +1,86 @@
package cn.iocoder.mall.userservice.manager.address;
import cn.iocoder.mall.userservice.convert.address.UserAddressConvert;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import cn.iocoder.mall.userservice.service.address.UserAddressService;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 用户收件地址 Manager
*/
@Service
public class UserAddressManager {
@Autowired
private UserAddressService userAddressService;
/**
* 创建用户收件地址
*
* @param createDTO 创建用户收件地址 DTO
* @return 用户收件地址
*/
public Integer createUserAddress(UserAddressCreateReqDTO createDTO) {
UserAddressBO userAddressBO = userAddressService.createUserAddress(UserAddressConvert.INSTANCE.convert(createDTO));
return userAddressBO.getId();
}
/**
* 更新用户收件地址
*
* @param updateDTO 更新用户收件地址 DTO
*/
public void updateUserAddress(UserAddressUpdateReqDTO updateDTO) {
userAddressService.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateDTO));
}
/**
* 删除用户收件地址
*
* @param userAddressId 用户收件地址编号
*/
public void deleteUserAddress(Integer userAddressId) {
userAddressService.deleteUserAddress(userAddressId);
}
/**
* 获得用户收件地址
*
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
public UserAddressRespDTO getUserAddress(Integer userAddressId) {
UserAddressBO userAddressBO = userAddressService.getUserAddress(userAddressId);
return UserAddressConvert.INSTANCE.convert(userAddressBO);
}
/**
* 获得用户收件地址列表
*
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
public List<UserAddressRespDTO> listUserAddresses(List<Integer> userAddressIds) {
List<UserAddressBO> userAddressBOs = userAddressService.listUserAddresses(userAddressIds);
return UserAddressConvert.INSTANCE.convertList02(userAddressBOs);
}
/**
* 获取指定用户的收件地址列表
*
* @param userId 用户编号
* @param type 地址类型
* @return 收件地址列表
*/
public List<UserAddressRespDTO> listUserAddresses(Integer userId, Integer type) {
List<UserAddressBO> userAddressBOs = userAddressService.listUserAddresses(userId, type);
return UserAddressConvert.INSTANCE.convertList02(userAddressBOs);
}
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.mall.userservice.rpc.address;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.manager.address.UserAddressManager;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 用户收件地址 Rpc 实现类
*/
@DubboService(version = "${dubbo.provider.UserAddressRpc.version}")
public class UserAddressRpcImpl implements UserAddressRpc {
@Autowired
private UserAddressManager userAddressManager;
@Override
public CommonResult<Integer> createUserAddress(UserAddressCreateReqDTO createDTO) {
return success(userAddressManager.createUserAddress(createDTO));
}
@Override
public CommonResult<Boolean> updateUserAddress(UserAddressUpdateReqDTO updateDTO) {
userAddressManager.updateUserAddress(updateDTO);
return success(true);
}
@Override
public CommonResult<Boolean> deleteUserAddress(Integer userAddressId) {
userAddressManager.deleteUserAddress(userAddressId);
return success(true);
}
@Override
public CommonResult<UserAddressRespDTO> getUserAddress(Integer userAddressId) {
return success(userAddressManager.getUserAddress(userAddressId));
}
@Override
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(List<Integer> userAddressIds) {
return success(userAddressManager.listUserAddresses(userAddressIds));
}
@Override
public CommonResult<List<UserAddressRespDTO>> listUserAddresses(Integer userId, Integer type) {
return success(userAddressManager.listUserAddresses(userId, type));
}
}

View File

@ -7,7 +7,7 @@ import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@Service(version = "${dubbo.provider.UserSmsCodeRpc.version}", validation = "false") @Service(version = "${dubbo.provider.UserSmsCodeRpc.version}")
public class UserSmsCodeRpcImpl implements UserSmsCodeRpc { public class UserSmsCodeRpcImpl implements UserSmsCodeRpc {
@Autowired @Autowired

View File

@ -0,0 +1,130 @@
package cn.iocoder.mall.userservice.service.address;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.mall.userservice.convert.address.UserAddressConvert;
import cn.iocoder.mall.userservice.dal.mysql.dataobject.address.UserAddressDO;
import cn.iocoder.mall.userservice.dal.mysql.mapper.address.UserAddressMapper;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressCreateBO;
import cn.iocoder.mall.userservice.service.address.bo.UserAddressUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.mall.userservice.enums.UserErrorCodeConstants.USER_ADDRESS_NOT_FOUND;
/**
* 用户收件地址 Service
*/
@Service
@Validated
public class UserAddressService {
@Autowired
private UserAddressMapper userAddressMapper;
/**
* 创建用户收件地址
*
* @param createBO 创建用户收件地址 BO
* @return 用户收件地址
*/
@Transactional
public UserAddressBO createUserAddress(@Valid UserAddressCreateBO createBO) {
// 如果添加的是默认收件地址则将原默认地址修改为非默认
if (UserAddressType.DEFAULT.getType().equals(createBO.getType())) {
List<UserAddressDO> addressDOs = userAddressMapper.selectListByUserIdAndType(
createBO.getUserId(), UserAddressType.DEFAULT.getType());
if (!CollectionUtils.isEmpty(addressDOs)) {
addressDOs.forEach(userAddressDO -> userAddressMapper.updateById(new UserAddressDO()
.setId(userAddressDO.getId()).setType(UserAddressType.DEFAULT.getType())));
}
}
// 插入到数据库
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(createBO);
userAddressMapper.insert(userAddressDO);
// 返回
return UserAddressConvert.INSTANCE.convert(userAddressDO);
}
/**
* 更新用户收件地址
*
* @param updateBO 更新用户收件地址 BO
*/
@Transactional
public void updateUserAddress(@Valid UserAddressUpdateBO updateBO) {
// 校验更新的用户收件地址是否存在
if (userAddressMapper.selectById(updateBO.getId()) == null) {
throw ServiceExceptionUtil.exception(USER_ADDRESS_NOT_FOUND);
}
// 如果修改的是默认收件地址则将原默认地址修改为非默认
if (UserAddressType.DEFAULT.getType().equals(updateBO.getType())) {
List<UserAddressDO> addressDOs = userAddressMapper.selectListByUserIdAndType(
updateBO.getUserId(), UserAddressType.DEFAULT.getType());
if (!CollectionUtils.isEmpty(addressDOs)) {
addressDOs.stream().filter(userAddressDO -> userAddressDO.getId().equals(updateBO.getId())) // 过滤掉更新的收件地址
.forEach(userAddressDO -> userAddressMapper.updateById(new UserAddressDO()
.setId(userAddressDO.getId()).setType(UserAddressType.DEFAULT.getType())));
}
}
// 更新到数据库
UserAddressDO updateObject = UserAddressConvert.INSTANCE.convert(updateBO);
userAddressMapper.updateById(updateObject);
}
/**
* 删除用户收件地址
*
* @param userAddressId 用户收件地址编号
*/
public void deleteUserAddress(Integer userAddressId) {
// 校验删除的用户收件地址是否存在
if (userAddressMapper.selectById(userAddressId) == null) {
throw ServiceExceptionUtil.exception(USER_ADDRESS_NOT_FOUND);
}
// 标记删除
userAddressMapper.deleteById(userAddressId);
}
/**
* 获得用户收件地址
*
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
public UserAddressBO getUserAddress(Integer userAddressId) {
UserAddressDO userAddressDO = userAddressMapper.selectById(userAddressId);
return UserAddressConvert.INSTANCE.convert(userAddressDO);
}
/**
* 获得用户收件地址列表
*
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
public List<UserAddressBO> listUserAddresses(List<Integer> userAddressIds) {
List<UserAddressDO> userAddressDOs = userAddressMapper.selectBatchIds(userAddressIds);
return UserAddressConvert.INSTANCE.convertList(userAddressDOs);
}
/**
* 获取指定用户的收件地址列表
*
* @param userId 用户编号
* @param type 地址类型
* @return 收件地址列表
*/
public List<UserAddressBO> listUserAddresses(Integer userId, Integer type) {
List<UserAddressDO> userAddressDOs = userAddressMapper.selectListByUserIdAndType(userId, type);
return UserAddressConvert.INSTANCE.convertList(userAddressDOs);
}
}

View File

@ -0,0 +1,64 @@
package cn.iocoder.mall.userservice.service.address.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 用户收件地址 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressBO {
/**
* 收件地址编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件人名称
*/
private String name;
/**
* 手机号
*/
private String mobile;
/**
* 省份编号
*/
private Integer provinceCode;
/**
* 城市编号
*/
private Integer cityCode;
/**
* 区域编号
*/
private Integer countyCode;
/**
* 收件详细地址
*/
private String detailAddress;
/**
* 地址类型
*/
private Integer type;
/**
* 创建时间
*/
private Date createTime;
/**
* 最后更新时间
*/
private Date updateTime;
/**
* 删除状态
*/
private Integer deleted;
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.mall.userservice.service.address.bo;
import cn.iocoder.common.framework.validator.Mobile;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 用户收件地址创建 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressCreateBO {
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
@Mobile
private String mobile;
/**
* 省份编号
*/
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
/**
* 城市编号
*/
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
/**
* 区域编号
*/
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -0,0 +1,62 @@
package cn.iocoder.mall.userservice.service.address.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 用户收件地址更新 BO
*/
@Data
@Accessors(chain = true)
public class UserAddressUpdateBO {
/**
* 收件地址编号
*/
@NotNull(message = "收件地址编号不能为空")
private Integer id;
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Integer userId;
/**
* 收件人名称
*/
@NotEmpty(message = "收件人名称不能为空")
private String name;
/**
* 手机号
*/
@NotEmpty(message = "手机号不能为空")
private String mobile;
/**
* 省份编号
*/
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
/**
* 城市编号
*/
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
/**
* 区域编号
*/
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
/**
* 收件详细地址
*/
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
/**
* 地址类型
*/
@NotNull(message = "地址类型不能为空")
private Integer type;
}

View File

@ -27,8 +27,13 @@
<dependencies> <dependencies>
<!-- Web 相关 --> <!-- Web 相关 -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>mall-spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot-starter-swagger</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -38,8 +43,8 @@
<!-- RPC 相关 --> <!-- RPC 相关 -->
<dependency> <dependency>
<groupId>com.alibaba.cloud</groupId> <groupId>cn.iocoder.mall</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId> <artifactId>mall-spring-boot-starter-dubbo</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -76,17 +81,6 @@
<artifactId>mapstruct-jdk8</artifactId> <artifactId>mapstruct-jdk8</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.el</groupId>-->
<!-- <artifactId>javax.el-api</artifactId>-->
<!-- <version>3.0.1-b06</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,74 @@
package cn.iocoder.mall.userweb.controller.address;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressRespVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressUpdateReqVO;
import cn.iocoder.mall.userweb.manager.address.UserAddressManager;
import cn.iocoder.security.annotations.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* 用户收件地址 Controller
*/
@RestController
@RequestMapping("/user_address")
@Api(tags = "用户收件地址")
@Validated
public class UserAddressController {
@Autowired
private UserAddressManager userAddressManager;
@PostMapping("/create")
@ApiOperation("创建用户收件地址")
@RequiresPermissions
public CommonResult<Integer> createUserAddress(@Valid UserAddressCreateReqVO createVO) {
return success(userAddressManager.createUserAddress(UserSecurityContextHolder.getUserId(), createVO));
}
@PostMapping("/update")
@ApiOperation("更新用户收件地址")
@RequiresPermissions
public CommonResult<Boolean> updateUserAddress(@Valid UserAddressUpdateReqVO updateVO) {
userAddressManager.updateUserAddress(UserSecurityContextHolder.getUserId(), updateVO);
return success(true);
}
@PostMapping("/delete")
@ApiOperation("删除用户收件地址")
@ApiImplicitParam(name = "userAddressId", value = "用户收件地址编号", required = true)
@RequiresPermissions
public CommonResult<Boolean> deleteUserAddress(@RequestParam("userAddressId") Integer userAddressId) {
userAddressManager.deleteUserAddress(UserSecurityContextHolder.getUserId(), userAddressId);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得用户收件地址")
@ApiImplicitParam(name = "userAddressId", value = "用户收件地址编号", required = true)
@RequiresPermissions
public CommonResult<UserAddressRespVO> getUserAddress(@RequestParam("userAddressId") Integer userAddressId) {
return success(userAddressManager.getUserAddress(UserSecurityContextHolder.getUserId(), userAddressId));
}
@GetMapping("/list")
@ApiOperation("获得用户收件地址列表")
@ApiImplicitParam(name = "userAddressIds", value = "用户收件地址编号列表", required = true)
@RequiresPermissions
public CommonResult<List<UserAddressRespVO>> listUserAddresses(@RequestParam("userAddressIds") List<Integer> userAddressIds) {
return success(userAddressManager.listUserAddresses(UserSecurityContextHolder.getUserId(), userAddressIds));
}
}

View File

@ -0,0 +1,39 @@
package cn.iocoder.mall.userweb.controller.address.vo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("用户收件地址创建 Request VO")
@Data
public class UserAddressCreateReqVO {
@ApiModelProperty(value = "收件人名称", required = true, example = "帅艿艿")
@NotEmpty(message = "收件人名称不能为空")
private String name;
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@NotEmpty(message = "手机号不能为空")
private String mobile;
@ApiModelProperty(value = "省份编号", required = true, example = "230000")
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
@ApiModelProperty(value = "城市编号", required = true, example = "469031")
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
@ApiModelProperty(value = "地址类型", required = true, example = "1", notes = "参见 UserAddressType 枚举类")
@NotNull(message = "地址类型不能为空")
@InEnum(value = UserAddressType.class, message = "地址类型必须是 {value}")
private Integer type;
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.userweb.controller.address.vo;
import lombok.*;
import io.swagger.annotations.*;
import java.util.*;
@ApiModel("用户收件地址 Response VO")
@Data
public class UserAddressRespVO {
@ApiModelProperty(value = "收件地址编号", required = true)
private Integer id;
@ApiModelProperty(value = "用户编号", required = true)
private Integer userId;
@ApiModelProperty(value = "收件人名称", required = true)
private String name;
@ApiModelProperty(value = "手机号", required = true)
private String mobile;
@ApiModelProperty(value = "省份编号", required = true)
private Integer provinceCode;
@ApiModelProperty(value = "城市编号", required = true)
private Integer cityCode;
@ApiModelProperty(value = "区域编号", required = true)
private Integer countyCode;
@ApiModelProperty(value = "收件详细地址", required = true)
private String detailAddress;
@ApiModelProperty(value = "地址类型", required = true)
private Integer type;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
@ApiModelProperty(value = "最后更新时间", required = true)
private Date updateTime;
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.mall.userweb.controller.address.vo;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.userservice.enums.address.UserAddressType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@ApiModel("用户收件地址更新 Request VO")
@Data
public class UserAddressUpdateReqVO {
@ApiModelProperty(value = "收件地址编号", required = true)
@NotNull(message = "收件地址编号不能为空")
private Integer id;
@ApiModelProperty(value = "收件人名称", required = true, example = "帅艿艿")
@NotEmpty(message = "收件人名称不能为空")
private String name;
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@NotEmpty(message = "手机号不能为空")
private String mobile;
@ApiModelProperty(value = "省份编号", required = true, example = "230000")
@NotNull(message = "省份编号不能为空")
private Integer provinceCode;
@ApiModelProperty(value = "城市编号", required = true, example = "469031")
@NotNull(message = "城市编号不能为空")
private Integer cityCode;
@ApiModelProperty(value = "区域编号", required = true, example = "610632")
@NotNull(message = "区域编号不能为空")
private Integer countyCode;
@ApiModelProperty(value = "收件详细地址", required = true, example = "芋道源码 233 号 666 室")
@NotEmpty(message = "收件详细地址不能为空")
private String detailAddress;
@ApiModelProperty(value = "地址类型", required = true, example = "1", notes = "参见 UserAddressType 枚举类")
@NotNull(message = "地址类型不能为空")
@InEnum(value = UserAddressType.class, message = "地址类型必须是 {value}")
private Integer type;
}

View File

@ -0,0 +1,13 @@
### /passport/login-by-sms 成功
POST {{user-api-base-url}}/passport/login-by-sms
Content-Type: application/x-www-form-urlencoded
mobile=15601691300&code=9999
### /passport/send-sms-code 成功
POST {{user-api-base-url}}/passport/send-sms-code
Content-Type: application/x-www-form-urlencoded
mobile=15601691300&scene=1
###

View File

@ -2,10 +2,11 @@ package cn.iocoder.mall.userweb.controller.passport;
import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.HttpUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportLoginBySmsDTO; import cn.iocoder.mall.userweb.controller.passport.vo.PassportLoginBySmsReqVO;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportSendSmsCodeDTO; import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportSendSmsRespVO;
import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportVO; import cn.iocoder.mall.userweb.controller.passport.vo.PassportAccessTokenRespVO;
import cn.iocoder.mall.userweb.manager.passport.UserPassportManager; import cn.iocoder.mall.userweb.manager.passport.UserPassportManager;
import cn.iocoder.security.annotations.RequiresNone;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,18 +26,18 @@ public class UserPassportController {
@Autowired @Autowired
private UserPassportManager userPassportManager; private UserPassportManager userPassportManager;
@PostMapping("/login_by_sms") @PostMapping("/login-by-sms")
@ApiOperation("手机验证码登陆") @ApiOperation("手机验证码登陆")
// @RequiresNone TODO 晚点加上 @RequiresNone
public CommonResult<UserPassportVO> loginBySms(UserPassportLoginBySmsDTO loginBySmsDTO, public CommonResult<PassportAccessTokenRespVO> loginBySms(PassportLoginBySmsReqVO loginBySmsDTO,
HttpServletRequest request) { HttpServletRequest request) {
return success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request))); return success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request)));
} }
@PostMapping("/send_sms_code") @PostMapping("/send-sms-code")
@ApiOperation("发送手机验证码") @ApiOperation("发送手机验证码")
// @RequiresNone TODO 晚点加上 @RequiresNone
public CommonResult<Boolean> sendSmsCode(UserPassportSendSmsCodeDTO sendSmsCodeDTO, public CommonResult<Boolean> sendSmsCode(UserPassportSendSmsRespVO sendSmsCodeDTO,
HttpServletRequest request) { HttpServletRequest request) {
userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request));
// 返回成功 // 返回成功

View File

@ -0,0 +1,22 @@
package cn.iocoder.mall.userweb.controller.passport.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("访问令牌信息 Response VO")
@Data
@Accessors(chain = true)
public class PassportAccessTokenRespVO {
@ApiModelProperty(value = "访问令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50")
private String accessToken;
@ApiModelProperty(value = "刷新令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50")
private String refreshToken;
@ApiModelProperty(value = "过期时间", required = true)
private Date expiresTime;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.userweb.controller.passport.dto; package cn.iocoder.mall.userweb.controller.passport.vo;
import cn.iocoder.common.framework.validator.Mobile; import cn.iocoder.common.framework.validator.Mobile;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -11,10 +11,10 @@ import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import java.io.Serializable; import java.io.Serializable;
@ApiModel("用户短信验证码登陆 DTO") @ApiModel("用户短信验证码登陆 Request VO")
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class UserPassportLoginBySmsDTO implements Serializable { public class PassportLoginBySmsReqVO implements Serializable {
@ApiModelProperty(value = "手机号", required = true, example = "15601691300") @ApiModelProperty(value = "手机号", required = true, example = "15601691300")
@NotEmpty(message = "手机号不能为空") @NotEmpty(message = "手机号不能为空")

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.userweb.controller.passport.dto; package cn.iocoder.mall.userweb.controller.passport.vo;
import cn.iocoder.common.framework.validator.Mobile; import cn.iocoder.common.framework.validator.Mobile;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -8,10 +8,10 @@ import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ApiModel("发送手机验证码 DTO") @ApiModel("发送手机验证码 Response VO")
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class UserPassportSendSmsCodeDTO { public class UserPassportSendSmsRespVO {
@ApiModelProperty(value = "手机号", example = "15601691234") @ApiModelProperty(value = "手机号", example = "15601691234")
@Mobile @Mobile

View File

@ -1,52 +0,0 @@
package cn.iocoder.mall.userweb.controller.passport.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("用户通信证信息 VO")
@Data
@Accessors(chain = true)
public class UserPassportVO {
@ApiModel("认证信息")
@Data
@Accessors(chain = true)
public static class Authentication {
@ApiModelProperty(value = "访问令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50")
private String accessToken;
@ApiModelProperty(value = "刷新令牌", required = true, example = "001e8f49b20e47f7b3a2de774497cd50")
private String refreshToken;
@ApiModelProperty(value = "过期时间", required = true)
private Date expiresTime;
}
@ApiModel("用户信息")
@Data
@Accessors(chain = true)
public static class User {
@ApiModelProperty(value = "用户编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "用户昵称", required = true, example = "小王")
private String nickname;
@ApiModelProperty(value = "用户头像", required = true, example = "http://www.iocoder.cn/image")
private String avatar;
}
/**
* 用户信息
*/
private User user;
/**
* 认证信息
*/
private Authentication authorization;
}

View File

@ -2,7 +2,7 @@ package cn.iocoder.mall.userweb.controller.user;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder; import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO; import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO;
import cn.iocoder.mall.userweb.manager.user.UserManager; import cn.iocoder.mall.userweb.manager.user.UserManager;
import cn.iocoder.security.annotations.RequiresAuthenticate; import cn.iocoder.security.annotations.RequiresAuthenticate;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -25,8 +25,8 @@ public class UserController {
@ApiOperation(value = "用户信息") @ApiOperation(value = "用户信息")
@GetMapping("/info") @GetMapping("/info")
@RequiresAuthenticate @RequiresAuthenticate
public CommonResult<UserInfoVO> info() { public CommonResult<UserRespVO> info() {
UserInfoVO user = userManager.getUser(UserSecurityContextHolder.getUserId()); UserRespVO user = userManager.getUser(UserSecurityContextHolder.getUserId());
return success(user); return success(user);
} }
@ -40,7 +40,7 @@ public class UserController {
// // 更新头像 // // 更新头像
// return success(userService.updateUser(userUpdateDTO)); // return success(userService.updateUser(userUpdateDTO));
// } // }
//
// @PostMapping("/update_nickname") // @PostMapping("/update_nickname")
// @RequiresLogin // @RequiresLogin
// @ApiOperation(value = "更新昵称") // @ApiOperation(value = "更新昵称")

View File

@ -8,7 +8,7 @@ import lombok.experimental.Accessors;
@ApiModel("用户信息 VO") @ApiModel("用户信息 VO")
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class UserInfoVO { public class UserRespVO {
@ApiModelProperty(value = "用户编号", required = true, example = "123") @ApiModelProperty(value = "用户编号", required = true, example = "123")
private Integer id; private Integer id;

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.userweb.convert.address;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressUpdateReqDTO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressRespVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressUpdateReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface UserAddressConvert {
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
UserAddressUpdateReqDTO convert(UserAddressUpdateReqVO bean);
UserAddressRespVO convert(UserAddressRespDTO bean);
List<UserAddressRespVO> convertList(List<UserAddressRespDTO> list);
UserAddressCreateReqDTO convert(UserAddressCreateReqVO bean);
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.mall.userweb.convert.passport;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
import cn.iocoder.mall.userweb.controller.passport.vo.PassportLoginBySmsReqVO;
import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportSendSmsRespVO;
import cn.iocoder.mall.userweb.controller.passport.vo.PassportAccessTokenRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface PassportConvert {
PassportConvert INSTANCE = Mappers.getMapper(PassportConvert.class);
UserVerifySmsCodeReqDTO convert(PassportLoginBySmsReqVO bean);
UserCreateReqDTO convert02(PassportLoginBySmsReqVO bean);
UserSendSmsCodeReqDTO convert(UserPassportSendSmsRespVO bean);
PassportAccessTokenRespVO convert(OAuth2AccessTokenRespDTO bean);
}

View File

@ -1,30 +0,0 @@
package cn.iocoder.mall.userweb.convert.passport;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportLoginBySmsDTO;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportSendSmsCodeDTO;
import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface UserPassportConvert {
UserPassportConvert INSTANCE = Mappers.getMapper(UserPassportConvert.class);
UserVerifySmsCodeReqDTO convert(UserPassportLoginBySmsDTO bean);
UserCreateReqDTO convert02(UserPassportLoginBySmsDTO bean);
default UserPassportVO convert(UserRespDTO userVO, OAuth2AccessTokenRespDTO accessTokenVO) {
return new UserPassportVO().setUser(convert(userVO)).setAuthorization(convert(accessTokenVO));
}
UserPassportVO.User convert(UserRespDTO userVO);
UserPassportVO.Authentication convert(OAuth2AccessTokenRespDTO accessTokenVO);
UserSendSmsCodeReqDTO convert(UserPassportSendSmsCodeDTO bean);
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.mall.userweb.convert.user; package cn.iocoder.mall.userweb.convert.user;
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO; import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO; import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -10,6 +10,6 @@ public interface UserConvert {
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
UserInfoVO convert(UserRespDTO bean); UserRespVO convert(UserRespDTO bean);
} }

View File

@ -0,0 +1,117 @@
package cn.iocoder.mall.userweb.manager.address;
import cn.iocoder.common.framework.exception.GlobalException;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.rpc.address.UserAddressRpc;
import cn.iocoder.mall.userservice.rpc.address.dto.UserAddressRespDTO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressCreateReqVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressRespVO;
import cn.iocoder.mall.userweb.controller.address.vo.UserAddressUpdateReqVO;
import cn.iocoder.mall.userweb.convert.address.UserAddressConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.util.List;
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.FORBIDDEN;
/**
* 用户收件地址 Manager
*/
@Service
public class UserAddressManager {
@DubboReference(version = "${dubbo.consumer.UserAddressRpc.version}")
private UserAddressRpc userAddressRpc;
/**
* 创建用户收件地址
*
* @param userId 用户编号
* @param createVO 创建用户收件地址 VO
* @return 用户收件地址
*/
public Integer createUserAddress(Integer userId, UserAddressCreateReqVO createVO) {
CommonResult<Integer> createUserAddressResult = userAddressRpc.createUserAddress(
UserAddressConvert.INSTANCE.convert(createVO).setUserId(userId));
createUserAddressResult.checkError();
return createUserAddressResult.getData();
}
/**
* 更新用户收件地址
*
* @param userId 用户编号
* @param updateVO 更新用户收件地址 VO
*/
public void updateUserAddress(Integer userId, UserAddressUpdateReqVO updateVO) {
// 校验是否能够操作
check(userId, updateVO.getId());
// 执行更新
CommonResult<Boolean> updateUserAddressResult = userAddressRpc.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateVO));
updateUserAddressResult.checkError();
}
/**
* 删除用户收件地址
*
* @param userId 用户编号
* @param userAddressId 用户收件地址编号
*/
public void deleteUserAddress(Integer userId, Integer userAddressId) {
// 校验是否能够操作
check(userId, userAddressId);
// 执行删除
CommonResult<Boolean> deleteUserAddressResult = userAddressRpc.deleteUserAddress(userAddressId);
deleteUserAddressResult.checkError();
}
/**
* 获得用户收件地址
*
* @param userId 用户编号
* @param userAddressId 用户收件地址编号
* @return 用户收件地址
*/
public UserAddressRespVO getUserAddress(Integer userId, Integer userAddressId) {
CommonResult<UserAddressRespDTO> getUserAddressResult = userAddressRpc.getUserAddress(userAddressId);
getUserAddressResult.checkError();
// 校验是否能够操作
this.check(userId, userAddressId);
return UserAddressConvert.INSTANCE.convert(getUserAddressResult.getData());
}
/**
* 获得用户收件地址列表
*
* @param userId 用户编号
* @param userAddressIds 用户收件地址编号列表
* @return 用户收件地址列表
*/
public List<UserAddressRespVO> listUserAddresses(Integer userId, List<Integer> userAddressIds) {
CommonResult<List<UserAddressRespDTO>> listUserAddressResult = userAddressRpc.listUserAddresses(userAddressIds);
listUserAddressResult.checkError();
// 校验是否能够操作
listUserAddressResult.getData().forEach(userAddressRespDTO -> check(userId, userAddressRespDTO));
return UserAddressConvert.INSTANCE.convertList(listUserAddressResult.getData());
}
/**
* 校验用户收件地址是不是属于该用户
*
* @param userId 用户编号
* @param userAddressId 用户收件地址
*/
private void check(Integer userId, Integer userAddressId) {
CommonResult<UserAddressRespDTO> getUserAddressResult = userAddressRpc.getUserAddress(userAddressId);
getUserAddressResult.checkError();
this.check(userId, getUserAddressResult.getData());
}
private void check(Integer userId, UserAddressRespDTO userAddressRespDTO) {
if (!userAddressRespDTO.getUserId().equals(userId)) {
throw new GlobalException(FORBIDDEN);
}
}
}

View File

@ -3,16 +3,16 @@ package cn.iocoder.mall.userweb.manager.passport;
import cn.iocoder.common.framework.enums.UserTypeEnum; import cn.iocoder.common.framework.enums.UserTypeEnum;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc; import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO; import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum; import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc; import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc;
import cn.iocoder.mall.userservice.rpc.user.UserRpc; import cn.iocoder.mall.userservice.rpc.user.UserRpc;
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO; import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportLoginBySmsDTO; import cn.iocoder.mall.userweb.controller.passport.vo.PassportLoginBySmsReqVO;
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportSendSmsCodeDTO; import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportSendSmsRespVO;
import cn.iocoder.mall.userweb.controller.passport.vo.UserPassportVO; import cn.iocoder.mall.userweb.controller.passport.vo.PassportAccessTokenRespVO;
import cn.iocoder.mall.userweb.convert.passport.UserPassportConvert; import cn.iocoder.mall.userweb.convert.passport.PassportConvert;
import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,14 +26,14 @@ public class UserPassportManager {
@Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false") @Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false")
private OAuth2Rpc oauth2Rpc; private OAuth2Rpc oauth2Rpc;
public UserPassportVO loginBySms(UserPassportLoginBySmsDTO loginBySmsDTO, String ip) { public PassportAccessTokenRespVO loginBySms(PassportLoginBySmsReqVO loginBySmsDTO, String ip) {
// 校验验证码 // 校验验证码
CommonResult<Boolean> verifySmsCodeResult = userSmsCodeRpc.verifySmsCode( CommonResult<Boolean> verifySmsCodeResult = userSmsCodeRpc.verifySmsCode(
UserPassportConvert.INSTANCE.convert(loginBySmsDTO).setScene(UserSmsSceneEnum.LOGIN_BY_SMS.getValue()).setIp(ip)); PassportConvert.INSTANCE.convert(loginBySmsDTO).setScene(UserSmsSceneEnum.LOGIN_BY_SMS.getValue()).setIp(ip));
verifySmsCodeResult.checkError(); verifySmsCodeResult.checkError();
// 获得用户 // 获得用户
CommonResult<UserRespDTO> createUserResult = userRpc.createUserIfAbsent( CommonResult<UserRespDTO> createUserResult = userRpc.createUserIfAbsent(
UserPassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip)); PassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip));
createUserResult.checkError(); createUserResult.checkError();
// 创建访问令牌 // 创建访问令牌
CommonResult<OAuth2AccessTokenRespDTO> createAccessTokenResult = oauth2Rpc.createAccessToken( CommonResult<OAuth2AccessTokenRespDTO> createAccessTokenResult = oauth2Rpc.createAccessToken(
@ -41,12 +41,12 @@ public class UserPassportManager {
.setUserType(UserTypeEnum.USER.getValue()).setCreateIp(ip)); .setUserType(UserTypeEnum.USER.getValue()).setCreateIp(ip));
createAccessTokenResult.checkError(); createAccessTokenResult.checkError();
// 返回 // 返回
return UserPassportConvert.INSTANCE.convert(createUserResult.getData(), createAccessTokenResult.getData()); return PassportConvert.INSTANCE.convert(createAccessTokenResult.getData());
} }
public void sendSmsCode(UserPassportSendSmsCodeDTO sendSmsCodeDTO, String ip) { public void sendSmsCode(UserPassportSendSmsRespVO sendSmsCodeDTO, String ip) {
CommonResult<Boolean> sendSmsCodeResult = userSmsCodeRpc.sendSmsCode( CommonResult<Boolean> sendSmsCodeResult = userSmsCodeRpc.sendSmsCode(
UserPassportConvert.INSTANCE.convert(sendSmsCodeDTO).setIp(ip)); PassportConvert.INSTANCE.convert(sendSmsCodeDTO).setIp(ip));
sendSmsCodeResult.checkError(); sendSmsCodeResult.checkError();
} }

View File

@ -3,18 +3,18 @@ package cn.iocoder.mall.userweb.manager.user;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.userservice.rpc.user.UserRpc; import cn.iocoder.mall.userservice.rpc.user.UserRpc;
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO; import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO; import cn.iocoder.mall.userweb.controller.user.vo.UserRespVO;
import cn.iocoder.mall.userweb.convert.user.UserConvert; import cn.iocoder.mall.userweb.convert.user.UserConvert;
import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class UserManager { public class UserManager {
@Reference(version = "${dubbo.consumer.UserRpc.version}", validation = "false") @DubboReference(version = "${dubbo.consumer.UserRpc.version}")
private UserRpc userRpc; private UserRpc userRpc;
public UserInfoVO getUser(Integer id) { public UserRespVO getUser(Integer id) {
CommonResult<UserRespDTO> userResult = userRpc.getUser(id); CommonResult<UserRespDTO> userResult = userRpc.getUser(id);
userResult.checkError(); userResult.checkError();
return UserConvert.INSTANCE.convert(userResult.getData()); return UserConvert.INSTANCE.convert(userResult.getData());

View File

@ -5,10 +5,11 @@ spring:
# Spring Cloud Nacos Discovery 配置项 # Spring Cloud Nacos Discovery 配置项
discovery: discovery:
server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址
namespace: local # Nacos 命名空间 namespace: dev # Nacos 命名空间
# Dubbo 配置项 # Dubbo 配置项
dubbo: dubbo:
# Dubbo 注册中心 # Dubbo 注册中心
registry: registry:
address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 # address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
address: nacos://400-infra.server.iocoder.cn:8848?namespace=dev # 指定 Dubbo 服务注册中心的地址

View File

@ -11,6 +11,10 @@ spring:
# Profile 的配置项 # Profile 的配置项
profiles: profiles:
active: local active: local
# SpringMVC 配置项
mvc:
throw-exception-if-no-handler-found: true # 匹配不到路径时,抛出 NoHandlerFoundException 异常
static-path-pattern: /doc.html # 静态资源的路径
# Dubbo 配置项 # Dubbo 配置项
dubbo: dubbo:
@ -27,5 +31,14 @@ dubbo:
version: 1.0.0 version: 1.0.0
OAuth2Rpc: OAuth2Rpc:
version: 1.0.0 version: 1.0.0
SystemLogRPC: SystemAccessLogRpc:
version: 1.0.0 version: 1.0.0
SystemExceptionLogRpc:
version: 1.0.0
# Swagger 配置项
swagger:
title: 用户中心
description: 提供用户注册、登陆、信息等等 API
version: 1.0.0
base-package: cn.iocoder.mall.userweb.controller

View File

@ -16,8 +16,6 @@
<!-- <module>user-service-api</module>--> <!-- <module>user-service-api</module>-->
<!-- <module>user-service-impl</module>--> <!-- <module>user-service-impl</module>-->
<module>user-rest</module> <module>user-rest</module>
<module>user-rpc</module>
<module>user-rpc-api</module>
<module>user-biz</module> <module>user-biz</module>
</modules> </modules>

View File

@ -1,89 +0,0 @@
<?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>user-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

@ -1,46 +0,0 @@
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;
}

View File

@ -1,35 +0,0 @@
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.UsersUserAddressDO;
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({})
UsersUserAddressDO convert(UserAddressAddDTO userAddressAddDTO);
@Mappings({})
UsersUserAddressDO convert(UserAddressUpdateDTO userAddressUpdateDTO);
@Mappings({})
UserAddressBO convert(UsersUserAddressDO userAddressDO);
@Mappings({})
List<UserAddressBO> convertUserAddressBOList(List<UsersUserAddressDO> userAddressDOList);
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.mall.user.biz.dao.user;
import cn.iocoder.mall.user.biz.dataobject.user.UsersUserAddressDO;
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 done FROM 芋艿 to 小范替换成 Mybatis Plus
public interface UserAddressMapper extends BaseMapper<UsersUserAddressDO> {
default List<UsersUserAddressDO> selectByUserId(Integer userId) {
LambdaQueryWrapper<UsersUserAddressDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UsersUserAddressDO::getUserId, userId);
return selectList(wrapper);
}
default UsersUserAddressDO selectHasDefault(Integer userId) {
LambdaQueryWrapper<UsersUserAddressDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UsersUserAddressDO::getUserId, userId);
wrapper.eq(UsersUserAddressDO::getHasDefault, UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
return selectOne(wrapper);
}
}

View File

@ -1,47 +0,0 @@
package cn.iocoder.mall.user.biz.dataobject.user;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 用户地址信息
*
* @author Sin
* @time 2019-04-06 13:22
*/
@Data
// TODO FROM 芋艿 to 小范如果继承了需要添加 @EqualsAndHashCode(callSuper = true) 注解
@Accessors(chain = true)
public class UsersUserAddressDO extends DeletableDO {
/**
* 编号
*/
private Integer id;
/**
* 用户编号
*/
private Integer userId;
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否为默认
*/
private Integer hasDefault;
}

View File

@ -1,45 +0,0 @@
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;
}

View File

@ -1,47 +0,0 @@
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)
// TODO FROM 芋艿 to 小范service 要做 validation 其它同理
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;
}

View File

@ -1,43 +0,0 @@
package cn.iocoder.mall.user.biz.enums;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
/**
* 错误码枚举类
*
* 用户系统使用 1-001-000-000
*/
public enum UserErrorCodeEnum implements ServiceExceptionUtil.Enumerable {
// ========== 用户地址 ==========
USER_ADDRESS_NOT_EXISTENT(1001004000, "用户地址不存在!"),
USER_ADDRESS_IS_DELETED(1001004001, "用户地址已被删除!"),
USER_GET_ADDRESS_NOT_EXISTS(1001004002, "获取的地址不存在!"),
// ========== 用户 ==========
// TODO DONE FROM 芋艿 to linhj是不是提示不对呀
USER_NOT_EXISTS(1001004003, "用户不存在!"),
;
private final int code;
private final String message;
UserErrorCodeEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
@Override
public int getGroup() {
return 0;
}
}

View File

@ -1,30 +0,0 @@
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;
}
}

View File

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

View File

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

View File

@ -1,62 +0,0 @@
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 {
/**
* 添加地址
*
* @param userAddressAddDTO
*/
void addAddress(UserAddressAddDTO userAddressAddDTO);
/**
* 更新 - 根据id 更新
*
* @param userAddressAddDTO
*/
void updateAddress(UserAddressUpdateDTO userAddressAddDTO);
/**
* 删除 - 更新id 删除
*
* @param userId
* @param addressId
*/
void removeAddress(Integer userId, Integer addressId);
/**
* 获取 - 用户所有地址
*
* @param userId
* @return
*/
List<UserAddressBO> listAddress(Integer userId);
/**
* 获取 - 根据id 获取地址
*
* @param id
* @return
*/
UserAddressBO getAddress(Integer id);
/**
* 获取 - 获取用户 default 地址
*
* @param userId
* @return
*/
UserAddressBO getDefaultAddress(Integer userId);
}

View File

@ -1,121 +0,0 @@
package cn.iocoder.mall.user.biz.service.user;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum;
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.UsersUserAddressDO;
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.UserErrorCodeEnum;
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) {
// 转换do设置默认数据
UsersUserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
userAddressDO.setCreateTime(new Date());
userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
// 检查是否设置为默认地址
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
if (defaultUserAddress != null) {
userAddressMapper.updateById(
new UsersUserAddressDO()
.setId(defaultUserAddress.getId())
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
}
// 保存地址
userAddressMapper.insert(userAddressDO);
}
@Override
@Transactional
public void updateAddress(UserAddressUpdateDTO userAddressAddDTO) {
// 检查地址
UsersUserAddressDO userAddress = userAddressMapper.selectById(userAddressAddDTO.getId());
if (userAddress == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
}
// 删除的地址不能更新
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
// 检查是否设置为默认地址
// 将数据库 default address 设置为 no
if (UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue() == userAddressAddDTO.getHasDefault()) {
UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userAddressAddDTO.getUserId());
if (defaultUserAddress != null && !userAddressAddDTO.getId().equals(defaultUserAddress.getId())) {
userAddressMapper.updateById(
new UsersUserAddressDO()
.setId(defaultUserAddress.getId())
.setHasDefault(UserAddressHasDefaultEnum.DEFAULT_ADDRESS_NO.getValue())
);
}
}
// 转换 vo, 并保存数据
UsersUserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
userAddressDO.setUpdateTime(new Date());
userAddressMapper.updateById(userAddressDO);
}
@Override
public void removeAddress(Integer userId, Integer addressId) {
// checked address is exists.
UsersUserAddressDO userAddress = userAddressMapper.selectById(addressId);
if (userAddress == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_ADDRESS_NOT_EXISTENT.getCode());
}
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
// skip
return;
}
// 更新状态为 remove
userAddressMapper.updateById(
(UsersUserAddressDO) new UsersUserAddressDO()
.setId(addressId)
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue())
);
}
@Override
public List<UserAddressBO> listAddress(Integer userId) {
List<UsersUserAddressDO> userAddressDOList = userAddressMapper.selectByUserId(userId);
List<UserAddressBO> userAddressBOList = UserAddressConvert.INSTANCE.convertUserAddressBOList(userAddressDOList);
return userAddressBOList;
}
@Override
public UserAddressBO getAddress(Integer id) {
UsersUserAddressDO userAddress = userAddressMapper.selectById(id);
return UserAddressConvert.INSTANCE.convert(userAddress);
}
@Override
public UserAddressBO getDefaultAddress(Integer userId) {
UsersUserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(userId);
return UserAddressConvert.INSTANCE.convert(defaultUserAddress);
}
}

View File

@ -1,12 +0,0 @@
# 服务器的配置项
server:
port: 18082
servlet:
context-path: /user-api/
# Swagger 配置项
swagger:
title: 用户子系统
description: 用户子系统
version: 1.0.0
base-package: cn.iocoder.mall.user.rest.controller

View File

@ -1,34 +0,0 @@
<?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-rpc-api</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<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>
</project>

View File

@ -1,29 +0,0 @@
package cn.iocoder.mall.user.rpc.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.rpc.response.user.UserAddressResponse;
/**
* 用户地址 RPC
*
* author: sin
* time: 2020/5/1 10:26 上午
*/
public interface UserAddressRPC {
/**
* 获取 - 根据id获取用户地址
*
* @param id
* @return
*/
CommonResult<UserAddressResponse> getAddress(Integer id);
/**
* 获取 - 获取用户默认地址
*
* @param userId
* @return
*/
CommonResult<UserAddressResponse> getDefaultAddress(Integer userId);
}

View File

@ -1,40 +0,0 @@
<?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-rpc</artifactId>
<dependencies>
<!-- Mall 相关 -->
<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>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.user.rpc.convert.user;
import cn.iocoder.mall.user.biz.bo.user.UserAddressBO;
import cn.iocoder.mall.user.rpc.response.user.UserAddressResponse;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* user address convert
*
* author: sin
* time: 2020/5/1 10:30 上午
*/
@Mapper
public interface UserAddressRPCConvert {
UserAddressRPCConvert INSTANCE = Mappers.getMapper(UserAddressRPCConvert.class);
UserAddressResponse convert(UserAddressBO userAddressBO);
}

View File

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

View File

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

View File

@ -1,32 +0,0 @@
package cn.iocoder.mall.user.rpc.rpc.user;
import cn.iocoder.common.framework.vo.CommonResult;
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.response.user.UserAddressResponse;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 用户地址 RPC
*
* author: sin
* time: 2020/5/1 10:26 上午
*/
@Service(version = "${dubbo.provider.UserAddressRPC.version}", validation = "true")
public class UserAddressRPCImpl implements UserAddressRPC {
@Autowired
private UserAddressService userAddressService;
@Override
public CommonResult<UserAddressResponse> getAddress(Integer id) {
return CommonResult.success(UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(id)));
}
@Override
public CommonResult<UserAddressResponse> getDefaultAddress(Integer userId) {
return CommonResult.success(UserAddressRPCConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId)));
}
}

View File

@ -1,14 +0,0 @@
spring:
# Spring Cloud 配置项
cloud:
nacos:
# Spring Cloud Nacos Discovery 配置项
discovery:
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
namespace: local # Nacos 命名空间
# Dubbo 配置项
dubbo:
# Dubbo 注册中心
registry:
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址

View File

@ -1,14 +0,0 @@
spring:
# Spring Cloud 配置项
cloud:
nacos:
# Spring Cloud Nacos Discovery 配置项
discovery:
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
namespace: test # Nacos 命名空间
# Dubbo 配置项
dubbo:
# Dubbo 注册中心
registry:
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址

View File

@ -1,19 +0,0 @@
# Dubbo 配置项
dubbo:
# Spring Cloud Alibaba Dubbo 专属配置
cloud:
subscribed-services: system-application # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
name: dubbo
port: -1
# Dubbo 提供服务的扫描基础包
scan:
base-packages: cn.iocoder.mall.user.rpc.rpc
# Dubbo 服务提供者的配置
provider:
filter: -exception
SystemLogRPC:
version: 1.0.0
UserAddressRPC:
version: 1.0.0

View File

@ -1,80 +0,0 @@
<?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-service-impl</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-service-api</artifactId>
<version>1.0-SNAPSHOT</version>
</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>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<!-- Registry 和 Config 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- MQ 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,35 +0,0 @@
package cn.iocoder.mall.user.biz.convert;
import cn.iocoder.mall.user.api.bo.UserAddressBO;
import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
import cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO;
import cn.iocoder.mall.user.biz.dataobject.UserAddressDO;
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);
}

View File

@ -1,40 +0,0 @@
package cn.iocoder.mall.user.biz.dao;
import cn.iocoder.mall.user.biz.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<UserAddressDO> selectByUserIdAndDeleted(
Integer deleted,
Integer userId
);
UserAddressDO selectByUserIdAndId(
Integer userId,
Integer id
);
UserAddressDO selectHasDefault(
Integer deleted,
Integer userId,
Integer hasDefault
);
}

View File

@ -1,49 +0,0 @@
package cn.iocoder.mall.user.biz.dataobject;
import cn.iocoder.common.framework.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;
// TODO FROM 芋艿 to 小范需要增加下省市区
// TODO FROM 芋艿 to 小范想了一个增强可以靠 API 实现自动识别哈哈哈https://open.kuaidihelp.com/apitool/1019
/**
* 收件区域编号
*/
private String areaNo;
/**
* 收件人名称
*/
private String name;
/**
* 收件手机号
*/
private String mobile;
/**
* 收件详细地址
*/
private String address;
/**
* 是否为默认
*/
// TODO FROM 芋艿 to 小范是不是一起在捉摸个单词总觉得 hasDefault 怪怪的
private Integer hasDefault;
}

View File

@ -1,29 +0,0 @@
package cn.iocoder.mall.user.biz.dataobject;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 用户注册信息
*/
@Data
@Accessors(chain = true)
@Deprecated
public class UserRegisterDO {
/**
* 用户编号
*/
private Integer id;
/**
* 创建时间
*/
private Date createTime;
// TODO 芋艿 ip
// TODO 芋艿 ua
// TODO 芋艿 方式手机注册qq 等等
}

View File

@ -1,71 +0,0 @@
package cn.iocoder.mall.user.biz.dataobject;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 用户三方开放平台授权例如QQ / 微博 / 微信等等
*/
@Data
@Accessors(chain = true)
public class UserThirdAuthDO {
/**
* 用户编号
*
* 外键 {@link UserDO#uid}
*/
private Long uid;
// ========== 授权相关字段
/**
* 用户的唯一标识
*/
private String openid;
/**
* 开放平台
*
* @see cn.iocoder.mall.user.api.constant.ThirdPlatformConstant
*/
private Integer platform;
/**
* 访问令牌
*/
private Date accessToken;
/**
* 过期时间
*/
private Date expireTime;
/**
* 刷新令牌
*/
private Date refreshToken;
/**
* 授权范围一般情况下使用逗号分隔
*/
private String scopes;
// ========== 基础信息
/**
* 用户昵称
*/
private String nickname;
/**
* 性别
*
* TODO 芋艿找地方统一枚举0-未知1-2-
*/
private Integer gender;
// TODO https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
// TODO 芋艿其他字段国家/省份/城市/地区等
// TODO 芋艿头像
// TODO 芋艿微信独有 unionid
/**
* 统一存储基础信息使用 JSON 格式化避免未有效解析的情况
*/
private String extras;
}

View File

@ -1,165 +0,0 @@
package cn.iocoder.mall.user.biz.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.api.constant.UserAddressHasDefaultEnum;
import cn.iocoder.mall.user.api.constant.UserErrorCodeEnum;
import cn.iocoder.mall.user.biz.convert.UserAddressConvert;
import cn.iocoder.mall.user.biz.dao.UserAddressMapper;
import cn.iocoder.mall.user.biz.dataobject.UserAddressDO;
import cn.iocoder.mall.user.api.UserAddressService;
import cn.iocoder.mall.user.api.bo.UserAddressBO;
import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
import cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO;
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
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.UserAddressService.version}")
public class UserAddressServiceImpl implements UserAddressService {
@Autowired
private UserAddressMapper userAddressMapper;
@Override
@Transactional
public CommonResult addAddress(UserAddressAddDTO userAddressAddDTO) {
UserAddressDO userAddressDO = UserAddressConvert.INSTANCE.convert(userAddressAddDTO);
userAddressDO.setCreateTime(new Date());
userAddressDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
// TODO FROM 芋艿 to 小范建议先更新然后在创建 UserAddressDO
// 检查是否设置为默认地址
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())
);
}
}
int result = userAddressMapper.insert(userAddressDO);
return CommonResult.success(result);
}
@Override
@Transactional
public CommonResult updateAddress(UserAddressUpdateDTO userAddressAddDTO) {
UserAddressDO userAddress = userAddressMapper
.selectByUserIdAndId(userAddressAddDTO.getUserId(), userAddressAddDTO.getId());
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
if (userAddress == null) {
return ServiceExceptionUtil.error(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);
return CommonResult.success(null);
}
@Override
public CommonResult removeAddress(Integer userId, Integer addressId) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, addressId);
// TODO FROM 芋艿 to 小范这个应该不会触发哈
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<List<UserAddressBO>> addressList(Integer userId) {
List<UserAddressDO> userAddressDOList = userAddressMapper
.selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId);
List<UserAddressBO> userAddressBOList = UserAddressConvert
.INSTANCE.convertUserAddressBOList(userAddressDOList);
return CommonResult.success(userAddressBOList);
}
@Override
public CommonResult<UserAddressBO> getAddress(Integer userId, Integer id) {
UserAddressDO userAddress = userAddressMapper.selectByUserIdAndId(userId, id);
if (userAddress == null) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_GET_ADDRESS_NOT_EXISTS.getCode());
}
if (DeletedStatusEnum.DELETED_YES.getValue().equals(userAddress.getDeleted())) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_ADDRESS_IS_DELETED.getCode());
}
UserAddressBO userAddressBO = UserAddressConvert.INSTANCE.convert(userAddress);
return CommonResult.success(userAddressBO);
}
@Override
public CommonResult<UserAddressBO> getDefaultAddress(Integer userId) {
UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault(
DeletedStatusEnum.DELETED_NO.getValue(),
userId,
UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue());
return CommonResult.success(UserAddressConvert.INSTANCE.convert(defaultUserAddress));
}
}

View File

@ -1,154 +0,0 @@
package cn.iocoder.mall.user.biz.service;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
import cn.iocoder.common.framework.constant.UserTypeEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.ValidationUtil;
import cn.iocoder.mall.system.api.OAuth2Service;
import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO;
import cn.iocoder.mall.system.api.dto.oauth2.OAuth2CreateTokenDTO;
import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RemoveTokenByUserDTO;
import cn.iocoder.mall.user.api.UserService;
import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO;
import cn.iocoder.mall.user.api.bo.UserBO;
import cn.iocoder.mall.user.api.bo.UserPageBO;
import cn.iocoder.mall.user.api.constant.UserConstants;
import cn.iocoder.mall.user.api.constant.UserErrorCodeEnum;
import cn.iocoder.mall.user.api.dto.UserPageDTO;
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
import cn.iocoder.mall.user.api.dto.user.UserAuthenticationByMobileCodeDTO;
import cn.iocoder.mall.user.biz.convert.UserConvert;
import cn.iocoder.mall.user.biz.dao.UserMapper;
import cn.iocoder.mall.user.biz.dao.UserRegisterMapper;
import cn.iocoder.mall.user.biz.dataobject.MobileCodeDO;
import cn.iocoder.mall.user.biz.dataobject.UserDO;
import cn.iocoder.mall.user.biz.dataobject.UserRegisterDO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* UserService 实现和用户信息相关的逻辑
*/
@Service
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.UserService.version}")
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private UserRegisterMapper userRegisterMapper;
@Reference(validation = "true", version = "${dubbo.consumer.OAuth2Service.version}")
private OAuth2Service oAuth2Service;
public UserDO getUser(String mobile) {
return userMapper.selectByMobile(mobile);
}
@Transactional
public UserDO createUser(String mobile) {
if (!ValidationUtil.isMobile(mobile)) {
throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓
}
// 校验用户是否已经存在
if (getUser(mobile) != null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode());
}
// 创建用户
UserDO userDO = new UserDO().setMobile(mobile).setStatus(UserConstants.STATUS_ENABLE);
userDO.setCreateTime(new Date());
userDO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
userMapper.insert(userDO);
// 插入注册信息
createUserRegister(userDO);
// 转换返回
return userDO;
}
private void createUserRegister(UserDO userDO) {
UserRegisterDO userRegisterDO = new UserRegisterDO().setId(userDO.getId())
.setCreateTime(new Date());
userRegisterMapper.insert(userRegisterDO);
}
@Override
public UserPageBO getUserPage(UserPageDTO userPageDTO) {
UserPageBO userPageBO = new UserPageBO();
// 查询分页数据
int offset = (userPageDTO.getPageNo() - 1) * userPageDTO.getPageSize();
userPageBO.setList(UserConvert.INSTANCE.convert(userMapper.selectListByNicknameLike(
userPageDTO.getNickname(), userPageDTO.getStatus(),
offset, userPageDTO.getPageSize())));
// 查询分页总数
userPageBO.setTotal(userMapper.selectCountByNicknameLike(userPageDTO.getNickname(), userPageDTO.getStatus()));
return userPageBO;
}
@Override
public UserBO getUser(Integer userId) {
return UserConvert.INSTANCE.convert(userMapper.selectById(userId));
}
@Override
public Boolean updateUser(UserUpdateDTO userUpdateDTO) {
// 校验用户存在
if (userMapper.selectById(userUpdateDTO.getId()) == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_NOT_EXISTS.getCode());
}
// 更新用户
UserDO updateUser = UserConvert.INSTANCE.convert(userUpdateDTO);
userMapper.update(updateUser);
// 返回成功
return true;
}
@Override
public Boolean updateUserStatus(Integer userId, Integer status) {
// 校验用户存在
UserDO user = userMapper.selectById(userId);
if (user == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_NOT_EXISTS.getCode());
}
// 如果状态相同则返回错误
if (status.equals(user.getStatus())) {
throw ServiceExceptionUtil.exception((UserErrorCodeEnum.USER_STATUS_EQUALS.getCode()));
}
// 更新管理员状态
UserDO updateUser = new UserDO().setId(userId).setStatus(status);
userMapper.update(updateUser);
// 如果是关闭管理员则标记 token 失效否则管理员还可以继续蹦跶
if (CommonStatusEnum.DISABLE.getValue().equals(status)) {
oAuth2Service.removeToken(new OAuth2RemoveTokenByUserDTO().setUserId(userId).setUserType(UserTypeEnum.USER.getValue()));
}
// 返回成功
return true;
}
@Override
public Boolean updateUserMobile(Integer userId, String mobile) {
if (!ValidationUtil.isMobile(mobile)) {
throw ServiceExceptionUtil.exception(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓
}
// 校验用户存在
UserDO user = userMapper.selectById(userId);
if (user == null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_NOT_EXISTS.getCode());
}
// 如果状态相同则返回错误
if (mobile.equals(user.getMobile())) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_MOBILE_EQUALS.getCode());
}
// 更新管理员状态
UserDO updateUser = new UserDO().setId(userId).setMobile(mobile);
userMapper.update(updateUser);
// 返回成功
return true;
}
}

View File

@ -1 +0,0 @@
##################### 业务模块 #####################

View File

@ -1,62 +0,0 @@
spring:
# datasource
datasource:
url: jdbc:mysql://s1.iocoder.cn:3306/mall_user?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 3WLiVUBEwTbvAfsh
# Spring Cloud 配置项
cloud:
nacos:
# Spring Cloud Nacos Discovery 配置项
discovery:
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
# mybatis-plus
mybatis-plus:
configuration:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
global-config:
db-config:
id-type: auto
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
mapperLocations: classpath*:mapper/*.xml
typeAliasesPackage: cn.iocoder.mall.user.biz.dataobject
# Dubbo 配置项
dubbo:
# Dubbo 注册中心
registry:
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
# Spring Cloud Alibaba Dubbo 专属配置
cloud:
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 提供者的协议
protocol:
name: dubbo
port: -1
# Dubbo 提供服务的扫描基础包
scan:
base-packages: cn.iocoder.mall.user.biz.service
# Dubbo 服务提供者的配置
provider:
filter: -exception
MobileCodeService:
version: 1.0.0
UserAccessLogService:
version: 1.0.0
UserAddressService:
version: 1.0.0
UserService:
version: 1.0.0
consumer:
OAuth2Service:
version: 1.0.0
# rocketmq
rocketmq:
name-server: 127.0.0.1:9876
producer:
group: user-producer-spu-collection-group

View File

@ -1,72 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.biz.dao.UserAddressMapper">
<sql id="FIELDS">
id, user_id, area_no, `name`, mobile, address,
create_time, update_time, has_default, deleted
</sql>
<insert id="insert" parameterType="UserAddressDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_address (
user_id, area_no, `name`, mobile, address,
create_time, update_time, has_default, deleted
) VALUES (
#{userId}, #{areaNo}, #{name}, #{mobile}, #{address},
#{createTime}, #{updateTime}, #{hasDefault}, #{deleted}
)
</insert>
<update id="updateById">
UPDATE user_address
<set>
<if test="userAddressDO.areaNo != null">
, area_no = #{userAddressDO.areaNo}
</if>
<if test="userAddressDO.name != null">
, `name` = #{userAddressDO.name}
</if>
<if test="userAddressDO.mobile != null">
, mobile = #{userAddressDO.mobile}
</if>
<if test="userAddressDO.address != null">
, address = #{userAddressDO.address}
</if>
<if test="userAddressDO.updateTime != null">
, update_time = #{userAddressDO.updateTime}
</if>
<if test="userAddressDO.hasDefault != null">
, has_default = #{userAddressDO.hasDefault}
</if>
<if test="userAddressDO.deleted != null">
, deleted = #{userAddressDO.deleted}
</if>
</set>
WHERE id = #{id}
</update>
<select id="selectByUserIdAndId" resultType="cn.iocoder.mall.user.biz.dataobject.UserAddressDO">
SELECT
<include refid="FIELDS" />
FROM user_address
WHERE user_id = #{userId}
AND id = #{id}
</select>
<select id="selectByUserIdAndDeleted" resultType="cn.iocoder.mall.user.biz.dataobject.UserAddressDO">
SELECT
<include refid="FIELDS" />
FROM user_address
WHERE deleted = #{deleted}
AND `user_id` = #{userId}
</select>
<select id="selectHasDefault" resultType="cn.iocoder.mall.user.biz.dataobject.UserAddressDO">
SELECT
<include refid="FIELDS" />
FROM user_address
WHERE deleted = #{deleted}
AND `user_id` = #{userId}
AND `has_default` = #{hasDefault}
</select>
</mapper>

View File

@ -1,88 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.biz.dao.UserMapper">
<sql id="FIELDS">
id, mobile, nickname, avatar, status,
create_time, deleted
</sql>
<insert id="insert" parameterType="UserDO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO users (
id, mobile, status, create_time, deleted
) VALUES (
#{id}, #{mobile}, #{status}, #{createTime}, #{deleted}
)
</insert>
<update id="update" parameterType="UserDO">
UPDATE users
<set>
<if test="mobile != null">
, mobile = #{mobile}
</if>
<if test="nickname != null">
, nickname = #{nickname}
</if>
<if test="avatar != null">
, avatar = #{avatar}
</if>
<if test="status != null">
, status = #{status}
</if>
<if test="deleted != null">
, deleted = #{deleted}
</if>
</set>
WHERE id = #{id}
</update>
<select id="selectById" parameterType="Integer" resultType="UserDO">
SELECT
<include refid="FIELDS" />
FROM users
WHERE id = #{id}
AND deleted = 0
</select>
<select id="selectByMobile" parameterType="String" resultType="UserDO">
SELECT
<include refid="FIELDS" />
FROM users
WHERE mobile = #{mobile}
AND deleted = 0
</select>
<select id="selectListByNicknameLike" resultType="UserDO">
SELECT
<include refid="FIELDS" />
FROM users
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
<if test="status != null">
status = #{status}
</if>
AND deleted = 0
</where>
LIMIT #{offset}, #{limit}
</select>
<select id="selectCountByNicknameLike" resultType="Integer">
SELECT
COUNT(1)
FROM users
<where>
<if test="nickname != null">
nickname LIKE "%"#{nickname}"%"
</if>
<if test="status != null">
status = #{status}
</if>
AND deleted = 0
</where>
</select>
</mapper>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.mall.user.biz.dao.UserRegisterMapper">
<insert id="insert" parameterType="UserRegisterDO">
INSERT INTO user_register (
id, create_time
) VALUES (
#{id}, #{createTime}
)
</insert>
</mapper>