Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
81c94215
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81c94215
编写于
9月 11, 2020
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
系统管理接口开发
上级
fd18d60d
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
184 addition
and
56 deletion
+184
-56
youlai-admin/src/main/java/com/youlai/admin/common/AdminConstant.java
.../src/main/java/com/youlai/admin/common/AdminConstant.java
+3
-1
youlai-admin/src/main/java/com/youlai/admin/controller/SysDictController.java
...n/java/com/youlai/admin/controller/SysDictController.java
+2
-2
youlai-admin/src/main/java/com/youlai/admin/controller/SysDictTypeController.java
...va/com/youlai/admin/controller/SysDictTypeController.java
+2
-2
youlai-admin/src/main/java/com/youlai/admin/controller/SysMenuController.java
...n/java/com/youlai/admin/controller/SysMenuController.java
+34
-9
youlai-admin/src/main/java/com/youlai/admin/controller/SysRoleController.java
...n/java/com/youlai/admin/controller/SysRoleController.java
+17
-21
youlai-admin/src/main/java/com/youlai/admin/controller/SysUserController.java
...n/java/com/youlai/admin/controller/SysUserController.java
+21
-21
youlai-admin/src/main/java/com/youlai/admin/domain/entity/SysRole.java
...src/main/java/com/youlai/admin/domain/entity/SysRole.java
+6
-0
youlai-admin/src/main/java/com/youlai/admin/service/ISysRoleService.java
...c/main/java/com/youlai/admin/service/ISysRoleService.java
+8
-0
youlai-admin/src/main/java/com/youlai/admin/service/impl/SysRoleServiceImpl.java
...ava/com/youlai/admin/service/impl/SysRoleServiceImpl.java
+91
-0
未找到文件。
youlai-admin/src/main/java/com/youlai/admin/common/AdminConstant.java
浏览文件 @
81c94215
...
...
@@ -5,5 +5,7 @@ package com.youlai.admin.common;
*/
public
interface
AdminConstant
{
int
ROOT_DEPT_ID
=
0
;
int
ROOT_DEPT_ID
=
0
;
// 根部门ID
int
ROOT_ROLE_ID
=
1
;
// 超级管理员角色ID
}
youlai-admin/src/main/java/com/youlai/admin/controller/SysDictController.java
浏览文件 @
81c94215
...
...
@@ -55,7 +55,7 @@ public class SysDictController {
@ApiOperation
(
value
=
"字典详情"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"字典id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
)
@GetMapping
(
"/{id}"
)
public
Result
detail
(
@PathVariable
Long
id
)
{
public
Result
detail
(
@PathVariable
Integer
id
)
{
SysDict
sysDict
=
iSysDictService
.
getById
(
id
);
return
Result
.
success
(
sysDict
);
}
...
...
@@ -75,7 +75,7 @@ public class SysDictController {
})
@PutMapping
(
value
=
"/{id}"
)
public
Result
update
(
@PathVariable
Long
id
,
@PathVariable
Integer
id
,
@RequestBody
SysDict
sysDict
)
{
sysDict
.
setUpdateTime
(
new
Date
());
boolean
status
=
iSysDictService
.
updateById
(
sysDict
);
...
...
youlai-admin/src/main/java/com/youlai/admin/controller/SysDictTypeController.java
浏览文件 @
81c94215
...
...
@@ -54,7 +54,7 @@ public class SysDictTypeController {
@ApiOperation
(
value
=
"字典类型详情"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"字典类型id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
)
@GetMapping
(
"/{id}"
)
public
Result
detail
(
@PathVariable
Long
id
)
{
public
Result
detail
(
@PathVariable
Integer
id
)
{
SysDictType
sysDictType
=
iSysDictTypeService
.
getById
(
id
);
return
Result
.
success
(
sysDictType
);
}
...
...
@@ -74,7 +74,7 @@ public class SysDictTypeController {
})
@PutMapping
(
value
=
"/{id}"
)
public
Result
update
(
@PathVariable
Long
id
,
@PathVariable
Integer
id
,
@RequestBody
SysDictType
sysDictType
)
{
boolean
status
=
iSysDictTypeService
.
updateById
(
sysDictType
);
return
Result
.
status
(
status
);
...
...
youlai-admin/src/main/java/com/youlai/admin/controller/SysMenuController.java
浏览文件 @
81c94215
...
...
@@ -4,10 +4,14 @@ import cn.hutool.core.util.StrUtil;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.youlai.admin.common.AdminConstant
;
import
com.youlai.admin.domain.entity.SysMenu
;
import
com.youlai.admin.domain.entity.SysMenu
;
import
com.youlai.admin.domain.entity.SysMenu
;
import
com.youlai.admin.domain.entity.SysRoleMenu
;
import
com.youlai.admin.domain.vo.TreeSelectVO
;
import
com.youlai.admin.service.ISysMenuService
;
import
com.youlai.admin.service.ISysRoleMenuService
;
import
com.youlai.common.result.PageResult
;
import
com.youlai.common.result.Result
;
import
io.swagger.annotations.Api
;
...
...
@@ -18,8 +22,8 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.
Date
;
import
java.util.
List
;
import
java.util.
*
;
import
java.util.
stream.Collectors
;
@Api
(
tags
=
"菜单接口"
)
@RestController
...
...
@@ -30,13 +34,18 @@ public class SysMenuController {
@Autowired
private
ISysMenuService
iSysMenuService
;
@Autowired
private
ISysRoleMenuService
iSysRoleMenuService
;
@ApiOperation
(
value
=
"列表分页"
,
httpMethod
=
"GET"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"name"
,
value
=
"菜单名称"
,
paramType
=
"query"
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"mode"
,
value
=
"查询模式: 1-表格数据 2-树形下拉"
,
paramType
=
"query"
,
dataType
=
"Integer"
)
@ApiImplicitParam
(
name
=
"roleId"
,
value
=
"角色ID"
,
paramType
=
"query"
,
dataType
=
"Integer"
),
@ApiImplicitParam
(
name
=
"mode"
,
value
=
"查询模式: 1-表格数据 2-树形数据"
,
paramType
=
"query"
,
dataType
=
"Integer"
)
})
@GetMapping
public
Result
list
(
String
name
,
Integer
mode
)
{
public
Result
list
(
String
name
,
Integer
roleId
,
Integer
mode
)
{
LambdaQueryWrapper
<
SysMenu
>
baseQuery
=
new
LambdaQueryWrapper
<
SysMenu
>()
.
orderByAsc
(
SysMenu:
:
getSort
)
.
orderByDesc
(
SysMenu:
:
getUpdateTime
)
...
...
@@ -45,8 +54,24 @@ public class SysMenuController {
if
(
mode
.
equals
(
1
))
{
// 表格数据
baseQuery
=
baseQuery
.
like
(
StrUtil
.
isNotBlank
(
name
),
SysMenu:
:
getName
,
name
);
list
=
iSysMenuService
.
listForTableData
(
baseQuery
);
}
else
if
(
mode
.
equals
(
2
))
{
//
tree-select 树形下拉
数据
}
else
if
(
mode
.
equals
(
2
))
{
//
树形
数据
list
=
iSysMenuService
.
listForTreeSelect
(
baseQuery
);
if
(
roleId
!=
null
)
{
// 菜单树形 + 角色权限
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"menus"
,
list
);
List
<
Integer
>
checkedKeys
;
if
(
roleId
.
equals
(
AdminConstant
.
ROOT_ROLE_ID
))
{
// 超级管理员拥有所有的菜单权限
checkedKeys
=
(
List
<
Integer
>)
list
.
stream
().
map
(
item
->
((
TreeSelectVO
)
item
).
getId
()).
collect
(
Collectors
.
toList
());
}
else
{
checkedKeys
=
iSysRoleMenuService
.
list
(
new
LambdaQueryWrapper
<
SysRoleMenu
>()
.
eq
(
SysRoleMenu:
:
getRoleId
,
roleId
))
.
stream
()
.
map
(
item
->
item
.
getMenuId
())
.
collect
(
Collectors
.
toList
());
}
map
.
put
(
"checkedKeys"
,
checkedKeys
);
return
Result
.
success
(
map
);
}
}
else
{
list
=
iSysMenuService
.
list
(
baseQuery
);
}
...
...
@@ -56,7 +81,7 @@ public class SysMenuController {
@ApiOperation
(
value
=
"菜单详情"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"菜单id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
)
@GetMapping
(
"/{id}"
)
public
Result
detail
(
@PathVariable
Long
id
)
{
public
Result
detail
(
@PathVariable
Integer
id
)
{
SysMenu
sysMenu
=
iSysMenuService
.
getById
(
id
);
return
Result
.
success
(
sysMenu
);
}
...
...
@@ -76,7 +101,7 @@ public class SysMenuController {
})
@PutMapping
(
value
=
"/{id}"
)
public
Result
update
(
@PathVariable
Long
id
,
@PathVariable
Integer
id
,
@RequestBody
SysMenu
sysMenu
)
{
sysMenu
.
setUpdateTime
(
new
Date
());
boolean
status
=
iSysMenuService
.
updateById
(
sysMenu
);
...
...
@@ -90,7 +115,7 @@ public class SysMenuController {
boolean
status
=
iSysMenuService
.
removeByIds
(
ids
);
return
Result
.
status
(
status
);
}
@ApiOperation
(
value
=
"修改菜单【局部更新】"
,
httpMethod
=
"PATCH"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"用户id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
),
...
...
@@ -101,7 +126,7 @@ public class SysMenuController {
LambdaUpdateWrapper
<
SysMenu
>
luw
=
new
LambdaUpdateWrapper
<
SysMenu
>().
eq
(
SysMenu:
:
getId
,
id
);
if
(
menu
.
getStatus
()
!=
null
)
{
// 状态更新
luw
.
set
(
SysMenu:
:
getStatus
,
menu
.
getStatus
());
}
else
{
}
else
{
return
Result
.
success
();
}
boolean
update
=
iSysMenuService
.
update
(
luw
);
...
...
youlai-admin/src/main/java/com/youlai/admin/controller/SysRoleController.java
浏览文件 @
81c94215
...
...
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.youlai.admin.domain.entity.SysRole
;
import
com.youlai.admin.domain.entity.SysRole
;
import
com.youlai.admin.service.ISysRoleService
;
import
com.youlai.common.result.PageResult
;
import
com.youlai.common.result.Result
;
...
...
@@ -13,21 +12,19 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
import
java.util.List
;
@Api
(
tags
=
"角色接口"
)
@RestController
@RequestMapping
(
"/roles"
)
@Slf4j
@AllArgsConstructor
public
class
SysRoleController
{
@Autowired
private
ISysRoleService
iSysRoleService
;
@ApiOperation
(
value
=
"列表分页"
,
httpMethod
=
"GET"
)
...
...
@@ -44,7 +41,7 @@ public class SysRoleController {
.
orderByDesc
(
SysRole:
:
getCreateTime
);
if
(
page
!=
null
&&
limit
!=
null
)
{
Page
<
SysRole
>
result
=
iSysRoleService
.
page
(
new
Page
<>(
page
,
limit
)
,
queryWrapper
);
Page
<
SysRole
>
result
=
iSysRoleService
.
page
(
new
Page
<>(
page
,
limit
)
,
queryWrapper
);
return
PageResult
.
success
(
result
.
getRecords
(),
result
.
getTotal
());
}
else
if
(
limit
!=
null
)
{
queryWrapper
.
last
(
"LIMIT "
+
limit
);
...
...
@@ -56,38 +53,37 @@ public class SysRoleController {
@ApiOperation
(
value
=
"角色详情"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"角色id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
)
@GetMapping
(
"/{id}"
)
public
Result
detail
(
@PathVariable
Long
id
)
{
public
Result
detail
(
@PathVariable
Integer
id
)
{
SysRole
sysRole
=
iSysRoleService
.
getById
(
id
);
return
Result
.
success
(
sysRole
);
}
@ApiOperation
(
value
=
"新增角色"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"
sysR
ole"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysRole"
)
@ApiImplicitParam
(
name
=
"
r
ole"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysRole"
)
@PostMapping
public
Result
add
(
@RequestBody
SysRole
sysR
ole
)
{
boolean
status
=
iSysRoleService
.
save
(
sysR
ole
);
public
Result
add
(
@RequestBody
SysRole
r
ole
)
{
boolean
status
=
iSysRoleService
.
add
(
r
ole
);
return
Result
.
status
(
status
);
}
@ApiOperation
(
value
=
"修改角色"
,
httpMethod
=
"PUT"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"角色id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
),
@ApiImplicitParam
(
name
=
"
sysR
ole"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysRole"
)
@ApiImplicitParam
(
name
=
"
r
ole"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysRole"
)
})
@PutMapping
(
value
=
"/{id}"
)
public
Result
update
(
@PathVariable
Long
id
,
@RequestBody
SysRole
sysRole
)
{
sysRole
.
setUpdateTime
(
new
Date
());
boolean
status
=
iSysRoleService
.
updateById
(
sysRole
);
@PathVariable
Integer
id
,
@RequestBody
SysRole
role
)
{
boolean
status
=
iSysRoleService
.
update
(
role
);
return
Result
.
status
(
status
);
}
@ApiOperation
(
value
=
"删除角色"
,
httpMethod
=
"DELETE"
)
@ApiImplicitParam
(
name
=
"ids[]"
,
value
=
"id集合"
,
required
=
true
,
paramType
=
"query"
,
allowMultiple
=
true
,
dataType
=
"Integer"
)
@DeleteMapping
public
Result
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
boolean
status
=
iSysRoleService
.
removeByIds
(
ids
);
public
Result
delete
(
@RequestParam
(
"ids"
)
List
<
Integer
>
ids
)
{
boolean
status
=
iSysRoleService
.
delete
(
ids
);
return
Result
.
status
(
status
);
}
...
...
@@ -102,11 +98,11 @@ public class SysRoleController {
LambdaUpdateWrapper
<
SysRole
>
luw
=
new
LambdaUpdateWrapper
<
SysRole
>().
eq
(
SysRole:
:
getId
,
id
);
if
(
role
.
getStatus
()
!=
null
)
{
// 状态更新
luw
.
set
(
SysRole:
:
getStatus
,
role
.
getStatus
());
}
else
{
return
Result
.
success
(
);
}
else
{
return
Result
.
error
(
"未发生任何更新"
);
}
boolean
update
=
iSysRoleService
.
update
(
luw
);
return
Result
.
s
uccess
(
update
);
boolean
status
=
iSysRoleService
.
update
(
luw
);
return
Result
.
s
tatus
(
status
);
}
}
youlai-admin/src/main/java/com/youlai/admin/controller/SysUserController.java
浏览文件 @
81c94215
...
...
@@ -51,42 +51,42 @@ public class SysUserController {
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"page"
,
value
=
"页码"
,
paramType
=
"query"
,
dataType
=
"Integer"
),
@ApiImplicitParam
(
name
=
"limit"
,
value
=
"每页数量"
,
paramType
=
"query"
,
dataType
=
"Integer"
),
@ApiImplicitParam
(
name
=
"
sysU
ser"
,
value
=
"用户信息"
,
paramType
=
"query"
,
dataType
=
"SysUser"
),
@ApiImplicitParam
(
name
=
"
u
ser"
,
value
=
"用户信息"
,
paramType
=
"query"
,
dataType
=
"SysUser"
),
})
@GetMapping
public
Result
list
(
Integer
page
,
Integer
limit
,
SysUser
sysU
ser
)
{
IPage
<
SysUser
>
result
=
iSysUserService
.
list
(
new
Page
<>(
page
,
limit
),
sysU
ser
);
public
Result
list
(
Integer
page
,
Integer
limit
,
SysUser
u
ser
)
{
IPage
<
SysUser
>
result
=
iSysUserService
.
list
(
new
Page
<>(
page
,
limit
),
u
ser
);
return
PageResult
.
success
(
result
.
getRecords
(),
result
.
getTotal
());
}
@ApiOperation
(
value
=
"用户详情"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"用户id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
)
@GetMapping
(
"/{id}"
)
public
Result
detail
(
@PathVariable
Long
id
)
{
SysUser
sysU
ser
=
iSysUserService
.
getById
(
id
);
return
Result
.
success
(
sysU
ser
);
public
Result
detail
(
@PathVariable
Integer
id
)
{
SysUser
u
ser
=
iSysUserService
.
getById
(
id
);
return
Result
.
success
(
u
ser
);
}
@ApiOperation
(
value
=
"新增用户"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"
sysU
ser"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysUser"
)
@ApiImplicitParam
(
name
=
"
u
ser"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysUser"
)
@PostMapping
public
Result
add
(
@RequestBody
SysUser
sysU
ser
)
{
boolean
status
=
iSysUserService
.
save
(
sysU
ser
);
public
Result
add
(
@RequestBody
SysUser
u
ser
)
{
boolean
status
=
iSysUserService
.
save
(
u
ser
);
return
Result
.
status
(
status
);
}
@ApiOperation
(
value
=
"修改用户"
,
httpMethod
=
"PUT"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"id"
,
value
=
"用户id"
,
required
=
true
,
paramType
=
"path"
,
dataType
=
"Integer"
),
@ApiImplicitParam
(
name
=
"
sysU
ser"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysUser"
)
@ApiImplicitParam
(
name
=
"
u
ser"
,
value
=
"实体JSON对象"
,
required
=
true
,
paramType
=
"body"
,
dataType
=
"SysUser"
)
})
@PutMapping
(
value
=
"/{id}"
)
public
Result
update
(
@PathVariable
Long
id
,
@RequestBody
SysUser
sysU
ser
)
{
sysU
ser
.
setUpdateTime
(
new
Date
());
boolean
status
=
iSysUserService
.
updateById
(
sysU
ser
);
@PathVariable
Integer
id
,
@RequestBody
SysUser
u
ser
)
{
u
ser
.
setUpdateTime
(
new
Date
());
boolean
status
=
iSysUserService
.
updateById
(
u
ser
);
return
Result
.
status
(
status
);
}
...
...
@@ -102,14 +102,14 @@ public class SysUserController {
@ApiImplicitParam
(
name
=
"username"
,
value
=
"用户名"
,
required
=
true
,
paramType
=
"query"
,
dataType
=
"String"
)
@GetMapping
(
"/loadUserByUsername"
)
public
UserDTO
loadUserByUsername
(
@RequestParam
String
username
)
{
SysUser
sysU
ser
=
iSysUserService
.
getOne
(
new
LambdaQueryWrapper
<
SysUser
>()
SysUser
u
ser
=
iSysUserService
.
getOne
(
new
LambdaQueryWrapper
<
SysUser
>()
.
eq
(
SysUser:
:
getUsername
,
username
));
UserDTO
userDTO
=
new
UserDTO
();
if
(
sysU
ser
!=
null
)
{
BeanUtil
.
copyProperties
(
sysU
ser
,
userDTO
);
if
(
u
ser
!=
null
)
{
BeanUtil
.
copyProperties
(
u
ser
,
userDTO
);
List
<
Integer
>
roleIds
=
iSysUserRoleService
.
list
(
new
LambdaQueryWrapper
<
SysUserRole
>()
.
eq
(
SysUserRole:
:
getUserId
,
sysU
ser
.
getId
())
.
eq
(
SysUserRole:
:
getUserId
,
u
ser
.
getId
())
).
stream
().
map
(
item
->
item
.
getRoleId
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtil
.
isNotEmpty
(
roleIds
))
{
List
<
String
>
roles
=
iSysRoleService
.
listByIds
(
roleIds
).
stream
()
...
...
@@ -127,11 +127,11 @@ public class SysUserController {
String
payload
=
request
.
getHeader
(
AuthConstant
.
USER_TOKEN_HEADER
);
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
payload
);
Integer
id
=
jsonObject
.
getInt
(
"id"
);
SysUser
sysU
ser
=
iSysUserService
.
getById
(
id
);
SysUser
u
ser
=
iSysUserService
.
getById
(
id
);
UserVO
userVO
=
new
UserVO
();
BeanUtil
.
copyProperties
(
sysU
ser
,
userVO
);
BeanUtil
.
copyProperties
(
u
ser
,
userVO
);
List
<
Integer
>
roleIds
=
iSysUserRoleService
.
list
(
new
LambdaQueryWrapper
<
SysUserRole
>()
.
eq
(
SysUserRole:
:
getUserId
,
sysU
ser
.
getId
())
.
eq
(
SysUserRole:
:
getUserId
,
u
ser
.
getId
())
).
stream
().
map
(
item
->
item
.
getRoleId
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtil
.
isNotEmpty
(
roleIds
))
{
List
<
String
>
roles
=
iSysRoleService
.
listByIds
(
roleIds
).
stream
()
...
...
youlai-admin/src/main/java/com/youlai/admin/domain/entity/SysRole.java
浏览文件 @
81c94215
package
com.youlai.admin.domain.entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.youlai.common.core.entity.BaseEntity
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
SysRole
extends
BaseEntity
{
...
...
@@ -23,5 +26,8 @@ public class SysRole extends BaseEntity {
private
String
remark
;
@TableField
(
exist
=
false
)
private
List
<
Integer
>
menuIds
;
}
youlai-admin/src/main/java/com/youlai/admin/service/ISysRoleService.java
浏览文件 @
81c94215
...
...
@@ -4,5 +4,13 @@ package com.youlai.admin.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.youlai.admin.domain.entity.SysRole
;
import
java.util.List
;
public
interface
ISysRoleService
extends
IService
<
SysRole
>
{
boolean
update
(
SysRole
role
);
boolean
delete
(
List
<
Integer
>
ids
);
boolean
add
(
SysRole
role
);
}
youlai-admin/src/main/java/com/youlai/admin/service/impl/SysRoleServiceImpl.java
浏览文件 @
81c94215
package
com.youlai.admin.service.impl
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.youlai.admin.domain.entity.SysRole
;
import
com.youlai.admin.domain.entity.SysRoleMenu
;
import
com.youlai.admin.domain.entity.SysUserRole
;
import
com.youlai.admin.mapper.SysRoleMapper
;
import
com.youlai.admin.service.ISysRoleMenuService
;
import
com.youlai.admin.service.ISysRoleService
;
import
com.youlai.admin.service.ISysUserRoleService
;
import
com.youlai.common.web.exception.BusinessException
;
import
lombok.AllArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
@Service
@AllArgsConstructor
public
class
SysRoleServiceImpl
extends
ServiceImpl
<
SysRoleMapper
,
SysRole
>
implements
ISysRoleService
{
private
ISysRoleMenuService
iSysRoleMenuService
;
private
ISysUserRoleService
iSysUserRoleService
;
@Override
public
boolean
add
(
SysRole
role
)
{
List
<
Integer
>
menuIds
=
role
.
getMenuIds
();
List
<
SysRoleMenu
>
roleMenus
=
new
ArrayList
<>();
Optional
.
ofNullable
(
menuIds
)
.
orElse
(
new
ArrayList
<>())
.
forEach
(
menuId
->
{
SysRoleMenu
roleMenu
=
new
SysRoleMenu
();
roleMenu
.
setRoleId
(
role
.
getId
());
roleMenu
.
setMenuId
(
menuId
);
roleMenus
.
add
(
roleMenu
);
});
iSysRoleMenuService
.
saveBatch
(
roleMenus
);
return
this
.
save
(
role
);
}
@Override
public
boolean
update
(
SysRole
role
)
{
List
<
Integer
>
menuIds
=
iSysRoleMenuService
.
list
(
new
LambdaQueryWrapper
<
SysRoleMenu
>()
.
eq
(
SysRoleMenu:
:
getRoleId
,
role
.
getId
()))
.
stream
()
.
map
(
item
->
item
.
getMenuId
())
.
collect
(
Collectors
.
toList
());
// 数据库角色拥有菜单权限ID
List
<
Integer
>
updatedMenuIds
=
role
.
getMenuIds
();
// 修改后的角色拥有菜单权限ID
// 删除的角色菜单ID集合
List
<
Integer
>
removeMenuIds
=
Optional
.
ofNullable
(
menuIds
)
.
orElse
(
new
ArrayList
<>())
.
stream
()
.
filter
(
menuId
->
!
Optional
.
ofNullable
(
updatedMenuIds
).
orElse
(
new
ArrayList
<>()).
contains
(
menuId
))
.
collect
(
Collectors
.
toList
());
if
(
CollectionUtil
.
isNotEmpty
(
removeMenuIds
))
{
iSysRoleMenuService
.
remove
(
new
LambdaQueryWrapper
<
SysRoleMenu
>().
in
(
SysRoleMenu:
:
getMenuId
,
removeMenuIds
));
}
// 新增的角色菜单ID集合
List
<
Integer
>
addMenuIds
=
Optional
.
ofNullable
(
updatedMenuIds
)
.
orElse
(
new
ArrayList
<>())
.
stream
()
.
filter
(
menuId
->
!
Optional
.
ofNullable
(
menuIds
).
orElse
(
new
ArrayList
<>()).
contains
(
menuId
))
.
collect
(
Collectors
.
toList
());
List
<
SysRoleMenu
>
roleMenus
=
new
ArrayList
<>();
Optional
.
ofNullable
(
addMenuIds
)
.
orElse
(
new
ArrayList
<>())
.
forEach
(
menuId
->
{
SysRoleMenu
roleMenu
=
new
SysRoleMenu
();
roleMenu
.
setRoleId
(
role
.
getId
());
roleMenu
.
setMenuId
(
menuId
);
roleMenus
.
add
(
roleMenu
);
});
iSysRoleMenuService
.
saveBatch
(
roleMenus
);
// 修改角色菜单
return
this
.
updateById
(
role
);
}
@Override
public
boolean
delete
(
List
<
Integer
>
ids
)
{
Optional
.
ofNullable
(
ids
).
orElse
(
new
ArrayList
<>()).
forEach
(
id
->
{
int
count
=
iSysUserRoleService
.
count
(
new
LambdaQueryWrapper
<
SysUserRole
>().
eq
(
SysUserRole:
:
getRoleId
,
id
));
if
(
count
>
0
)
{
throw
new
BusinessException
(
"该角色已分配用户,无法删除"
);
}
// 删除角色菜单
iSysRoleMenuService
.
remove
(
new
LambdaQueryWrapper
<
SysRoleMenu
>().
eq
(
SysRoleMenu:
:
getRoleId
,
id
));
});
return
this
.
removeByIds
(
ids
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录