Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 46fbafee
authored
Sep 26, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
https://gitlab.dituhui.com/bsh/project/project
into de…
…velop_16542_system_auth
2 parents
b4959be6
0142709e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
191 additions
and
11 deletions
project-interface/src/main/java/com/dituhui/pea/common/PageResult.java
project-interface/src/main/java/com/dituhui/pea/pojo/PageRequest.java
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
project-order/src/main/java/com/dituhui/pea/order/controller/RoleController.java
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
project-interface/src/main/java/com/dituhui/pea/common/PageResult.java
0 → 100644
View file @
46fbafe
package
com
.
dituhui
.
pea
.
common
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 分页结果返回
*/
public
class
PageResult
<
E
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 当前页
*/
public
int
currPage
=
0
;
/**
* 总共页数
*/
public
int
totalPage
=
0
;
/**
* 总记录数
*/
public
long
recordCount
=
0
;
/**
* 数据明细
*/
public
List
<
E
>
dataList
=
new
ArrayList
<
E
>();
public
PageResult
()
{
}
public
PageResult
(
int
currPage
,
List
<
E
>
dataList
,
long
recordCount
,
int
totalPage
)
{
this
.
currPage
=
currPage
;
this
.
dataList
=
dataList
;
this
.
recordCount
=
recordCount
;
this
.
totalPage
=
totalPage
;
}
public
int
getCurrPage
()
{
return
currPage
;
}
public
void
setCurrPage
(
int
currPage
)
{
this
.
currPage
=
currPage
;
}
public
int
getTotalPage
()
{
return
totalPage
;
}
public
void
setTotalPage
(
int
totalPage
)
{
this
.
totalPage
=
totalPage
;
}
public
long
getRecordCount
()
{
return
recordCount
;
}
public
void
setRecordCount
(
long
recordCount
)
{
this
.
recordCount
=
recordCount
;
}
public
List
<
E
>
getDataList
()
{
return
dataList
;
}
public
void
setDataList
(
List
<
E
>
dataList
)
{
this
.
dataList
=
dataList
;
}
}
project-interface/src/main/java/com/dituhui/pea/pojo/PageRequest.java
0 → 100644
View file @
46fbafe
package
com
.
dituhui
.
pea
.
pojo
;
import
lombok.Data
;
@Data
public
class
PageRequest
{
private
Integer
size
=
10
;
private
Integer
page
=
1
;
}
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
View file @
46fbafe
package
com
.
dituhui
.
pea
.
pojo
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 角色信息
*/
...
...
@@ -14,19 +18,33 @@ public class RoleInfo {
* 主键
*/
private
String
id
;
/**
* 名称
*/
@NotBlank
(
message
=
"角色名称不能为空!"
)
private
String
name
;
/**
* 角色组id
*/
private
String
groupId
;
/**
* 角色自定义条件
*/
@NotBlank
(
message
=
"角色条件不能为空!"
)
private
String
extra
;
/**
* 创建时间
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
createdTime
;
/**
* 到修改时间
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
updatedTime
;
}
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
View file @
46fbafe
package
com
.
dituhui
.
pea
.
user
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.pojo.PageRequest
;
import
com.dituhui.pea.pojo.ResourceInfo
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.WebResult
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.data.domain.Page
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
...
@@ -17,6 +20,7 @@ public interface IRole {
/**
* 添加角色
*
* @param roleInfo 角色信息
* @return
*/
...
...
@@ -25,6 +29,7 @@ public interface IRole {
/**
* 删除角色
*
* @param roleId 角色ID
* @return
*/
...
...
@@ -33,6 +38,7 @@ public interface IRole {
/**
* 添加用户角色
*
* @param roleId 角色ID
* @param userId 用户ID
* @return
...
...
@@ -42,6 +48,7 @@ public interface IRole {
/**
* 删除用户角色
*
* @param userId 用户ID
* @param roleId 角色ID
* @return
...
...
@@ -51,6 +58,7 @@ public interface IRole {
/**
* 添加资源
*
* @param resourceInfo 资源信息
* @return
*/
...
...
@@ -59,6 +67,7 @@ public interface IRole {
/**
* 删除资源
*
* @param resourceId 资源ID
* @return
*/
...
...
@@ -67,7 +76,8 @@ public interface IRole {
/**
* 添加角色资源
* @param roleId 角色ID
*
* @param roleId 角色ID
* @param resourceId 资源ID
* @return
*/
...
...
@@ -76,7 +86,8 @@ public interface IRole {
/**
* 批量更新/替换角色权限/资源,会清空原来的权限/资源
* @param roleId 角色Id
*
* @param roleId 角色Id
* @param resourceIds 资源ID集合
* @return
*/
...
...
@@ -85,11 +96,21 @@ public interface IRole {
/**
* 删除角色资源
* @param roleId 角色ID
*
* @param roleId 角色ID
* @param resourceId 资源ID
* @return
*/
@RequestMapping
(
value
=
"/v1/role/deleteResource"
,
method
=
RequestMethod
.
POST
)
WebResult
<
Boolean
>
deleteRoleResource
(
@RequestParam
(
"id"
)
String
roleId
,
@RequestParam
(
"resource_id"
)
String
resourceId
);
/**
* 获取角色列表
*
* @param pageRequest 分页参数
* @return
*/
@RequestMapping
(
value
=
"/v1/role/list"
,
method
=
RequestMethod
.
GET
)
WebResult
<
PageResult
<
RoleInfo
>>
listRole
(
PageRequest
pageRequest
);
}
project-order/src/main/java/com/dituhui/pea/order/controller/RoleController.java
0 → 100644
View file @
46fbafe
package
com
.
dituhui
.
pea
.
order
.
controller
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.pojo.PageRequest
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.WebResult
;
import
com.dituhui.pea.user.IRole
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@Slf4j
@RestController
@RequestMapping
(
"/pea-order"
)
public
class
RoleController
{
@Autowired
IRole
roleService
;
@GetMapping
(
"/pea-role/list"
)
public
Result
<
PageResult
<
RoleInfo
>>
listRole
(
PageRequest
pageRequest
)
{
WebResult
<
PageResult
<
RoleInfo
>>
result
=
roleService
.
listRole
(
pageRequest
);
return
Result
.
success
(
result
.
getResult
());
}
}
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
View file @
46fbafe
package
com
.
dituhui
.
pea
.
user
.
controller
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.pojo.PageRequest
;
import
com.dituhui.pea.pojo.ResourceInfo
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.pojo.WebResult
;
...
...
@@ -31,7 +33,7 @@ public class RoleController implements IRole {
@Override
public
WebResult
<
Boolean
>
deleteRole
(
String
roleId
)
{
if
(
StringUtils
.
isBlank
(
roleId
)){
if
(
StringUtils
.
isBlank
(
roleId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
roleService
.
deleteRole
(
roleId
);
...
...
@@ -52,7 +54,7 @@ public class RoleController implements IRole {
if
(
StringUtils
.
isBlank
(
roleId
)
||
StringUtils
.
isBlank
(
userId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
roleService
.
deleteUserRole
(
roleId
,
userId
);
roleService
.
deleteUserRole
(
roleId
,
userId
);
return
WebResult
.
ok
();
}
...
...
@@ -82,7 +84,7 @@ public class RoleController implements IRole {
@Override
public
WebResult
<
Boolean
>
replaceRoleResource
(
String
roleId
,
String
resourceIds
)
{
if
(
StringUtils
.
isBlank
(
roleId
)
||
StringUtils
.
isBlank
(
resourceIds
)){
if
(
StringUtils
.
isBlank
(
roleId
)
||
StringUtils
.
isBlank
(
resourceIds
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
roleService
.
replaceRoleResource
(
roleId
,
resourceIds
);
...
...
@@ -94,9 +96,15 @@ public class RoleController implements IRole {
if
(
StringUtils
.
isBlank
(
roleId
)
||
StringUtils
.
isBlank
(
resourceId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
}
roleService
.
deleteRoleResource
(
roleId
,
resourceId
);
roleService
.
deleteRoleResource
(
roleId
,
resourceId
);
return
WebResult
.
ok
();
}
@Override
public
WebResult
<
PageResult
<
RoleInfo
>>
listRole
(
PageRequest
pageRequest
)
{
PageResult
<
RoleInfo
>
result
=
roleService
.
listRole
(
pageRequest
);
return
WebResult
.
ok
(
result
);
}
}
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
View file @
46fbafe
...
...
@@ -3,22 +3,28 @@ package com.dituhui.pea.user.service;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.dituhui.pea.common.PageResult
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
import
com.dituhui.pea.exception.BusinessException
;
import
com.dituhui.pea.pojo.PageRequest
;
import
com.dituhui.pea.pojo.ResourceInfo
;
import
com.dituhui.pea.pojo.RoleInfo
;
import
com.dituhui.pea.user.dao.*
;
import
com.dituhui.pea.user.entity.*
;
import
com.google.common.collect.Lists
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* 角色业务层
*
* @author zl
*/
@Service
...
...
@@ -62,7 +68,7 @@ public class RoleService {
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
addUserRole
(
String
roleId
,
String
userId
){
public
void
addUserRole
(
String
roleId
,
String
userId
)
{
// 查询角色是否存在
RoleEntity
roleEntity
=
roleDao
.
findById
(
roleId
).
orElse
(
null
);
if
(
ObjectUtil
.
isNull
(
roleEntity
))
{
...
...
@@ -181,7 +187,7 @@ public class RoleService {
}
private
RoleResourceEntity
assembleRoleResource
(
String
roleId
,
String
resourceId
){
private
RoleResourceEntity
assembleRoleResource
(
String
roleId
,
String
resourceId
)
{
RoleResourceEntity
roleResourceEntity
=
new
RoleResourceEntity
();
roleResourceEntity
.
setRoleId
(
roleId
);
roleResourceEntity
.
setResourceId
(
resourceId
);
...
...
@@ -189,6 +195,19 @@ public class RoleService {
}
public
PageResult
<
RoleInfo
>
listRole
(
PageRequest
pageRequest
)
{
Pageable
pageable
=
org
.
springframework
.
data
.
domain
.
PageRequest
.
of
(
pageRequest
.
getPage
()
-
1
,
pageRequest
.
getSize
());
Page
<
RoleEntity
>
page
=
roleDao
.
findAll
(
pageable
);
List
<
RoleInfo
>
roleInfos
=
new
ArrayList
<>();
for
(
RoleEntity
role
:
page
.
getContent
())
{
RoleInfo
roleInfo
=
BeanUtil
.
copyProperties
(
role
,
RoleInfo
.
class
);
roleInfos
.
add
(
roleInfo
);
}
PageResult
<
RoleInfo
>
result
=
new
PageResult
<>();
result
.
setDataList
(
roleInfos
);
result
.
setCurrPage
(
page
.
getNumber
());
result
.
setRecordCount
(
page
.
getTotalElements
());
result
.
setTotalPage
(
page
.
getTotalPages
());
return
result
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment