From 3ffdc44669ba43c2c6fb16fdbf3d156f0d1fd9b1 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 10 Mar 2019 20:39:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=87=AA=E5=B7=B1=E5=A4=B4=E5=83=8F=E5=92=8C=E6=98=B5?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/users/PassportController.java | 4 +- .../controller/users/UserController.java | 11 ++-- .../application/convert/PassportConvert.java | 2 +- .../user/application/convert/UserConvert.java | 7 ++- .../mall/user/application/vo/UsersUserVO.java | 21 -------- .../vo/{ => users}/MobileRegisterVO.java | 2 +- .../application/vo/users/UsersUserVO.java | 54 +++++++++++++++++++ .../interceptor/UserSecurityInterceptor.java | 2 +- .../mall/user/service/api/UserService.java | 3 ++ .../api/bo/OAuth2AuthenticationBO.java | 10 ++-- .../user/service/MobileCodeServiceImpl.java | 8 +-- .../mall/user/service/UserServiceImpl.java | 6 +++ .../resources/mapper/MobileCodeMapper.xml | 6 +-- .../mapper/OAuth2AccessTokenMapper.xml | 2 +- .../mall/user/convert/UserConvertImpl.java | 39 +++++++++++++- 15 files changed, 131 insertions(+), 46 deletions(-) delete mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java rename user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/{ => users}/MobileRegisterVO.java (95%) create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersUserVO.java diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java index 01b06ffa7..29c423a64 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java @@ -7,7 +7,7 @@ import cn.iocoder.mall.user.service.api.MobileCodeService; import cn.iocoder.mall.user.service.api.OAuth2Service; import cn.iocoder.mall.user.service.api.UserService; import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO; -import cn.iocoder.mall.user.application.vo.MobileRegisterVO; +import cn.iocoder.mall.user.application.vo.users.MobileRegisterVO; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("user/passport") +@RequestMapping("users/passport") @Api("Passport 模块") public class PassportController { diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java index 6cb216695..67d740a36 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java @@ -1,9 +1,11 @@ package cn.iocoder.mall.user.application.controller.users; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.application.convert.UserConvert; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; -import cn.iocoder.mall.user.application.vo.UsersUserVO; +import cn.iocoder.mall.user.application.vo.users.UsersUserVO; import cn.iocoder.mall.user.service.api.UserService; +import cn.iocoder.mall.user.service.api.bo.UserBO; import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; @@ -15,15 +17,14 @@ import org.springframework.web.bind.annotation.*; @Api("用户模块") public class UserController { - @Reference + @Reference(validation = "true") private UserService userService; @GetMapping("/info") @ApiOperation(value = "用户信息") public CommonResult info() { - // TODO 芋艿,正在实现中 - UsersUserVO user = new UsersUserVO().setId(UserSecurityContextHolder.getContext().getUserId()); - return CommonResult.success(user); + CommonResult userResult = userService.getUser(UserSecurityContextHolder.getContext().getUserId()); + return UserConvert.INSTANCE.convert2(userResult); } @PostMapping("/update_avatar") diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/PassportConvert.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/PassportConvert.java index 3d45a34eb..8ba1c0dea 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/PassportConvert.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/PassportConvert.java @@ -2,7 +2,7 @@ package cn.iocoder.mall.user.application.convert; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO; -import cn.iocoder.mall.user.application.vo.MobileRegisterVO; +import cn.iocoder.mall.user.application.vo.users.MobileRegisterVO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java index dcdfe33a0..bdb929f0f 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java @@ -2,6 +2,8 @@ package cn.iocoder.mall.user.application.convert; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO; +import cn.iocoder.mall.user.application.vo.users.UsersUserVO; +import cn.iocoder.mall.user.service.api.bo.UserBO; import cn.iocoder.mall.user.service.api.bo.UserPageBO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -15,4 +17,7 @@ public interface UserConvert { @Mappings({}) CommonResult convert(CommonResult result); -} + @Mappings({}) + CommonResult convert2(CommonResult result); + +} \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java deleted file mode 100644 index a54394332..000000000 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.user.application.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -@ApiModel("用户信息 VO") -public class UsersUserVO { - - @ApiModelProperty(value = "用户编号", required = true, example = "123") - private Integer id; - - public Integer getId() { - return id; - } - - public UsersUserVO setId(Integer id) { - this.id = id; - return this; - } - -} \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/MobileRegisterVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/MobileRegisterVO.java similarity index 95% rename from user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/MobileRegisterVO.java rename to user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/MobileRegisterVO.java index cf0e98c3d..fa5ba739f 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/MobileRegisterVO.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/MobileRegisterVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.user.application.vo; +package cn.iocoder.mall.user.application.vo.users; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersUserVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersUserVO.java new file mode 100644 index 000000000..cb8171251 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersUserVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.user.application.vo.users; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel("用户信息 VO") +public class UsersUserVO { + + @ApiModelProperty(value = "用户编号", required = true, example = "123") + private Integer id; + @ApiModelProperty(value = "手机号", required = true, example = "15601691300") + private String mobile; + @ApiModelProperty(value = "昵称", required = true, example = "小王") + private String nickname; + @ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg") + private String avatar; + + public Integer getId() { + return id; + } + + public UsersUserVO setId(Integer id) { + this.id = id; + return this; + } + + public String getMobile() { + return mobile; + } + + public UsersUserVO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getNickname() { + return nickname; + } + + public UsersUserVO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public String getAvatar() { + return avatar; + } + + public UsersUserVO setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + +} \ No newline at end of file diff --git a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java index cb7a8d165..b11c643b8 100644 --- a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java +++ b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/interceptor/UserSecurityInterceptor.java @@ -38,7 +38,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter { } authentication = result.getData(); // 添加到 SecurityContext - UserSecurityContext context = new UserSecurityContext(authentication.getUid()); + UserSecurityContext context = new UserSecurityContext(authentication.getUserId()); UserSecurityContextHolder.setContext(context); } // 校验是否需要已授权 diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserService.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserService.java index c36e18616..1dc7ba41f 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserService.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/UserService.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.user.service.api; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.service.api.bo.UserBO; import cn.iocoder.mall.user.service.api.bo.UserPageBO; import cn.iocoder.mall.user.service.api.dto.UserPageDTO; import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO; @@ -9,6 +10,8 @@ public interface UserService { CommonResult getUserPage(UserPageDTO userPageDTO); + CommonResult getUser(Integer userId); + /** * 更新用户基本信息 * diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/OAuth2AuthenticationBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/OAuth2AuthenticationBO.java index bbfc8b45e..432b9fb97 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/OAuth2AuthenticationBO.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/OAuth2AuthenticationBO.java @@ -7,14 +7,14 @@ public class OAuth2AuthenticationBO implements Serializable { /** * 用户编号 */ - private Integer uid; + private Integer userId; - public Integer getUid() { - return uid; + public Integer getUserId() { + return userId; } - public OAuth2AuthenticationBO setUid(Integer uid) { - this.uid = uid; + public OAuth2AuthenticationBO setUserId(Integer userId) { + this.userId = userId; return this; } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/MobileCodeServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/MobileCodeServiceImpl.java index 6057ff77d..824ce668a 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/MobileCodeServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/MobileCodeServiceImpl.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.user.service; +import cn.iocoder.common.framework.constant.SysErrorCodeEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.util.ValidationUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.user.dao.MobileCodeMapper; import cn.iocoder.mall.user.dataobject.MobileCodeDO; @@ -77,10 +79,8 @@ public class MobileCodeServiceImpl implements MobileCodeService { // TODO 芋艿,后面要返回有效时间 public CommonResult send(String mobile) { - // TODO 芋艿,校验手机格式 - // 校验手机号码是否已经注册 - if (userService.getUser(mobile) != null) { - return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode()); + if (!ValidationUtil.isMobile(mobile)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓 } // 校验是否可以发送验证码 MobileCodeDO lastMobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile); diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserServiceImpl.java index db75d1fd5..19a8e08a5 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/UserServiceImpl.java @@ -11,6 +11,7 @@ import cn.iocoder.mall.user.dao.UserRegisterMapper; import cn.iocoder.mall.user.dataobject.UserDO; import cn.iocoder.mall.user.dataobject.UserRegisterDO; import cn.iocoder.mall.user.service.api.UserService; +import cn.iocoder.mall.user.service.api.bo.UserBO; import cn.iocoder.mall.user.service.api.bo.UserPageBO; import cn.iocoder.mall.user.service.api.constant.UserConstants; import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum; @@ -76,6 +77,11 @@ public class UserServiceImpl implements UserService { return CommonResult.success(userPageBO); } + @Override + public CommonResult getUser(Integer userId) { + return CommonResult.success(UserConvert.INSTANCE.convert(userMapper.selectById(userId))); + } + @Override public CommonResult updateUser(UserUpdateDTO userUpdateDTO) { // 校验用户存在 diff --git a/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml b/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml index 5d8b2d918..625da5667 100644 --- a/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml +++ b/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml @@ -5,7 +5,7 @@ INSERT INTO mobile_code ( id, mobile, code, today_index, used, - used_uid, used_time, create_time + userd_user_id, used_time, create_time ) VALUES ( #{id}, #{mobile}, #{code}, #{todayIndex}, #{used}, #{usedUserId}, #{usedTime}, #{createTime} @@ -16,7 +16,7 @@ UPDATE mobile_code used = #{used}, - used_uid = #{usedUserId}, + userd_user_id = #{usedUserId}, used_time = #{usedTime}, WHERE id = #{id} @@ -25,7 +25,7 @@ SELECT - id, adminId, valid, expires_time + id, user_id, valid, expires_time FROM oauth2_access_token WHERE id = #{id} diff --git a/user/user-service-impl/target/generated-sources/annotations/cn/iocoder/mall/user/convert/UserConvertImpl.java b/user/user-service-impl/target/generated-sources/annotations/cn/iocoder/mall/user/convert/UserConvertImpl.java index f60c914d1..b46f13370 100644 --- a/user/user-service-impl/target/generated-sources/annotations/cn/iocoder/mall/user/convert/UserConvertImpl.java +++ b/user/user-service-impl/target/generated-sources/annotations/cn/iocoder/mall/user/convert/UserConvertImpl.java @@ -2,11 +2,14 @@ package cn.iocoder.mall.user.convert; import cn.iocoder.mall.user.dataobject.UserDO; import cn.iocoder.mall.user.service.api.bo.UserBO; +import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO; +import java.util.ArrayList; +import java.util.List; import javax.annotation.Generated; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2019-03-08T17:14:01+0800", + date = "2019-03-10T20:36:11+0800", comments = "version: 1.3.0.Final, compiler: javac, environment: Java 11.0.1 (Oracle Corporation)" ) public class UserConvertImpl implements UserConvert { @@ -19,8 +22,42 @@ public class UserConvertImpl implements UserConvert { UserBO userBO = new UserBO(); + userBO.setId( userDO.getId() ); userBO.setMobile( userDO.getMobile() ); + userBO.setNickname( userDO.getNickname() ); + userBO.setAvatar( userDO.getAvatar() ); + userBO.setStatus( userDO.getStatus() ); + userBO.setCreateTime( userDO.getCreateTime() ); return userBO; } + + @Override + public UserDO convert(UserUpdateDTO userUpdateDTO) { + if ( userUpdateDTO == null ) { + return null; + } + + UserDO userDO = new UserDO(); + + userDO.setId( userUpdateDTO.getId() ); + userDO.setNickname( userUpdateDTO.getNickname() ); + userDO.setAvatar( userUpdateDTO.getAvatar() ); + + return userDO; + } + + @Override + public List convert(List userDOs) { + if ( userDOs == null ) { + return null; + } + + List list = new ArrayList( userDOs.size() ); + for ( UserDO userDO : userDOs ) { + list.add( convert( userDO ) ); + } + + return list; + } }