增加用户修改自己头像和昵称
This commit is contained in:
parent
e771a9a5ae
commit
3ffdc44669
@ -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.OAuth2Service;
|
||||||
import cn.iocoder.mall.user.service.api.UserService;
|
import cn.iocoder.mall.user.service.api.UserService;
|
||||||
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
|
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 com.alibaba.dubbo.config.annotation.Reference;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("user/passport")
|
@RequestMapping("users/passport")
|
||||||
@Api("Passport 模块")
|
@Api("Passport 模块")
|
||||||
public class PassportController {
|
public class PassportController {
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package cn.iocoder.mall.user.application.controller.users;
|
package cn.iocoder.mall.user.application.controller.users;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
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.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.UserService;
|
||||||
|
import cn.iocoder.mall.user.service.api.bo.UserBO;
|
||||||
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
|
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
|
||||||
import com.alibaba.dubbo.config.annotation.Reference;
|
import com.alibaba.dubbo.config.annotation.Reference;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -15,15 +17,14 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@Api("用户模块")
|
@Api("用户模块")
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
@Reference
|
@Reference(validation = "true")
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@GetMapping("/info")
|
@GetMapping("/info")
|
||||||
@ApiOperation(value = "用户信息")
|
@ApiOperation(value = "用户信息")
|
||||||
public CommonResult<UsersUserVO> info() {
|
public CommonResult<UsersUserVO> info() {
|
||||||
// TODO 芋艿,正在实现中
|
CommonResult<UserBO> userResult = userService.getUser(UserSecurityContextHolder.getContext().getUserId());
|
||||||
UsersUserVO user = new UsersUserVO().setId(UserSecurityContextHolder.getContext().getUserId());
|
return UserConvert.INSTANCE.convert2(userResult);
|
||||||
return CommonResult.success(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update_avatar")
|
@PostMapping("/update_avatar")
|
||||||
|
@ -2,7 +2,7 @@ package cn.iocoder.mall.user.application.convert;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
|
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.Mapper;
|
||||||
import org.mapstruct.Mappings;
|
import org.mapstruct.Mappings;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
@ -2,6 +2,8 @@ package cn.iocoder.mall.user.application.convert;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
|
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 cn.iocoder.mall.user.service.api.bo.UserPageBO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mappings;
|
import org.mapstruct.Mappings;
|
||||||
@ -15,4 +17,7 @@ public interface UserConvert {
|
|||||||
@Mappings({})
|
@Mappings({})
|
||||||
CommonResult<AdminsUserPageVO> convert(CommonResult<UserPageBO> result);
|
CommonResult<AdminsUserPageVO> convert(CommonResult<UserPageBO> result);
|
||||||
|
|
||||||
|
@Mappings({})
|
||||||
|
CommonResult<UsersUserVO> convert2(CommonResult<UserBO> result);
|
||||||
|
|
||||||
}
|
}
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,7 +38,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
|||||||
}
|
}
|
||||||
authentication = result.getData();
|
authentication = result.getData();
|
||||||
// 添加到 SecurityContext
|
// 添加到 SecurityContext
|
||||||
UserSecurityContext context = new UserSecurityContext(authentication.getUid());
|
UserSecurityContext context = new UserSecurityContext(authentication.getUserId());
|
||||||
UserSecurityContextHolder.setContext(context);
|
UserSecurityContextHolder.setContext(context);
|
||||||
}
|
}
|
||||||
// 校验是否需要已授权
|
// 校验是否需要已授权
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.mall.user.service.api;
|
package cn.iocoder.mall.user.service.api;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
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.bo.UserPageBO;
|
||||||
import cn.iocoder.mall.user.service.api.dto.UserPageDTO;
|
import cn.iocoder.mall.user.service.api.dto.UserPageDTO;
|
||||||
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
|
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
|
||||||
@ -9,6 +10,8 @@ public interface UserService {
|
|||||||
|
|
||||||
CommonResult<UserPageBO> getUserPage(UserPageDTO userPageDTO);
|
CommonResult<UserPageBO> getUserPage(UserPageDTO userPageDTO);
|
||||||
|
|
||||||
|
CommonResult<UserBO> getUser(Integer userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新用户基本信息
|
* 更新用户基本信息
|
||||||
*
|
*
|
||||||
|
@ -7,14 +7,14 @@ public class OAuth2AuthenticationBO implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 用户编号
|
* 用户编号
|
||||||
*/
|
*/
|
||||||
private Integer uid;
|
private Integer userId;
|
||||||
|
|
||||||
public Integer getUid() {
|
public Integer getUserId() {
|
||||||
return uid;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuth2AuthenticationBO setUid(Integer uid) {
|
public OAuth2AuthenticationBO setUserId(Integer userId) {
|
||||||
this.uid = uid;
|
this.userId = userId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package cn.iocoder.mall.user.service;
|
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.ServiceExceptionUtil;
|
||||||
|
import cn.iocoder.common.framework.util.ValidationUtil;
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.user.dao.MobileCodeMapper;
|
import cn.iocoder.mall.user.dao.MobileCodeMapper;
|
||||||
import cn.iocoder.mall.user.dataobject.MobileCodeDO;
|
import cn.iocoder.mall.user.dataobject.MobileCodeDO;
|
||||||
@ -77,10 +79,8 @@ public class MobileCodeServiceImpl implements MobileCodeService {
|
|||||||
|
|
||||||
// TODO 芋艿,后面要返回有效时间
|
// TODO 芋艿,后面要返回有效时间
|
||||||
public CommonResult<Void> send(String mobile) {
|
public CommonResult<Void> send(String mobile) {
|
||||||
// TODO 芋艿,校验手机格式
|
if (!ValidationUtil.isMobile(mobile)) {
|
||||||
// 校验手机号码是否已经注册
|
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓
|
||||||
if (userService.getUser(mobile) != null) {
|
|
||||||
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode());
|
|
||||||
}
|
}
|
||||||
// 校验是否可以发送验证码
|
// 校验是否可以发送验证码
|
||||||
MobileCodeDO lastMobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile);
|
MobileCodeDO lastMobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile);
|
||||||
|
@ -11,6 +11,7 @@ import cn.iocoder.mall.user.dao.UserRegisterMapper;
|
|||||||
import cn.iocoder.mall.user.dataobject.UserDO;
|
import cn.iocoder.mall.user.dataobject.UserDO;
|
||||||
import cn.iocoder.mall.user.dataobject.UserRegisterDO;
|
import cn.iocoder.mall.user.dataobject.UserRegisterDO;
|
||||||
import cn.iocoder.mall.user.service.api.UserService;
|
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.bo.UserPageBO;
|
||||||
import cn.iocoder.mall.user.service.api.constant.UserConstants;
|
import cn.iocoder.mall.user.service.api.constant.UserConstants;
|
||||||
import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum;
|
import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum;
|
||||||
@ -76,6 +77,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
return CommonResult.success(userPageBO);
|
return CommonResult.success(userPageBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<UserBO> getUser(Integer userId) {
|
||||||
|
return CommonResult.success(UserConvert.INSTANCE.convert(userMapper.selectById(userId)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Boolean> updateUser(UserUpdateDTO userUpdateDTO) {
|
public CommonResult<Boolean> updateUser(UserUpdateDTO userUpdateDTO) {
|
||||||
// 校验用户存在
|
// 校验用户存在
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<insert id="insert" parameterType="MobileCodeDO">
|
<insert id="insert" parameterType="MobileCodeDO">
|
||||||
INSERT INTO mobile_code (
|
INSERT INTO mobile_code (
|
||||||
id, mobile, code, today_index, used,
|
id, mobile, code, today_index, used,
|
||||||
used_uid, used_time, create_time
|
userd_user_id, used_time, create_time
|
||||||
) VALUES (
|
) VALUES (
|
||||||
#{id}, #{mobile}, #{code}, #{todayIndex}, #{used},
|
#{id}, #{mobile}, #{code}, #{todayIndex}, #{used},
|
||||||
#{usedUserId}, #{usedTime}, #{createTime}
|
#{usedUserId}, #{usedTime}, #{createTime}
|
||||||
@ -16,7 +16,7 @@
|
|||||||
UPDATE mobile_code
|
UPDATE mobile_code
|
||||||
<set>
|
<set>
|
||||||
<if test="used != null"> used = #{used}, </if>
|
<if test="used != null"> used = #{used}, </if>
|
||||||
<if test="usedUserId != null"> used_uid = #{usedUserId}, </if>
|
<if test="usedUserId != null"> userd_user_id = #{usedUserId}, </if>
|
||||||
<if test="usedTime != null"> used_time = #{usedTime}, </if>
|
<if test="usedTime != null"> used_time = #{usedTime}, </if>
|
||||||
</set>
|
</set>
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
@ -25,7 +25,7 @@
|
|||||||
<select id="selectLast1ByMobile" parameterType="String" resultType="MobileCodeDO">
|
<select id="selectLast1ByMobile" parameterType="String" resultType="MobileCodeDO">
|
||||||
SELECT
|
SELECT
|
||||||
id, mobile, code, today_index, used,
|
id, mobile, code, today_index, used,
|
||||||
used_uid, used_time, create_time
|
userd_user_id, used_time, create_time
|
||||||
FROM mobile_code
|
FROM mobile_code
|
||||||
WHERE mobile = #{mobile}
|
WHERE mobile = #{mobile}
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<select id="selectByTokenId" parameterType="String" resultType="OAuth2AccessTokenDO">
|
<select id="selectByTokenId" parameterType="String" resultType="OAuth2AccessTokenDO">
|
||||||
SELECT
|
SELECT
|
||||||
id, adminId, valid, expires_time
|
id, user_id, valid, expires_time
|
||||||
FROM oauth2_access_token
|
FROM oauth2_access_token
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
@ -2,11 +2,14 @@ package cn.iocoder.mall.user.convert;
|
|||||||
|
|
||||||
import cn.iocoder.mall.user.dataobject.UserDO;
|
import cn.iocoder.mall.user.dataobject.UserDO;
|
||||||
import cn.iocoder.mall.user.service.api.bo.UserBO;
|
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;
|
import javax.annotation.Generated;
|
||||||
|
|
||||||
@Generated(
|
@Generated(
|
||||||
value = "org.mapstruct.ap.MappingProcessor",
|
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)"
|
comments = "version: 1.3.0.Final, compiler: javac, environment: Java 11.0.1 (Oracle Corporation)"
|
||||||
)
|
)
|
||||||
public class UserConvertImpl implements UserConvert {
|
public class UserConvertImpl implements UserConvert {
|
||||||
@ -19,8 +22,42 @@ public class UserConvertImpl implements UserConvert {
|
|||||||
|
|
||||||
UserBO userBO = new UserBO();
|
UserBO userBO = new UserBO();
|
||||||
|
|
||||||
|
userBO.setId( userDO.getId() );
|
||||||
userBO.setMobile( userDO.getMobile() );
|
userBO.setMobile( userDO.getMobile() );
|
||||||
|
userBO.setNickname( userDO.getNickname() );
|
||||||
|
userBO.setAvatar( userDO.getAvatar() );
|
||||||
|
userBO.setStatus( userDO.getStatus() );
|
||||||
|
userBO.setCreateTime( userDO.getCreateTime() );
|
||||||
|
|
||||||
return userBO;
|
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<UserBO> convert(List<UserDO> userDOs) {
|
||||||
|
if ( userDOs == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserBO> list = new ArrayList<UserBO>( userDOs.size() );
|
||||||
|
for ( UserDO userDO : userDOs ) {
|
||||||
|
list.add( convert( userDO ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user