refactor: 用户接口和相关功能优化

This commit is contained in:
郝先瑞 2022-01-15 23:32:53 +08:00
parent 3411414cba
commit f78de70869
23 changed files with 335 additions and 255 deletions

View File

@ -1,15 +1,14 @@
package com.youlai.admin.api; package com.youlai.admin.api;
import com.youlai.admin.dto.OAuth2ClientDTO; import com.youlai.admin.dto.AuthClientDTO;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(value = "youlai-admin", contextId = "oauth-client") @FeignClient(value = "youlai-admin", contextId = "oauth-client")
public interface OAuthClientFeignClient { public interface OAuthClientFeignClient {
@GetMapping("/api/v1/oauth-clients/getOAuth2ClientById") @GetMapping("/api/v1/oauth-clients/getOAuth2ClientById")
Result<OAuth2ClientDTO> getOAuth2ClientById(@RequestParam String clientId); Result<AuthClientDTO> getOAuth2ClientById(@RequestParam String clientId);
} }

View File

@ -1,7 +1,7 @@
package com.youlai.admin.api; package com.youlai.admin.api;
import com.youlai.admin.api.fallback.UserFeignFallbackClient; 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 com.youlai.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -11,5 +11,5 @@ import org.springframework.web.bind.annotation.PathVariable;
public interface UserFeignClient { public interface UserFeignClient {
@GetMapping("/api/v1/users/username/{username}") @GetMapping("/api/v1/users/username/{username}")
Result<UserAuthDTO> getUserByUsername(@PathVariable String username); Result<AuthUserDTO> getUserByUsername(@PathVariable String username);
} }

View File

@ -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;
}

View File

@ -5,13 +5,13 @@ import lombok.Data;
import java.util.List; import java.util.List;
/** /**
* 系统用户认证信息 * OAuth2认证用户信息传输层对象
* *
* @author <a href="mailto:xianrui0365@163.com">haoxr</a> * @author haoxr
* @date 2021/9/27 * @date 2021/9/27
*/ */
@Data @Data
public class UserAuthDTO { public class AuthUserDTO {
/** /**
* 用户ID * 用户ID
@ -29,7 +29,7 @@ public class UserAuthDTO {
private String password; private String password;
/** /**
* 用户状态1-有效0-禁用 * 用户状态(1:正常;0:禁用)
*/ */
private Integer status; private Integer status;
@ -43,6 +43,4 @@ public class UserAuthDTO {
*/ */
private Long deptId; private Long deptId;
} }

View File

@ -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;
}

View File

@ -33,24 +33,23 @@ public class DictController {
@ApiOperation(value = "列表分页") @ApiOperation(value = "列表分页")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页数量", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "name", value = "字典名称", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "name", value = "字典名称", paramType = "query", dataType = "String"),
}) })
@GetMapping("/page") @GetMapping("/page")
public Result list( Integer page,Integer limit, String name) { public Result list(Long pageNum, Long pageSize, String name) {
Page<SysDict> result = iSysDictService.page(new Page<>(page, limit), new LambdaQueryWrapper<SysDict>() Page<SysDict> result = iSysDictService.page(new Page<>(pageNum, pageSize), new LambdaQueryWrapper<SysDict>()
.like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name)) .like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name))
.orderByDesc(SysDict::getGmtModified) .orderByDesc(SysDict::getGmtModified)
.orderByDesc(SysDict::getGmtCreate)); .orderByDesc(SysDict::getGmtCreate));
return Result.success(result.getRecords(), result.getTotal()); return Result.success(result.getRecords(), result.getTotal());
} }
@ApiOperation(value = "字典列表") @ApiOperation(value = "字典列表")
@GetMapping @GetMapping
public Result list() { public Result list() {
List<SysDict> list = iSysDictService.list( new LambdaQueryWrapper<SysDict>() List<SysDict> list = iSysDictService.list(new LambdaQueryWrapper<SysDict>()
.orderByDesc(SysDict::getGmtModified) .orderByDesc(SysDict::getGmtModified)
.orderByDesc(SysDict::getGmtCreate)); .orderByDesc(SysDict::getGmtCreate));
return Result.success(list); return Result.success(list);

View File

@ -35,12 +35,12 @@ public class DictItemController {
}) })
@GetMapping("/page") @GetMapping("/page")
public Result getPageList( public Result getPageList(
Integer page, long pageNum,
Integer limit, long pageSize,
String name, String name,
String dictCode 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)); new SysDictItem().setName(name).setDictCode(dictCode));
return Result.success(result.getRecords(), result.getTotal()); return Result.success(result.getRecords(), result.getTotal());
} }

