mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
refactor: 用户接口和相关功能优化
This commit is contained in:
parent
3411414cba
commit
f78de70869
@ -1,15 +1,14 @@
|
||||
package com.youlai.admin.api;
|
||||
|
||||
import com.youlai.admin.dto.OAuth2ClientDTO;
|
||||
import com.youlai.admin.dto.AuthClientDTO;
|
||||
import com.youlai.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@FeignClient(value = "youlai-admin", contextId = "oauth-client")
|
||||
public interface OAuthClientFeignClient {
|
||||
|
||||
@GetMapping("/api/v1/oauth-clients/getOAuth2ClientById")
|
||||
Result<OAuth2ClientDTO> getOAuth2ClientById(@RequestParam String clientId);
|
||||
Result<AuthClientDTO> getOAuth2ClientById(@RequestParam String clientId);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.youlai.admin.api;
|
||||
|
||||
import com.youlai.admin.api.fallback.UserFeignFallbackClient;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -11,5 +11,5 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
public interface UserFeignClient {
|
||||
|
||||
@GetMapping("/api/v1/users/username/{username}")
|
||||
Result<UserAuthDTO> getUserByUsername(@PathVariable String username);
|
||||
Result<AuthUserDTO> getUserByUsername(@PathVariable String username);
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.youlai.admin.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* OAuth2客户端传输层对象
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2021/1/15
|
||||
*/
|
||||
@Data
|
||||
public class AuthClientDTO {
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端密钥
|
||||
*/
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 资源id列表
|
||||
*/
|
||||
private String resourceIds;
|
||||
|
||||
/**
|
||||
* 域
|
||||
*/
|
||||
private String scope;
|
||||
|
||||
/**
|
||||
* 授权方式
|
||||
*/
|
||||
private String authorizedGrantTypes;
|
||||
|
||||
/**
|
||||
* 回调地址
|
||||
*/
|
||||
private String webServerRedirectUri;
|
||||
|
||||
/**
|
||||
* 权限列表
|
||||
*/
|
||||
private String authorities;
|
||||
|
||||
/**
|
||||
* 认证令牌时效
|
||||
*/
|
||||
private Integer accessTokenValidity;
|
||||
|
||||
/**
|
||||
* 刷新令牌时效
|
||||
*/
|
||||
private Integer refreshTokenValidity;
|
||||
|
||||
/**
|
||||
* 扩展信息
|
||||
*/
|
||||
private String additionalInformation;
|
||||
|
||||
/**
|
||||
* 是否自动放行
|
||||
*/
|
||||
private String autoapprove;
|
||||
|
||||
}
|
@ -5,13 +5,13 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户认证信息
|
||||
* OAuth2认证用户信息传输层对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @author haoxr
|
||||
* @date 2021/9/27
|
||||
*/
|
||||
@Data
|
||||
public class UserAuthDTO {
|
||||
public class AuthUserDTO {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
@ -29,7 +29,7 @@ public class UserAuthDTO {
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 用户状态:1-有效;0-禁用
|
||||
* 用户状态(1:正常;0:禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@ -43,6 +43,4 @@ public class UserAuthDTO {
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.youlai.admin.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 客户端实体
|
||||
*/
|
||||
@Data
|
||||
public class OAuth2ClientDTO {
|
||||
|
||||
@ApiModelProperty(value = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
@ApiModelProperty(value = "客户端密钥")
|
||||
private String clientSecret;
|
||||
|
||||
@ApiModelProperty(value = "资源id列表")
|
||||
private String resourceIds;
|
||||
|
||||
@ApiModelProperty(value = "域")
|
||||
private String scope;
|
||||
|
||||
@ApiModelProperty(value = "授权方式")
|
||||
private String authorizedGrantTypes;
|
||||
|
||||
@ApiModelProperty("回调地址")
|
||||
private String webServerRedirectUri;
|
||||
|
||||
@ApiModelProperty(value = "权限列表")
|
||||
private String authorities;
|
||||
|
||||
@ApiModelProperty(value = "认证令牌时效")
|
||||
private Integer accessTokenValidity;
|
||||
|
||||
@ApiModelProperty(value = "刷新令牌时效")
|
||||
private Integer refreshTokenValidity;
|
||||
|
||||
@ApiModelProperty(value = "扩展信息")
|
||||
private String additionalInformation;
|
||||
|
||||
@ApiModelProperty(value = "是否自动放行")
|
||||
private String autoapprove;
|
||||
|
||||
}
|
@ -33,20 +33,19 @@ public class DictController {
|
||||
|
||||
@ApiOperation(value = "列表分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页数量", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "name", value = "字典名称", paramType = "query", dataType = "String"),
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public Result list( Integer page,Integer limit, String name) {
|
||||
Page<SysDict> result = iSysDictService.page(new Page<>(page, limit), new LambdaQueryWrapper<SysDict>()
|
||||
public Result list(Long pageNum, Long pageSize, String name) {
|
||||
Page<SysDict> result = iSysDictService.page(new Page<>(pageNum, pageSize), new LambdaQueryWrapper<SysDict>()
|
||||
.like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name))
|
||||
.orderByDesc(SysDict::getGmtModified)
|
||||
.orderByDesc(SysDict::getGmtCreate));
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "字典列表")
|
||||
@GetMapping
|
||||
public Result list() {
|
||||
|
@ -35,12 +35,12 @@ public class DictItemController {
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public Result getPageList(
|
||||
Integer page,
|
||||
Integer limit,
|
||||
long pageNum,
|
||||
long pageSize,
|
||||
String name,
|
||||
String dictCode
|
||||
) {
|
||||
IPage<SysDictItem> result = iSysDictItemService.list(new Page<>(page, limit),
|
||||
IPage<SysDictItem> result = iSysDictItemService.list(new Page<>(pageNum, pageSize),
|
||||
new SysDictItem().setName(name).setDictCode(dictCode));
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.admin.dto.OAuth2ClientDTO;
|
||||
import com.youlai.admin.dto.AuthClientDTO;
|
||||
import com.youlai.admin.pojo.entity.SysOauthClient;
|
||||
import com.youlai.admin.service.ISysOauthClientService;
|
||||
import com.youlai.common.result.Result;
|
||||
@ -84,11 +84,11 @@ public class OauthClientController {
|
||||
|
||||
@ApiOperation(hidden = true, value = "获取 OAuth2 客户端认证信息", notes = "Feign 调用")
|
||||
@GetMapping("/getOAuth2ClientById")
|
||||
public Result<OAuth2ClientDTO> getOAuth2ClientById(@RequestParam String clientId) {
|
||||
public Result<AuthClientDTO> getOAuth2ClientById(@RequestParam String clientId) {
|
||||
SysOauthClient client = iSysOauthClientService.getById(clientId);
|
||||
Assert.isTrue(client!=null, "OAuth2 客户端不存在");
|
||||
OAuth2ClientDTO oAuth2ClientDTO = new OAuth2ClientDTO();
|
||||
BeanUtil.copyProperties(client, oAuth2ClientDTO);
|
||||
return Result.success(oAuth2ClientDTO);
|
||||
AuthClientDTO authClientDTO = new AuthClientDTO();
|
||||
BeanUtil.copyProperties(client, authClientDTO);
|
||||
return Result.success(authClientDTO);
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,17 @@ package com.youlai.admin.controller;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.pojo.query.UserPageQuery;
|
||||
import com.youlai.admin.pojo.vo.LoginUserVO;
|
||||
import com.youlai.admin.pojo.vo.UserDetailVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserFormVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserPageVO;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.admin.service.ISysUserRoleService;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.web.util.JwtUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -25,30 +24,37 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Api(tags = "用户接口")
|
||||
/**
|
||||
* 用户管理控制器
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2022/1/15 10:25
|
||||
*/
|
||||
@Api(tags = "用户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/users")
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final ISysUserService iSysUserService;
|
||||
private final ISysUserRoleService iSysUserRoleService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final ISysPermissionService iSysPermissionService;
|
||||
|
||||
@ApiOperation(value = "用户分页列表")
|
||||
@GetMapping
|
||||
public Result list(UserPageQuery queryParam) {
|
||||
IPage<SysUser> result = iSysUserService.list(queryParam);
|
||||
@GetMapping("/page")
|
||||
public Result<List<UserPageVO>> listUsersWithPage(
|
||||
UserPageQuery queryParam
|
||||
) {
|
||||
IPage<UserPageVO> result = iSysUserService.listUsersWithPage(queryParam);
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "用户详情")
|
||||
@GetMapping("/{userId}")
|
||||
public Result<UserDetailVO> getUserDetail(
|
||||
@ApiOperation(value = "获取用户表单详情")
|
||||
@GetMapping("/{userId}/form")
|
||||
public Result<UserFormVO> getUserDetail(
|
||||
@ApiParam(value = "用户ID", example = "1") @PathVariable Long userId
|
||||
) {
|
||||
UserDetailVO userDetail = iSysUserService.getUserDetailById(userId);
|
||||
UserFormVO userDetail = iSysUserService.getUserFormById(userId);
|
||||
return Result.success(userDetail);
|
||||
}
|
||||
|
||||
@ -70,34 +76,38 @@ public class UserController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除用户")
|
||||
@ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete(@PathVariable String ids) {
|
||||
public Result deleteUsers(
|
||||
@ApiParam("用户ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean status = iSysUserService.removeByIds(Arrays.asList(ids.split(",")).stream().collect(Collectors.toList()));
|
||||
return Result.judge(status);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "选择性更新用户")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long")
|
||||
@PatchMapping(value = "/{id}")
|
||||
public Result patch(@PathVariable Long id, @RequestBody SysUser user) {
|
||||
System.out.println(user.getPassword() != null);
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>().eq(SysUser::getId, id);
|
||||
@PatchMapping(value = "/{userId}")
|
||||
public Result updateUserPart(
|
||||
@ApiParam("用户ID") @PathVariable Long userId,
|
||||
@RequestBody SysUser user
|
||||
) {
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>()
|
||||
.eq(SysUser::getId, userId);
|
||||
updateWrapper.set(user.getStatus() != null, SysUser::getStatus, user.getStatus());
|
||||
updateWrapper.set(user.getPassword() != null, SysUser::getPassword, user.getPassword() != null ? passwordEncoder.encode(user.getPassword()) : null);
|
||||
updateWrapper.set(user.getPassword() != null, SysUser::getPassword,
|
||||
user.getPassword() != null ? passwordEncoder.encode(user.getPassword())
|
||||
: null);
|
||||
boolean status = iSysUserService.update(updateWrapper);
|
||||
return Result.judge(status);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提供用于用户登录认证信息
|
||||
*/
|
||||
@ApiOperation(value = "根据用户名获取用户信息")
|
||||
@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "path", dataType = "String")
|
||||
@ApiOperation(value = "根据用户名获取认证信息")
|
||||
@GetMapping("/username/{username}")
|
||||
public Result<UserAuthDTO> getUserByUsername(@PathVariable String username) {
|
||||
UserAuthDTO user = iSysUserService.getByUsername(username);
|
||||
public Result<AuthUserDTO> getAuthInfoByUsername(
|
||||
@ApiParam("用户名") @PathVariable String username) {
|
||||
AuthUserDTO user = iSysUserService.getAuthInfoByUsername(username);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
@ -117,4 +127,5 @@ public class UserController {
|
||||
loginUserVO.setPerms(perms);
|
||||
return Result.success(loginUserVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,13 @@ import com.youlai.admin.pojo.entity.SysDictItem;
|
||||
import com.youlai.admin.service.ISysDictItemService;
|
||||
import com.youlai.admin.service.ISysDictService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "字典接口")
|
||||
@Api(tags = "字典管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/dict")
|
||||
@RequiredArgsConstructor
|
||||
@ -28,13 +25,12 @@ public class DictV2Controller {
|
||||
private final ISysDictItemService iSysDictItemService;
|
||||
|
||||
@ApiOperation(value = "字典分页列表")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页数量", paramType = "query", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "name", value = "字典名称", paramType = "query", dataType = "String"),
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public Result listDictByPage(long pageNum, long pageSize, String name) {
|
||||
public Result listDictByPage(
|
||||
@ApiParam("页码") long pageNum,
|
||||
@ApiParam("每页数量") long pageSize,
|
||||
@ApiParam("字典名称") String name
|
||||
) {
|
||||
Page<SysDict> result = iSysDictService.page(new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<SysDict>()
|
||||
.like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name))
|
||||
@ -45,7 +41,9 @@ public class DictV2Controller {
|
||||
|
||||
@ApiOperation(value = "字典详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result getDictDetail(@PathVariable Long id) {
|
||||
public Result getDictDetail(
|
||||
@ApiParam("字典ID") @PathVariable Long id
|
||||
) {
|
||||
SysDict dict = iSysDictService.getById(id);
|
||||
return Result.success(dict);
|
||||
}
|
||||
@ -65,9 +63,10 @@ public class DictV2Controller {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除字典")
|
||||
@ApiImplicitParam(name = "ids", value = "以,分割拼接字符串", required = true, paramType = "query", dataType = "String")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result deleteDict(@PathVariable String ids) {
|
||||
public Result deleteDict(
|
||||
@ApiParam("字典ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = iSysDictService.deleteDictByIds(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
@ -80,7 +79,12 @@ public class DictV2Controller {
|
||||
@ApiImplicitParam(name = "dictCode", value = "字典编码", paramType = "query", dataType = "String")
|
||||
})
|
||||
@GetMapping("/items/page")
|
||||
public Result getPageList(long pageNum, long pageSize, String name, String dictCode) {
|
||||
public Result getPageList(
|
||||
long pageNum,
|
||||
long pageSize,
|
||||
String name,
|
||||
String dictCode
|
||||
) {
|
||||
IPage<SysDictItem> result = iSysDictItemService.list(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new SysDictItem().setName(name).setDictCode(dictCode)
|
||||
|
@ -1,53 +0,0 @@
|
||||
package com.youlai.admin.controller.v2;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.admin.service.ISysUserRoleService;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
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;
|
||||
|
||||
@Api(tags = "用户接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/users")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class UserV2Controller {
|
||||
|
||||
private final ISysUserService iSysUserService;
|
||||
|
||||
@ApiOperation(value = "列表分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "mobile", value = "手机号码", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "status", value = "状态", paramType = "query", dataType = "Long"),
|
||||
@ApiImplicitParam(name = "deptId", value = "部门ID", paramType = "query", dataType = "Long"),
|
||||
})
|
||||
@GetMapping("pageList")
|
||||
public Result list(Integer page, Integer limit, String keywords, String mobile, Integer status, Long deptId) {
|
||||
SysUser user = new SysUser();
|
||||
user.setKeywords(keywords);
|
||||
user.setMobile(mobile);
|
||||
user.setStatus(status);
|
||||
user.setDeptId(deptId);
|
||||
|
||||
IPage<SysUser> result = iSysUserService.list(new Page<>(page, limit), user);
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,10 +2,11 @@ package com.youlai.admin.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.pojo.query.UserPageQuery;
|
||||
import com.youlai.admin.pojo.vo.UserDetailVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserFormVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserPageVO;
|
||||
import com.youlai.common.mybatis.handler.InterceptorIgnore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@ -23,14 +24,12 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
/**
|
||||
* 获取用户分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param pageParam
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
@InterceptorIgnore(deptAlias = "d")
|
||||
List<SysUser> list(Page<SysUser> page, UserPageQuery queryParam);
|
||||
|
||||
UserAuthDTO getByUsername(String username);
|
||||
List<UserPageVO> listUsersWithPage(Page<UserPageVO> pageParam, UserPageQuery queryParam);
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户详情
|
||||
@ -38,5 +37,15 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
UserDetailVO getUserDetailById(Long userId);
|
||||
UserFormVO getUserFormById(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
AuthUserDTO getAuthInfoByUsername(String username);
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.youlai.admin.pojo.entity.SysUserRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户角色持久层
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/15
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
||||
|
||||
|
@ -51,9 +51,4 @@ public class SysUser extends BaseEntity {
|
||||
@TableField(exist = false)
|
||||
private List<String> roles;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String keywords;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.user;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -7,14 +7,14 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户详情视图对象
|
||||
* 用户表单视图对象
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/14
|
||||
*/
|
||||
@ApiModel("用户详情视图对象")
|
||||
@ApiModel("用户表单视图对象")
|
||||
@Data
|
||||
public class UserDetailVO {
|
||||
public class UserFormVO {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long id;
|
@ -0,0 +1,54 @@
|
||||
package com.youlai.admin.pojo.vo.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户分页视图对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2022/1/15 9:41
|
||||
*/
|
||||
@ApiModel("用户分页视图对象")
|
||||
@Data
|
||||
public class UserPageVO {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("用户名")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty("用户昵称")
|
||||
private String nickname;
|
||||
|
||||
@ApiModelProperty("手机号")
|
||||
private String mobile;
|
||||
|
||||
@ApiModelProperty("性别(1:男;2:女)")
|
||||
private Integer gender;
|
||||
|
||||
@ApiModelProperty("用户头像地址")
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty("用户邮箱")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty("用户状态(1:启用;0:禁用)")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("部门名称")
|
||||
private String deptName;
|
||||
|
||||
@ApiModelProperty("角色名称,多个使用英文逗号(,)分割")
|
||||
private String roleNames;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private Date gmtCreate;
|
||||
|
||||
}
|
@ -3,10 +3,11 @@ package com.youlai.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.pojo.query.UserPageQuery;
|
||||
import com.youlai.admin.pojo.vo.UserDetailVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserFormVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserPageVO;
|
||||
|
||||
/**
|
||||
* 用户业务接口
|
||||
@ -21,7 +22,7 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<SysUser> list(UserPageQuery userPageQuery);
|
||||
IPage<UserPageVO> listUsersWithPage(UserPageQuery userPageQuery);
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
@ -40,12 +41,12 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
boolean updateUser(SysUser user);
|
||||
|
||||
/**
|
||||
* 根据用户名获取认证用户信息,携带角色和密码
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
UserAuthDTO getByUsername(String username);
|
||||
AuthUserDTO getAuthInfoByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据用户ID获取用户详情
|
||||
@ -53,5 +54,5 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
UserDetailVO getUserDetailById(Long userId);
|
||||
UserFormVO getUserFormById(Long userId);
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.admin.constant.SystemConstants;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.mapper.SysUserMapper;
|
||||
import com.youlai.admin.pojo.entity.SysUserRole;
|
||||
import com.youlai.admin.pojo.query.UserPageQuery;
|
||||
import com.youlai.admin.pojo.vo.UserDetailVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserFormVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserPageVO;
|
||||
import com.youlai.admin.service.ISysUserRoleService;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -38,12 +39,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
/**
|
||||
* 获取用户分页列表
|
||||
*
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<SysUser> list(UserPageQuery queryParam) {
|
||||
Page<SysUser> page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize());
|
||||
List<SysUser> list = this.baseMapper.list(page, queryParam);
|
||||
public IPage<UserPageVO> listUsersWithPage(UserPageQuery queryParam) {
|
||||
Page<UserPageVO> page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize());
|
||||
List<UserPageVO> list = this.baseMapper.listUsersWithPage(page, queryParam);
|
||||
page.setRecords(list);
|
||||
return page;
|
||||
}
|
||||
@ -109,9 +111,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return this.updateById(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserAuthDTO getByUsername(String username) {
|
||||
UserAuthDTO userAuthInfo = this.baseMapper.getByUsername(username);
|
||||
public AuthUserDTO getAuthInfoByUsername(String username) {
|
||||
AuthUserDTO userAuthInfo = this.baseMapper.getAuthInfoByUsername(username);
|
||||
return userAuthInfo;
|
||||
}
|
||||
|
||||
@ -122,8 +130,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserDetailVO getUserDetailById(Long userId) {
|
||||
UserDetailVO userDetail = this.baseMapper.getUserDetailById(userId);
|
||||
public UserFormVO getUserFormById(Long userId) {
|
||||
UserFormVO userDetail = this.baseMapper.getUserFormById(userId);
|
||||
return userDetail;
|
||||
}
|
||||
|
||||
|
@ -4,43 +4,19 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.youlai.admin.mapper.SysUserMapper">
|
||||
|
||||
<resultMap id="UserAuthMap" type="com.youlai.admin.dto.UserAuthDTO">
|
||||
<id property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||
<result property="deptId" column="deptId" jdbcType="BIGINT"></result>
|
||||
<collection property="roles" ofType="string" javaType="list">
|
||||
<result column="roleCode"></result>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="getByUsername" resultMap="UserAuthMap">
|
||||
<!-- 获取用户分页列表 -->
|
||||
<select id="listUsersWithPage" resultType="com.youlai.admin.pojo.vo.user.UserPageVO">
|
||||
SELECT
|
||||
t1.id userId,
|
||||
t1.username,
|
||||
t1.nickname,
|
||||
t1.PASSWORD,
|
||||
t1.STATUS,
|
||||
t1.dept_id deptId,
|
||||
t3.CODE roleCode
|
||||
FROM
|
||||
sys_user t1,
|
||||
sys_user_role t2,
|
||||
sys_role t3
|
||||
WHERE
|
||||
t1.username = #{username}
|
||||
AND t1.deleted = 0
|
||||
AND t1.id = t2.user_id
|
||||
AND t2.role_id = t3.id
|
||||
</select>
|
||||
|
||||
|
||||
<select id="list" resultType="com.youlai.admin.pojo.entity.SysUser">
|
||||
SELECT
|
||||
u.*,
|
||||
u.id,
|
||||
u.username,
|
||||
u.nickname,
|
||||
u.mobile,
|
||||
u.gender,
|
||||
u.avatar,
|
||||
u.STATUS,
|
||||
d.NAME AS dept_name,
|
||||
GROUP_CONCAT( r.NAME ) AS roleNames
|
||||
GROUP_CONCAT( r.NAME ) AS roleNames,
|
||||
u.gmt_create
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_dept d ON u.dept_id = d.id
|
||||
@ -62,9 +38,44 @@
|
||||
GROUP BY u.id
|
||||
</select>
|
||||
|
||||
<!-- 用户表单信息映射 -->
|
||||
<resultMap id="UserFormMap" type="com.youlai.admin.pojo.vo.user.UserFormVO">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||
<result property="nickname" column="password" jdbcType="VARCHAR"/>
|
||||
<result property="mobile" column="mobile" jdbcType="VARCHAR"/>
|
||||
<result property="gender" column="gender" jdbcType="TINYINT"/>
|
||||
<result property="avatar" column="avatar" jdbcType="VARCHAR"/>
|
||||
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||
<result property="deptId" column="dept_id" jdbcType="BIGINT"></result>
|
||||
<collection
|
||||
property="roleIds"
|
||||
column="id"
|
||||
select="com.youlai.admin.mapper.SysUserRoleMapper.listRoleIdsByUserId" >
|
||||
<result column="role_id" />
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="UserDetailMap" type="com.youlai.admin.pojo.vo.UserDetailVO">
|
||||
<id property="id" column="userId" jdbcType="BIGINT"/>
|
||||
<!-- 根据用户ID获取用户详情 -->
|
||||
<select id="getUserFormById" resultMap="UserFormMap">
|
||||
SELECT id,
|
||||
username,
|
||||
nickname,
|
||||
mobile,
|
||||
gender,
|
||||
avatar,
|
||||
email,
|
||||
STATUS,
|
||||
dept_id
|
||||
FROM sys_user
|
||||
WHERE id = #{userId}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 用户认证信息映射 -->
|
||||
<resultMap id="AuthUserMap" type="com.youlai.admin.dto.AuthUserDTO">
|
||||
<id property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||
@ -74,23 +85,21 @@
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<!-- 根据用户ID获取用户详情 -->
|
||||
<select id="getUserDetailById" resultMap="UserDetailMap">
|
||||
<!-- 根据用户名获取认证信息 -->
|
||||
<select id="getAuthInfoByUsername" resultMap="AuthUserMap">
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
nickname,
|
||||
mobile,
|
||||
gender,
|
||||
avatar,
|
||||
email,
|
||||
STATUS,
|
||||
dept_id
|
||||
t1.id userId,
|
||||
t1.username,
|
||||
t1.nickname,
|
||||
t1.PASSWORD,
|
||||
t1.STATUS,
|
||||
t1.dept_id deptId,
|
||||
t3.CODE roleCode
|
||||
FROM
|
||||
sys_user
|
||||
sys_user t1
|
||||
LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id
|
||||
LEFT JOIN sys_role t3 ON t3.id = t2.role_id
|
||||
WHERE
|
||||
id = #{userId}
|
||||
AND deleted =0
|
||||
t1.username = #{username} and t1.deleted=0
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.youlai.admin.mapper.SysUserRoleMapper">
|
||||
|
||||
<!-- 根据用户ID获取角色ID集合 -->
|
||||
<select id="listRoleIdsByUserId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
role_id
|
||||
FROM
|
||||
sys_user_role
|
||||
WHERE
|
||||
user_id = #{userId}
|
||||
</select>
|
||||
</mapper>
|
@ -1,7 +1,7 @@
|
||||
package com.youlai.auth.security.core.clientdetails;
|
||||
|
||||
import com.youlai.admin.api.OAuthClientFeignClient;
|
||||
import com.youlai.admin.dto.OAuth2ClientDTO;
|
||||
import com.youlai.admin.dto.AuthClientDTO;
|
||||
import com.youlai.auth.common.enums.PasswordEncoderTypeEnum;
|
||||
import com.youlai.common.result.Result;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -26,9 +26,9 @@ public class ClientDetailsServiceImpl implements ClientDetailsService {
|
||||
@Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId")
|
||||
public ClientDetails loadClientByClientId(String clientId) {
|
||||
try {
|
||||
Result<OAuth2ClientDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId);
|
||||
Result<AuthClientDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId);
|
||||
if (Result.success().getCode().equals(result.getCode())) {
|
||||
OAuth2ClientDTO client = result.getData();
|
||||
AuthClientDTO client = result.getData();
|
||||
BaseClientDetails clientDetails = new BaseClientDetails(
|
||||
client.getClientId(),
|
||||
client.getResourceIds(),
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.youlai.auth.security.core.userdetails.user;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.auth.common.enums.PasswordEncoderTypeEnum;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import lombok.Data;
|
||||
@ -40,7 +40,7 @@ public class SysUserDetails implements UserDetails {
|
||||
/**
|
||||
* 系统管理用户
|
||||
*/
|
||||
public SysUserDetails(UserAuthDTO user) {
|
||||
public SysUserDetails(AuthUserDTO user) {
|
||||
this.setUserId(user.getUserId());
|
||||
this.setUsername(user.getUsername());
|
||||
this.setDeptId(user.getDeptId());
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.youlai.auth.security.core.userdetails.user;
|
||||
|
||||
import com.youlai.admin.api.UserFeignClient;
|
||||
import com.youlai.admin.dto.UserAuthDTO;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.common.result.Result;
|
||||
import com.youlai.common.result.ResultCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -29,9 +29,9 @@ public class SysUserDetailsServiceImpl implements UserDetailsService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
SysUserDetails userDetails = null;
|
||||
Result<UserAuthDTO> result = userFeignClient.getUserByUsername(username);
|
||||
Result<AuthUserDTO> result = userFeignClient.getUserByUsername(username);
|
||||
if (Result.isSuccess(result)) {
|
||||
UserAuthDTO user = result.getData();
|
||||
AuthUserDTO user = result.getData();
|
||||
if (null != user) {
|
||||
userDetails = new SysUserDetails(user);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user