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 1a45eacb
authored
Oct 07, 2023
by
huangjinxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:角色增删改
1 parent
e91d8816
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
84 deletions
project-interface/src/main/java/com/dituhui/pea/common/Result.java
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
project-interface/src/main/java/com/dituhui/pea/common/Result.java
View file @
1a45eac
...
@@ -16,80 +16,90 @@
...
@@ -16,80 +16,90 @@
package
com
.
dituhui
.
pea
.
common
;
package
com
.
dituhui
.
pea
.
common
;
import
com.dituhui.pea.enums.StatusCodeEnum
;
/**
/**
* @author TrevorLink
* @author TrevorLink
*/
*/
public
class
Result
<
T
>
{
public
class
Result
<
T
>
{
private
String
code
;
private
String
code
;
private
String
message
;
private
String
message
;
private
T
result
;
private
T
result
;
public
static
<
T
>
Result
<
T
>
success
(
T
result
)
{
public
static
<
T
>
Result
<
T
>
success
(
T
result
)
{
return
new
Result
<>(
ResultEnum
.
SUCCESS
.
getCode
(),
ResultEnum
.
SUCCESS
.
getMessage
(),
result
);
return
new
Result
<>(
ResultEnum
.
SUCCESS
.
getCode
(),
ResultEnum
.
SUCCESS
.
getMessage
(),
result
);
}
}
public
static
<
T
>
Result
<
T
>
success
(
String
message
,
T
result
)
{
public
static
<
T
>
Result
<
T
>
success
(
String
message
,
T
result
)
{
return
new
Result
<>(
ResultEnum
.
SUCCESS
.
getCode
(),
message
,
result
);
return
new
Result
<>(
ResultEnum
.
SUCCESS
.
getCode
(),
message
,
result
);
}
}
public
static
Result
<?>
failed
()
{
public
static
Result
<?>
failed
()
{
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
ResultEnum
.
COMMON_FAILED
.
getMessage
(),
null
);
ResultEnum
.
COMMON_FAILED
.
getMessage
(),
null
);
}
}
public
static
Result
<?>
failed
(
String
message
)
{
public
static
Result
<?>
failed
(
String
message
)
{
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
message
,
null
);
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
message
,
null
);
}
}
public
static
<
T
>
Result
<
T
>
failure
(
String
message
)
{
public
static
<
T
>
Result
<
T
>
failure
(
String
message
)
{
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
message
,
null
);
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
message
,
null
);
}
}
public
static
Result
<?>
failed
(
IResult
errorResult
)
{
public
static
Result
<?>
failed
(
IResult
errorResult
)
{
return
new
Result
<>(
errorResult
.
getCode
(),
errorResult
.
getMessage
(),
null
);
return
new
Result
<>(
errorResult
.
getCode
(),
errorResult
.
getMessage
(),
null
);
}
}
public
Result
()
{
public
static
<
T
>
Result
<
T
>
failed
(
T
result
)
{
}
return
new
Result
<>(
ResultEnum
.
COMMON_FAILED
.
getCode
(),
ResultEnum
.
COMMON_FAILED
.
getMessage
(),
result
);
}
public
Result
(
String
code
,
String
message
,
T
result
)
{
this
.
code
=
code
;
public
static
<
T
>
Result
<
T
>
failed
(
StatusCodeEnum
resultEnum
,
T
result
)
{
this
.
message
=
message
;
return
new
Result
<>(
resultEnum
.
getCode
(),
resultEnum
.
getDesc
(),
result
);
this
.
result
=
result
;
}
}
public
Result
()
{
public
String
getCode
()
{
}
return
this
.
code
;
}
public
Result
(
String
code
,
String
message
,
T
result
)
{
this
.
code
=
code
;
public
void
setCode
(
String
code
)
{
this
.
message
=
message
;
this
.
code
=
code
;
this
.
result
=
result
;
}
}
public
String
getMessage
()
{
public
String
getCode
()
{
return
this
.
message
;
return
this
.
code
;
}
}
public
void
setMessage
(
String
message
)
{
public
void
setCode
(
String
code
)
{
this
.
message
=
message
;
this
.
code
=
code
;
}
}
public
T
getResult
()
{
public
String
getMessage
()
{
return
this
.
result
;
return
this
.
message
;
}
}
public
void
setResult
(
T
result
)
{
public
void
setMessage
(
String
message
)
{
this
.
result
=
result
;
this
.
message
=
message
;
}
}
public
static
<
T
>
Result
<
T
>
instance
(
String
code
,
String
message
,
T
result
)
{
public
T
getResult
()
{
Result
<
T
>
r
=
new
Result
<>();
return
this
.
result
;
r
.
setCode
(
code
);
}
r
.
setMessage
(
message
);
r
.
setResult
(
result
);
public
void
setResult
(
T
result
)
{
return
r
;
this
.
result
=
result
;
}
}
public
static
<
T
>
Result
<
T
>
instance
(
String
code
,
String
message
,
T
result
)
{
Result
<
T
>
r
=
new
Result
<>();
r
.
setCode
(
code
);
r
.
setMessage
(
message
);
r
.
setResult
(
result
);
return
r
;
}
}
}
project-interface/src/main/java/com/dituhui/pea/pojo/RoleInfo.java
View file @
1a45eac
...
@@ -32,9 +32,14 @@ public class RoleInfo {
...
@@ -32,9 +32,14 @@ public class RoleInfo {
private
String
groupId
;
private
String
groupId
;
/**
/**
* 备注
*/
private
String
notes
;
/**
* 角色自定义条件
* 角色自定义条件
*/
*/
@NotBlank
(
message
=
"角色条件不能为空!"
)
//
@NotBlank(message = "角色条件不能为空!")
private
String
extra
;
private
String
extra
;
/**
/**
...
@@ -50,4 +55,12 @@ public class RoleInfo {
...
@@ -50,4 +55,12 @@ public class RoleInfo {
private
Date
updatedTime
;
private
Date
updatedTime
;
private
List
<
RoleResourceInfo
>
resourceInfos
;
private
List
<
RoleResourceInfo
>
resourceInfos
;
/**
* 创建人
*/
private
String
createdBy
;
/**
* 更新人
*/
private
String
updatedBy
;
}
}
project-interface/src/main/java/com/dituhui/pea/user/IRole.java
View file @
1a45eac
...
@@ -27,7 +27,7 @@ public interface IRole {
...
@@ -27,7 +27,7 @@ public interface IRole {
* @return
* @return
*/
*/
@RequestMapping
(
value
=
"/pea-user/role/add"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/pea-user/role/add"
,
method
=
RequestMethod
.
POST
)
Web
Result
<
RoleInfo
>
addRole
(
@RequestBody
RoleInfo
roleInfo
);
Result
<
RoleInfo
>
addRole
(
@RequestBody
RoleInfo
roleInfo
);
/**
/**
...
@@ -37,7 +37,7 @@ public interface IRole {
...
@@ -37,7 +37,7 @@ public interface IRole {
* @return
* @return
*/
*/
@RequestMapping
(
value
=
"/pea-user/role/update"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/pea-user/role/update"
,
method
=
RequestMethod
.
POST
)
Web
Result
<
RoleInfo
>
updateRole
(
@RequestBody
RoleInfo
roleInfo
);
Result
<
RoleInfo
>
updateRole
(
@RequestBody
RoleInfo
roleInfo
);
/**
/**
* 删除角色
* 删除角色
...
@@ -46,7 +46,7 @@ public interface IRole {
...
@@ -46,7 +46,7 @@ public interface IRole {
* @return
* @return
*/
*/
@RequestMapping
(
value
=
"/pea-user/role/delete"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/pea-user/role/delete"
,
method
=
RequestMethod
.
POST
)
Web
Result
<
Boolean
>
deleteRole
(
@RequestParam
(
"id"
)
String
roleId
);
Result
<
Boolean
>
deleteRole
(
@RequestParam
(
"id"
)
String
roleId
);
/**
/**
* 添加用户角色
* 添加用户角色
...
...
project-user/src/main/java/com/dituhui/pea/user/controller/RoleController.java
View file @
1a45eac
...
@@ -33,25 +33,25 @@ public class RoleController implements IRole {
...
@@ -33,25 +33,25 @@ public class RoleController implements IRole {
RoleService
roleService
;
RoleService
roleService
;
@Override
@Override
public
Web
Result
<
RoleInfo
>
addRole
(
@Validated
RoleInfo
roleInfo
)
{
public
Result
<
RoleInfo
>
addRole
(
@Validated
RoleInfo
roleInfo
)
{
roleInfo
=
roleService
.
addRole
(
roleInfo
);
roleInfo
=
roleService
.
addRole
(
roleInfo
);
return
WebResult
.
ok
(
roleInfo
);
return
Result
.
success
(
roleInfo
);
}
}
@Override
@Override
public
Web
Result
<
RoleInfo
>
updateRole
(
@Validated
RoleInfo
roleInfo
)
{
public
Result
<
RoleInfo
>
updateRole
(
@Validated
RoleInfo
roleInfo
)
{
roleInfo
=
roleService
.
updateRole
(
roleInfo
);
roleInfo
=
roleService
.
updateRole
(
roleInfo
);
return
WebResult
.
ok
(
roleInfo
);
return
Result
.
success
(
roleInfo
);
}
}
@Override
@Override
public
Web
Result
<
Boolean
>
deleteRole
(
String
roleId
)
{
public
Result
<
Boolean
>
deleteRole
(
String
roleId
)
{
if
(
StringUtils
.
isBlank
(
roleId
))
{
if
(
StringUtils
.
isBlank
(
roleId
))
{
return
WebResult
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
);
return
Result
.
failed
(
StatusCodeEnum
.
COMMON_PARAM_EMPTY
,
false
);
}
}
roleService
.
deleteRole
(
roleId
);
roleService
.
deleteRole
(
roleId
);
return
WebResult
.
ok
(
);
return
Result
.
success
(
true
);
}
}
@Override
@Override
...
...
project-user/src/main/java/com/dituhui/pea/user/entity/RoleEntity.java
View file @
1a45eac
...
@@ -69,4 +69,9 @@ public class RoleEntity implements Serializable {
...
@@ -69,4 +69,9 @@ public class RoleEntity implements Serializable {
@LastModifiedDate
@LastModifiedDate
private
Date
updatedTime
;
private
Date
updatedTime
;
/**
* 备注
*/
private
String
notes
;
}
}
project-user/src/main/java/com/dituhui/pea/user/service/RoleService.java
View file @
1a45eac
...
@@ -84,9 +84,9 @@ public class RoleService {
...
@@ -84,9 +84,9 @@ public class RoleService {
roleEntity
=
roleDao
.
save
(
roleEntity
);
roleEntity
=
roleDao
.
save
(
roleEntity
);
List
<
RoleResourceInfo
>
resourceInfos
=
roleInfo
.
getResourceInfos
();
List
<
RoleResourceInfo
>
resourceInfos
=
roleInfo
.
getResourceInfos
();
if
(
CollectionUtils
.
isNotEmpty
(
resourceInfos
))
{
if
(
CollectionUtils
.
isNotEmpty
(
resourceInfos
))
{
// 先清除
roleResourceDao
.
deleteByRoleId
(
roleEntity
.
getId
());
for
(
RoleResourceInfo
resourceInfo
:
resourceInfos
)
{
for
(
RoleResourceInfo
resourceInfo
:
resourceInfos
)
{
// 先清除
roleResourceDao
.
deleteByRoleId
(
roleEntity
.
getId
());
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
roleEntity
.
getId
(),
resourceInfo
.
getResourceId
());
RoleResourceEntity
roleResourceEntity
=
assembleRoleResource
(
roleEntity
.
getId
(),
resourceInfo
.
getResourceId
());
roleResourceDao
.
save
(
roleResourceEntity
);
roleResourceDao
.
save
(
roleResourceEntity
);
}
}
...
...
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