View File

@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.pojo.entity.SysOauthClient;
import com.youlai.admin.service.ISysOauthClientService; import com.youlai.admin.service.ISysOauthClientService;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
@ -84,11 +84,11 @@ public class OauthClientController {
@ApiOperation(hidden = true, value = "获取 OAuth2 客户端认证信息", notes = "Feign 调用") @ApiOperation(hidden = true, value = "获取 OAuth2 客户端认证信息", notes = "Feign 调用")
@GetMapping("/getOAuth2ClientById") @GetMapping("/getOAuth2ClientById")
public Result<OAuth2ClientDTO> getOAuth2ClientById(@RequestParam String clientId) { public Result<AuthClientDTO> getOAuth2ClientById(@RequestParam String clientId) {
SysOauthClient client = iSysOauthClientService.getById(clientId); SysOauthClient client = iSysOauthClientService.getById(clientId);
Assert.isTrue(client!=null, "OAuth2 客户端不存在"); Assert.isTrue(client!=null, "OAuth2 客户端不存在");
OAuth2ClientDTO oAuth2ClientDTO = new OAuth2ClientDTO(); AuthClientDTO authClientDTO = new AuthClientDTO();
BeanUtil.copyProperties(client, oAuth2ClientDTO); BeanUtil.copyProperties(client, authClientDTO);
return Result.success(oAuth2ClientDTO); return Result.success(authClientDTO);
} }
} }

View File

@ -3,18 +3,17 @@ package com.youlai.admin.controller;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; 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.entity.SysUser;
import com.youlai.admin.pojo.query.UserPageQuery; import com.youlai.admin.pojo.query.UserPageQuery;
import com.youlai.admin.pojo.vo.LoginUserVO; 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.ISysPermissionService;
import com.youlai.admin.service.ISysUserRoleService;
import com.youlai.admin.service.ISysUserService; import com.youlai.admin.service.ISysUserService;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.common.web.util.JwtUtils; import com.youlai.common.web.util.JwtUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -25,30 +24,37 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; 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 @RestController
@RequestMapping("/api/v1/users") @RequestMapping("/api/v1/users")
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserController { public class UserController {
private final ISysUserService iSysUserService; private final ISysUserService iSysUserService;
private final ISysUserRoleService iSysUserRoleService;
private final PasswordEncoder passwordEncoder; private final PasswordEncoder passwordEncoder;
private final ISysPermissionService iSysPermissionService; private final ISysPermissionService iSysPermissionService;
@ApiOperation(value = "用户分页列表") @ApiOperation(value = "用户分页列表")
@GetMapping @GetMapping("/page")
public Result list(UserPageQuery queryParam) { public Result<List<UserPageVO>> listUsersWithPage(
IPage<SysUser> result = iSysUserService.list(queryParam); UserPageQuery queryParam
) {
IPage<UserPageVO> result = iSysUserService.listUsersWithPage(queryParam);
return Result.success(result.getRecords(), result.getTotal()); return Result.success(result.getRecords(), result.getTotal());
} }
@ApiOperation(value = "用户详情") @ApiOperation(value = "获取用户表单详情")
@GetMapping("/{userId}") @GetMapping("/{userId}/form")
public Result<UserDetailVO> getUserDetail( public Result<UserFormVO> getUserDetail(
@ApiParam(value = "用户ID", example = "1") @PathVariable Long userId @ApiParam(value = "用户ID", example = "1") @PathVariable Long userId
) { ) {
UserDetailVO userDetail = iSysUserService.getUserDetailById(userId); UserFormVO userDetail = iSysUserService.getUserFormById(userId);
return Result.success(userDetail); return Result.success(userDetail);
} }
@ -70,34 +76,38 @@ public class UserController {
} }
@ApiOperation(value = "删除用户") @ApiOperation(value = "删除用户")
@ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}") @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())); boolean status = iSysUserService.removeByIds(Arrays.asList(ids.split(",")).stream().collect(Collectors.toList()));
return Result.judge(status); return Result.judge(status);
} }
@ApiOperation(value = "选择性更新用户") @ApiOperation(value = "选择性更新用户")
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long") @PatchMapping(value = "/{userId}")
@PatchMapping(value = "/{id}") public Result updateUserPart(
public Result patch(@PathVariable Long id, @RequestBody SysUser user) { @ApiParam("用户ID") @PathVariable Long userId,
System.out.println(user.getPassword() != null); @RequestBody SysUser user
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>().eq(SysUser::getId, id); ) {
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<SysUser>()
.eq(SysUser::getId, userId);
updateWrapper.set(user.getStatus() != null, SysUser::getStatus, user.getStatus()); 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); boolean status = iSysUserService.update(updateWrapper);
return Result.judge(status); return Result.judge(status);
} }
/** /**
* 提供用于用户登录认证信息 * 提供用于用户登录认证信息
*/ */
@ApiOperation(value = "根据用户名获取用户信息") @ApiOperation(value = "根据用户名获取认证信息")
@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "path", dataType = "String")
@GetMapping("/username/{username}") @GetMapping("/username/{username}")
public Result<UserAuthDTO> getUserByUsername(@PathVariable String username) { public Result<AuthUserDTO> getAuthInfoByUsername(
UserAuthDTO user = iSysUserService.getByUsername(username); @ApiParam("用户名") @PathVariable String username) {
AuthUserDTO user = iSysUserService.getAuthInfoByUsername(username);
return Result.success(user); return Result.success(user);
} }
@ -117,4 +127,5 @@ public class UserController {
loginUserVO.setPerms(perms); loginUserVO.setPerms(perms);
return Result.success(loginUserVO); return Result.success(loginUserVO);
} }
} }

View File

