用户的功能迁移
This commit is contained in:
parent
8edc49f4e7
commit
ef1354478e
@ -24,7 +24,7 @@ public class DubboWebAutoConfiguration implements WebMvcConfigurer {
|
|||||||
registry.addInterceptor(new DubboRouterTagWebInterceptor()).order(-1000);
|
registry.addInterceptor(new DubboRouterTagWebInterceptor()).order(-1000);
|
||||||
logger.info("[addInterceptors][加载 DubboRouterTagWebInterceptor 拦截器完成]");
|
logger.info("[addInterceptors][加载 DubboRouterTagWebInterceptor 拦截器完成]");
|
||||||
} catch (NoSuchBeanDefinitionException e) {
|
} catch (NoSuchBeanDefinitionException e) {
|
||||||
logger.warn("[addInterceptors][无法获取 DubboRouterTagWebInterceptor 拦截器,无法使用 Dubbo 标签路由]");
|
logger.warn("[addInterceptors][无法获取 DubboRouterTagWebInterceptor 拦截器,无法使用基于 dubbo-tag 请求头进行 Dubbo 标签路由]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
|
|||||||
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContext;
|
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContext;
|
||||||
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
|
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.PermissionRpc;
|
import cn.iocoder.mall.systemservice.rpc.permission.PermissionRpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionCheckDTO;
|
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionCheckDTO;
|
||||||
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
||||||
@ -48,7 +48,7 @@ public class AdminSecurityInterceptor extends HandlerInterceptorAdapter {
|
|||||||
String accessToken = HttpUtil.obtainAuthorization(request);
|
String accessToken = HttpUtil.obtainAuthorization(request);
|
||||||
Integer adminId = null;
|
Integer adminId = null;
|
||||||
if (accessToken != null) {
|
if (accessToken != null) {
|
||||||
CommonResult<OAuth2AccessTokenVO> checkAccessTokenResult = oauth2Rpc.checkAccessToken(accessToken);
|
CommonResult<OAuth2AccessTokenRespDTO> checkAccessTokenResult = oauth2Rpc.checkAccessToken(accessToken);
|
||||||
checkAccessTokenResult.checkError();
|
checkAccessTokenResult.checkError();
|
||||||
// 校验用户类型正确
|
// 校验用户类型正确
|
||||||
if (!UserTypeEnum.ADMIN.getValue().equals(checkAccessTokenResult.getData().getUserType())) {
|
if (!UserTypeEnum.ADMIN.getValue().equals(checkAccessTokenResult.getData().getUserType())) {
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package cn.iocoder.mall.security.user.core.interceptor;
|
package cn.iocoder.mall.security.user.core.interceptor;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.exception.enums.GlobalErrorCodeEnum;
|
|
||||||
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
||||||
import cn.iocoder.common.framework.util.HttpUtil;
|
|
||||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||||
|
import cn.iocoder.common.framework.util.HttpUtil;
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.security.user.core.context.UserSecurityContext;
|
import cn.iocoder.mall.security.user.core.context.UserSecurityContext;
|
||||||
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
|
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
import cn.iocoder.mall.web.core.util.CommonWebUtil;
|
||||||
import cn.iocoder.security.annotations.RequiresAuthenticate;
|
import cn.iocoder.security.annotations.RequiresAuthenticate;
|
||||||
import cn.iocoder.security.annotations.RequiresPermissions;
|
import cn.iocoder.security.annotations.RequiresPermissions;
|
||||||
@ -19,6 +18,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import static cn.iocoder.common.framework.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
|
||||||
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants.OAUTH_USER_TYPE_ERROR;
|
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants.OAUTH_USER_TYPE_ERROR;
|
||||||
|
|
||||||
public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
||||||
@ -39,7 +39,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
|||||||
String accessToken = HttpUtil.obtainAuthorization(request);
|
String accessToken = HttpUtil.obtainAuthorization(request);
|
||||||
Integer userId = null;
|
Integer userId = null;
|
||||||
if (accessToken != null) {
|
if (accessToken != null) {
|
||||||
CommonResult<OAuth2AccessTokenVO> checkAccessTokenResult = oauth2Rpc.checkAccessToken(accessToken);
|
CommonResult<OAuth2AccessTokenRespDTO> checkAccessTokenResult = oauth2Rpc.checkAccessToken(accessToken);
|
||||||
checkAccessTokenResult.checkError();
|
checkAccessTokenResult.checkError();
|
||||||
// 校验用户类型正确
|
// 校验用户类型正确
|
||||||
if (!UserTypeEnum.USER.getValue().equals(checkAccessTokenResult.getData().getUserType())) {
|
if (!UserTypeEnum.USER.getValue().equals(checkAccessTokenResult.getData().getUserType())) {
|
||||||
@ -64,7 +64,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
|
|||||||
requiresAuthenticate = true;
|
requiresAuthenticate = true;
|
||||||
}
|
}
|
||||||
if (requiresAuthenticate && userId == null) {
|
if (requiresAuthenticate && userId == null) {
|
||||||
throw ServiceExceptionUtil.exception(GlobalErrorCodeEnum.UNAUTHORIZED);
|
throw ServiceExceptionUtil.exception(UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,14 @@ public class PassportController {
|
|||||||
return success(passportManager.getAdmin(AdminSecurityContextHolder.getAdminId()));
|
return success(passportManager.getAdmin(AdminSecurityContextHolder.getAdminId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 优化点:迁移到 PermissionController
|
||||||
@GetMapping("/tree-admin-menu")
|
@GetMapping("/tree-admin-menu")
|
||||||
@ApiOperation("获得当前管理员的菜单树")
|
@ApiOperation("获得当前管理员的菜单树")
|
||||||
public CommonResult<List<PassportAdminMenuTreeNodeVO>> treeAdminMenu() {
|
public CommonResult<List<PassportAdminMenuTreeNodeVO>> treeAdminMenu() {
|
||||||
return success(passportManager.treeAdminMenu(AdminSecurityContextHolder.getAdminId()));
|
return success(passportManager.treeAdminMenu(AdminSecurityContextHolder.getAdminId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 优化点:迁移到 PermissionController
|
||||||
@GetMapping("/list-admin-permission")
|
@GetMapping("/list-admin-permission")
|
||||||
@ApiOperation("获得当前管理员的权限列表")
|
@ApiOperation("获得当前管理员的权限列表")
|
||||||
public CommonResult<Set<String>> listAdminPermission() {
|
public CommonResult<Set<String>> listAdminPermission() {
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.user;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserPageReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserRespVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateInfoReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateStatusReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.manager.user.UserManager;
|
||||||
|
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")
|
||||||
|
@Api(tags = "用户")
|
||||||
|
@Validated
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserManager userManager;
|
||||||
|
|
||||||
|
@PostMapping("/update-info")
|
||||||
|
@ApiOperation("更新用户信息")
|
||||||
|
public CommonResult<Boolean> updateUserInfo(@Valid UserUpdateInfoReqVO updateInfoReqVO) {
|
||||||
|
userManager.updateUserInfo(updateInfoReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update-status")
|
||||||
|
@ApiOperation("更新用户信息")
|
||||||
|
public CommonResult<Boolean> updateUserStatus(@Valid UserUpdateStatusReqVO updateStatusReqVO) {
|
||||||
|
userManager.updateUserStatus(updateStatusReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@ApiOperation("获得用户")
|
||||||
|
@ApiImplicitParam(name = "userId", value = "用户编号", required = true)
|
||||||
|
public CommonResult<UserRespVO> getUser(@RequestParam("userId") Integer userId) {
|
||||||
|
return success(userManager.getUser(userId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("获得用户列表")
|
||||||
|
@ApiImplicitParam(name = "userIds", value = "用户编号列表", required = true)
|
||||||
|
public CommonResult<List<UserRespVO>> listUsers(@RequestParam("userIds") List<Integer> userIds) {
|
||||||
|
return success(userManager.listUsers(userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("获得用户分页")
|
||||||
|
public CommonResult<PageResult<UserRespVO>> pageUser(UserPageReqVO pageVO) {
|
||||||
|
return success(userManager.pageUser(pageVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
package cn.iocoder.mall.managementweb.controller.user.dto;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 管理员 - 用户信息 - 用户分页列表
|
|
||||||
*/
|
|
||||||
@ApiModel("用户分页列表Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsUserPageRequest {
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "nickname", value = "昵称,模糊匹配", example = "小王")
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "status", value = "状态。1 - 开启;2 - 禁用", example = "0")
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "pageNo", value = "页码,从 1 开始", example = "1")
|
|
||||||
private Integer pageNo = 1;
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "pageSize", value = "每页条数", required = true, example = "10")
|
|
||||||
private Integer pageSize = 10;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.managementweb.controller.user.dto;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 管理员 - 用户信息 - 更新用户状态
|
|
||||||
*/
|
|
||||||
@ApiModel("更新用户状态Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsUserUpdateStatusRequest {
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "id", value = "用户编号", required = true, example = "1")
|
|
||||||
@NotNull(message = "用户编号不能为空")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@ApiModelProperty(name = "status", value = "用户状态。1 - 开启;2 - 禁用", required = true, example = "1")
|
|
||||||
@NotNull(message = "用户状态不能为空")
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.user.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.PageParam;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@ApiModel("用户分页 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class UserPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "昵称", example = "丑艿艿", notes = "模糊匹配")
|
||||||
|
private String nickname;
|
||||||
|
@ApiModelProperty(value = "状态", example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.user.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@ApiModel("用户 Response VO")
|
||||||
|
@Data
|
||||||
|
public class UserRespVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
||||||
|
private Integer id;
|
||||||
|
@ApiModelProperty(value = "昵称", example = "丑艿艿")
|
||||||
|
private String nickname;
|
||||||
|
@ApiModelProperty(value = "头像", example = "http://www.iocoder.cn/xxx.jpg")
|
||||||
|
private String avatar;
|
||||||
|
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||||
|
private Integer status;
|
||||||
|
@ApiModelProperty(value = "手机号", required = true, example = "15601691399")
|
||||||
|
private String mobile;
|
||||||
|
@ApiModelProperty(value = "注册 IP", required = true, example = "127.0.0.1")
|
||||||
|
private String createIp;
|
||||||
|
@ApiModelProperty(value = "创建时间", required = true)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.user.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@ApiModel("用户更新信息 Request VO")
|
||||||
|
@Data
|
||||||
|
public class UserUpdateInfoReqVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer id;
|
||||||
|
@ApiModelProperty(value = "昵称", example = "臭艿艿")
|
||||||
|
private String nickname;
|
||||||
|
@ApiModelProperty(value = "头像", example = "http://www.iocoder.cn/nainainai.jpg")
|
||||||
|
private String avatar;
|
||||||
|
@ApiModelProperty(value = "手机号", example = "15601691300")
|
||||||
|
private String mobile;
|
||||||
|
@ApiModelProperty(value = "密码", example = "123456")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.user.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@ApiModel("用户更新状态 Request VO")
|
||||||
|
@Data
|
||||||
|
public class UserUpdateStatusReqVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户编号", required = true)
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer id;
|
||||||
|
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
@ -5,7 +5,7 @@ import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAccessTokenV
|
|||||||
import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminVO;
|
import cn.iocoder.mall.managementweb.controller.passport.vo.PassportAdminVO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminVerifyPasswordDTO;
|
import cn.iocoder.mall.systemservice.rpc.admin.dto.AdminVerifyPasswordDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ public interface AdminPassportConvert {
|
|||||||
|
|
||||||
AdminVerifyPasswordDTO convert(PassportLoginDTO bean);
|
AdminVerifyPasswordDTO convert(PassportLoginDTO bean);
|
||||||
|
|
||||||
PassportAccessTokenVO convert(OAuth2AccessTokenVO bean);
|
PassportAccessTokenVO convert(OAuth2AccessTokenRespDTO bean);
|
||||||
|
|
||||||
PassportAdminVO convert(AdminVO bean);
|
PassportAdminVO convert(AdminVO bean);
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.convert.user;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserPageReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserRespVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateInfoReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateStatusReqVO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserPageReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserConvert {
|
||||||
|
|
||||||
|
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||||
|
|
||||||
|
UserUpdateReqDTO convert(UserUpdateInfoReqVO bean);
|
||||||
|
|
||||||
|
UserRespVO convert(UserRespDTO bean);
|
||||||
|
|
||||||
|
List<UserRespVO> convertList(List<UserRespDTO> list);
|
||||||
|
|
||||||
|
UserPageReqDTO convert(UserPageReqVO bean);
|
||||||
|
|
||||||
|
PageResult<UserRespVO> convertPage(PageResult<UserRespDTO> bean);
|
||||||
|
|
||||||
|
UserUpdateReqDTO convert(UserUpdateStatusReqVO bean);
|
||||||
|
|
||||||
|
}
|
@ -15,8 +15,8 @@ import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
|
|||||||
import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc;
|
import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc;
|
import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc;
|
import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO;
|
import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO;
|
||||||
@ -45,8 +45,8 @@ public class PassportManager {
|
|||||||
CommonResult<AdminVO> verifyPasswordResult = adminRpc.verifyPassword(AdminPassportConvert.INSTANCE.convert(loginDTO).setIp(ip));
|
CommonResult<AdminVO> verifyPasswordResult = adminRpc.verifyPassword(AdminPassportConvert.INSTANCE.convert(loginDTO).setIp(ip));
|
||||||
verifyPasswordResult.checkError();
|
verifyPasswordResult.checkError();
|
||||||
// 创建访问令牌
|
// 创建访问令牌
|
||||||
CommonResult<OAuth2AccessTokenVO> createAccessTokenResult = oauth2Rpc.createAccessToken(
|
CommonResult<OAuth2AccessTokenRespDTO> createAccessTokenResult = oauth2Rpc.createAccessToken(
|
||||||
new OAuth2CreateAccessTokenDTO().setUserId(verifyPasswordResult.getData().getId())
|
new OAuth2CreateAccessTokenReqDTO().setUserId(verifyPasswordResult.getData().getId())
|
||||||
.setUserType(UserTypeEnum.ADMIN.getValue()).setCreateIp(ip));
|
.setUserType(UserTypeEnum.ADMIN.getValue()).setCreateIp(ip));
|
||||||
createAccessTokenResult.checkError();
|
createAccessTokenResult.checkError();
|
||||||
// 返回
|
// 返回
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.manager.user;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserPageReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserRespVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateInfoReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.user.vo.UserUpdateStatusReqVO;
|
||||||
|
import cn.iocoder.mall.managementweb.convert.user.UserConvert;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
|
import org.apache.dubbo.config.annotation.Reference;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户 Manager
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserManager {
|
||||||
|
|
||||||
|
@Reference(version = "$ {dubbo.consumer.UserRpc.version}", validation = "false")
|
||||||
|
private UserRpc userRpc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
*
|
||||||
|
* @param updateInfoReqVO 更新用户信息 VO
|
||||||
|
*/
|
||||||
|
public void updateUserInfo(UserUpdateInfoReqVO updateInfoReqVO) {
|
||||||
|
CommonResult<Boolean> updateUserResult = userRpc.updateUser(UserConvert.INSTANCE.convert(updateInfoReqVO));
|
||||||
|
updateUserResult.checkError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户状态
|
||||||
|
*
|
||||||
|
* @param updateStatusReqVO 更新用户状态 VO
|
||||||
|
*/
|
||||||
|
public void updateUserStatus(UserUpdateStatusReqVO updateStatusReqVO) {
|
||||||
|
CommonResult<Boolean> updateUserResult = userRpc.updateUser(UserConvert.INSTANCE.convert(updateStatusReqVO));
|
||||||
|
updateUserResult.checkError();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
public UserRespVO getUser(Integer userId) {
|
||||||
|
CommonResult<UserRespDTO> getUserResult = userRpc.getUser(userId);
|
||||||
|
getUserResult.checkError();
|
||||||
|
return UserConvert.INSTANCE.convert(getUserResult.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户列表
|
||||||
|
*
|
||||||
|
* @param userIds 用户编号列表
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
public List<UserRespVO> listUsers(List<Integer> userIds) {
|
||||||
|
CommonResult<List<UserRespDTO>> listUserResult = userRpc.listUsers(userIds);
|
||||||
|
listUserResult.checkError();
|
||||||
|
return UserConvert.INSTANCE.convertList(listUserResult.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户分页
|
||||||
|
*
|
||||||
|
* @param pageVO 用户分页查询
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
public PageResult<UserRespVO> pageUser(UserPageReqVO pageVO) {
|
||||||
|
CommonResult<PageResult<UserRespDTO>> pageUserResult = userRpc.pageUser(UserConvert.INSTANCE.convert(pageVO));
|
||||||
|
pageUserResult.checkError();
|
||||||
|
return UserConvert.INSTANCE.convertPage(pageUserResult.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
pom.xml
2
pom.xml
@ -18,7 +18,7 @@
|
|||||||
<!-- <module>order</module>-->
|
<!-- <module>order</module>-->
|
||||||
<module>user</module>
|
<module>user</module>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
<module>system</module>
|
<!-- <module>system</module>-->
|
||||||
<!-- <module>ops</module>-->
|
<!-- <module>ops</module>-->
|
||||||
<!-- <module>pay</module>-->
|
<!-- <module>pay</module>-->
|
||||||
<!-- <module>promotion</module>-->
|
<!-- <module>promotion</module>-->
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
package cn.iocoder.mall.systemservice.rpc.oauth;
|
package cn.iocoder.mall.systemservice.rpc.oauth;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RemoveTokenByUserReqDTO;
|
||||||
|
|
||||||
public interface OAuth2Rpc {
|
public interface OAuth2Rpc {
|
||||||
|
|
||||||
CommonResult<OAuth2AccessTokenVO> createAccessToken(OAuth2CreateAccessTokenDTO createAccessTokenDTO);
|
CommonResult<OAuth2AccessTokenRespDTO> createAccessToken(OAuth2CreateAccessTokenReqDTO createAccessTokenDTO);
|
||||||
|
|
||||||
CommonResult<OAuth2AccessTokenVO> checkAccessToken(String accessToken);
|
CommonResult<OAuth2AccessTokenRespDTO> checkAccessToken(String accessToken);
|
||||||
|
|
||||||
CommonResult<OAuth2AccessTokenVO> refreshAccessToken(OAuth2RefreshAccessTokenDTO refreshAccessTokenDTO);
|
CommonResult<OAuth2AccessTokenRespDTO> refreshAccessToken(OAuth2RefreshAccessTokenReqDTO refreshAccessTokenDTO);
|
||||||
|
|
||||||
|
CommonResult<Boolean> removeToken(OAuth2RemoveTokenByUserReqDTO removeTokenDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.systemservice.rpc.oauth.vo;
|
package cn.iocoder.mall.systemservice.rpc.oauth.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@ -7,11 +7,11 @@ import java.io.Serializable;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth2.0 访问令牌 VO
|
* OAuth2.0 访问令牌 Response DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class OAuth2AccessTokenVO implements Serializable {
|
public class OAuth2AccessTokenRespDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问令牌
|
* 访问令牌
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.systemservice.rpc.oauth.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OAuth2.0 访问令牌创建 DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class OAuth2CreateAccessTokenDTO implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户编号
|
|
||||||
*/
|
|
||||||
private Integer userId;
|
|
||||||
/**
|
|
||||||
* 用户类型
|
|
||||||
*/
|
|
||||||
private Integer userType;
|
|
||||||
/**
|
|
||||||
* 创建 IP
|
|
||||||
*/
|
|
||||||
private String createIp;
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package cn.iocoder.mall.systemservice.rpc.oauth.dto;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth2.0 访问令牌创建 Request DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class OAuth2CreateAccessTokenReqDTO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer userId;
|
||||||
|
/**
|
||||||
|
* 用户类型
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户类型不能为空")
|
||||||
|
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
|
||||||
|
private Integer userType;
|
||||||
|
/**
|
||||||
|
* 创建 IP
|
||||||
|
*/
|
||||||
|
private String createIp;
|
||||||
|
|
||||||
|
}
|
@ -6,11 +6,11 @@ import lombok.experimental.Accessors;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth2.0 访问令牌创建 DTO
|
* OAuth2.0 访问令牌创建 Request DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class OAuth2RefreshAccessTokenDTO implements Serializable {
|
public class OAuth2RefreshAccessTokenReqDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新令牌
|
* 刷新令牌
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.iocoder.mall.systemservice.rpc.oauth.dto;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth2.0 移除用户令牌 Request DTO
|
||||||
|
*
|
||||||
|
* 包括访问令牌和刷新令牌
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class OAuth2RemoveTokenByUserReqDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer userId;
|
||||||
|
/**
|
||||||
|
* 用户类型
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户类型不能为空")
|
||||||
|
@InEnum(value = UserTypeEnum.class, message = "用户类型必须是 {value}")
|
||||||
|
private Integer userType;
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.mall.systemservice.convert.oauth;
|
package cn.iocoder.mall.systemservice.convert.oauth;
|
||||||
|
|
||||||
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.oauth.OAuth2AccessTokenDO;
|
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.oauth.OAuth2AccessTokenDO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.systemservice.service.oauth.bo.OAuth2AccessTokenBO;
|
import cn.iocoder.mall.systemservice.service.oauth.bo.OAuth2AccessTokenBO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
@ -15,6 +15,6 @@ public interface OAuth2Convert {
|
|||||||
@Mapping(source = "id", target = "accessToken")
|
@Mapping(source = "id", target = "accessToken")
|
||||||
OAuth2AccessTokenBO convert(OAuth2AccessTokenDO bean);
|
OAuth2AccessTokenBO convert(OAuth2AccessTokenDO bean);
|
||||||
|
|
||||||
OAuth2AccessTokenVO convert(OAuth2AccessTokenBO bean);
|
OAuth2AccessTokenRespDTO convert(OAuth2AccessTokenBO bean);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,47 @@
|
|||||||
package cn.iocoder.mall.systemservice.manager.oauth;
|
package cn.iocoder.mall.systemservice.manager.oauth;
|
||||||
|
|
||||||
import cn.iocoder.mall.systemservice.convert.oauth.OAuth2Convert;
|
import cn.iocoder.mall.systemservice.convert.oauth.OAuth2Convert;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenReqDTO;
|
||||||
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RemoveTokenByUserReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.service.oauth.OAuth2Service;
|
import cn.iocoder.mall.systemservice.service.oauth.OAuth2Service;
|
||||||
import cn.iocoder.mall.systemservice.service.oauth.bo.OAuth2AccessTokenBO;
|
import cn.iocoder.mall.systemservice.service.oauth.bo.OAuth2AccessTokenBO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth2.0 Manager
|
* OAuth2.0 Manager
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Validated
|
||||||
public class OAuth2Manager {
|
public class OAuth2Manager {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OAuth2Service oauth2Service;
|
private OAuth2Service oauth2Service;
|
||||||
|
|
||||||
public OAuth2AccessTokenVO createAccessToken(OAuth2CreateAccessTokenDTO createAccessTokenDTO) {
|
public OAuth2AccessTokenRespDTO createAccessToken(@Valid OAuth2CreateAccessTokenReqDTO createAccessTokenDTO) {
|
||||||
OAuth2AccessTokenBO accessTokenBO = oauth2Service.createAccessToken(createAccessTokenDTO.getUserId(),
|
OAuth2AccessTokenBO accessTokenBO = oauth2Service.createAccessToken(createAccessTokenDTO.getUserId(),
|
||||||
createAccessTokenDTO.getUserType(), createAccessTokenDTO.getCreateIp());
|
createAccessTokenDTO.getUserType(), createAccessTokenDTO.getCreateIp());
|
||||||
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuth2AccessTokenVO checkAccessToken(String accessToken) {
|
public OAuth2AccessTokenRespDTO checkAccessToken(String accessToken) {
|
||||||
OAuth2AccessTokenBO accessTokenBO = oauth2Service.checkAccessToken(accessToken);
|
OAuth2AccessTokenBO accessTokenBO = oauth2Service.checkAccessToken(accessToken);
|
||||||
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuth2AccessTokenVO refreshAccessToken(OAuth2RefreshAccessTokenDTO refreshAccessTokenDTO) {
|
public OAuth2AccessTokenRespDTO refreshAccessToken(@Valid OAuth2RefreshAccessTokenReqDTO refreshAccessTokenDTO) {
|
||||||
OAuth2AccessTokenBO accessTokenBO = oauth2Service.refreshAccessToken(refreshAccessTokenDTO.getRefreshToken(),
|
OAuth2AccessTokenBO accessTokenBO = oauth2Service.refreshAccessToken(refreshAccessTokenDTO.getRefreshToken(),
|
||||||
refreshAccessTokenDTO.getCreateIp());
|
refreshAccessTokenDTO.getCreateIp());
|
||||||
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
return OAuth2Convert.INSTANCE.convert(accessTokenBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeToken(@Valid OAuth2RemoveTokenByUserReqDTO removeTokenDTO) {
|
||||||
|
oauth2Service.removeToken(removeTokenDTO.getUserId(), removeTokenDTO.getUserType());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ package cn.iocoder.mall.systemservice.rpc.oauth;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.systemservice.manager.oauth.OAuth2Manager;
|
import cn.iocoder.mall.systemservice.manager.oauth.OAuth2Manager;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RefreshAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RemoveTokenByUserReqDTO;
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.Service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
@ -17,18 +18,24 @@ public class OAuth2RpcImpl implements OAuth2Rpc {
|
|||||||
private OAuth2Manager oauth2Manager;
|
private OAuth2Manager oauth2Manager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<OAuth2AccessTokenVO> createAccessToken(OAuth2CreateAccessTokenDTO createAccessTokenDTO) {
|
public CommonResult<OAuth2AccessTokenRespDTO> createAccessToken(OAuth2CreateAccessTokenReqDTO createAccessTokenDTO) {
|
||||||
return success(oauth2Manager.createAccessToken(createAccessTokenDTO));
|
return success(oauth2Manager.createAccessToken(createAccessTokenDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<OAuth2AccessTokenVO> checkAccessToken(String accessToken) {
|
public CommonResult<OAuth2AccessTokenRespDTO> checkAccessToken(String accessToken) {
|
||||||
return success(oauth2Manager.checkAccessToken(accessToken));
|
return success(oauth2Manager.checkAccessToken(accessToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<OAuth2AccessTokenVO> refreshAccessToken(OAuth2RefreshAccessTokenDTO refreshAccessTokenDTO) {
|
public CommonResult<OAuth2AccessTokenRespDTO> refreshAccessToken(OAuth2RefreshAccessTokenReqDTO refreshAccessTokenDTO) {
|
||||||
return success(oauth2Manager.refreshAccessToken(refreshAccessTokenDTO));
|
return success(oauth2Manager.refreshAccessToken(refreshAccessTokenDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Boolean> removeToken(OAuth2RemoveTokenByUserReqDTO removeTokenDTO) {
|
||||||
|
oauth2Manager.removeToken(removeTokenDTO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,34 +81,34 @@ public class AdminService {
|
|||||||
return DigestUtils.bcrypt(password, salt);
|
return DigestUtils.bcrypt(password, salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAdmin(AdminUpdateBO updateDTO) {
|
public void updateAdmin(AdminUpdateBO updateBO) {
|
||||||
// 校验账号存在
|
// 校验账号存在
|
||||||
AdminDO admin = adminMapper.selectById(updateDTO.getId());
|
AdminDO adminDO = adminMapper.selectById(updateBO.getId());
|
||||||
if (admin == null) {
|
if (adminDO == null) {
|
||||||
throw ServiceExceptionUtil.exception(ADMIN_NOT_FOUND);
|
throw ServiceExceptionUtil.exception(ADMIN_NOT_FOUND);
|
||||||
}
|
}
|
||||||
// 校验是否为特殊账号,不允许编辑
|
// 校验是否为特殊账号,不允许编辑
|
||||||
if (AdminUsernameEnum.ADMIN.getUsername().equals(admin.getUsername())
|
if (AdminUsernameEnum.ADMIN.getUsername().equals(adminDO.getUsername())
|
||||||
|| AdminUsernameEnum.DEMO.getUsername().equals(admin.getUsername())) {
|
|| AdminUsernameEnum.DEMO.getUsername().equals(adminDO.getUsername())) {
|
||||||
throw ServiceExceptionUtil.exception(ADMIN_ADMIN_CAN_NOT_UPDATE);
|
throw ServiceExceptionUtil.exception(ADMIN_ADMIN_CAN_NOT_UPDATE);
|
||||||
}
|
}
|
||||||
// 校验账号唯一
|
// 校验账号唯一
|
||||||
if (StringUtils.hasText(updateDTO.getUsername())) {
|
if (StringUtils.hasText(updateBO.getUsername())) {
|
||||||
AdminDO usernameAdmin = adminMapper.selectByUsername(updateDTO.getUsername());
|
AdminDO usernameAdmin = adminMapper.selectByUsername(updateBO.getUsername());
|
||||||
if (usernameAdmin != null && !usernameAdmin.getId().equals(updateDTO.getId())) {
|
if (usernameAdmin != null && !usernameAdmin.getId().equals(updateBO.getId())) {
|
||||||
throw ServiceExceptionUtil.exception(ADMIN_USERNAME_EXISTS);
|
throw ServiceExceptionUtil.exception(ADMIN_USERNAME_EXISTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果有更新状态,则校验是否已经是该状态
|
// 如果有更新状态,则校验是否已经是该状态
|
||||||
if (updateDTO.getStatus() != null && updateDTO.getStatus().equals(admin.getStatus())) {
|
if (updateBO.getStatus() != null && updateBO.getStatus().equals(adminDO.getStatus())) {
|
||||||
throw ServiceExceptionUtil.exception(ADMIN_STATUS_EQUALS);
|
throw ServiceExceptionUtil.exception(ADMIN_STATUS_EQUALS);
|
||||||
}
|
}
|
||||||
// 更新到数据库
|
// 更新到数据库
|
||||||
AdminDO updateAdmin = AdminConvert.INSTANCE.convert(updateDTO);
|
AdminDO updateAdmin = AdminConvert.INSTANCE.convert(updateBO);
|
||||||
// 如果更新密码,需要特殊加密
|
// 如果更新密码,需要特殊加密
|
||||||
if (StringUtils.hasText(updateDTO.getPassword())) {
|
if (StringUtils.hasText(updateBO.getPassword())) {
|
||||||
String passwordSalt = genPasswordSalt();
|
String passwordSalt = genPasswordSalt();
|
||||||
String password = encodePassword(updateDTO.getPassword(), passwordSalt);
|
String password = encodePassword(updateBO.getPassword(), passwordSalt);
|
||||||
updateAdmin.setPassword(password).setPasswordSalt(passwordSalt);
|
updateAdmin.setPassword(password).setPasswordSalt(passwordSalt);
|
||||||
}
|
}
|
||||||
adminMapper.updateById(updateAdmin);
|
adminMapper.updateById(updateAdmin);
|
||||||
@ -119,65 +119,4 @@ public class AdminService {
|
|||||||
return AdminConvert.INSTANCE.convert(adminDO);
|
return AdminConvert.INSTANCE.convert(adminDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Map<Integer, Collection<RoleBO>> getAdminRolesMap(Collection<Integer> adminIds) {
|
|
||||||
// // 查询管理员拥有的角色关联数据
|
|
||||||
// List<AdminRoleDO> adminRoleList = adminRoleMapper.selectListByAdminIds(adminIds);
|
|
||||||
// if (adminRoleList.isEmpty()) {
|
|
||||||
// return Collections.emptyMap();
|
|
||||||
// }
|
|
||||||
// // 查询角色数据
|
|
||||||
// List<RoleBO> roleList = roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId));
|
|
||||||
// Map<Integer, RoleBO> roleMap = CollectionUtil.convertMap(roleList, RoleBO::getId);
|
|
||||||
// // 拼接数据
|
|
||||||
// Multimap<Integer, RoleBO> result = ArrayListMultimap.create();
|
|
||||||
// adminRoleList.forEach(adminRole -> result.put(adminRole.getAdminId(), roleMap.get(adminRole.getRoleId())));
|
|
||||||
// return result.asMap();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public List<RoleBO> getRoleList(Integer adminId) {
|
|
||||||
// // 查询管理员拥有的角色关联数据
|
|
||||||
// List<AdminRoleDO> adminRoleList = adminRoleMapper.selectByAdminId(adminId);
|
|
||||||
// if (adminRoleList.isEmpty()) {
|
|
||||||
// return Collections.emptyList();
|
|
||||||
// }
|
|
||||||
// // 查询角色数据
|
|
||||||
// return roleService.getRoleList(CollectionUtil.convertSet(adminRoleList, AdminRoleDO::getRoleId));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// @Transactional
|
|
||||||
// public Boolean assignAdminRole(Integer adminId, AdminAssignRoleDTO adminAssignRoleDTO) {
|
|
||||||
// // 校验账号存在
|
|
||||||
// AdminDO admin = adminMapper.selectById(adminAssignRoleDTO.getId());
|
|
||||||
// if (admin == null) {
|
|
||||||
// throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_USERNAME_NOT_REGISTERED.getCode());
|
|
||||||
// }
|
|
||||||
// // 校验是否有不存在的角色
|
|
||||||
// if (!CollectionUtil.isEmpty(adminAssignRoleDTO.getRoleIds())) {
|
|
||||||
// List<RoleDO> roles = roleService.getRoles(adminAssignRoleDTO.getRoleIds());
|
|
||||||
// if (roles.size() != adminAssignRoleDTO.getRoleIds().size()) {
|
|
||||||
// throw ServiceExceptionUtil.exception(AdminErrorCodeEnum.ADMIN_ASSIGN_ROLE_NOT_EXISTS.getCode());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // TODO 芋艿,这里先简单实现。即方式是,删除老的分配的角色关系,然后添加新的分配的角色关系
|
|
||||||
// // 标记管理员角色源关系都为删除
|
|
||||||
// adminRoleMapper.deleteByAdminId(adminAssignRoleDTO.getId());
|
|
||||||
// // 创建 RoleResourceDO 数组,并插入到数据库
|
|
||||||
// if (!CollectionUtil.isEmpty(adminAssignRoleDTO.getRoleIds())) {
|
|
||||||
// List<AdminRoleDO> adminRoleDOs = adminAssignRoleDTO.getRoleIds().stream().map(roleId -> {
|
|
||||||
// AdminRoleDO roleResource = new AdminRoleDO().setAdminId(adminAssignRoleDTO.getId()).setRoleId(roleId);
|
|
||||||
// roleResource.setCreateTime(new Date());
|
|
||||||
// roleResource.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
|
||||||
// return roleResource;
|
|
||||||
// }).collect(Collectors.toList());
|
|
||||||
// adminRoleMapper.insertList(adminRoleDOs);
|
|
||||||
// }
|
|
||||||
// // TODO 插入操作日志
|
|
||||||
// // 返回成功
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,11 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>system-application</module>
|
|
||||||
<!-- <module>system-sdk</module>-->
|
<!-- <module>system-sdk</module>-->
|
||||||
<!-- <module>system-service-api</module>-->
|
<!-- <module>system-service-api</module>-->
|
||||||
<!-- <module>system-service-impl</module>-->
|
<!-- <module>system-service-impl</module>-->
|
||||||
<module>system-rpc-api</module>
|
|
||||||
<module>system-rpc</module>
|
|
||||||
<module>system-rest</module>
|
<module>system-rest</module>
|
||||||
<module>system-biz</module>
|
<module>system-biz</module>
|
||||||
<module>system-biz-api</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>system</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>system-application</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>system-rest</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>system-rpc</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,24 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.application;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.system"})
|
|
||||||
public class SystemApplication {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置需要读取的配置文件的名字。
|
|
||||||
* 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
|
|
||||||
*/
|
|
||||||
private static final String CONFIG_NAME_VALUE = "biz,rest,rpc,application";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// 设置环境变量
|
|
||||||
System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
|
|
||||||
|
|
||||||
// 启动 Spring Boot 应用
|
|
||||||
SpringApplication.run(SystemApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.biz.convert.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dataobject.admin.AdminDO;
|
|
||||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserConvert {
|
|
||||||
|
|
||||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
|
||||||
|
|
||||||
UserBO convert(UserDO bean);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户分页列表 - DOPage转换BO
|
|
||||||
* @param userDOPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Mapping(source = "records", target = "list")
|
|
||||||
PageResult<UserBO> convertToPage(IPage<UserDO> userDOPage);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户信息 - DTO转换DO
|
|
||||||
* @param userUpdateDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
UserDO convertToUserDO(UserUpdateDTO userUpdateDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户状态 - DTO转换DO
|
|
||||||
* @param userUpdateStatusDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
UserDO convertToUserDO(UserUpdateStatusDTO userUpdateStatusDTO);
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.biz.dto.user;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 用户信息 - 用户分页列表DTO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class UserPageDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 昵称,模糊匹配
|
|
||||||
*/
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态。1 - 开启;2 - 禁用
|
|
||||||
*/
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 页码,从 1 开始
|
|
||||||
*/
|
|
||||||
@NotNull(message = "页码不能为空")
|
|
||||||
private Integer pageNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每页条数
|
|
||||||
*/
|
|
||||||
@NotNull(message = "每页条数不能为空")
|
|
||||||
private Integer pageSize;
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.biz.service.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户 Service 接口
|
|
||||||
*/
|
|
||||||
@Validated
|
|
||||||
public interface UserService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据条件分页获取用户列表
|
|
||||||
* @param userPageDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
PageResult<UserBO> getUserPage(UserPageDTO userPageDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户信息
|
|
||||||
* @param userUpdateDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean updateUserInfo(@Valid UserUpdateDTO userUpdateDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户状态
|
|
||||||
* @param userUpdateStatusDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean updateUserStatus(@Valid UserUpdateStatusDTO userUpdateStatusDTO);
|
|
||||||
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.biz.service.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.convert.user.UserConvert;
|
|
||||||
import cn.iocoder.mall.system.biz.dao.user.UserMapper;
|
|
||||||
import cn.iocoder.mall.system.biz.dataobject.user.UserDO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.enums.user.UserStatusEnum;
|
|
||||||
import cn.iocoder.mall.system.biz.service.oauth2.OAuth2Service;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import static cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class UserServiceImpl implements UserService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据条件分页获取用户列表
|
|
||||||
* @param userPageDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PageResult<UserBO> getUserPage(UserPageDTO userPageDTO) {
|
|
||||||
return UserConvert.INSTANCE.convertToPage(userMapper.selectUserPage(userPageDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户信息
|
|
||||||
* @param userUpdateDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Boolean updateUserInfo(UserUpdateDTO userUpdateDTO) {
|
|
||||||
// 查询用户是否存在
|
|
||||||
UserDO userDO = userMapper.selectById(userUpdateDTO.getId());
|
|
||||||
if (null == userDO) {
|
|
||||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 更新用户信息
|
|
||||||
UserDO updateDO = UserConvert.INSTANCE.convertToUserDO(userUpdateDTO);
|
|
||||||
userMapper.updateById(updateDO);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户状态
|
|
||||||
* @param userUpdateStatusDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Boolean updateUserStatus(UserUpdateStatusDTO userUpdateStatusDTO) {
|
|
||||||
// 查询用户是否存在
|
|
||||||
UserDO userDO = userMapper.selectById(userUpdateStatusDTO.getId());
|
|
||||||
if (null == userDO) {
|
|
||||||
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 判断更新状态是否存在
|
|
||||||
if (null != userUpdateStatusDTO.getStatus() &&
|
|
||||||
Arrays.stream(UserStatusEnum.ARRAYS).noneMatch(status -> status == userUpdateStatusDTO.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(USER_STATUS_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 如果状态相同,则返回错误
|
|
||||||
if (null != userUpdateStatusDTO.getStatus() && userUpdateStatusDTO.getStatus().equals(userDO.getStatus())) {
|
|
||||||
throw ServiceExceptionUtil.exception(USER_STATUS_EQUALS);
|
|
||||||
}
|
|
||||||
// 更新用户信息
|
|
||||||
UserDO updateStatusDO = UserConvert.INSTANCE.convertToUserDO(userUpdateStatusDTO);
|
|
||||||
userMapper.updateById(updateStatusDO);
|
|
||||||
// TODO 伟帆 操作日志
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.controller.admin;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.enums.MallConstants;
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.service.user.UserService;
|
|
||||||
import cn.iocoder.mall.system.rest.convert.admin.AdminsUserConvert;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserPageRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateStatusRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.response.admin.AdminsUserPageResponse;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 管理员 - 用户信息
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/user-info")
|
|
||||||
@Api(tags = "管理员 - 用户信息 API")
|
|
||||||
public class AdminsUserController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@GetMapping("/page")
|
|
||||||
@ApiOperation(value = "用户分页列表")
|
|
||||||
public CommonResult<PageResult<AdminsUserPageResponse>> page(AdminsUserPageRequest adminsUserPageRequest) {
|
|
||||||
PageResult<UserBO> userPage = userService.getUserPage(AdminsUserConvert.INSTANCE.convertToPageDTO(adminsUserPageRequest));
|
|
||||||
return success(AdminsUserConvert.INSTANCE.convertToPageResponse(userPage));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/update")
|
|
||||||
@ApiOperation(value = "更新用户基本信息")
|
|
||||||
public CommonResult<Boolean> update(AdminsUserUpdateRequest adminsUserUpdateRequest) {
|
|
||||||
return success(userService.updateUserInfo(AdminsUserConvert.INSTANCE.convertToUpdateDTO(adminsUserUpdateRequest)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/update_status")
|
|
||||||
@ApiOperation(value = "更新用户状态")
|
|
||||||
public CommonResult<Boolean> updateStatus(AdminsUserUpdateStatusRequest adminsUserUpdateStatusRequest) {
|
|
||||||
return success(userService.updateUserStatus(AdminsUserConvert.INSTANCE.convertToUpdateStatusDTO(adminsUserUpdateStatusRequest)));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.convert.admin;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserPageDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.user.UserUpdateStatusDTO;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserPageRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.admin.AdminsUserUpdateStatusRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.response.admin.AdminsUserPageResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: jiangweifan
|
|
||||||
* @Date: 2020/5/12
|
|
||||||
* @Description: 管理后台 - 用户数据转换
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface AdminsUserConvert {
|
|
||||||
|
|
||||||
AdminsUserConvert INSTANCE = Mappers.getMapper(AdminsUserConvert.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取用户列表 - Request转DTO
|
|
||||||
* @param adminsUserPageRequest
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
UserPageDTO convertToPageDTO(AdminsUserPageRequest adminsUserPageRequest);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户信息 - Request转DTO
|
|
||||||
* @param adminsUserUpdateRequest
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
UserUpdateDTO convertToUpdateDTO(AdminsUserUpdateRequest adminsUserUpdateRequest);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户状态 - Request转DTO
|
|
||||||
* @param adminsUserUpdateStatusRequest
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
UserUpdateStatusDTO convertToUpdateStatusDTO(AdminsUserUpdateStatusRequest adminsUserUpdateStatusRequest);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取用户列表 - BO转Response
|
|
||||||
* @param userPage
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
PageResult<AdminsUserPageResponse> convertToPageResponse(PageResult<UserBO> userPage);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.convert.systemlog;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.systemlog.AccessLogBO;
|
|
||||||
import cn.iocoder.mall.system.rest.response.systemlog.AccessLogPageResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mappings;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author:ycjx
|
|
||||||
* @descriptio
|
|
||||||
* @create:2019-06-23 17:36
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface AccessLogConvert {
|
|
||||||
|
|
||||||
|
|
||||||
AccessLogConvert INSTANCE = Mappers.getMapper(AccessLogConvert.class);
|
|
||||||
|
|
||||||
|
|
||||||
@Mappings({}) // TODO FROM 芋艿 to 2447007062:注意空行哟;另外,如果不需要专门 mapping,可以不添加该注解,嘿嘿。
|
|
||||||
PageResult<AccessLogPageResponse> convert(PageResult<AccessLogBO> result);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.request.errorcode;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
|
|
||||||
@ApiModel("管理员 - 错误码模块 - 添加错误码 Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class ErrorCodeAddRequest {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码信息", required = true, example = "系统管理员")
|
|
||||||
@NotEmpty(message = "错误码信息不能为空")
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码编码", example = "SUPER_ADMIN")
|
|
||||||
@NotEmpty(message = "错误码编码不能为空")
|
|
||||||
private Integer code;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码分组,字典表获取")
|
|
||||||
@NotEmpty(message = "错误码分组不能为空")
|
|
||||||
private Integer group;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码角色,系统内置(枚举)还是自定义")
|
|
||||||
@NotEmpty(message = "错误码角色不能空")
|
|
||||||
private Integer type;
|
|
||||||
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.request.errorcode;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ding
|
|
||||||
*/
|
|
||||||
@ApiModel("管理员 - 错误码模块 - 错误码分页 Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class ErrorCodePageRequest {
|
|
||||||
|
|
||||||
// TODO FROM 芋艿 to 鱿鱼须:分页参数?
|
|
||||||
// TODO FROM 芋艿 to 鱿鱼须:对于 rest 的接口,要区分下是给 Admins 管理员还是 Users 用户的
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.request.errorcode;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 类 描 述:错误码模块
|
|
||||||
* @author ding
|
|
||||||
*/
|
|
||||||
@ApiModel("管理员 - 错误码模块 - 修改错误码 Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class ErrorCodeUpdateRequest {
|
|
||||||
@ApiModelProperty(value = "错误码编号", required = true, example = "1")
|
|
||||||
@NotNull(message = "错误码不能为空")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码信息", required = true, example = "系统管理员")
|
|
||||||
@NotEmpty(message = "错误码信息不能为空")
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码编码", example = "SUPER_ADMIN")
|
|
||||||
@NotEmpty(message = "错误码编码不能为空")
|
|
||||||
private Integer code;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.response.authorization;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ApiModel(value = "管理员 - 授权模块 - 菜单资源树 Response", description = "一般用于首页菜单树")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsAuthorizationMenuTreeResponse {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单编号", required = true, example = "1")
|
|
||||||
private Integer id;
|
|
||||||
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
|
|
||||||
private String name;
|
|
||||||
@ApiModelProperty(value = "前端路由", required = true, example = "/order/list")
|
|
||||||
private String route;
|
|
||||||
@ApiModelProperty(value = "菜单图标", required = true, example = "user")
|
|
||||||
private String icon;
|
|
||||||
/**
|
|
||||||
* 子节点数组
|
|
||||||
*/
|
|
||||||
private List<AdminsAuthorizationMenuTreeResponse> children;
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.response.authorization;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ApiModel(value = "管理员 - 授权模块 - 角色拥有的资源树 Response")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsAuthorizationRoleResourceTreeResponse {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单编号", required = true, example = "1")
|
|
||||||
private Integer id;
|
|
||||||
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
|
|
||||||
private String name;
|
|
||||||
@ApiModelProperty(value = "是否分配", required = true, notes = "即角色是否拥有该资源")
|
|
||||||
private Boolean assigned;
|
|
||||||
/**
|
|
||||||
* 子节点数组
|
|
||||||
*/
|
|
||||||
private List<AdminsAuthorizationRoleResourceTreeResponse> children;
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.response.authorization;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ApiModel("管理员 - 授权模块 - 菜单资源树 Response")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsResourceTreeResponse {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单编号", required = true, example = "1")
|
|
||||||
private Integer id;
|
|
||||||
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
|
|
||||||
private String name;
|
|
||||||
@ApiModelProperty(value = "权限标识", example = "/order/list")
|
|
||||||
private String permission;
|
|
||||||
@ApiModelProperty(value = "资源类型", required = true, example = "1-菜单;2-按钮")
|
|
||||||
private Integer type;
|
|
||||||
@ApiModelProperty(value = "排序", required = true, example = "1")
|
|
||||||
private Integer sort;
|
|
||||||
@ApiModelProperty(value = "父菜单编号", required = true, example = "1", notes = "如果无父菜单,则值为 0")
|
|
||||||
private Integer pid;
|
|
||||||
@ApiModelProperty(value = "前端路由", example = "/order/list")
|
|
||||||
private String route;
|
|
||||||
@ApiModelProperty(value = "菜单图标", example = "user")
|
|
||||||
private String icon;
|
|
||||||
/**
|
|
||||||
* 子节点数组
|
|
||||||
*/
|
|
||||||
private List<AdminsResourceTreeResponse> children;
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.response.errorcode;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 类 描 述:错误码模块
|
|
||||||
* @author ding
|
|
||||||
*/
|
|
||||||
@ApiModel("管理员 - 错误码模块 - 查询错误码 Request")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class ErrorCodePageResponse {
|
|
||||||
/**
|
|
||||||
* 错误码编号
|
|
||||||
*/
|
|
||||||
private Integer id;
|
|
||||||
/**
|
|
||||||
* 错误码编码
|
|
||||||
*/
|
|
||||||
private Integer code;
|
|
||||||
/**
|
|
||||||
* 错误码错误信息
|
|
||||||
*/
|
|
||||||
private String message;
|
|
||||||
/**
|
|
||||||
* 添加时间
|
|
||||||
*/
|
|
||||||
private Date createTime;
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.response.systemlog;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author mxc
|
|
||||||
* @date 2020/5/11 22:11
|
|
||||||
*/
|
|
||||||
@ApiModel("访问日志 VO")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AccessLogPageResponse {
|
|
||||||
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "链路追踪编号", required = true, example = "1")
|
|
||||||
private String traceId;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "账号编号", required = true, example = "1")
|
|
||||||
private Integer accountId;;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "应用名", required = true, example = "1")
|
|
||||||
private String applicationName;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "访问地址", required = true, example = "1")
|
|
||||||
private String uri;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "请求参数", required = true, example = "1")
|
|
||||||
private String queryString;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "http 请求方法", required = true, example = "1")
|
|
||||||
private String method;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "User-Agent ", required = true, example = "1")
|
|
||||||
private String userAgent;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "ip", required = true, example = "1")
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "请求时间", required = true, example = "1")
|
|
||||||
private Date startTime;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "响应时长", required = true, example = "1")
|
|
||||||
private Integer responseTime;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "错误码", required = true, example = "1")
|
|
||||||
private Integer errorCode;
|
|
||||||
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>system</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>system-rpc-api</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>system-biz-api</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 工具类相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.validation</groupId>
|
|
||||||
<artifactId>validation-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,15 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rpc.api.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
|
||||||
import cn.iocoder.mall.system.rpc.response.user.UserResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User RPC 接口
|
|
||||||
*/
|
|
||||||
public interface UserRPC {
|
|
||||||
|
|
||||||
// CommonResult<UserResponse> getUser(Integer id);
|
|
||||||
|
|
||||||
CommonResult<UserResponse> getUserByAccountId(Integer accountId);
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rpc.response.user;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User 模块 - User 信息 Response
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class UserResponse implements Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户编号
|
|
||||||
*/
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>system</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>system-rpc</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>system-rpc-api</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>system-biz</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- RPC 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Registry 和 Config 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,15 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rpc.convert.user;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.rpc.response.user.UserResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserConvert {
|
|
||||||
|
|
||||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
|
||||||
|
|
||||||
UserResponse convert(UserBO bean);
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rpc.rpc.user;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserBO;
|
|
||||||
import cn.iocoder.mall.system.biz.service.user.UserService;
|
|
||||||
import cn.iocoder.mall.system.rpc.api.user.UserRPC;
|
|
||||||
import cn.iocoder.mall.system.rpc.convert.user.UserConvert;
|
|
||||||
import cn.iocoder.mall.system.rpc.response.user.UserResponse;
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
@Service(version = "${dubbo.provider.UserRPC.version}", validation = "true")
|
|
||||||
public class UserRPCImpl implements UserRPC {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CommonResult<UserResponse> getUserByAccountId(Integer accountId) {
|
|
||||||
UserBO userBO = userService.getUserByAccountId(accountId);
|
|
||||||
return CommonResult.success(UserConvert.INSTANCE.convert(userBO));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
spring:
|
|
||||||
# Spring Cloud 配置项
|
|
||||||
cloud:
|
|
||||||
nacos:
|
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
|
||||||
discovery:
|
|
||||||
server-addr: 400-infra.server.iocoder.cn:8848 # Nacos 服务器地址
|
|
||||||
namespace: local # Nacos 命名空间
|
|
||||||
|
|
||||||
# Dubbo 配置项
|
|
||||||
dubbo:
|
|
||||||
# Dubbo 注册中心
|
|
||||||
registry:
|
|
||||||
address: spring-cloud://400-infra.server.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
|
@ -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 服务注册中心的地址
|
|
@ -1,44 +0,0 @@
|
|||||||
# Dubbo 配置项
|
|
||||||
dubbo:
|
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
|
||||||
cloud:
|
|
||||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
|
||||||
# Dubbo 提供者的协议
|
|
||||||
protocol:
|
|
||||||
name: dubbo
|
|
||||||
port: -1
|
|
||||||
# Dubbo 提供服务的扫描基础包
|
|
||||||
scan:
|
|
||||||
base-packages: cn.iocoder.mall.system.rpc.rpc
|
|
||||||
# Dubbo 服务提供者的配置
|
|
||||||
provider:
|
|
||||||
filter: -exception
|
|
||||||
SystemLogRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
OAuth2RPC:
|
|
||||||
version: 1.0.0
|
|
||||||
AuthorizationRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
AdminRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
UserRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
UserAddressRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
ErrorCodeRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
|
|
||||||
# Dubbo 服务消费者的配置
|
|
||||||
consumer:
|
|
||||||
SystemLogRPC: # 用于 AccessLogInterceptor 等拦截器,记录 HTTP API 请求的访问日志
|
|
||||||
version: 1.0.0
|
|
||||||
OAuth2RPC: # 用于 AccountAuthInterceptor 拦截器,执行认证
|
|
||||||
version: 1.0.0
|
|
||||||
AuthorizationRPC: # 用于 AccountAuthInterceptor 拦截器,执行鉴权(权限验证)
|
|
||||||
version: 1.0.0
|
|
||||||
AdminRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
UserRPC:
|
|
||||||
version: 1.0.0
|
|
||||||
ErrorCodeRPC:
|
|
||||||
version: 1.0.0
|
|
@ -34,6 +34,12 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>system-service-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 自身项目 -->
|
<!-- 自身项目 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
@ -24,7 +24,7 @@ public interface UserErrorCodeConstants {
|
|||||||
|
|
||||||
// ========== 用户信息模块 1004004100 ==========
|
// ========== 用户信息模块 1004004100 ==========
|
||||||
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004004100, "用户不存在");
|
ErrorCode USER_NOT_EXISTS = new ErrorCode(1004004100, "用户不存在");
|
||||||
ErrorCode USER_STATUS_NOT_EXISTS = new ErrorCode(1004004101, "用户状态不存在");
|
|
||||||
ErrorCode USER_STATUS_EQUALS = new ErrorCode(1004004101, "用户已经是该状态");
|
ErrorCode USER_STATUS_EQUALS = new ErrorCode(1004004101, "用户已经是该状态");
|
||||||
|
ErrorCode USER_MOBILE_EXISTS = new ErrorCode(1004004102, "手机号已经存在");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.sms;
|
package cn.iocoder.mall.userservice.rpc.sms;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserSendSmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserVerifySmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户短信验证码 Rpc 接口
|
* 用户短信验证码 Rpc 接口
|
||||||
*/
|
*/
|
||||||
public interface UserSmsCodeRpc {
|
public interface UserSmsCodeRpc {
|
||||||
|
|
||||||
CommonResult<Boolean> sendSmsCode(UserSendSmsCodeDTO sendSmsCodeDTO);
|
CommonResult<Boolean> sendSmsCode(UserSendSmsCodeReqDTO sendSmsCodeDTO);
|
||||||
|
|
||||||
CommonResult<Boolean> verifySmsCode(UserVerifySmsCodeDTO verifySmsCodeDTO);
|
CommonResult<Boolean> verifySmsCode(UserVerifySmsCodeReqDTO verifySmsCodeDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.sms.vo;
|
package cn.iocoder.mall.userservice.rpc.sms.dto;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.validator.InEnum;
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
||||||
@ -10,12 +10,12 @@ import javax.validation.constraints.NotNull;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户发送短信验证码 DTO
|
* 用户发送短信验证码 Request DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Builder
|
@Builder
|
||||||
public class UserSendSmsCodeDTO implements Serializable {
|
public class UserSendSmsCodeReqDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.sms.vo;
|
package cn.iocoder.mall.userservice.rpc.sms.dto;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.validator.InEnum;
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
||||||
@ -10,12 +10,12 @@ import javax.validation.constraints.NotNull;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户校验验证码 DTO
|
* 用户校验验证码 Request DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Builder
|
@Builder
|
||||||
public class UserVerifySmsCodeDTO implements Serializable {
|
public class UserVerifySmsCodeReqDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
@ -1,13 +1,54 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.user;
|
package cn.iocoder.mall.userservice.rpc.user;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserPageReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserRpc {
|
public interface UserRpc {
|
||||||
|
|
||||||
CommonResult<UserVO> getUser(Integer id);
|
/**
|
||||||
|
* 获得用户
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
CommonResult<UserRespDTO> getUser(Integer userId);
|
||||||
|
|
||||||
CommonResult<UserVO> createUserIfAbsent(UserCreateDTO createDTO);
|
/**
|
||||||
|
* 基于手机号创建用户。
|
||||||
|
* 如果用户已经存在,则直接进行返回
|
||||||
|
*
|
||||||
|
* @param createDTO 创建用户 DTO
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
CommonResult<UserRespDTO> createUserIfAbsent(UserCreateReqDTO createDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户
|
||||||
|
*
|
||||||
|
* @param updateDTO 更新用户 DTO
|
||||||
|
*/
|
||||||
|
CommonResult<Boolean> updateUser(UserUpdateReqDTO updateDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户列表
|
||||||
|
*
|
||||||
|
* @param userIds 用户编号列表
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
CommonResult<List<UserRespDTO>> listUsers(List<Integer> userIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户分页
|
||||||
|
*
|
||||||
|
* @param pageDTO 用户分页查询
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
CommonResult<PageResult<UserRespDTO>> pageUser(UserPageReqDTO pageDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ import javax.validation.constraints.NotNull;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户创建 DTO
|
* 用户创建 Request DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class UserCreateDTO implements Serializable {
|
public class UserCreateReqDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.mall.userservice.rpc.user.dto;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import cn.iocoder.common.framework.vo.PageParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户分页 Request DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserPageReqDTO extends PageParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昵称,模糊匹配
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.user.vo;
|
package cn.iocoder.mall.userservice.rpc.user.dto;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -7,11 +7,11 @@ import lombok.experimental.Accessors;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户响应
|
* 用户信息 Response DTO
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class UserVO implements Serializable {
|
public class UserRespDTO implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户编号
|
* 用户编号
|
@ -0,0 +1,47 @@
|
|||||||
|
package cn.iocoder.mall.userservice.rpc.user.dto;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.Mobile;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户更新 Request DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserUpdateReqDTO implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
@Mobile
|
||||||
|
private String mobile;
|
||||||
|
/**
|
||||||
|
* 加密后的密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
@ -17,6 +17,12 @@
|
|||||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!-- 系统服务 -->
|
||||||
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
<artifactId>system-service-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<!-- 用户服务 -->
|
<!-- 用户服务 -->
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
<groupId>cn.iocoder.mall</groupId>
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package cn.iocoder.mall.userservice.config;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
|
||||||
import cn.iocoder.mall.userservice.enums.UserErrorCodeConstants;
|
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.event.EventListener;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class ServiceExceptionConfiguration {
|
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
|
||||||
public void initMessages() {
|
|
||||||
Arrays.stream(UserErrorCodeConstants.values()).forEach(
|
|
||||||
item -> ServiceExceptionUtil.put(item.getCode(), item.getMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +1,49 @@
|
|||||||
package cn.iocoder.mall.userservice.convert.user;
|
package cn.iocoder.mall.userservice.convert.user;
|
||||||
|
|
||||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserPageReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||||
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
||||||
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
import cn.iocoder.mall.userservice.service.user.bo.UserCreateBO;
|
import cn.iocoder.mall.userservice.service.user.bo.UserCreateBO;
|
||||||
|
import cn.iocoder.mall.userservice.service.user.bo.UserPageBO;
|
||||||
|
import cn.iocoder.mall.userservice.service.user.bo.UserUpdateBO;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserConvert {
|
public interface UserConvert {
|
||||||
|
|
||||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||||
|
|
||||||
UserVO convert(UserBO bean);
|
UserRespDTO convert(UserBO bean);
|
||||||
|
|
||||||
UserBO convert(UserDO bean);
|
UserBO convert(UserDO bean);
|
||||||
|
|
||||||
UserDO convert(UserCreateBO bean);
|
UserDO convert(UserCreateBO bean);
|
||||||
|
|
||||||
@Mapping(source = "ip", target = "createIp")
|
@Mapping(source = "ip", target = "createIp")
|
||||||
UserCreateBO convert(UserCreateDTO createDTO);
|
UserCreateBO convert(UserCreateReqDTO bean);
|
||||||
|
|
||||||
|
UserDO convert(UserUpdateBO bean);
|
||||||
|
|
||||||
|
@Mapping(source = "records", target = "list")
|
||||||
|
PageResult<UserBO> convertPage(IPage<UserDO> page);
|
||||||
|
|
||||||
|
UserUpdateBO convert(UserUpdateReqDTO bean);
|
||||||
|
|
||||||
|
List<UserBO> convertList(List<UserDO> list);
|
||||||
|
|
||||||
|
UserPageBO convert(UserPageReqDTO bean);
|
||||||
|
|
||||||
|
PageResult<UserRespDTO> convertPage(PageResult<UserBO> page);
|
||||||
|
|
||||||
|
List<UserRespDTO> convertList02(List<UserBO> list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package cn.iocoder.mall.userservice.dal.mysql.mapper.user;
|
package cn.iocoder.mall.userservice.dal.mysql.mapper.user;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||||
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
||||||
|
import cn.iocoder.mall.userservice.service.user.bo.UserPageBO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@ -14,18 +18,10 @@ public interface UserMapper extends BaseMapper<UserDO> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
default IPage<UserDO> selectPage(UserPageBO pageBO) {
|
||||||
// * 根据条件分页查询用户列表
|
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
|
||||||
// * @param userPageDTO
|
new QueryWrapperX<UserDO>().likeIfPresent("nickname", pageBO.getNickname())
|
||||||
// * @return
|
.eqIfPresent("status", pageBO.getStatus()));
|
||||||
// */
|
}
|
||||||
// default IPage<UserDO> selectUserPage(UserPageDTO userPageDTO) {
|
|
||||||
// // TODO FROM 芋艿 to jwf1173:看下 QueryWrapperX 噢,已经提供判空啦 [DONE]
|
|
||||||
// return this.selectPage(new Page<>(userPageDTO.getPageNo(), userPageDTO.getPageSize()),
|
|
||||||
// new QueryWrapperX<UserDO>()
|
|
||||||
// .eq(StringUtils.isNotBlank(userPageDTO.getNickname()), "nickname", userPageDTO.getNickname())
|
|
||||||
// .eq(null != userPageDTO.getStatus(), "status", userPageDTO.getStatus())
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.mall.userservice.manager.sms;
|
package cn.iocoder.mall.userservice.manager.sms;
|
||||||
|
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserSendSmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserVerifySmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.service.sms.UserSmsCodeService;
|
import cn.iocoder.mall.userservice.service.sms.UserSmsCodeService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -12,14 +12,14 @@ public class UserSmsCodeManager {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserSmsCodeService userSmsCodeService;
|
private UserSmsCodeService userSmsCodeService;
|
||||||
|
|
||||||
public void sendSmsCode(UserSendSmsCodeDTO sendSmsCodeDTO) {
|
public void sendSmsCode(UserSendSmsCodeReqDTO sendSmsCodeDTO) {
|
||||||
// 生成短信验证码
|
// 生成短信验证码
|
||||||
String smsCode = userSmsCodeService.createSmsCode(sendSmsCodeDTO.getMobile(),
|
String smsCode = userSmsCodeService.createSmsCode(sendSmsCodeDTO.getMobile(),
|
||||||
sendSmsCodeDTO.getScene(), sendSmsCodeDTO.getIp());
|
sendSmsCodeDTO.getScene(), sendSmsCodeDTO.getIp());
|
||||||
// TODO 调用发送验证码
|
// TODO 调用发送验证码
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifySmsCode(UserVerifySmsCodeDTO verifySmsCodeDTO) {
|
public void verifySmsCode(UserVerifySmsCodeReqDTO verifySmsCodeDTO) {
|
||||||
userSmsCodeService.verifySmsCode(verifySmsCodeDTO.getMobile(), verifySmsCodeDTO.getCode(),
|
userSmsCodeService.verifySmsCode(verifySmsCodeDTO.getMobile(), verifySmsCodeDTO.getCode(),
|
||||||
verifySmsCodeDTO.getScene(), verifySmsCodeDTO.getIp());
|
verifySmsCodeDTO.getScene(), verifySmsCodeDTO.getIp());
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,34 @@
|
|||||||
package cn.iocoder.mall.userservice.manager.user;
|
package cn.iocoder.mall.userservice.manager.user;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
||||||
|
import cn.iocoder.common.framework.util.StringUtils;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
||||||
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2RemoveTokenByUserReqDTO;
|
||||||
import cn.iocoder.mall.userservice.convert.user.UserConvert;
|
import cn.iocoder.mall.userservice.convert.user.UserConvert;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserPageReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||||
import cn.iocoder.mall.userservice.service.user.UserService;
|
import cn.iocoder.mall.userservice.service.user.UserService;
|
||||||
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
||||||
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserManager {
|
public class UserManager {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
public UserVO getUser(Integer id) {
|
@DubboReference(version = "${dubbo.consumer.OAuth2Rpc.version}")
|
||||||
UserBO userBO = userService.getUser(id);
|
private OAuth2Rpc oauth2Rpc;
|
||||||
return UserConvert.INSTANCE.convert(userBO);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserVO createUserIfAbsent(UserCreateDTO createDTO) {
|
public UserRespDTO createUserIfAbsent(UserCreateReqDTO createDTO) {
|
||||||
// 用户已经存在
|
// 用户已经存在
|
||||||
UserBO userBO = userService.getUser(createDTO.getMobile());
|
UserBO userBO = userService.getUser(createDTO.getMobile());
|
||||||
if (userBO != null) {
|
if (userBO != null) {
|
||||||
@ -30,4 +39,53 @@ public class UserManager {
|
|||||||
return UserConvert.INSTANCE.convert(userBO);
|
return UserConvert.INSTANCE.convert(userBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户
|
||||||
|
*
|
||||||
|
* @param updateDTO 更新用户 DTO
|
||||||
|
*/
|
||||||
|
public void updateUser(UserUpdateReqDTO updateDTO) {
|
||||||
|
// 更新管理员信息
|
||||||
|
userService.updateUser(UserConvert.INSTANCE.convert(updateDTO));
|
||||||
|
// 如果修改密码,或者禁用管理员
|
||||||
|
if (StringUtils.hasText(updateDTO.getPassword())
|
||||||
|
|| CommonStatusEnum.DISABLE.getValue().equals(updateDTO.getStatus())) {
|
||||||
|
oauth2Rpc.removeToken(new OAuth2RemoveTokenByUserReqDTO().setUserId(updateDTO.getId())
|
||||||
|
.setUserType(UserTypeEnum.ADMIN.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @return 用户
|
||||||
|
*/
|
||||||
|
public UserRespDTO getUser(Integer userId) {
|
||||||
|
UserBO userBO = userService.getUser(userId);
|
||||||
|
return UserConvert.INSTANCE.convert(userBO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户列表
|
||||||
|
*
|
||||||
|
* @param userIds 用户编号列表
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
public List<UserRespDTO> listUsers(List<Integer> userIds) {
|
||||||
|
List<UserBO> userBOs = userService.listUsers(userIds);
|
||||||
|
return UserConvert.INSTANCE.convertList02(userBOs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户分页
|
||||||
|
*
|
||||||
|
* @param pageDTO 用户分页查询
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
public PageResult<UserRespDTO> pageUser(UserPageReqDTO pageDTO) {
|
||||||
|
PageResult<UserBO> pageResultBO = userService.pageUser(UserConvert.INSTANCE.convert(pageDTO));
|
||||||
|
return UserConvert.INSTANCE.convertPage(pageResultBO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ package cn.iocoder.mall.userservice.rpc.sms;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.userservice.manager.sms.UserSmsCodeManager;
|
import cn.iocoder.mall.userservice.manager.sms.UserSmsCodeManager;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserSendSmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserVerifySmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.Service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
@ -14,13 +14,13 @@ public class UserSmsCodeRpcImpl implements UserSmsCodeRpc {
|
|||||||
private UserSmsCodeManager userSmsCodeManager;
|
private UserSmsCodeManager userSmsCodeManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Boolean> sendSmsCode(UserSendSmsCodeDTO sendSmsCodeDTO) {
|
public CommonResult<Boolean> sendSmsCode(UserSendSmsCodeReqDTO sendSmsCodeDTO) {
|
||||||
userSmsCodeManager.sendSmsCode(sendSmsCodeDTO);
|
userSmsCodeManager.sendSmsCode(sendSmsCodeDTO);
|
||||||
return CommonResult.success(true);
|
return CommonResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Boolean> verifySmsCode(UserVerifySmsCodeDTO verifySmsCodeDTO) {
|
public CommonResult<Boolean> verifySmsCode(UserVerifySmsCodeReqDTO verifySmsCodeDTO) {
|
||||||
userSmsCodeManager.verifySmsCode(verifySmsCodeDTO);
|
userSmsCodeManager.verifySmsCode(verifySmsCodeDTO);
|
||||||
return CommonResult.success(true);
|
return CommonResult.success(true);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package cn.iocoder.mall.userservice.rpc.user;
|
package cn.iocoder.mall.userservice.rpc.user;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
import cn.iocoder.mall.userservice.manager.user.UserManager;
|
import cn.iocoder.mall.userservice.manager.user.UserManager;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserPageReqDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserRespDTO;
|
||||||
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserUpdateReqDTO;
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.Service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||||
|
|
||||||
@Service(version = "${dubbo.provider.UserRpc.version}", validation = "false")
|
@Service(version = "${dubbo.provider.UserRpc.version}", validation = "false")
|
||||||
@ -16,13 +21,29 @@ public class UserRpcImpl implements UserRpc {
|
|||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<UserVO> getUser(Integer id) {
|
public CommonResult<UserRespDTO> getUser(Integer id) {
|
||||||
return success(userManager.getUser(id));
|
return success(userManager.getUser(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<UserVO> createUserIfAbsent(UserCreateDTO createDTO) {
|
public CommonResult<List<UserRespDTO>> listUsers(List<Integer> userIds) {
|
||||||
|
return success(userManager.listUsers(userIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<UserRespDTO> createUserIfAbsent(UserCreateReqDTO createDTO) {
|
||||||
return success(userManager.createUserIfAbsent(createDTO));
|
return success(userManager.createUserIfAbsent(createDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Boolean> updateUser(UserUpdateReqDTO updateDTO) {
|
||||||
|
userManager.updateUser(updateDTO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<PageResult<UserRespDTO>> pageUser(UserPageReqDTO pageDTO) {
|
||||||
|
return success(userManager.pageUser(pageDTO));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
package cn.iocoder.mall.userservice.service.user;
|
package cn.iocoder.mall.userservice.service.user;
|
||||||
|
|
||||||
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||||
import cn.iocoder.common.framework.util.DigestUtils;
|
import cn.iocoder.common.framework.util.DigestUtils;
|
||||||
import cn.iocoder.common.framework.util.StringUtils;
|
import cn.iocoder.common.framework.util.StringUtils;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
import cn.iocoder.mall.userservice.convert.user.UserConvert;
|
import cn.iocoder.mall.userservice.convert.user.UserConvert;
|
||||||
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
|
||||||
import cn.iocoder.mall.userservice.dal.mysql.mapper.user.UserMapper;
|
import cn.iocoder.mall.userservice.dal.mysql.mapper.user.UserMapper;
|
||||||
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
|
||||||
import cn.iocoder.mall.userservice.service.user.bo.UserCreateBO;
|
import cn.iocoder.mall.userservice.service.user.bo.UserCreateBO;
|
||||||
|
import cn.iocoder.mall.userservice.service.user.bo.UserPageBO;
|
||||||
|
import cn.iocoder.mall.userservice.service.user.bo.UserUpdateBO;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.mall.userservice.enums.UserErrorCodeConstants.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
|
||||||
@ -22,6 +31,17 @@ public class UserService {
|
|||||||
return UserConvert.INSTANCE.convert(userDO);
|
return UserConvert.INSTANCE.convert(userDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户列表
|
||||||
|
*
|
||||||
|
* @param userIds 用户编号列表
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
public List<UserBO> listUsers(List<Integer> userIds) {
|
||||||
|
List<UserDO> userDOs = userMapper.selectBatchIds(userIds);
|
||||||
|
return UserConvert.INSTANCE.convertList(userDOs);
|
||||||
|
}
|
||||||
|
|
||||||
public UserBO getUser(String mobile) {
|
public UserBO getUser(String mobile) {
|
||||||
UserDO userDO = userMapper.selectByMobile(mobile);
|
UserDO userDO = userMapper.selectByMobile(mobile);
|
||||||
return UserConvert.INSTANCE.convert(userDO);
|
return UserConvert.INSTANCE.convert(userDO);
|
||||||
@ -43,6 +63,45 @@ public class UserService {
|
|||||||
return UserConvert.INSTANCE.convert(userDO);
|
return UserConvert.INSTANCE.convert(userDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateUser(UserUpdateBO updateBO) {
|
||||||
|
// 校验用户存在
|
||||||
|
UserDO userDO = userMapper.selectById(updateBO.getId());
|
||||||
|
if (userDO == null) {
|
||||||
|
throw ServiceExceptionUtil.exception(USER_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
// 校验手机唯一
|
||||||
|
if (StringUtils.hasText(updateBO.getMobile())) {
|
||||||
|
UserDO mobileAdmin = userMapper.selectByMobile(updateBO.getMobile());
|
||||||
|
if (mobileAdmin != null && !mobileAdmin.getId().equals(updateBO.getId())) {
|
||||||
|
throw ServiceExceptionUtil.exception(USER_MOBILE_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果有更新状态,则校验是否已经是该状态
|
||||||
|
if (updateBO.getStatus() != null && updateBO.getStatus().equals(userDO.getStatus())) {
|
||||||
|
throw ServiceExceptionUtil.exception(USER_STATUS_EQUALS);
|
||||||
|
}
|
||||||
|
// 更新到数据库
|
||||||
|
UserDO updateUser = UserConvert.INSTANCE.convert(updateBO);
|
||||||
|
// 如果更新密码,需要特殊加密
|
||||||
|
if (StringUtils.hasText(updateBO.getPassword())) {
|
||||||
|
String passwordSalt = genPasswordSalt();
|
||||||
|
String password = encodePassword(updateBO.getPassword(), passwordSalt);
|
||||||
|
updateUser.setPassword(password).setPasswordSalt(passwordSalt);
|
||||||
|
}
|
||||||
|
userMapper.updateById(updateUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得用户分页
|
||||||
|
*
|
||||||
|
* @param pageBO 用户分页查询
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
public PageResult<UserBO> pageUser(UserPageBO pageBO) {
|
||||||
|
IPage<UserDO> userDOPage = userMapper.selectPage(pageBO);
|
||||||
|
return UserConvert.INSTANCE.convertPage(userDOPage);
|
||||||
|
}
|
||||||
|
|
||||||
private String genPasswordSalt() {
|
private String genPasswordSalt() {
|
||||||
return DigestUtils.genBcryptSalt();
|
return DigestUtils.genBcryptSalt();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.mall.userservice.service.user.bo;
|
package cn.iocoder.mall.userservice.service.user.bo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.validator.Mobile;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ public class UserCreateBO {
|
|||||||
* 手机
|
* 手机
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "手机号不能为空")
|
@NotNull(message = "手机号不能为空")
|
||||||
|
@Mobile
|
||||||
private String mobile;
|
private String mobile;
|
||||||
/**
|
/**
|
||||||
* 原始密码,允许空
|
* 原始密码,允许空
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package cn.iocoder.mall.userservice.service.user.bo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import cn.iocoder.common.framework.vo.PageParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户分页 BO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserPageBO extends PageParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*
|
||||||
|
* 模糊
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package cn.iocoder.mall.userservice.service.user.bo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import cn.iocoder.common.framework.validator.Mobile;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户更新 BO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UserUpdateBO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户编号
|
||||||
|
*/
|
||||||
|
@NotNull(message = "用户编号不能为空")
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 昵称
|
||||||
|
*/
|
||||||
|
private String nickname;
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String avatar;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
@Mobile
|
||||||
|
private String mobile;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
}
|
@ -38,3 +38,7 @@ dubbo:
|
|||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
UserSmsCodeRpc:
|
UserSmsCodeRpc:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
# Dubbo 服务消费者的配置
|
||||||
|
consumer:
|
||||||
|
OAuth2Rpc:
|
||||||
|
versoin: 1.0.0
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package cn.iocoder.mall.userweb.convert.passport;
|
package cn.iocoder.mall.userweb.convert.passport;
|
||||||
|
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserSendSmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserSendSmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserVerifySmsCodeDTO;
|
import cn.iocoder.mall.userservice.rpc.sms.dto.UserVerifySmsCodeReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateReqDTO;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
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.UserPassportLoginBySmsDTO;
|
||||||
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportSendSmsCodeDTO;
|
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.UserPassportVO;
|
||||||
@ -16,15 +16,15 @@ public interface UserPassportConvert {
|
|||||||
|
|
||||||
UserPassportConvert INSTANCE = Mappers.getMapper(UserPassportConvert.class);
|
UserPassportConvert INSTANCE = Mappers.getMapper(UserPassportConvert.class);
|
||||||
|
|
||||||
UserVerifySmsCodeDTO convert(UserPassportLoginBySmsDTO bean);
|
UserVerifySmsCodeReqDTO convert(UserPassportLoginBySmsDTO bean);
|
||||||
UserCreateDTO convert02(UserPassportLoginBySmsDTO bean);
|
UserCreateReqDTO convert02(UserPassportLoginBySmsDTO bean);
|
||||||
|
|
||||||
default UserPassportVO convert(UserVO userVO, OAuth2AccessTokenVO accessTokenVO) {
|
default UserPassportVO convert(UserRespDTO userVO, OAuth2AccessTokenRespDTO accessTokenVO) {
|
||||||
return new UserPassportVO().setUser(convert(userVO)).setAuthorization(convert(accessTokenVO));
|
return new UserPassportVO().setUser(convert(userVO)).setAuthorization(convert(accessTokenVO));
|
||||||
}
|
}
|
||||||
UserPassportVO.User convert(UserVO userVO);
|
UserPassportVO.User convert(UserRespDTO userVO);
|
||||||
UserPassportVO.Authentication convert(OAuth2AccessTokenVO accessTokenVO);
|
UserPassportVO.Authentication convert(OAuth2AccessTokenRespDTO accessTokenVO);
|
||||||
|
|
||||||
UserSendSmsCodeDTO convert(UserPassportSendSmsCodeDTO bean);
|
UserSendSmsCodeReqDTO convert(UserPassportSendSmsCodeDTO bean);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.mall.userweb.convert.user;
|
package cn.iocoder.mall.userweb.convert.user;
|
||||||
|
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
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.UserInfoVO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
@ -10,6 +10,6 @@ public interface UserConvert {
|
|||||||
|
|
||||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||||
|
|
||||||
UserInfoVO convert(UserVO bean);
|
UserInfoVO convert(UserRespDTO bean);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ package cn.iocoder.mall.userweb.manager.passport;
|
|||||||
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
import cn.iocoder.common.framework.enums.UserTypeEnum;
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
import cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenDTO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2CreateAccessTokenReqDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO;
|
import cn.iocoder.mall.systemservice.rpc.oauth.dto.OAuth2AccessTokenRespDTO;
|
||||||
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
||||||
import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc;
|
import cn.iocoder.mall.userservice.rpc.sms.UserSmsCodeRpc;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
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.UserPassportLoginBySmsDTO;
|
||||||
import cn.iocoder.mall.userweb.controller.passport.dto.UserPassportSendSmsCodeDTO;
|
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.UserPassportVO;
|
||||||
@ -32,12 +32,12 @@ public class UserPassportManager {
|
|||||||
UserPassportConvert.INSTANCE.convert(loginBySmsDTO).setScene(UserSmsSceneEnum.LOGIN_BY_SMS.getValue()).setIp(ip));
|
UserPassportConvert.INSTANCE.convert(loginBySmsDTO).setScene(UserSmsSceneEnum.LOGIN_BY_SMS.getValue()).setIp(ip));
|
||||||
verifySmsCodeResult.checkError();
|
verifySmsCodeResult.checkError();
|
||||||
// 获得用户
|
// 获得用户
|
||||||
CommonResult<UserVO> createUserResult = userRpc.createUserIfAbsent(
|
CommonResult<UserRespDTO> createUserResult = userRpc.createUserIfAbsent(
|
||||||
UserPassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip));
|
UserPassportConvert.INSTANCE.convert02(loginBySmsDTO).setIp(ip));
|
||||||
createUserResult.checkError();
|
createUserResult.checkError();
|
||||||
// 创建访问令牌
|
// 创建访问令牌
|
||||||
CommonResult<OAuth2AccessTokenVO> createAccessTokenResult = oauth2Rpc.createAccessToken(
|
CommonResult<OAuth2AccessTokenRespDTO> createAccessTokenResult = oauth2Rpc.createAccessToken(
|
||||||
new OAuth2CreateAccessTokenDTO().setUserId(createUserResult.getData().getId())
|
new OAuth2CreateAccessTokenReqDTO().setUserId(createUserResult.getData().getId())
|
||||||
.setUserType(UserTypeEnum.USER.getValue()).setCreateIp(ip));
|
.setUserType(UserTypeEnum.USER.getValue()).setCreateIp(ip));
|
||||||
createAccessTokenResult.checkError();
|
createAccessTokenResult.checkError();
|
||||||
// 返回
|
// 返回
|
||||||
|
@ -2,7 +2,7 @@ package cn.iocoder.mall.userweb.manager.user;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
||||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
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.UserInfoVO;
|
||||||
import cn.iocoder.mall.userweb.convert.user.UserConvert;
|
import cn.iocoder.mall.userweb.convert.user.UserConvert;
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
import org.apache.dubbo.config.annotation.Reference;
|
||||||
@ -15,7 +15,7 @@ public class UserManager {
|
|||||||
private UserRpc userRpc;
|
private UserRpc userRpc;
|
||||||
|
|
||||||
public UserInfoVO getUser(Integer id) {
|
public UserInfoVO getUser(Integer id) {
|
||||||
CommonResult<UserVO> userResult = userRpc.getUser(id);
|
CommonResult<UserRespDTO> userResult = userRpc.getUser(id);
|
||||||
userResult.checkError();
|
userResult.checkError();
|
||||||
return UserConvert.INSTANCE.convert(userResult.getData());
|
return UserConvert.INSTANCE.convert(userResult.getData());
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
<module>user-rest</module>
|
<module>user-rest</module>
|
||||||
<module>user-rpc</module>
|
<module>user-rpc</module>
|
||||||
<module>user-rpc-api</module>
|
<module>user-rpc-api</module>
|
||||||
<module>user-biz-api</module>
|
|
||||||
<module>user-biz</module>
|
<module>user-biz</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>user</artifactId>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>user-biz-api</artifactId>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- Mall 相关 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>cn.iocoder.mall</groupId>
|
|
||||||
<artifactId>common-framework</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:31 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.user.biz.bo;
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:31 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.user.biz.convert;
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:28 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.user.biz.dao;
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:27 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.user.biz.dataobject;
|
|
@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* author: sin
|
|
||||||
* time: 2020/5/3 8:29 下午
|
|
||||||
*/
|
|
||||||
package cn.iocoder.mall.user.biz.dto;
|
|
@ -1,22 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.api.bo.user;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
@ApiModel("用户认证 BO")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class UserAuthenticationBO {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户编号", required = true, example = "1")
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "昵称", required = true, example = "小王")
|
|
||||||
private String nickname;
|
|
||||||
|
|
||||||
private OAuth2AccessTokenBO token;
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.api.dto.user;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import org.hibernate.validator.constraints.Length;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.Pattern;
|
|
||||||
|
|
||||||
@ApiModel("用户认证 DTO")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class UserAuthenticationByMobileCodeDTO {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
|
||||||
@NotEmpty(message = "手机号不能为空")
|
|
||||||
@Length(min = 11, max = 11, message = "账号长度为 11 位")
|
|
||||||
@Pattern(regexp = "^[0-9]+$", message = "手机号必须都是数字")
|
|
||||||
private String mobile;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "手机验证码", required = true, example = "1024")
|
|
||||||
@NotEmpty(message = "手机验证码不能为空")
|
|
||||||
@Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位")
|
|
||||||
@Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字")
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.biz.convert;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.user.api.bo.user.UserAuthenticationBO;
|
|
||||||
import cn.iocoder.mall.user.api.bo.UserBO;
|
|
||||||
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.user.biz.dataobject.UserDO;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mappings;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserConvert {
|
|
||||||
|
|
||||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
UserBO convert(UserDO userDO);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
UserAuthenticationBO convert2(UserDO userDO);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
UserDO convert(UserUpdateDTO userUpdateDTO);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
List<UserBO> convert(List<UserDO> userDOs);
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.biz.dao;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.user.biz.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);
|
|
||||||
|
|
||||||
int update(UserDO entity);
|
|
||||||
|
|
||||||
UserDO selectByMobile(@Param("mobile") String mobile);
|
|
||||||
|
|
||||||
UserDO selectById(@Param("id") Integer id);
|
|
||||||
|
|
||||||
List<UserDO> selectListByNicknameLike(@Param("nickname") String nickname,
|
|
||||||
@Param("status") Integer status,
|
|
||||||
@Param("offset") Integer offset,
|
|
||||||
@Param("limit") Integer limit);
|
|
||||||
|
|
||||||
Integer selectCountByNicknameLike(@Param("nickname") String nickname,
|
|
||||||
@Param("status") Integer status);
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.biz.dao;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.user.biz.dataobject.UserRegisterDO;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface UserRegisterMapper {
|
|
||||||
|
|
||||||
void insert(UserRegisterDO entity);
|
|
||||||
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.application.controller.admins;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
|
||||||
import cn.iocoder.mall.user.api.UserService;
|
|
||||||
import cn.iocoder.mall.user.api.bo.UserPageBO;
|
|
||||||
import cn.iocoder.mall.user.api.dto.UserPageDTO;
|
|
||||||
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
|
|
||||||
import cn.iocoder.mall.user.application.convert.UserConvert;
|
|
||||||
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/admins/user")
|
|
||||||
@Api("用户模块")
|
|
||||||
public class AdminsUserController {
|
|
||||||
|
|
||||||
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
// 分页
|
|
||||||
@GetMapping("/page")
|
|
||||||
@ApiOperation(value = "用户分页")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"),
|
|
||||||
@ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"),
|
|
||||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"),
|
|
||||||
})
|
|
||||||
public CommonResult<AdminsUserPageVO> page(@RequestParam(value = "nickname", required = false) String nickname,
|
|
||||||
@RequestParam(value = "status", required = false) Integer status,
|
|
||||||
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
|
||||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
|
||||||
UserPageDTO userPageDTO = new UserPageDTO().setNickname(nickname).setStatus(status)
|
|
||||||
.setPageNo(pageNo).setPageSize(pageSize);
|
|
||||||
// 查询分页
|
|
||||||
UserPageBO result = userService.getUserPage(userPageDTO);
|
|
||||||
// 转换结果
|
|
||||||
return success(UserConvert.INSTANCE.convert(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/update")
|
|
||||||
@ApiOperation(value = "更新用户基本信息")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "id", value = "用户编号", required = true, example = "1"),
|
|
||||||
@ApiImplicitParam(name = "nickname", value = "昵称", required = true, example = "小王"),
|
|
||||||
@ApiImplicitParam(name = "avatar", value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg"),
|
|
||||||
})
|
|
||||||
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
|
|
||||||
@RequestParam("nickname") String nickname,
|
|
||||||
@RequestParam("avatar") String avatar) {
|
|
||||||
UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(id).setNickname(nickname).setNickname(nickname).setAvatar(avatar);
|
|
||||||
// 更新
|
|
||||||
return success(userService.updateUser(userUpdateDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/update_status")
|
|
||||||
@ApiOperation(value = "更新用户状态")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "id", value = "用户编号", required = true, example = "1"),
|
|
||||||
@ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"),
|
|
||||||
})
|
|
||||||
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
|
|
||||||
@RequestParam("status") Integer status) {
|
|
||||||
return success(userService.updateUserStatus(id, status));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.application.convert;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.user.application.po.UserAddressAddPO;
|
|
||||||
import cn.iocoder.mall.user.application.po.UserAddressUpdatePO;
|
|
||||||
import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
|
|
||||||
import cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mappings;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sin
|
|
||||||
* @time 2019-04-06 14:19
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface UserAddressConvert {
|
|
||||||
|
|
||||||
UserAddressConvert INSTANCE = Mappers.getMapper(UserAddressConvert.class);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
UserAddressAddDTO convert(UserAddressAddPO userAddressAddPO);
|
|
||||||
|
|
||||||
@Mappings({})
|
|
||||||
UserAddressUpdateDTO convert(UserAddressUpdatePO userAddressUpdatePO);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.application.vo.admins;
|
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@ApiModel("用户分页 VO")
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class AdminsUserPageVO {
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户数组")
|
|
||||||
private List<AdminsUserVO> list;
|
|
||||||
@ApiModelProperty(value = "用户总数")
|
|
||||||
private Integer total;
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.user.application.vo.admins;
|
|
||||||
|
|
||||||
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 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;
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user