From 1afea13f5612b2580177dbca218b4e991405481f Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Sun, 10 Mar 2019 19:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20User=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=20=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=9F=A5=E7=9C=8B=20User=20=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../common/framework/util/ValidationUtil.java | 16 ++++ user/user-application/pom.xml | 10 ++ .../controller/UserController.java | 25 ----- .../admins/AdminsUserController.java | 50 ++++++++++ .../{ => users}/PassportController.java | 6 +- .../controller/users/UserController.java | 49 ++++++++++ .../user/application/convert/UserConvert.java | 18 ++++ .../vo/{UserInfoVO.java => UsersUserVO.java} | 8 +- .../vo/admins/AdminsUserPageVO.java | 34 +++++++ .../application/vo/admins/AdminsUserVO.java | 78 +++++++++++++++ .../user/sdk/context/UserSecurityContext.java | 10 +- .../mall/user/service/api/UserService.java | 33 +++++++ .../api/bo/OAuth2AuthenticationBO.java | 6 +- .../mall/user/service/api/bo/UserBO.java | 66 ++++++++++++- .../mall/user/service/api/bo/UserPageBO.java | 34 +++++++ .../service/api/constant/UserConstants.java | 14 +++ .../api/constant/UserErrorCodeEnum.java | 3 + .../user/service/api/dto/UserPageDTO.java | 46 +++++++++ .../user/service/api/dto/UserUpdateDTO.java | 48 ++++++++++ .../mall/user/convert/UserConvert.java | 9 ++ .../user/dao/OAuth2AccessTokenMapper.java | 3 + .../user/dao/OAuth2RefreshTokenMapper.java | 3 + .../cn/iocoder/mall/user/dao/UserMapper.java | 15 ++- .../mall/user/dataobject/MobileCodeDO.java | 16 ++-- .../user/dataobject/OAuth2AccessTokenDO.java | 10 +- .../user/dataobject/OAuth2RefreshTokenDO.java | 10 +- .../iocoder/mall/user/dataobject/UserDO.java | 22 ++++- .../mall/user/dataobject/UserRegisterDO.java | 6 +- .../user/service/MobileCodeServiceImpl.java | 6 +- .../mall/user/service/OAuth2ServiceImpl.java | 21 +++- .../mall/user/service/UserServiceImpl.java | 95 ++++++++++++++++++- .../main/resources/config/application.yaml | 8 +- .../resources/mapper/MobileCodeMapper.xml | 4 +- .../mapper/OAuth2AccessTokenMapper.xml | 11 ++- .../mapper/OAuth2RefreshTokenMapper.xml | 11 ++- .../src/main/resources/mapper/UserMapper.xml | 76 +++++++++++++-- 37 files changed, 785 insertions(+), 96 deletions(-) create mode 100644 common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java delete mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/UserController.java create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java rename user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/{ => users}/PassportController.java (95%) create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java rename user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/{UserInfoVO.java => UsersUserVO.java} (72%) create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserPageVO.java create mode 100644 user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserVO.java create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserPageBO.java create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserConstants.java create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserPageDTO.java create mode 100644 user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserUpdateDTO.java diff --git a/.gitignore b/.gitignore index ca176b996..ed55f8b35 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ *.iml *.ipr target/* +target/* *.class ### NetBeans ### diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java new file mode 100644 index 000000000..9b76c92a4 --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ValidationUtil.java @@ -0,0 +1,16 @@ +package cn.iocoder.common.framework.util; + +/** + * 校验工具类 + */ +public class ValidationUtil { + + public static boolean isMobile(String mobile) { + if (mobile == null || mobile.length() != 11) { + return false; + } + // TODO 芋艿,后面完善手机校验 + return true; + } + +} \ No newline at end of file diff --git a/user/user-application/pom.xml b/user/user-application/pom.xml index 847b2ba3d..4de3bd291 100644 --- a/user/user-application/pom.xml +++ b/user/user-application/pom.xml @@ -119,6 +119,16 @@ + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/UserController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/UserController.java deleted file mode 100644 index f6ad37d30..000000000 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/UserController.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.user.application.controller; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; -import cn.iocoder.mall.user.application.vo.UserInfoVO; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/user") -@Api("用户模块") -public class UserController { - - @GetMapping("/info") - @ApiOperation(value = "用户信息") - public CommonResult info() { - // TODO 芋艿,正在实现中 - UserInfoVO user = new UserInfoVO().setId(UserSecurityContextHolder.getContext().getUid()); - return CommonResult.success(user); - } - -} \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java new file mode 100644 index 000000000..4b0b27fb2 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java @@ -0,0 +1,50 @@ +package cn.iocoder.mall.user.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.application.convert.UserConvert; +import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO; +import cn.iocoder.mall.user.service.api.UserService; +import cn.iocoder.mall.user.service.api.bo.UserPageBO; +import cn.iocoder.mall.user.service.api.dto.UserPageDTO; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/admins/user") +@Api("用户模块") +public class AdminsUserController { + + @Reference(validation = "true") + private UserService userService; + + // 分页 + @GetMapping("/page") + @ApiOperation(value = "管理员分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + public CommonResult page(@RequestParam(value = "nickname", required = false) String nickname, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + // 创建 UserPageDTO + UserPageDTO userPageDTO = new UserPageDTO().setNickname(nickname).setPageNo(pageNo).setPageSize(pageSize); + // 查询分页 + CommonResult result = userService.getUserPage(userPageDTO); + // 转换结果 + return UserConvert.INSTANCE.convert(result); + } + + // 更新用户信息 + + // 开启禁用 + +} \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/PassportController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java similarity index 95% rename from user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/PassportController.java rename to user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java index 27a25282a..01b06ffa7 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/PassportController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.user.application.controller; +package cn.iocoder.mall.user.application.controller.users; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.user.application.convert.PassportConvert; @@ -51,13 +51,15 @@ public class PassportController { } @PermitAll - @PostMapping("mobile/send") + @PostMapping("mobile/send_register_code") @ApiOperation(value = "发送手机验证码") @ApiImplicitParam(name = "mobile", value = "手机号", required = true, example = "15601691300") public CommonResult mobileSend(@RequestParam("mobile") String mobile) { return mobileCodeService.send(mobile); } + // TODO 芋艿,改绑手机号 + // TODO 功能:qq 登陆 @PermitAll @PostMapping("/qq/login") 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 new file mode 100644 index 000000000..6cb216695 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java @@ -0,0 +1,49 @@ +package cn.iocoder.mall.user.application.controller.users; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; +import cn.iocoder.mall.user.application.vo.UsersUserVO; +import cn.iocoder.mall.user.service.api.UserService; +import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/users/user") +@Api("用户模块") +public class UserController { + + @Reference + private UserService userService; + + @GetMapping("/info") + @ApiOperation(value = "用户信息") + public CommonResult info() { + // TODO 芋艿,正在实现中 + UsersUserVO user = new UsersUserVO().setId(UserSecurityContextHolder.getContext().getUserId()); + return CommonResult.success(user); + } + + @PostMapping("/update_avatar") + @ApiOperation(value = "更新头像") + public CommonResult updateAvatar(@RequestParam("avatar") String avatar) { + // 创建 + UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId()) + .setAvatar(avatar); + // 更新头像 + return userService.updateUser(userUpdateDTO); + } + + @PostMapping("/update_nickname") + @ApiOperation(value = "更新昵称") + public CommonResult updateNickname(@RequestParam("nickname") String nickname) { + // 创建 + UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId()) + .setNickname(nickname); + // 更新头像 + return userService.updateUser(userUpdateDTO); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..dcdfe33a0 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java @@ -0,0 +1,18 @@ +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.service.api.bo.UserPageBO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface UserConvert { + + UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); + + @Mappings({}) + CommonResult convert(CommonResult result); + +} diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UserInfoVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java similarity index 72% rename from user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UserInfoVO.java rename to user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java index df4df46fd..a54394332 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UserInfoVO.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/UsersUserVO.java @@ -4,16 +4,16 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @ApiModel("用户信息 VO") -public class UserInfoVO { +public class UsersUserVO { @ApiModelProperty(value = "用户编号", required = true, example = "123") - private Long id; + private Integer id; - public Long getId() { + public Integer getId() { return id; } - public UserInfoVO setId(Long id) { + public UsersUserVO setId(Integer id) { this.id = id; return this; } diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserPageVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserPageVO.java new file mode 100644 index 000000000..07b0e57f7 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.user.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("用户分页 VO") +public class AdminsUserPageVO { + + @ApiModelProperty(value = "用户数组") + private List users; + @ApiModelProperty(value = "用户总数") + private Integer count; + + public List getUsers() { + return users; + } + + public AdminsUserPageVO setUsers(List users) { + this.users = users; + return this; + } + + public Integer getCount() { + return count; + } + + public AdminsUserPageVO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserVO.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserVO.java new file mode 100644 index 000000000..f1f550790 --- /dev/null +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/vo/admins/AdminsUserVO.java @@ -0,0 +1,78 @@ +package cn.iocoder.mall.user.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel("用户 VO") +public class AdminsUserVO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1") + 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; + @ApiModelProperty(value = "账号状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + + public Integer getId() { + return id; + } + + public AdminsUserVO setId(Integer id) { + this.id = id; + return this; + } + + public String getMobile() { + return mobile; + } + + public AdminsUserVO setMobile(String mobile) { + this.mobile = mobile; + return this; + } + + public String getNickname() { + return nickname; + } + + public AdminsUserVO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public String getAvatar() { + return avatar; + } + + public AdminsUserVO setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminsUserVO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminsUserVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file diff --git a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java index cfadba524..c43328309 100644 --- a/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java +++ b/user/user-sdk/src/main/java/cn/iocoder/mall/user/sdk/context/UserSecurityContext.java @@ -5,14 +5,14 @@ package cn.iocoder.mall.user.sdk.context; */ public class UserSecurityContext { - private final Long uid; + private final Integer userId; - public UserSecurityContext(Long uid) { - this.uid = uid; + public UserSecurityContext(Integer userId) { + this.userId = userId; } - public Long getUid() { - return uid; + public Integer getUserId() { + return userId; } } \ No newline at end of file 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 149cff1b5..c36e18616 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,5 +1,38 @@ package cn.iocoder.mall.user.service.api; +import cn.iocoder.common.framework.vo.CommonResult; +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; + public interface UserService { + CommonResult getUserPage(UserPageDTO userPageDTO); + + /** + * 更新用户基本信息 + * + * @param userUpdateDTO 更新 DTO + * @return 更新结果 + */ + CommonResult updateUser(UserUpdateDTO userUpdateDTO); + + /** + * 更新用户状态 + * + * @param userId 用户编号 + * @param status 状态 + * @return 更新结果 + */ + CommonResult updateUserStatus(Integer userId, Integer status); + + /** + * 更新用户手机号 + * + * @param userId 用户编号 + * @param mobile 手机号 + * @return 更新结果 + */ + CommonResult updateUserMobile(Integer userId, String mobile); + } \ No newline at end of file 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 8c649b730..bbfc8b45e 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,13 +7,13 @@ public class OAuth2AuthenticationBO implements Serializable { /** * 用户编号 */ - private Long uid; + private Integer uid; - public Long getUid() { + public Integer getUid() { return uid; } - public OAuth2AuthenticationBO setUid(Long uid) { + public OAuth2AuthenticationBO setUid(Integer uid) { this.uid = uid; return this; } diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserBO.java index c28bb8d40..6cf155de5 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserBO.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserBO.java @@ -1,22 +1,43 @@ package cn.iocoder.mall.user.service.api.bo; +import java.util.Date; + public class UserBO { /** * 用户编号 */ - private Long uid; + private Integer id; /** * 手机号 */ private String mobile; + /** + * 昵称 + */ + private String nickname; + /** + * 头像 + */ + private String avatar; + /** + * 账号状态 + * + * 1 - 开启 + * 2 - 禁用 + */ + private Integer status; + /** + * 创建时间 + */ + private Date createTime; - public Long getUid() { - return uid; + public Integer getId() { + return id; } - public UserBO setUid(Long uid) { - this.uid = uid; + public UserBO setId(Integer id) { + this.id = id; return this; } @@ -29,4 +50,39 @@ public class UserBO { return this; } + public String getNickname() { + return nickname; + } + + public UserBO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public String getAvatar() { + return avatar; + } + + public UserBO setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + + public Integer getStatus() { + return status; + } + + public UserBO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public UserBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } } \ No newline at end of file diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserPageBO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserPageBO.java new file mode 100644 index 000000000..b27d937ec --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/bo/UserPageBO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.user.service.api.bo; + +import java.util.List; + +public class UserPageBO { + + /** + * 用户数组 + */ + private List users; + /** + * 总量 + */ + private Integer count; + + public List getUsers() { + return users; + } + + public UserPageBO setUsers(List users) { + this.users = users; + return this; + } + + public Integer getCount() { + return count; + } + + public UserPageBO setCount(Integer count) { + this.count = count; + return this; + } + +} \ No newline at end of file diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserConstants.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserConstants.java new file mode 100644 index 000000000..9ba1beb67 --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserConstants.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.user.service.api.constant; + +public class UserConstants { + + /** + * 状态 - 开启 + */ + public static final Integer STATUS_ENABLE = 1; + /** + * 状态 - 关闭 + */ + public static final Integer STATUS_DISABLE = 2; + +} diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java index 7577a6436..47a338ec6 100644 --- a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/constant/UserErrorCodeEnum.java @@ -20,6 +20,9 @@ public enum UserErrorCodeEnum { // ========== 用户模块 ========== USER_MOBILE_NOT_REGISTERED(1001002000, "手机号未注册用户"), USER_MOBILE_ALREADY_REGISTERED(1001002001, "手机号已经注册用户"), + USER_NOT_EXISTS(1001002002, "用户不存在"), + USER_STATUS_EQUALS(1001002003, "账号已经是该状态"), + USER_MOBILE_EQUALS(1001002004, "账号已经是该手机号"), // ========== 手机验证码模块 ========== MOBILE_CODE_NOT_FOUND(1001003000, "验证码不存在"), diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserPageDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserPageDTO.java new file mode 100644 index 000000000..d76b71ddf --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserPageDTO.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.user.service.api.dto; + +import javax.validation.constraints.NotNull; + +public class UserPageDTO { + + /** + * 查询的昵称 + * + * 模糊查询 + */ + private String nickname; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public String getNickname() { + return nickname; + } + + public UserPageDTO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public UserPageDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public UserPageDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + +} \ No newline at end of file diff --git a/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserUpdateDTO.java b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserUpdateDTO.java new file mode 100644 index 000000000..cbb2af030 --- /dev/null +++ b/user/user-service-api/src/main/java/cn/iocoder/mall/user/service/api/dto/UserUpdateDTO.java @@ -0,0 +1,48 @@ +package cn.iocoder.mall.user.service.api.dto; + +/** + * 用户更新 DTO + */ +public class UserUpdateDTO { + + /** + * 用户编号 + */ + private Integer id; + /** + * 昵称 + */ + private String nickname; + /** + * 头像 + */ + private String avatar; + + public Integer getId() { + return id; + } + + public UserUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getNickname() { + return nickname; + } + + public UserUpdateDTO setNickname(String nickname) { + this.nickname = nickname; + return this; + } + + public String getAvatar() { + return avatar; + } + + public UserUpdateDTO setAvatar(String avatar) { + this.avatar = avatar; + return this; + } + +} \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserConvert.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserConvert.java index b5bb64230..ea54f275b 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserConvert.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/convert/UserConvert.java @@ -2,10 +2,13 @@ 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 org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.List; + @Mapper public interface UserConvert { @@ -14,4 +17,10 @@ public interface UserConvert { @Mappings({}) UserBO convert(UserDO userDO); + @Mappings({}) + UserDO convert(UserUpdateDTO userUpdateDTO); + + @Mappings({}) + List convert(List userDOs); + } \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2AccessTokenMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2AccessTokenMapper.java index 81178bdbc..0472ce5f0 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2AccessTokenMapper.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2AccessTokenMapper.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.user.dao; import cn.iocoder.mall.user.dataobject.OAuth2AccessTokenDO; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository @@ -10,4 +11,6 @@ public interface OAuth2AccessTokenMapper { OAuth2AccessTokenDO selectByTokenId(String tokenId); + void updateToInvalidByUserId(@Param("userId") Integer userId); + } \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2RefreshTokenMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2RefreshTokenMapper.java index dec6e75dd..04fcbcc43 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2RefreshTokenMapper.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/OAuth2RefreshTokenMapper.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.user.dao; import cn.iocoder.mall.user.dataobject.OAuth2RefreshTokenDO; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @Repository @@ -8,4 +9,6 @@ public interface OAuth2RefreshTokenMapper { void insert(OAuth2RefreshTokenDO entity); + void updateToInvalidByUserId(@Param("userId") Integer userId); + } \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserMapper.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserMapper.java index e78ec15c8..890117210 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserMapper.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dao/UserMapper.java @@ -1,13 +1,26 @@ package cn.iocoder.mall.user.dao; import cn.iocoder.mall.user.dataobject.UserDO; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface UserMapper { void insert(UserDO entity); - UserDO selectByMobile(String mobile); + int update(UserDO entity); + + UserDO selectByMobile(@Param("mobile") String mobile); + + UserDO selectById(@Param("id") Integer id); + + List selectListByNicknameLike(@Param("nickname") String nickname, + @Param("offset") Integer offset, + @Param("limit") Integer limit); + + Integer selectCountByNicknameLike(@Param("nickname") String nickname); } \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/MobileCodeDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/MobileCodeDO.java index a152a305a..88a69fd96 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/MobileCodeDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/MobileCodeDO.java @@ -8,7 +8,7 @@ public class MobileCodeDO { /** * 编号 */ - private Long id; + private Integer id; /** * 手机号 */ @@ -28,7 +28,7 @@ public class MobileCodeDO { /** * 注册的用户编号 */ - private Long usedUid; + private Integer usedUserId; /** * 创建时间 */ @@ -38,11 +38,11 @@ public class MobileCodeDO { */ private Date usedTime; - public Long getId() { + public Integer getId() { return id; } - public MobileCodeDO setId(Long id) { + public MobileCodeDO setId(Integer id) { this.id = id; return this; } @@ -83,12 +83,12 @@ public class MobileCodeDO { return this; } - public Long getUsedUid() { - return usedUid; + public Integer getUsedUserId() { + return usedUserId; } - public MobileCodeDO setUsedUid(Long usedUid) { - this.usedUid = usedUid; + public MobileCodeDO setUsedUserId(Integer usedUserId) { + this.usedUserId = usedUserId; return this; } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2AccessTokenDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2AccessTokenDO.java index 77fd16515..ce0a80c7c 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2AccessTokenDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2AccessTokenDO.java @@ -15,7 +15,7 @@ public class OAuth2AccessTokenDO { /** * 用户编号 */ - private Long uid; + private Integer userId; /** * 过期时间 */ @@ -47,12 +47,12 @@ public class OAuth2AccessTokenDO { return this; } - public Long getUid() { - return uid; + public Integer getUserId() { + return userId; } - public OAuth2AccessTokenDO setUid(Long uid) { - this.uid = uid; + public OAuth2AccessTokenDO setUserId(Integer userId) { + this.userId = userId; return this; } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2RefreshTokenDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2RefreshTokenDO.java index d63b21524..3ba047b33 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2RefreshTokenDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/OAuth2RefreshTokenDO.java @@ -16,7 +16,7 @@ public class OAuth2RefreshTokenDO { /** * 用户编号 */ - private Long uid; + private Integer userId; /** * 是否有效 */ @@ -39,12 +39,12 @@ public class OAuth2RefreshTokenDO { return this; } - public Long getUid() { - return uid; + public Integer getUserId() { + return userId; } - public OAuth2RefreshTokenDO setUid(Long uid) { - this.uid = uid; + public OAuth2RefreshTokenDO setUserId(Integer userId) { + this.userId = userId; return this; } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserDO.java index b51d2b8bd..c79feec97 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserDO.java @@ -12,7 +12,7 @@ public class UserDO extends BaseDO { /** * 用户编号 */ - private Long id; + private Integer id; /** * 手机号 */ @@ -25,12 +25,19 @@ public class UserDO extends BaseDO { * 头像 */ private String avatar; + /** + * 账号状态 + * + * 1 - 开启 + * 2 - 禁用 + */ + private Integer status; - public Long getId() { + public Integer getId() { return id; } - public UserDO setId(Long id) { + public UserDO setId(Integer id) { this.id = id; return this; } @@ -62,4 +69,13 @@ public class UserDO extends BaseDO { return this; } + public Integer getStatus() { + return status; + } + + public UserDO setStatus(Integer status) { + this.status = status; + return this; + } + } \ No newline at end of file diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserRegisterDO.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserRegisterDO.java index 4c5c2c396..2c9bc1c63 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserRegisterDO.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/dataobject/UserRegisterDO.java @@ -10,7 +10,7 @@ public class UserRegisterDO { /** * 用户编号 */ - private Long id; + private Integer id; /** * 创建时间 */ @@ -21,11 +21,11 @@ public class UserRegisterDO { // TODO 芋艿 方式,手机注册、qq 等等 - public Long getId() { + public Integer getId() { return id; } - public UserRegisterDO setId(Long id) { + public UserRegisterDO setId(Integer id) { this.id = id; 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 5df55576a..6057ff77d 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 @@ -68,10 +68,10 @@ public class MobileCodeServiceImpl implements MobileCodeService { * 更新手机验证码已使用 * * @param id 验证码编号 - * @param uid 用户编号 + * @param userId 用户编号 */ - public void useMobileCode(Long id, Long uid) { - MobileCodeDO update = new MobileCodeDO().setId(id).setUsed(true).setUsedUid(uid).setUsedTime(new Date()); + public void useMobileCode(Integer id, Integer userId) { + MobileCodeDO update = new MobileCodeDO().setId(id).setUsed(true).setUsedUserId(userId).setUsedTime(new Date()); mobileCodeMapper.update(update); } diff --git a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/OAuth2ServiceImpl.java b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/OAuth2ServiceImpl.java index f85161458..456b99d4f 100644 --- a/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/OAuth2ServiceImpl.java +++ b/user/user-service-impl/src/main/java/cn/iocoder/mall/user/service/OAuth2ServiceImpl.java @@ -94,19 +94,32 @@ public class OAuth2ServiceImpl implements OAuth2Service { return CommonResult.success(OAuth2Convert.INSTANCE.convertToAuthentication(accessTokenDO)); } - private OAuth2AccessTokenDO createOAuth2AccessToken(Long uid, String refreshToken) { + /** + * 移除用户对应的 Token + * + * @param userId 管理员编号 + */ + @Transactional + public void removeToken(Integer userId) { + // 设置 access token 失效 + oauth2AccessTokenMapper.updateToInvalidByUserId(userId); + // 设置 refresh token 失效 + oauth2RefreshTokenMapper.updateToInvalidByUserId(userId); + } + + private OAuth2AccessTokenDO createOAuth2AccessToken(Integer uid, String refreshToken) { OAuth2AccessTokenDO accessToken = new OAuth2AccessTokenDO().setId(generateAccessToken()) .setRefreshToken(refreshToken) - .setUid(uid) + .setUserId(uid) .setExpiresTime(new Date(System.currentTimeMillis() + accessTokenExpireTimeMillis)) .setValid(true); oauth2AccessTokenMapper.insert(accessToken); return accessToken; } - private OAuth2RefreshTokenDO createOAuth2RefreshToken(Long uid) { + private OAuth2RefreshTokenDO createOAuth2RefreshToken(Integer uid) { OAuth2RefreshTokenDO refreshToken = new OAuth2RefreshTokenDO().setId(generateRefreshToken()) - .setUid(uid) + .setUserId(uid) .setExpiresTime(new Date(System.currentTimeMillis() + refreshTokenExpireTimeMillis)) .setValid(true); oauth2RefreshTokenMapper.insert(refreshToken); 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 adbdf7e34..db75d1fd5 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 @@ -1,13 +1,21 @@ package cn.iocoder.mall.user.service; +import cn.iocoder.common.framework.constant.SysErrorCodeEnum; +import cn.iocoder.common.framework.dataobject.BaseDO; 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.convert.UserConvert; import cn.iocoder.mall.user.dao.UserMapper; 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.UserPageBO; +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.dto.UserPageDTO; +import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -25,7 +33,7 @@ public class UserServiceImpl implements UserService { @Autowired private UserRegisterMapper userRegisterMapper; @Autowired - private MobileCodeServiceImpl mobileCodeService; + private OAuth2ServiceImpl oAuth2Service; public UserDO getUser(String mobile) { return userMapper.selectByMobile(mobile); @@ -33,14 +41,16 @@ public class UserServiceImpl implements UserService { @Transactional public CommonResult createUser(String mobile) { - // TODO 芋艿,校验手机格式 + if (!ValidationUtil.isMobile(mobile)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓 + } // 校验用户是否已经存在 if (getUser(mobile) != null) { return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode()); } // 创建用户 - UserDO userDO = new UserDO().setMobile(mobile); - userDO.setCreateTime(new Date()); + UserDO userDO = new UserDO().setMobile(mobile).setStatus(UserConstants.STATUS_ENABLE); + userDO.setCreateTime(new Date()).setDeleted(BaseDO.DELETED_NO); userMapper.insert(userDO); // 插入注册信息 createUserRegister(userDO); @@ -54,4 +64,81 @@ public class UserServiceImpl implements UserService { userRegisterMapper.insert(userRegisterDO); } + @Override + public CommonResult getUserPage(UserPageDTO userPageDTO) { + UserPageBO userPageBO = new UserPageBO(); + // 查询分页数据 + int offset = userPageDTO.getPageNo() * userPageDTO.getPageSize(); + userPageBO.setUsers(UserConvert.INSTANCE.convert(userMapper.selectListByNicknameLike(userPageDTO.getNickname(), + offset, userPageDTO.getPageSize()))); + // 查询分页总数 + userPageBO.setCount(userMapper.selectCountByNicknameLike(userPageDTO.getNickname())); + return CommonResult.success(userPageBO); + } + + @Override + public CommonResult updateUser(UserUpdateDTO userUpdateDTO) { + // 校验用户存在 + if (userMapper.selectById(userUpdateDTO.getId()) == null) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_NOT_EXISTS.getCode()); + } + // 更新用户 + UserDO updateUser = UserConvert.INSTANCE.convert(userUpdateDTO); + userMapper.update(updateUser); + // 返回成功 + return CommonResult.success(true); + } + + @Override + public CommonResult updateUserStatus(Integer userId, Integer status) { + // 校验参数 + if (!isValidStatus(status)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启(1)或关闭(2)"); // TODO 有点搓 + } + // 校验用户存在 + UserDO user = userMapper.selectById(userId); + if (user == null) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_NOT_EXISTS.getCode()); + } + // 如果状态相同,则返回错误 + if (status.equals(user.getStatus())) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_STATUS_EQUALS.getCode()); + } + // 更新管理员状态 + UserDO updateUser = new UserDO().setId(userId).setStatus(status); + userMapper.update(updateUser); + // 如果是关闭管理员,则标记 token 失效。否则,管理员还可以继续蹦跶 + if (UserConstants.STATUS_DISABLE.equals(status)) { + oAuth2Service.removeToken(userId); + } + // 返回成功 + return CommonResult.success(true); + } + + @Override + public CommonResult updateUserMobile(Integer userId, String mobile) { + if (!ValidationUtil.isMobile(mobile)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓 + } + // 校验用户存在 + UserDO user = userMapper.selectById(userId); + if (user == null) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_NOT_EXISTS.getCode()); + } + // 如果状态相同,则返回错误 + if (mobile.equals(user.getMobile())) { + return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_EQUALS.getCode()); + } + // 更新管理员状态 + UserDO updateUser = new UserDO().setId(userId).setMobile(mobile); + userMapper.update(updateUser); + // 返回成功 + return CommonResult.success(true); + } + + private boolean isValidStatus(Integer status) { + return UserConstants.STATUS_ENABLE.equals(status) + || UserConstants.STATUS_DISABLE.equals(status); + } + } \ No newline at end of file diff --git a/user/user-service-impl/src/main/resources/config/application.yaml b/user/user-service-impl/src/main/resources/config/application.yaml index 86d0d17cc..f012f56d8 100644 --- a/user/user-service-impl/src/main/resources/config/application.yaml +++ b/user/user-service-impl/src/main/resources/config/application.yaml @@ -1,14 +1,16 @@ spring: # datasource datasource: - url: jdbc:mysql://127.0.0.1:33061/mall_user?useSSL=false + url: jdbc:mysql://180.167.213.26:13306/mall_user?useSSL=false&useUnicode=true&characterEncoding=UTF-8 driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: ${MALL_MYSQL_PASSWORD} # server server: - port: 8082 + port: 18082 + servlet: + context-path: /user-api/ # mybatis mybatis: 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 f2676639e..5d8b2d918 100644 --- a/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml +++ b/user/user-service-impl/src/main/resources/mapper/MobileCodeMapper.xml @@ -8,7 +8,7 @@ used_uid, used_time, create_time ) VALUES ( #{id}, #{mobile}, #{code}, #{todayIndex}, #{used}, - #{usedUid}, #{usedTime}, #{createTime} + #{usedUserId}, #{usedTime}, #{createTime} ) @@ -16,7 +16,7 @@ UPDATE mobile_code used = #{used}, - used_uid = #{usedUid}, + used_uid = #{usedUserId}, used_time = #{usedTime}, WHERE id = #{id} diff --git a/user/user-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml b/user/user-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml index ee3b4dcaa..801a509b5 100644 --- a/user/user-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml +++ b/user/user-service-impl/src/main/resources/mapper/OAuth2AccessTokenMapper.xml @@ -4,10 +4,10 @@ INSERT INTO oauth2_access_token ( - id, refresh_token, adminId, valid, expires_time, + id, refresh_token, user_id, valid, expires_time, create_time ) VALUES ( - #{id}, #{refreshToken}, #{adminId}, #{valid}, #{expiresTime}, + #{id}, #{refreshToken}, #{userId}, #{valid}, #{expiresTime}, #{createTime} ) @@ -19,4 +19,11 @@ WHERE id = #{id} + + UPDATE oauth2_access_token + SET valid = 0 + WHERE user_id = #{userId} + AND valid = 1 + + \ No newline at end of file diff --git a/user/user-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml b/user/user-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml index b4646aee4..b8ffe778f 100644 --- a/user/user-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml +++ b/user/user-service-impl/src/main/resources/mapper/OAuth2RefreshTokenMapper.xml @@ -4,10 +4,17 @@ INSERT INTO oauth2_refresh_token ( - id, adminId, valid, expires_time, create_time + id, user_id, valid, expires_time, create_time ) VALUES ( - #{id}, #{adminId}, #{valid}, #{expiresTime}, #{createTime} + #{id}, #{userId}, #{valid}, #{expiresTime}, #{createTime} ) + + UPDATE oauth2_refresh_token + SET valid = 0 + WHERE user_id = #{userId} + AND valid = 1 + + \ 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 index 48897afae..933694a89 100644 --- a/user/user-service-impl/src/main/resources/mapper/UserMapper.xml +++ b/user/user-service-impl/src/main/resources/mapper/UserMapper.xml @@ -2,19 +2,81 @@ + + id, mobile, nickname, avatar, status, + create_time, deleted + + INSERT INTO users ( - id, mobile, create_time + id, mobile, status, create_time, deleted ) VALUES ( - #{id}, #{mobile}, #{createTime} + #{id}, #{mobile}, #{status} #{createTime}, #{deleted} ) - + SELECT + + FROM users + WHERE id = #{id} + AND deleted = 0 + + + + + + + \ No newline at end of file