@ -9,16 +9,13 @@ import com.youlai.admin.pojo.entity.SysDictItem;
import com.youlai.admin.service.ISysDictItemService; import com.youlai.admin.service.ISysDictItemService;
import com.youlai.admin.service.ISysDictService; import com.youlai.admin.service.ISysDictService;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import io.swagger.annotations.Api; import io.swagger.annotations.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@Api(tags = "字典接口") @Api(tags = "字典管理")
@RestController @RestController
@RequestMapping("/api/v2/dict") @RequestMapping("/api/v2/dict")
@RequiredArgsConstructor @RequiredArgsConstructor
@ -28,13 +25,12 @@ public class DictV2Controller {
private final ISysDictItemService iSysDictItemService; private final ISysDictItemService iSysDictItemService;
@ApiOperation(value = "字典分页列表") @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") @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), Page<SysDict> result = iSysDictService.page(new Page<>(pageNum, pageSize),
new LambdaQueryWrapper<SysDict>() new LambdaQueryWrapper<SysDict>()
.like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name)) .like(StrUtil.isNotBlank(name), SysDict::getName, StrUtil.trimToNull(name))
@ -45,7 +41,9 @@ public class DictV2Controller {
@ApiOperation(value = "字典详情") @ApiOperation(value = "字典详情")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result getDictDetail(@PathVariable Long id) { public Result getDictDetail(
@ApiParam("字典ID") @PathVariable Long id
) {
SysDict dict = iSysDictService.getById(id); SysDict dict = iSysDictService.getById(id);
return Result.success(dict); return Result.success(dict);
} }
@ -65,9 +63,10 @@ public class DictV2Controller {
} }
@ApiOperation(value = "删除字典") @ApiOperation(value = "删除字典")
@ApiImplicitParam(name = "ids", value = "以,分割拼接字符串", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public Result deleteDict(@PathVariable String ids) { public Result deleteDict(
@ApiParam("字典ID多个以英文逗号(,)分割") @PathVariable String ids
) {
boolean result = iSysDictService.deleteDictByIds(ids); boolean result = iSysDictService.deleteDictByIds(ids);
return Result.judge(result); return Result.judge(result);
} }
@ -80,7 +79,12 @@ public class DictV2Controller {
@ApiImplicitParam(name = "dictCode", value = "字典编码", paramType = "query", dataType = "String") @ApiImplicitParam(name = "dictCode", value = "字典编码", paramType = "query", dataType = "String")
}) })
@GetMapping("/items/page") @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( IPage<SysDictItem> result = iSysDictItemService.list(
new Page<>(pageNum, pageSize), new Page<>(pageNum, pageSize),
new SysDictItem().setName(name).setDictCode(dictCode) new SysDictItem().setName(name).setDictCode(dictCode)

View File

@ -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());
}
}

View File

@ -2,10 +2,11 @@ package com.youlai.admin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.entity.SysUser;
import com.youlai.admin.pojo.query.UserPageQuery; 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 com.youlai.common.mybatis.handler.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -23,14 +24,12 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
/** /**
* 获取用户分页列表 * 获取用户分页列表
* *
* @param page * @param pageParam
* @param queryParam * @param queryParam
* @return * @return
*/ */
@InterceptorIgnore(deptAlias = "d") @InterceptorIgnore(deptAlias = "d")
List<SysUser> list(Page<SysUser> page, UserPageQuery queryParam); List<UserPageVO> listUsersWithPage(Page<UserPageVO> pageParam, UserPageQuery queryParam);
UserAuthDTO getByUsername(String username);
/** /**
* 根据用户ID获取用户详情 * 根据用户ID获取用户详情
@ -38,5 +37,15 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @param userId * @param userId
* @return * @return
*/ */
UserDetailVO getUserDetailById(Long userId); UserFormVO getUserFormById(Long userId);
/**
* 根据用户名获取认证信息
*
* @param username
* @return
*/
AuthUserDTO getAuthInfoByUsername(String username);
} }

View File

@ -4,6 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.admin.pojo.entity.SysUserRole; import com.youlai.admin.pojo.entity.SysUserRole;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/**
* 用户角色持久层
*
* @author haoxr
* @date 2022/1/15
*/
@Mapper @Mapper
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

View File

@ -51,9 +51,4 @@ public class SysUser extends BaseEntity {
@TableField(exist = false) @TableField(exist = false)
private List<String> roles; private List<String> roles;
@TableField(exist = false)
private String keywords;
} }

View File

@ -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.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -7,14 +7,14 @@ import lombok.Data;
import java.util.List; import java.util.List;
/** /**
* 用户详情视图对象 * 用户表单视图对象
* *
* @author haoxr * @author haoxr
* @date 2022/1/14 * @date 2022/1/14
*/ */
@ApiModel("用户详情视图对象") @ApiModel("用户表单视图对象")
@Data @Data
public class UserDetailVO { public class UserFormVO {
@ApiModelProperty("用户ID") @ApiModelProperty("用户ID")
private Long id; private Long id;

View File

@ -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;
}

View File

@ -3,10 +3,11 @@ package com.youlai.admin.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; 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.entity.SysUser;
import com.youlai.admin.pojo.query.UserPageQuery; 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 * @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); boolean updateUser(SysUser user);
/** /**
* 根据用户名获取认证用户信息携带角色和密码 * 根据用户名获取认证信息
* *
* @param username * @param username
* @return * @return
*/ */
UserAuthDTO getByUsername(String username); AuthUserDTO getAuthInfoByUsername(String username);
/** /**
* 根据用户ID获取用户详情 * 根据用户ID获取用户详情
@ -53,5 +54,5 @@ public interface ISysUserService extends IService<SysUser> {
* @param userId * @param userId
* @return * @return
*/ */
UserDetailVO getUserDetailById(Long userId); UserFormVO getUserFormById(Long userId);
} }

