Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
2f079c5e
Commit
2f079c5e
authored
Jun 24, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
0584c7e7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
192 additions
and
7 deletions
+192
-7
RoleController.java
...ain/java/cn/qg/holmes/controller/auth/RoleController.java
+15
-0
RolePermissionController.java
...n/qg/holmes/controller/auth/RolePermissionController.java
+55
-0
UserController.java
...ain/java/cn/qg/holmes/controller/auth/UserController.java
+42
-5
UserRoleController.java
...java/cn/qg/holmes/controller/auth/UserRoleController.java
+37
-2
User.java
src/main/java/cn/qg/holmes/entity/auth/User.java
+11
-0
UserMapper.java
src/main/java/cn/qg/holmes/mapper/auth/UserMapper.java
+3
-0
UserService.java
src/main/java/cn/qg/holmes/service/auth/UserService.java
+3
-0
UserServiceImpl.java
.../java/cn/qg/holmes/service/auth/impl/UserServiceImpl.java
+20
-0
UserMapper.xml
src/main/resources/mapper/auth/UserMapper.xml
+6
-0
No files found.
src/main/java/cn/qg/holmes/controller/auth/RoleController.java
View file @
2f079c5e
...
@@ -14,16 +14,31 @@ public class RoleController {
...
@@ -14,16 +14,31 @@ public class RoleController {
@Autowired
@Autowired
RoleService
roleService
;
RoleService
roleService
;
/**
* 新增角色
* @param role 角色实体
* @return
*/
@PostMapping
(
"/add"
)
@PostMapping
(
"/add"
)
public
JsonResult
addRole
(
@RequestBody
Role
role
)
{
public
JsonResult
addRole
(
@RequestBody
Role
role
)
{
return
JsonResult
.
buildSuccessResult
(
roleService
.
save
(
role
));
return
JsonResult
.
buildSuccessResult
(
roleService
.
save
(
role
));
}
}
/**
* 编辑角色
* @param role 角色实体
* @return
*/
@PostMapping
(
"/edit"
)
@PostMapping
(
"/edit"
)
public
JsonResult
editRole
(
@RequestBody
Role
role
)
{
public
JsonResult
editRole
(
@RequestBody
Role
role
)
{
return
JsonResult
.
buildSuccessResult
(
roleService
.
saveOrUpdate
(
role
));
return
JsonResult
.
buildSuccessResult
(
roleService
.
saveOrUpdate
(
role
));
}
}
/**
* 删除角色
* @param roleId 角色id
* @return
*/
@PostMapping
(
"/delete"
)
@PostMapping
(
"/delete"
)
public
JsonResult
delRole
(
Integer
roleId
)
{
public
JsonResult
delRole
(
Integer
roleId
)
{
return
JsonResult
.
buildSuccessResult
(
roleService
.
removeById
(
roleId
));
return
JsonResult
.
buildSuccessResult
(
roleService
.
removeById
(
roleId
));
...
...
src/main/java/cn/qg/holmes/controller/auth/RolePermissionController.java
View file @
2f079c5e
package
cn
.
qg
.
holmes
.
controller
.
auth
;
package
cn
.
qg
.
holmes
.
controller
.
auth
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.auth.RolePermission
;
import
cn.qg.holmes.service.auth.RolePermissionService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
@CrossOrigin
@RestController
@RequestMapping
(
"/role/permission"
)
public
class
RolePermissionController
{
public
class
RolePermissionController
{
@Autowired
RolePermissionService
rolePermissionService
;
/**
* 新增角色权限
* @param roleId 角色id
* @param permissionIdList 权限id列表
* @return
*/
@PostMapping
(
"/add"
)
public
JsonResult
addRolePermission
(
Integer
roleId
,
List
<
Integer
>
permissionIdList
)
{
List
<
RolePermission
>
rolePermissionList
=
new
ArrayList
<>();
permissionIdList
.
forEach
(
permissionId
->
{
RolePermission
rolePermission
=
new
RolePermission
();
rolePermission
.
setRoleId
(
roleId
);
rolePermission
.
setPermissionId
(
permissionId
);
rolePermissionList
.
add
(
rolePermission
);
});
return
JsonResult
.
buildSuccessResult
(
rolePermissionService
.
saveBatch
(
rolePermissionList
));
}
/**
* 编辑角色权限
* @param rolePermissionList 角色权限列表
* @return
*/
@PostMapping
(
"/edit"
)
public
JsonResult
editRolePermission
(
List
<
RolePermission
>
rolePermissionList
)
{
// todo 角色权限编辑
return
JsonResult
.
buildSuccessResult
(
rolePermissionService
.
saveOrUpdateBatch
(
rolePermissionList
));
}
/**
* 删除角色权限
* @param rolePermissionId 角色权限
* @return
*/
@GetMapping
(
"/del"
)
public
JsonResult
delRolePermission
(
Integer
rolePermissionId
)
{
return
JsonResult
.
buildSuccessResult
(
rolePermissionService
.
removeById
(
rolePermissionId
));
}
}
}
src/main/java/cn/qg/holmes/controller/auth/
Login
Controller.java
→
src/main/java/cn/qg/holmes/controller/auth/
User
Controller.java
View file @
2f079c5e
...
@@ -5,7 +5,9 @@ import cn.qg.holmes.entity.auth.User;
...
@@ -5,7 +5,9 @@ import cn.qg.holmes.entity.auth.User;
import
cn.qg.holmes.entity.auth.UserInfoVo
;
import
cn.qg.holmes.entity.auth.UserInfoVo
;
import
cn.qg.holmes.service.auth.LoginService
;
import
cn.qg.holmes.service.auth.LoginService
;
import
cn.qg.holmes.service.auth.TokenService
;
import
cn.qg.holmes.service.auth.TokenService
;
import
cn.qg.holmes.service.auth.UserRoleService
;
import
cn.qg.holmes.service.auth.UserService
;
import
cn.qg.holmes.service.auth.UserService
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -15,19 +17,28 @@ import java.util.HashMap;
...
@@ -15,19 +17,28 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
@CrossOrigin
@CrossOrigin
@RequestMapping
(
"/user"
)
@RestController
@RestController
@RequestMapping
(
"/auth"
)
public
class
UserController
{
public
class
LoginController
{
@Autowired
@Autowired
LoginService
login
Service
;
UserService
user
Service
;
@Autowired
@Autowired
TokenService
token
Service
;
UserRoleService
userRole
Service
;
@Autowired
@Autowired
UserService
userService
;
LoginService
loginService
;
@Autowired
TokenService
tokenService
;
/**
* 登录,鉴权走ldap
* @param username 用户名
* @param password 密码
* @return
*/
@PostMapping
(
"/login"
)
@PostMapping
(
"/login"
)
public
JsonResult
login
(
String
username
,
String
password
)
{
public
JsonResult
login
(
String
username
,
String
password
)
{
boolean
loginResult
=
loginService
.
login
(
username
,
password
);
boolean
loginResult
=
loginService
.
login
(
username
,
password
);
...
@@ -50,15 +61,41 @@ public class LoginController {
...
@@ -50,15 +61,41 @@ public class LoginController {
return
JsonResult
.
buildSuccessResult
(
map
);
return
JsonResult
.
buildSuccessResult
(
map
);
}
}
/**
* 登出
* @param token token
* @return
*/
@PostMapping
(
"/logout"
)
@PostMapping
(
"/logout"
)
public
JsonResult
logout
(
String
token
)
{
public
JsonResult
logout
(
String
token
)
{
tokenService
.
invalidateToken
(
token
);
tokenService
.
invalidateToken
(
token
);
return
JsonResult
.
buildSuccessResult
(
"登出成功!"
,
true
);
return
JsonResult
.
buildSuccessResult
(
"登出成功!"
,
true
);
}
}
/**
* 获取用户信息
* @param username 用户名
* @return
*/
@GetMapping
(
"/info"
)
@GetMapping
(
"/info"
)
public
JsonResult
getInfo
(
String
username
)
{
public
JsonResult
getInfo
(
String
username
)
{
UserInfoVo
userInfoVo
=
userService
.
getUserInfoByUsername
(
username
);
UserInfoVo
userInfoVo
=
userService
.
getUserInfoByUsername
(
username
);
return
JsonResult
.
buildSuccessResult
(
userInfoVo
);
return
JsonResult
.
buildSuccessResult
(
userInfoVo
);
}
}
/**
* 获取用户信息列表
* @param pageNum 第几页
* @param pageSize 每页多少个
* @return
*/
@GetMapping
(
"/list"
)
public
JsonResult
getUserList
(
@RequestParam
(
defaultValue
=
"1"
)
Integer
pageNum
,
@RequestParam
(
defaultValue
=
"10"
)
Integer
pageSize
)
{
IPage
<
User
>
userIPage
=
userService
.
getUserInfoList
(
pageNum
,
pageSize
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"total"
,
userIPage
.
getTotal
());
map
.
put
(
"list"
,
userIPage
.
getRecords
());
return
JsonResult
.
buildSuccessResult
(
map
);
}
}
}
src/main/java/cn/qg/holmes/controller/auth/UserRoleController.java
View file @
2f079c5e
package
cn
.
qg
.
holmes
.
controller
.
auth
;
package
cn
.
qg
.
holmes
.
controller
.
auth
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.common.JsonResult
;
import
cn.qg.holmes.entity.auth.UserRole
;
import
cn.qg.holmes.service.auth.UserRoleService
;
import
cn.qg.holmes.service.auth.UserRoleService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
@@ -16,8 +18,41 @@ public class UserRoleController {
...
@@ -16,8 +18,41 @@ public class UserRoleController {
@Autowired
@Autowired
UserRoleService
userRoleService
;
UserRoleService
userRoleService
;
/**
* 用户新增角色
* @param userId 用户id
* @param roleId 角色id
* @return
*/
@PostMapping
(
"/add"
)
@PostMapping
(
"/add"
)
public
JsonResult
addUserRole
()
{
public
JsonResult
addUserRole
(
Integer
userId
,
Integer
roleId
)
{
return
null
;
QueryWrapper
<
UserRole
>
userRoleQueryWrapper
=
new
QueryWrapper
<>();
userRoleQueryWrapper
.
eq
(
"user_id"
,
userId
);
userRoleQueryWrapper
.
eq
(
"role_id"
,
roleId
);
if
(
userRoleService
.
getOne
(
userRoleQueryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"用户角色已存在!"
,
false
);
}
userRoleQueryWrapper
.
clear
();
userRoleQueryWrapper
.
eq
(
"user_id"
,
userId
);
UserRole
userRole
=
userRoleService
.
getOne
(
userRoleQueryWrapper
);
if
(
userRole
==
null
)
{
UserRole
newUserRole
=
new
UserRole
();
newUserRole
.
setUserId
(
userId
);
newUserRole
.
setRoleId
(
roleId
);
return
JsonResult
.
buildSuccessResult
(
userRoleService
.
save
(
newUserRole
));
}
else
{
userRole
.
setRoleId
(
roleId
);
return
JsonResult
.
buildSuccessResult
(
userRoleService
.
saveOrUpdate
(
userRole
));
}
}
/**
* 编辑用户角色权限
* @param userRole 用户角色实体
* @return
*/
@PostMapping
(
"/edit"
)
public
JsonResult
editUserRole
(
UserRole
userRole
)
{
return
JsonResult
.
buildSuccessResult
(
userRoleService
.
updateById
(
userRole
));
}
}
}
}
src/main/java/cn/qg/holmes/entity/auth/User.java
View file @
2f079c5e
package
cn
.
qg
.
holmes
.
entity
.
auth
;
package
cn
.
qg
.
holmes
.
entity
.
auth
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -11,10 +12,20 @@ import java.util.Date;
...
@@ -11,10 +12,20 @@ import java.util.Date;
public
class
User
{
public
class
User
{
@TableId
(
type
=
IdType
.
AUTO
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
Integer
id
;
private
String
username
;
private
String
username
;
private
String
password
;
private
String
password
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
updateTime
;
private
Date
updateTime
;
@TableField
(
exist
=
false
)
private
Integer
roleId
;
@TableField
(
exist
=
false
)
private
String
roleName
;
}
}
src/main/java/cn/qg/holmes/mapper/auth/UserMapper.java
View file @
2f079c5e
...
@@ -2,6 +2,9 @@ package cn.qg.holmes.mapper.auth;
...
@@ -2,6 +2,9 @@ package cn.qg.holmes.mapper.auth;
import
cn.qg.holmes.entity.auth.User
;
import
cn.qg.holmes.entity.auth.User
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
public
interface
UserMapper
extends
BaseMapper
<
User
>
{
IPage
<
User
>
getUserInfoList
(
IPage
<
User
>
page
);
}
}
src/main/java/cn/qg/holmes/service/auth/UserService.java
View file @
2f079c5e
...
@@ -2,6 +2,7 @@ package cn.qg.holmes.service.auth;
...
@@ -2,6 +2,7 @@ package cn.qg.holmes.service.auth;
import
cn.qg.holmes.entity.auth.User
;
import
cn.qg.holmes.entity.auth.User
;
import
cn.qg.holmes.entity.auth.UserInfoVo
;
import
cn.qg.holmes.entity.auth.UserInfoVo
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
UserService
extends
IService
<
User
>
{
public
interface
UserService
extends
IService
<
User
>
{
...
@@ -9,4 +10,6 @@ public interface UserService extends IService<User> {
...
@@ -9,4 +10,6 @@ public interface UserService extends IService<User> {
User
getUserByUsername
(
String
username
);
User
getUserByUsername
(
String
username
);
UserInfoVo
getUserInfoByUsername
(
String
username
);
UserInfoVo
getUserInfoByUsername
(
String
username
);
IPage
<
User
>
getUserInfoList
(
Integer
pageNum
,
Integer
pageSize
);
}
}
src/main/java/cn/qg/holmes/service/auth/impl/UserServiceImpl.java
View file @
2f079c5e
...
@@ -7,6 +7,8 @@ import cn.qg.holmes.service.auth.RolePermissionService;
...
@@ -7,6 +7,8 @@ import cn.qg.holmes.service.auth.RolePermissionService;
import
cn.qg.holmes.service.auth.UserRoleService
;
import
cn.qg.holmes.service.auth.UserRoleService
;
import
cn.qg.holmes.service.auth.UserService
;
import
cn.qg.holmes.service.auth.UserService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -33,6 +35,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
...
@@ -33,6 +35,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return
userMapper
.
selectOne
(
userQueryWrapper
);
return
userMapper
.
selectOne
(
userQueryWrapper
);
}
}
/**
* 根据用户名获取用户信息
* @param username
* @return
*/
@Override
@Override
public
UserInfoVo
getUserInfoByUsername
(
String
username
)
{
public
UserInfoVo
getUserInfoByUsername
(
String
username
)
{
UserInfoVo
userInfoVo
=
new
UserInfoVo
();
UserInfoVo
userInfoVo
=
new
UserInfoVo
();
...
@@ -49,4 +56,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
...
@@ -49,4 +56,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
userInfoVo
.
setMenuList
(
menuCodeSet
);
userInfoVo
.
setMenuList
(
menuCodeSet
);
return
userInfoVo
;
return
userInfoVo
;
}
}
/**
* 获取用户信息列表
* @param pageNum
* @param pageSize
* @return
*/
@Override
public
IPage
<
User
>
getUserInfoList
(
Integer
pageNum
,
Integer
pageSize
)
{
IPage
<
User
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
return
userMapper
.
getUserInfoList
(
page
);
}
}
}
src/main/resources/mapper/auth/UserMapper.xml
View file @
2f079c5e
...
@@ -2,4 +2,10 @@
...
@@ -2,4 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper
namespace=
"cn.qg.holmes.mapper.auth.UserMapper"
>
<mapper
namespace=
"cn.qg.holmes.mapper.auth.UserMapper"
>
<select
id=
"getUserInfoList"
resultType=
"cn.qg.holmes.entity.auth.User"
>
SELECT u.*, r.`id` as roleId, r.`role_name` as roleName FROM `user` u
INNER JOIN `role` r
INNER JOIN `user_role` ur
ON u.`id` = ur.`user_id` AND r.`id` = ur.`role_id`
</select>
</mapper>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment