diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/Mobile.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/Mobile.java index 9e3aab35d..8e965aedf 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/Mobile.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/validator/Mobile.java @@ -15,7 +15,7 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Documented @Constraint( - validatedBy = InEnumValidator.class + validatedBy = MobileValidator.class ) public @interface Mobile { diff --git a/common/mall-spring-boot-starter-dubbo/src/main/java/cn/iocoder/mall/dubbo/core/filter/DubboProviderExceptionFilter.java b/common/mall-spring-boot-starter-dubbo/src/main/java/cn/iocoder/mall/dubbo/core/filter/DubboProviderExceptionFilter.java index 9a33e1676..4d5b7110c 100644 --- a/common/mall-spring-boot-starter-dubbo/src/main/java/cn/iocoder/mall/dubbo/core/filter/DubboProviderExceptionFilter.java +++ b/common/mall-spring-boot-starter-dubbo/src/main/java/cn/iocoder/mall/dubbo/core/filter/DubboProviderExceptionFilter.java @@ -97,7 +97,7 @@ public class DubboProviderExceptionFilter implements Filter, Filter.Listener { */ private GlobalException defaultExceptionHandler(Throwable exception, Invocation invocation) { logger.error("[defaultExceptionHandler][service({}) method({}) params({}) 执行异常]", - invocation.getServiceName(), invocation.getServiceName(), invocation.getArguments(), exception); + invocation.getTargetServiceUniqueName(), invocation.getMethodName(), invocation.getArguments(), exception); // 如果已经是 GlobalException 全局异常,直接返回即可 if (exception instanceof GlobalException) { return (GlobalException) exception; @@ -108,7 +108,7 @@ public class DubboProviderExceptionFilter implements Filter, Filter.Listener { private String buildDetailMessage(Throwable exception, Invocation invocation) { return String.format("Service(%s) Method(%s) 发生异常(%s)", - invocation.getServiceName(), invocation.getMethodName(), ExceptionUtil.getRootCauseMessage(exception)); + invocation.getTargetServiceUniqueName(), invocation.getMethodName(), ExceptionUtil.getRootCauseMessage(exception)); } } diff --git a/http-client.env.json b/http-client.env.json new file mode 100644 index 000000000..40249acc8 --- /dev/null +++ b/http-client.env.json @@ -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}" + } +} diff --git a/management-web-app/pom.xml b/management-web-app/pom.xml index 6e7f22392..70ef8d3eb 100644 --- a/management-web-app/pom.xml +++ b/management-web-app/pom.xml @@ -82,17 +82,6 @@ mapstruct-jdk8 - - - - - - - - - - - diff --git a/management-web-app/src/main/resources/http-client.env.json b/management-web-app/src/main/resources/http-client.env.json deleted file mode 100644 index 5f4c46002..000000000 --- a/management-web-app/src/main/resources/http-client.env.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "local": { - "baseUrl": "http://127.0.0.1:18083/management-api/", - "accessToken": "yudaoyuanma", - "dubboTag": "${HOSTNAME}" - } -} diff --git a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/enums/UserErrorCodeConstants.java b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/enums/UserErrorCodeConstants.java index febb0d14b..b56cca8f5 100644 --- a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/enums/UserErrorCodeConstants.java +++ b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/enums/UserErrorCodeConstants.java @@ -18,9 +18,8 @@ public interface UserErrorCodeConstants { ErrorCode USER_SMS_CODE_SEND_TOO_FAST = new ErrorCode(1001001205, "短信发送过于频率"); // ========== 用户地址 ========== - ErrorCode USER_ADDRESS_NOT_EXISTENT = new ErrorCode(1001004000, "用户地址不存在!"); - ErrorCode USER_ADDRESS_IS_DELETED = new ErrorCode(1001004001, "用户地址已被删除!"); - ErrorCode USER_GET_ADDRESS_NOT_EXISTS = new ErrorCode(1001004002, "获取的地址不存在!"); + ErrorCode USER_ADDRESS_NOT_FOUND = new ErrorCode(1001004000, "用户地址不存在!"); + ErrorCode USER_GET_ADDRESS_NOT_EXISTS = new ErrorCode(1001004001, "获取的地址不存在!"); // ========== 用户信息模块 1004004100 ========== ErrorCode USER_NOT_EXISTS = new ErrorCode(1004004100, "用户不存在"); diff --git a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpc.java b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpc.java new file mode 100644 index 000000000..ebbcfc467 --- /dev/null +++ b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpc.java @@ -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 createUserAddress(UserAddressCreateReqDTO createDTO); + + /** + * 更新用户收件地址 + * + * @param updateDTO 更新用户收件地址 DTO + */ + CommonResult updateUserAddress(UserAddressUpdateReqDTO updateDTO); + + /** + * 删除用户收件地址 + * + * @param userAddressId 用户收件地址编号 + */ + CommonResult deleteUserAddress(Integer userAddressId); + + /** + * 获得用户收件地址 + * + * @param userAddressId 用户收件地址编号 + * @return 用户收件地址 + */ + CommonResult getUserAddress(Integer userAddressId); + + /** + * 获得用户收件地址列表 + * + * @param userAddressIds 用户收件地址编号列表 + * @return 用户收件地址列表 + */ + CommonResult> listUserAddresses(List userAddressIds); + + /** + * 获取指定用户的收件地址列表 + * + * @param userId 用户编号 + * @param type 地址类型 + * @return 收件地址列表 + */ + CommonResult> listUserAddresses(Integer userId, Integer type); + +} diff --git a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressCreateReqDTO.java b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressCreateReqDTO.java new file mode 100644 index 000000000..c5cb42cf2 --- /dev/null +++ b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressCreateReqDTO.java @@ -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; + +} diff --git a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressRespDTO.java b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressRespDTO.java new file mode 100644 index 000000000..93c5b95fd --- /dev/null +++ b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressRespDTO.java @@ -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; + +} diff --git a/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressUpdateReqDTO.java b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressUpdateReqDTO.java new file mode 100644 index 000000000..5ff0b9865 --- /dev/null +++ b/user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/address/dto/UserAddressUpdateReqDTO.java @@ -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; + +} diff --git a/user-service-project/user-service-app/pom.xml b/user-service-project/user-service-app/pom.xml index cf93ccd66..9675294bc 100644 --- a/user-service-project/user-service-app/pom.xml +++ b/user-service-project/user-service-app/pom.xml @@ -64,6 +64,7 @@ org.springframework.boot spring-boot-starter-validation + org.projectlombok lombok @@ -78,18 +79,6 @@ mapstruct-jdk8 - - - - - - - - - - - - diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/address/UserAddressConvert.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/address/UserAddressConvert.java new file mode 100644 index 000000000..607b0dfd1 --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/address/UserAddressConvert.java @@ -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 convertList(List list); + + UserAddressCreateBO convert(UserAddressCreateReqDTO bean); + + UserAddressUpdateBO convert(UserAddressUpdateReqDTO bean); + + UserAddressRespDTO convert(UserAddressBO bean); + + List convertList02(List list); + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UsersUserAddressDO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UserAddressDO.java similarity index 85% rename from user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UsersUserAddressDO.java rename to user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UserAddressDO.java index ff8706ce0..eb24f7be1 100644 --- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UsersUserAddressDO.java +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/address/UserAddressDO.java @@ -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.userservice.enums.address.UserAddressType; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -9,13 +10,16 @@ import lombok.experimental.Accessors; /** * 用户收件地址 * + * idx_userId 索引:基于 {@link #userId} 字段 + * * @author Sin * @time 2019-04-06 13:22 */ @Data @Accessors(chain = true) @EqualsAndHashCode(callSuper = true) -public class UsersUserAddressDO extends DeletableDO { +@TableName("user_address") +public class UserAddressDO extends DeletableDO { /** * 编号 diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/address/UserAddressMapper.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/address/UserAddressMapper.java new file mode 100644 index 000000000..c67b9cedf --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/mapper/address/UserAddressMapper.java @@ -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 { + + default List selectListByUserIdAndType(Integer userId, @Nullable Integer type) { + return selectList(new QueryWrapperX().eq("userId", userId) + .eqIfPresent("type", type)); + } + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/address/UserAddressManager.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/address/UserAddressManager.java new file mode 100644 index 000000000..a6602acc0 --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/address/UserAddressManager.java @@ -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 listUserAddresses(List userAddressIds) { + List userAddressBOs = userAddressService.listUserAddresses(userAddressIds); + return UserAddressConvert.INSTANCE.convertList02(userAddressBOs); + } + + /** + * 获取指定用户的收件地址列表 + * + * @param userId 用户编号 + * @param type 地址类型 + * @return 收件地址列表 + */ + public List listUserAddresses(Integer userId, Integer type) { + List userAddressBOs = userAddressService.listUserAddresses(userId, type); + return UserAddressConvert.INSTANCE.convertList02(userAddressBOs); + } + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpcImpl.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpcImpl.java new file mode 100644 index 000000000..4e9b331b2 --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/address/UserAddressRpcImpl.java @@ -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 createUserAddress(UserAddressCreateReqDTO createDTO) { + return success(userAddressManager.createUserAddress(createDTO)); + } + + @Override + public CommonResult updateUserAddress(UserAddressUpdateReqDTO updateDTO) { + userAddressManager.updateUserAddress(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteUserAddress(Integer userAddressId) { + userAddressManager.deleteUserAddress(userAddressId); + return success(true); + } + + @Override + public CommonResult getUserAddress(Integer userAddressId) { + return success(userAddressManager.getUserAddress(userAddressId)); + } + + @Override + public CommonResult> listUserAddresses(List userAddressIds) { + return success(userAddressManager.listUserAddresses(userAddressIds)); + } + + @Override + public CommonResult> listUserAddresses(Integer userId, Integer type) { + return success(userAddressManager.listUserAddresses(userId, type)); + } + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/sms/UserSmsCodeRpcImpl.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/sms/UserSmsCodeRpcImpl.java index e54618250..db4050575 100644 --- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/sms/UserSmsCodeRpcImpl.java +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/rpc/sms/UserSmsCodeRpcImpl.java @@ -7,7 +7,7 @@ import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO; import org.apache.dubbo.config.annotation.Service; 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 { @Autowired diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/UserAddressService.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/UserAddressService.java new file mode 100644 index 000000000..a71093fa7 --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/UserAddressService.java @@ -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 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 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 listUserAddresses(List userAddressIds) { + List userAddressDOs = userAddressMapper.selectBatchIds(userAddressIds); + return UserAddressConvert.INSTANCE.convertList(userAddressDOs); + } + + /** + * 获取指定用户的收件地址列表 + * + * @param userId 用户编号 + * @param type 地址类型 + * @return 收件地址列表 + */ + public List listUserAddresses(Integer userId, Integer type) { + List userAddressDOs = userAddressMapper.selectListByUserIdAndType(userId, type); + return UserAddressConvert.INSTANCE.convertList(userAddressDOs); + } + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressBO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressBO.java new file mode 100644 index 000000000..2bae5cb6b --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressBO.java @@ -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; + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressCreateBO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressCreateBO.java new file mode 100644 index 000000000..1a6a72b79 --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressCreateBO.java @@ -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; + +} diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressUpdateBO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressUpdateBO.java new file mode 100644 index 000000000..75b12772d --- /dev/null +++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/address/bo/UserAddressUpdateBO.java @@ -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; + +} diff --git a/user-web-app/pom.xml b/user-web-app/pom.xml index 267160eb4..176c28e97 100644 --- a/user-web-app/pom.xml +++ b/user-web-app/pom.xml @@ -27,8 +27,13 @@ - org.springframework.boot - spring-boot-starter-web + cn.iocoder.mall + mall-spring-boot-starter-web + + + + cn.iocoder.mall + mall-spring-boot-starter-swagger @@ -38,8 +43,8 @@ - com.alibaba.cloud - spring-cloud-starter-dubbo + cn.iocoder.mall + mall-spring-boot-starter-dubbo @@ -76,17 +81,6 @@ mapstruct-jdk8 - - - - - - - - - - - diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/UserAddressController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/UserAddressController.java new file mode 100644 index 000000000..72403e33d --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/UserAddressController.java @@ -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 createUserAddress(@Valid UserAddressCreateReqVO createVO) { + return success(userAddressManager.createUserAddress(UserSecurityContextHolder.getUserId(), createVO)); + } + + @PostMapping("/update") + @ApiOperation("更新用户收件地址") + @RequiresPermissions + public CommonResult updateUserAddress(@Valid UserAddressUpdateReqVO updateVO) { + userAddressManager.updateUserAddress(UserSecurityContextHolder.getUserId(), updateVO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除用户收件地址") + @ApiImplicitParam(name = "userAddressId", value = "用户收件地址编号", required = true) + @RequiresPermissions + public CommonResult 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 getUserAddress(@RequestParam("userAddressId") Integer userAddressId) { + return success(userAddressManager.getUserAddress(UserSecurityContextHolder.getUserId(), userAddressId)); + } + + @GetMapping("/list") + @ApiOperation("获得用户收件地址列表") + @ApiImplicitParam(name = "userAddressIds", value = "用户收件地址编号列表", required = true) + @RequiresPermissions + public CommonResult> listUserAddresses(@RequestParam("userAddressIds") List userAddressIds) { + return success(userAddressManager.listUserAddresses(UserSecurityContextHolder.getUserId(), userAddressIds)); + } + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressCreateReqVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressCreateReqVO.java new file mode 100644 index 000000000..4b2ae5862 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressCreateReqVO.java @@ -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; + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressRespVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressRespVO.java new file mode 100644 index 000000000..f46089220 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressRespVO.java @@ -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; + +} + diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressUpdateReqVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressUpdateReqVO.java new file mode 100644 index 000000000..215b9fad7 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/address/vo/UserAddressUpdateReqVO.java @@ -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; + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.http b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.http new file mode 100644 index 000000000..9812438c5 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.http @@ -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 + +### diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java index 253ace630..1f430fc1e 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java @@ -2,10 +2,11 @@ package cn.iocoder.mall.userweb.controller.passport; import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.vo.CommonResult; -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 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 cn.iocoder.mall.userweb.manager.passport.UserPassportManager; +import cn.iocoder.security.annotations.RequiresNone; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -25,18 +26,18 @@ public class UserPassportController { @Autowired private UserPassportManager userPassportManager; - @PostMapping("/login_by_sms") + @PostMapping("/login-by-sms") @ApiOperation("手机验证码登陆") -// @RequiresNone TODO 晚点加上 - public CommonResult loginBySms(UserPassportLoginBySmsDTO loginBySmsDTO, - HttpServletRequest request) { + @RequiresNone + public CommonResult loginBySms(PassportLoginBySmsReqVO loginBySmsDTO, + HttpServletRequest request) { return success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request))); } - @PostMapping("/send_sms_code") + @PostMapping("/send-sms-code") @ApiOperation("发送手机验证码") -// @RequiresNone TODO 晚点加上 - public CommonResult sendSmsCode(UserPassportSendSmsCodeDTO sendSmsCodeDTO, + @RequiresNone + public CommonResult sendSmsCode(UserPassportSendSmsRespVO sendSmsCodeDTO, HttpServletRequest request) { userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); // 返回成功 diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportAccessTokenRespVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportAccessTokenRespVO.java new file mode 100644 index 000000000..089ca602c --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportAccessTokenRespVO.java @@ -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; + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportLoginBySmsDTO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportLoginBySmsReqVO.java similarity index 84% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportLoginBySmsDTO.java rename to user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportLoginBySmsReqVO.java index 5f4171146..ae16d6519 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportLoginBySmsDTO.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/PassportLoginBySmsReqVO.java @@ -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 io.swagger.annotations.ApiModel; @@ -11,10 +11,10 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; import java.io.Serializable; -@ApiModel("用户短信验证码登陆 DTO") +@ApiModel("用户短信验证码登陆 Request VO") @Data @Accessors(chain = true) -public class UserPassportLoginBySmsDTO implements Serializable { +public class PassportLoginBySmsReqVO implements Serializable { @ApiModelProperty(value = "手机号", required = true, example = "15601691300") @NotEmpty(message = "手机号不能为空") diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportSendSmsCodeDTO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportSendSmsRespVO.java similarity index 79% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportSendSmsCodeDTO.java rename to user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportSendSmsRespVO.java index 1880f70e3..e656b35a1 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/dto/UserPassportSendSmsCodeDTO.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportSendSmsRespVO.java @@ -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 io.swagger.annotations.ApiModel; @@ -8,10 +8,10 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotNull; -@ApiModel("发送手机验证码 DTO") +@ApiModel("发送手机验证码 Response VO") @Data @Accessors(chain = true) -public class UserPassportSendSmsCodeDTO { +public class UserPassportSendSmsRespVO { @ApiModelProperty(value = "手机号", example = "15601691234") @Mobile diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportVO.java deleted file mode 100644 index 81b11650d..000000000 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/vo/UserPassportVO.java +++ /dev/null @@ -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; - -} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java index 619c86551..892f860a7 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java @@ -2,7 +2,7 @@ package cn.iocoder.mall.userweb.controller.user; import cn.iocoder.common.framework.vo.CommonResult; 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.security.annotations.RequiresAuthenticate; import io.swagger.annotations.Api; @@ -25,8 +25,8 @@ public class UserController { @ApiOperation(value = "用户信息") @GetMapping("/info") @RequiresAuthenticate - public CommonResult info() { - UserInfoVO user = userManager.getUser(UserSecurityContextHolder.getUserId()); + public CommonResult info() { + UserRespVO user = userManager.getUser(UserSecurityContextHolder.getUserId()); return success(user); } @@ -40,7 +40,7 @@ public class UserController { // // 更新头像 // return success(userService.updateUser(userUpdateDTO)); // } -// + // @PostMapping("/update_nickname") // @RequiresLogin // @ApiOperation(value = "更新昵称") diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserInfoVO.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserRespVO.java similarity index 96% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserInfoVO.java rename to user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserRespVO.java index ac373bacb..719b18920 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserInfoVO.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserRespVO.java @@ -8,7 +8,7 @@ import lombok.experimental.Accessors; @ApiModel("用户信息 VO") @Data @Accessors(chain = true) -public class UserInfoVO { +public class UserRespVO { @ApiModelProperty(value = "用户编号", required = true, example = "123") private Integer id; diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/address/UserAddressConvert.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/address/UserAddressConvert.java new file mode 100644 index 000000000..a22e4dd60 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/address/UserAddressConvert.java @@ -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 convertList(List list); + + UserAddressCreateReqDTO convert(UserAddressCreateReqVO bean); + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/PassportConvert.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/PassportConvert.java new file mode 100644 index 000000000..39e0cbcc3 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/PassportConvert.java @@ -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); + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/UserPassportConvert.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/UserPassportConvert.java deleted file mode 100644 index a4ab405a4..000000000 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/passport/UserPassportConvert.java +++ /dev/null @@ -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); - -} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/user/UserConvert.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/user/UserConvert.java index e2b8f622f..375faa22c 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/user/UserConvert.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/user/UserConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.userweb.convert.user; 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.factory.Mappers; @@ -10,6 +10,6 @@ public interface UserConvert { UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); - UserInfoVO convert(UserRespDTO bean); + UserRespVO convert(UserRespDTO bean); } diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/address/UserAddressManager.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/address/UserAddressManager.java new file mode 100644 index 000000000..062026448 --- /dev/null +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/address/UserAddressManager.java @@ -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 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 updateUserAddressResult = userAddressRpc.updateUserAddress(UserAddressConvert.INSTANCE.convert(updateVO)); + updateUserAddressResult.checkError(); + } + + /** + * 删除用户收件地址 + * + * @param userId 用户编号 + * @param userAddressId 用户收件地址编号 + */ + public void deleteUserAddress(Integer userId, Integer userAddressId) { + // 校验是否能够操作 + check(userId, userAddressId); + // 执行删除 + CommonResult deleteUserAddressResult = userAddressRpc.deleteUserAddress(userAddressId); + deleteUserAddressResult.checkError(); + } + + /** + * 获得用户收件地址 + * + * @param userId 用户编号 + * @param userAddressId 用户收件地址编号 + * @return 用户收件地址 + */ + public UserAddressRespVO getUserAddress(Integer userId, Integer userAddressId) { + CommonResult getUserAddressResult = userAddressRpc.getUserAddress(userAddressId); + getUserAddressResult.checkError(); + // 校验是否能够操作 + this.check(userId, userAddressId); + return UserAddressConvert.INSTANCE.convert(getUserAddressResult.getData()); + } + + /** + * 获得用户收件地址列表 + * + * @param userId 用户编号 + * @param userAddressIds 用户收件地址编号列表 + * @return 用户收件地址列表 + */ + public List listUserAddresses(Integer userId, List userAddressIds) { + CommonResult> 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 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); + } + } + +} diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/passport/UserPassportManager.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/passport/UserPassportManager.java index 18f13674a..26a4f1cf5 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/passport/UserPassportManager.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/passport/UserPassportManager.java @@ -3,16 +3,16 @@ package cn.iocoder.mall.userweb.manager.passport; import cn.iocoder.common.framework.enums.UserTypeEnum; import cn.iocoder.common.framework.vo.CommonResult; 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.OAuth2CreateAccessTokenReqDTO; import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum; import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc; import cn.iocoder.mall.userservice.rpc.user.UserRpc; 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 cn.iocoder.mall.userweb.convert.passport.UserPassportConvert; +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 cn.iocoder.mall.userweb.convert.passport.PassportConvert; import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Service; @@ -26,14 +26,14 @@ public class UserPassportManager { @Reference(version = "${dubbo.consumer.OAuth2Rpc.version}", validation = "false") private OAuth2Rpc oauth2Rpc; - public UserPassportVO loginBySms(UserPassportLoginBySmsDTO loginBySmsDTO, String ip) { + public PassportAccessTokenRespVO loginBySms(PassportLoginBySmsReqVO loginBySmsDTO, String ip) { // 校验验证码 CommonResult 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(); // 获得用户 CommonResult createUserResult = userRpc.createUserIfAbsent( - UserPassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip)); + PassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip)); createUserResult.checkError(); // 创建访问令牌 CommonResult createAccessTokenResult = oauth2Rpc.createAccessToken( @@ -41,12 +41,12 @@ public class UserPassportManager { .setUserType(UserTypeEnum.USER.getValue()).setCreateIp(ip)); 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 sendSmsCodeResult = userSmsCodeRpc.sendSmsCode( - UserPassportConvert.INSTANCE.convert(sendSmsCodeDTO).setIp(ip)); + PassportConvert.INSTANCE.convert(sendSmsCodeDTO).setIp(ip)); sendSmsCodeResult.checkError(); } diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java index 4634d3603..b28df9638 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java @@ -3,18 +3,18 @@ package cn.iocoder.mall.userweb.manager.user; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.userservice.rpc.user.UserRpc; 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 org.apache.dubbo.config.annotation.Reference; +import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.stereotype.Service; @Service public class UserManager { - @Reference(version = "${dubbo.consumer.UserRpc.version}", validation = "false") + @DubboReference(version = "${dubbo.consumer.UserRpc.version}") private UserRpc userRpc; - public UserInfoVO getUser(Integer id) { + public UserRespVO getUser(Integer id) { CommonResult userResult = userRpc.getUser(id); userResult.checkError(); return UserConvert.INSTANCE.convert(userResult.getData()); diff --git a/user-web-app/src/main/resources/application-local.yml b/user-web-app/src/main/resources/application-local.yml index 2e9e99973..2e26cd388 100644 --- a/user-web-app/src/main/resources/application-local.yml +++ b/user-web-app/src/main/resources/application-local.yml @@ -5,10 +5,11 @@ spring: # Spring Cloud Nacos Discovery 配置项 discovery: server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址 - namespace: local # Nacos 命名空间 + namespace: dev # Nacos 命名空间 # Dubbo 配置项 dubbo: # Dubbo 注册中心 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 服务注册中心的地址 diff --git a/user-web-app/src/main/resources/application.yml b/user-web-app/src/main/resources/application.yml index 8d3df60bf..6fdcf7997 100644 --- a/user-web-app/src/main/resources/application.yml +++ b/user-web-app/src/main/resources/application.yml @@ -11,6 +11,10 @@ spring: # Profile 的配置项 profiles: active: local + # SpringMVC 配置项 + mvc: + throw-exception-if-no-handler-found: true # 匹配不到路径时,抛出 NoHandlerFoundException 异常 + static-path-pattern: /doc.html # 静态资源的路径 # Dubbo 配置项 dubbo: @@ -27,5 +31,14 @@ dubbo: version: 1.0.0 OAuth2Rpc: version: 1.0.0 - SystemLogRPC: + SystemAccessLogRpc: 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 diff --git a/user/pom.xml b/user/pom.xml index 2357ddc73..f2d71e10b 100644 --- a/user/pom.xml +++ b/user/pom.xml @@ -16,8 +16,6 @@ user-rest - user-rpc - user-rpc-api user-biz diff --git a/user/user-biz/pom.xml b/user/user-biz/pom.xml deleted file mode 100644 index 0fb88e044..000000000 --- a/user/user-biz/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - user - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - user-biz - - - - - - cn.iocoder.mall - user-biz-api - 1.0-SNAPSHOT - - - - - org.springframework.boot - spring-boot-starter - - - - - mysql - mysql-connector-java - - - - org.springframework - spring-tx - - - org.springframework - spring-jdbc - - - com.alibaba - druid-spring-boot-starter - - - - cn.iocoder.mall - mall-spring-boot-starter-mybatis - 1.0-SNAPSHOT - - - - - com.yunpian.sdk - yunpian-java-sdk - - - com.aliyun - aliyun-java-sdk-core - - - - - com.qiniu - qiniu-java-sdk - - - - - org.mapstruct - mapstruct - - - org.mapstruct - mapstruct-jdk8 - - - org.projectlombok - lombok - - - - com.alibaba - fastjson - - - \ No newline at end of file diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/bo/user/UserAddressBO.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/bo/user/UserAddressBO.java deleted file mode 100644 index e598e5a9b..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/bo/user/UserAddressBO.java +++ /dev/null @@ -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; -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java deleted file mode 100644 index abbf44eea..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/convert/user/UserAddressConvert.java +++ /dev/null @@ -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 convertUserAddressBOList(List userAddressDOList); -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java deleted file mode 100644 index e9aed689b..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dao/user/UserAddressMapper.java +++ /dev/null @@ -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 { - - default List selectByUserId(Integer userId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(UsersUserAddressDO::getUserId, userId); - return selectList(wrapper); - } - - default UsersUserAddressDO selectHasDefault(Integer userId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(UsersUserAddressDO::getUserId, userId); - wrapper.eq(UsersUserAddressDO::getHasDefault, UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); - return selectOne(wrapper); - } -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java deleted file mode 100644 index c294d4379..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dataobject/user/UsersUserAddressDO.java +++ /dev/null @@ -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; - -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressAddDTO.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressAddDTO.java deleted file mode 100644 index acb828acb..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressAddDTO.java +++ /dev/null @@ -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; -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressUpdateDTO.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressUpdateDTO.java deleted file mode 100644 index 6144b31cf..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/dto/user/UserAddressUpdateDTO.java +++ /dev/null @@ -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; -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/UserErrorCodeEnum.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/UserErrorCodeEnum.java deleted file mode 100644 index 1b30e491e..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/UserErrorCodeEnum.java +++ /dev/null @@ -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; - } - -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/user/UserAddressHasDefaultEnum.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/user/UserAddressHasDefaultEnum.java deleted file mode 100644 index 8306399b7..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/enums/user/UserAddressHasDefaultEnum.java +++ /dev/null @@ -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; - } -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/package-info.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/package-info.java deleted file mode 100644 index 4f549a42f..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * author: sin - * time: 2020/5/3 8:27 下午 - */ -package cn.iocoder.mall.user.biz; \ No newline at end of file diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/package-info.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/package-info.java deleted file mode 100644 index 343388589..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * author: sin - * time: 2020/5/3 8:30 下午 - */ -package cn.iocoder.mall.user.biz.service; \ No newline at end of file diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java deleted file mode 100644 index 294357237..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressService.java +++ /dev/null @@ -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 listAddress(Integer userId); - - /** - * 获取 - 根据id 获取地址 - * - * @param id - * @return - */ - UserAddressBO getAddress(Integer id); - - /** - * 获取 - 获取用户 default 地址 - * - * @param userId - * @return - */ - UserAddressBO getDefaultAddress(Integer userId); -} diff --git a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java b/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java deleted file mode 100644 index 7b2652c82..000000000 --- a/user/user-biz/src/main/java/cn/iocoder/mall/user/biz/service/user/UserAddressServiceImpl.java +++ /dev/null @@ -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 listAddress(Integer userId) { - List userAddressDOList = userAddressMapper.selectByUserId(userId); - List 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); - } -} diff --git a/user/user-rest/src/main/resources/rest.yaml b/user/user-rest/src/main/resources/rest.yaml deleted file mode 100644 index d193b39e4..000000000 --- a/user/user-rest/src/main/resources/rest.yaml +++ /dev/null @@ -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 diff --git a/user/user-rpc-api/pom.xml b/user/user-rpc-api/pom.xml deleted file mode 100644 index 9aa52648e..000000000 --- a/user/user-rpc-api/pom.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - user - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - user-rpc-api - - - - - cn.iocoder.mall - system-biz-api - 1.0-SNAPSHOT - - - - - javax.validation - validation-api - - - org.projectlombok - lombok - - - - - diff --git a/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java b/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java deleted file mode 100644 index 700f39be1..000000000 --- a/user/user-rpc-api/src/main/java/cn/iocoder/mall/user/rpc/api/UserAddressRPC.java +++ /dev/null @@ -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 getAddress(Integer id); - - /** - * 获取 - 获取用户默认地址 - * - * @param userId - * @return - */ - CommonResult getDefaultAddress(Integer userId); -} diff --git a/user/user-rpc/pom.xml b/user/user-rpc/pom.xml deleted file mode 100644 index d8dda724d..000000000 --- a/user/user-rpc/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - user - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - user-rpc - - - - - cn.iocoder.mall - user-rpc-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - user-biz - 1.0-SNAPSHOT - - - - - com.alibaba.cloud - spring-cloud-starter-dubbo - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/package-info.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/package-info.java deleted file mode 100644 index 31da5c336..000000000 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * author: sin - * time: 2020/5/3 8:43 下午 - */ -package cn.iocoder.mall.user.rpc.convert; \ No newline at end of file diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/user/UserAddressRPCConvert.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/user/UserAddressRPCConvert.java deleted file mode 100644 index 16056e749..000000000 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/convert/user/UserAddressRPCConvert.java +++ /dev/null @@ -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); - -} diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/package-info.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/package-info.java deleted file mode 100644 index 878f636ef..000000000 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * author: sin - * time: 2020/5/3 8:36 下午 - */ -package cn.iocoder.mall.user.rpc; \ No newline at end of file diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/package-info.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/package-info.java deleted file mode 100644 index 07960fd0d..000000000 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * author: sin - * time: 2020/5/3 8:37 下午 - */ -package cn.iocoder.mall.user.rpc.rpc; \ No newline at end of file diff --git a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java b/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java deleted file mode 100644 index fcd85b991..000000000 --- a/user/user-rpc/src/main/java/cn/iocoder/mall/user/rpc/rpc/user/UserAddressRPCImpl.java +++ /dev/null @@ -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 getAddress(Integer id) { - return CommonResult.success(UserAddressRPCConvert.INSTANCE.convert(userAddressService.getAddress(id))); - } - - @Override - public CommonResult getDefaultAddress(Integer userId) { - return CommonResult.success(UserAddressRPCConvert.INSTANCE.convert(userAddressService.getDefaultAddress(userId))); - } -} diff --git a/user/user-rpc/src/main/resources/rpc-local.yaml b/user/user-rpc/src/main/resources/rpc-local.yaml deleted file mode 100644 index e056170af..000000000 --- a/user/user-rpc/src/main/resources/rpc-local.yaml +++ /dev/null @@ -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 服务注册中心的地址 diff --git a/user/user-rpc/src/main/resources/rpc-test.yaml b/user/user-rpc/src/main/resources/rpc-test.yaml deleted file mode 100644 index d3d0e9e69..000000000 --- a/user/user-rpc/src/main/resources/rpc-test.yaml +++ /dev/null @@ -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 服务注册中心的地址 diff --git a/user/user-rpc/src/main/resources/rpc.yaml b/user/user-rpc/src/main/resources/rpc.yaml deleted file mode 100644 index 12748b6d6..000000000 --- a/user/user-rpc/src/main/resources/rpc.yaml +++ /dev/null @@ -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 diff --git a/user/user-service-impl/pom.xml b/user/user-service-impl/pom.xml deleted file mode 100644 index 35721d9a6..000000000 --- a/user/user-service-impl/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - user - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - user-service-impl - - - - cn.iocoder.mall - user-service-api - 1.0-SNAPSHOT - - - - - mysql - mysql-connector-java - - - - org.springframework - spring-tx - - - org.springframework - spring-jdbc - - - - org.mybatis.spring.boot - mybatis-spring-boot-starter - - - - com.alibaba - druid-spring-boot-starter - - - - com.baomidou - mybatis-plus-boot-starter - - - - - com.alibaba.cloud - spring-cloud-starter-dubbo - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-discovery - - - - - com.alibaba.cloud - spring-cloud-starter-stream-rocketmq - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java deleted file mode 100644 index 2cc008454..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/convert/UserAddressConvert.java +++ /dev/null @@ -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 convertUserAddressBOList(List userAddressDOList); -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/UserAddressMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/UserAddressMapper.java deleted file mode 100644 index 8aaaa74fb..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/UserAddressMapper.java +++ /dev/null @@ -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 selectByUserIdAndDeleted( - Integer deleted, - Integer userId - ); - - UserAddressDO selectByUserIdAndId( - Integer userId, - Integer id - ); - - UserAddressDO selectHasDefault( - Integer deleted, - Integer userId, - Integer hasDefault - ); -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserAddressDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserAddressDO.java deleted file mode 100644 index a9c6c7865..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserAddressDO.java +++ /dev/null @@ -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; - -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserRegisterDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserRegisterDO.java deleted file mode 100644 index f753aeb8e..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserRegisterDO.java +++ /dev/null @@ -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 等等 - -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserThirdAuthDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserThirdAuthDO.java deleted file mode 100644 index dc6d42407..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserThirdAuthDO.java +++ /dev/null @@ -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; - -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java deleted file mode 100644 index 1386064cf..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java +++ /dev/null @@ -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> addressList(Integer userId) { - - List userAddressDOList = userAddressMapper - .selectByUserIdAndDeleted(DeletedStatusEnum.DELETED_NO.getValue(), userId); - - List userAddressBOList = UserAddressConvert - .INSTANCE.convertUserAddressBOList(userAddressDOList); - - return CommonResult.success(userAddressBOList); - } - - @Override - public CommonResult 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 getDefaultAddress(Integer userId) { - - UserAddressDO defaultUserAddress = userAddressMapper.selectHasDefault( - DeletedStatusEnum.DELETED_NO.getValue(), - userId, - UserAddressHasDefaultEnum.DEFAULT_ADDRESS_YES.getValue()); - - return CommonResult.success(UserAddressConvert.INSTANCE.convert(defaultUserAddress)); - } -} diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java deleted file mode 100644 index ba8e554cb..000000000 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserServiceImpl.java +++ /dev/null @@ -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; - } - -} diff --git a/user/user-service-impl/src/main/resources/config/application.properties b/user/user-service-impl/src/main/resources/config/application.properties deleted file mode 100644 index 5bce24ab7..000000000 --- a/user/user-service-impl/src/main/resources/config/application.properties +++ /dev/null @@ -1 +0,0 @@ -##################### 业务模块 ##################### diff --git a/user/user-service-impl/src/main/resources/config/application.yaml b/user/user-service-impl/src/main/resources/config/application.yaml deleted file mode 100644 index 59643bee2..000000000 --- a/user/user-service-impl/src/main/resources/config/application.yaml +++ /dev/null @@ -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 diff --git a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml b/user/user-service-impl/src/main/resources/mapper/UserAddress.xml deleted file mode 100644 index 20432b8f6..000000000 --- a/user/user-service-impl/src/main/resources/mapper/UserAddress.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - id, user_id, area_no, `name`, mobile, address, - create_time, update_time, has_default, deleted - - - - 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} - ) - - - - UPDATE user_address - - - , area_no = #{userAddressDO.areaNo} - - - , `name` = #{userAddressDO.name} - - - , mobile = #{userAddressDO.mobile} - - - , address = #{userAddressDO.address} - - - , update_time = #{userAddressDO.updateTime} - - - , has_default = #{userAddressDO.hasDefault} - - - , deleted = #{userAddressDO.deleted} - - - WHERE id = #{id} - - - - - - - - \ No newline at end of file diff --git a/user/user-service-impl/src/main/resources/mapper/UserMapper.xml b/user/user-service-impl/src/main/resources/mapper/UserMapper.xml deleted file mode 100644 index 5c0a85e23..000000000 --- a/user/user-service-impl/src/main/resources/mapper/UserMapper.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - id, mobile, nickname, avatar, status, - create_time, deleted - - - - INSERT INTO users ( - id, mobile, status, create_time, deleted - ) VALUES ( - #{id}, #{mobile}, #{status}, #{createTime}, #{deleted} - ) - - - - UPDATE users - - - , mobile = #{mobile} - - - , nickname = #{nickname} - - - , avatar = #{avatar} - - - , status = #{status} - - - , deleted = #{deleted} - - - WHERE id = #{id} - - - - - - - - - - - - diff --git a/user/user-service-impl/src/main/resources/mapper/UserRegisterMapper.xml b/user/user-service-impl/src/main/resources/mapper/UserRegisterMapper.xml deleted file mode 100644 index 8b0453b39..000000000 --- a/user/user-service-impl/src/main/resources/mapper/UserRegisterMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - INSERT INTO user_register ( - id, create_time - ) VALUES ( - #{id}, #{createTime} - ) - - - \ No newline at end of file