View File

@ -6,12 +6,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.admin.constant.SystemConstants; 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.pojo.entity.SysUser;
import com.youlai.admin.mapper.SysUserMapper; import com.youlai.admin.mapper.SysUserMapper;
import com.youlai.admin.pojo.entity.SysUserRole; import com.youlai.admin.pojo.entity.SysUserRole;
import com.youlai.admin.pojo.query.UserPageQuery; 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.ISysUserRoleService;
import com.youlai.admin.service.ISysUserService; import com.youlai.admin.service.ISysUserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -38,12 +39,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
/** /**
* 获取用户分页列表 * 获取用户分页列表
* *
* @param queryParam
* @return * @return
*/ */
@Override @Override
public IPage<SysUser> list(UserPageQuery queryParam) { public IPage<UserPageVO> listUsersWithPage(UserPageQuery queryParam) {
Page<SysUser> page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize()); Page<UserPageVO> page = new Page<>(queryParam.getPageNum(), queryParam.getPageSize());
List<SysUser> list = this.baseMapper.list(page, queryParam); List<UserPageVO> list = this.baseMapper.listUsersWithPage(page, queryParam);
page.setRecords(list); page.setRecords(list);
return page; return page;
} }
@ -109,9 +111,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return this.updateById(user); return this.updateById(user);
} }
/**
* 根据用户名获取认证信息
*
* @param username
* @return
*/
@Override @Override
public UserAuthDTO getByUsername(String username) { public AuthUserDTO getAuthInfoByUsername(String username) {
UserAuthDTO userAuthInfo = this.baseMapper.getByUsername(username); AuthUserDTO userAuthInfo = this.baseMapper.getAuthInfoByUsername(username);
return userAuthInfo; return userAuthInfo;
} }
@ -122,8 +130,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
* @return * @return
*/ */
@Override @Override
public UserDetailVO getUserDetailById(Long userId) { public UserFormVO getUserFormById(Long userId) {
UserDetailVO userDetail = this.baseMapper.getUserDetailById(userId); UserFormVO userDetail = this.baseMapper.getUserFormById(userId);
return userDetail; return userDetail;
} }

View File

@ -4,43 +4,19 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.admin.mapper.SysUserMapper"> <mapper namespace="com.youlai.admin.mapper.SysUserMapper">
<resultMap id="UserAuthMap" type="com.youlai.admin.dto.UserAuthDTO"> <!-- 获取用户分页列表 -->
<id property="userId" column="userId" jdbcType="BIGINT"/> <select id="listUsersWithPage" resultType="com.youlai.admin.pojo.vo.user.UserPageVO">
<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 SELECT
t1.id userId, u.id,
t1.username, u.username,
t1.nickname, u.nickname,
t1.PASSWORD, u.mobile,
t1.STATUS, u.gender,
t1.dept_id deptId, u.avatar,
t3.CODE roleCode u.STATUS,
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.*,
d.NAME AS dept_name, d.NAME AS dept_name,
GROUP_CONCAT( r.NAME ) AS roleNames GROUP_CONCAT( r.NAME ) AS roleNames,
u.gmt_create
FROM FROM
sys_user u sys_user u
LEFT JOIN sys_dept d ON u.dept_id = d.id LEFT JOIN sys_dept d ON u.dept_id = d.id
@ -62,9 +38,44 @@
GROUP BY u.id GROUP BY u.id
</select> </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获取用户详情 -->
<id property="id" column="userId" jdbcType="BIGINT"/> <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="username" column="username" jdbcType="VARCHAR"/>
<result property="password" column="password" jdbcType="VARCHAR"/> <result property="password" column="password" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="BOOLEAN"/> <result property="status" column="status" jdbcType="BOOLEAN"/>
@ -74,23 +85,21 @@
</collection> </collection>
</resultMap> </resultMap>
<!-- 根据用户名获取认证信息 -->
<!-- 根据用户ID获取用户详情 --> <select id="getAuthInfoByUsername" resultMap="AuthUserMap">
<select id="getUserDetailById" resultMap="UserDetailMap">
SELECT SELECT
id, t1.id userId,
username, t1.username,
nickname, t1.nickname,
mobile, t1.PASSWORD,
gender, t1.STATUS,
avatar, t1.dept_id deptId,
email, t3.CODE roleCode
STATUS,
dept_id
FROM 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 WHERE
id = #{userId} t1.username = #{username} and t1.deleted=0
AND deleted =0
</select> </select>
</mapper> </mapper>

View File

@ -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>

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.clientdetails; package com.youlai.auth.security.core.clientdetails;
import com.youlai.admin.api.OAuthClientFeignClient; 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.auth.common.enums.PasswordEncoderTypeEnum;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -26,9 +26,9 @@ public class ClientDetailsServiceImpl implements ClientDetailsService {
@Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId") @Cacheable(cacheNames = "auth", key = "'oauth-client:'+#clientId")
public ClientDetails loadClientByClientId(String clientId) { public ClientDetails loadClientByClientId(String clientId) {
try { try {
Result<OAuth2ClientDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId); Result<AuthClientDTO> result = oAuthClientFeignClient.getOAuth2ClientById(clientId);
if (Result.success().getCode().equals(result.getCode())) { if (Result.success().getCode().equals(result.getCode())) {
OAuth2ClientDTO client = result.getData(); AuthClientDTO client = result.getData();
BaseClientDetails clientDetails = new BaseClientDetails( BaseClientDetails clientDetails = new BaseClientDetails(
client.getClientId(), client.getClientId(),
client.getResourceIds(), client.getResourceIds(),

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.userdetails.user; package com.youlai.auth.security.core.userdetails.user;
import cn.hutool.core.collection.CollectionUtil; 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.auth.common.enums.PasswordEncoderTypeEnum;
import com.youlai.common.constant.GlobalConstants; import com.youlai.common.constant.GlobalConstants;
import lombok.Data; 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.setUserId(user.getUserId());
this.setUsername(user.getUsername()); this.setUsername(user.getUsername());
this.setDeptId(user.getDeptId()); this.setDeptId(user.getDeptId());

View File

@ -1,7 +1,7 @@
package com.youlai.auth.security.core.userdetails.user; package com.youlai.auth.security.core.userdetails.user;
import com.youlai.admin.api.UserFeignClient; 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.Result;
import com.youlai.common.result.ResultCode; import com.youlai.common.result.ResultCode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -29,9 +29,9 @@ public class SysUserDetailsServiceImpl implements UserDetailsService {
@Override @Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
SysUserDetails userDetails = null; SysUserDetails userDetails = null;
Result<UserAuthDTO> result = userFeignClient.getUserByUsername(username); Result<AuthUserDTO> result = userFeignClient.getUserByUsername(username);
if (Result.isSuccess(result)) { if (Result.isSuccess(result)) {
UserAuthDTO user = result.getData(); AuthUserDTO user = result.getData();
if (null != user) { if (null != user) {
userDetails = new SysUserDetails(user); userDetails = new SysUserDetails(user);
} }