Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
T
tcm-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
TCM
tcm-system
Commits
13496897
Commit
13496897
authored
May 10, 2019
by
zjy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user/role/tright 5.10 20:33
parent
5ba6bd1c
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
508 additions
and
285 deletions
+508
-285
readme.md
src/main/java/com/pangding/web/readme.md
+137
-0
RoleController.java
...va/com/pangding/web/tright/controller/RoleController.java
+6
-21
TrightController.java
.../com/pangding/web/tright/controller/TrightController.java
+1
-13
UserController.java
...va/com/pangding/web/tright/controller/UserController.java
+45
-36
RoleDao.java
src/main/java/com/pangding/web/tright/dao/RoleDao.java
+6
-6
UserDao.java
src/main/java/com/pangding/web/tright/dao/UserDao.java
+6
-6
UserRoleDao.java
src/main/java/com/pangding/web/tright/dao/UserRoleDao.java
+6
-4
RoleDaoImpl.java
...in/java/com/pangding/web/tright/dao/impl/RoleDaoImpl.java
+7
-10
UserDaoImpl.java
...in/java/com/pangding/web/tright/dao/impl/UserDaoImpl.java
+7
-28
UserRoleDaoImpl.java
...ava/com/pangding/web/tright/dao/impl/UserRoleDaoImpl.java
+6
-4
RoleService.java
...ain/java/com/pangding/web/tright/service/RoleService.java
+11
-40
TrightService.java
...n/java/com/pangding/web/tright/service/TrightService.java
+1
-15
UserService.java
...ain/java/com/pangding/web/tright/service/UserService.java
+26
-20
RoleServiceImpl.java
...com/pangding/web/tright/service/impl/RoleServiceImpl.java
+49
-41
TrightServiceImpl.java
...m/pangding/web/tright/service/impl/TrightServiceImpl.java
+8
-12
UserServiceImpl.java
...com/pangding/web/tright/service/impl/UserServiceImpl.java
+81
-29
GetRoleByRoleIdReqVo.java
...java/com/pangding/web/tright/vo/GetRoleByRoleIdReqVo.java
+17
-0
GetRoleByRoleNameReqVo.java
...va/com/pangding/web/tright/vo/GetRoleByRoleNameReqVo.java
+17
-0
GetUserByAccountReqVo.java
...ava/com/pangding/web/tright/vo/GetUserByAccountReqVo.java
+20
-0
GetUserByIdReqVo.java
...ain/java/com/pangding/web/tright/vo/GetUserByIdReqVo.java
+17
-0
GetUserRoleListByUserIdReqVo.java
.../pangding/web/tright/vo/GetUserRoleListByUserIdReqVo.java
+17
-0
UserRoleDaoRemoveReqVo.java
...va/com/pangding/web/tright/vo/UserRoleDaoRemoveReqVo.java
+17
-0
No files found.
src/main/java/com/pangding/web/readme.md
View file @
13496897
# 参数请符合实体,而不是单独的参数,专注于参数内容,专注于参数顺序
```
java
{
id:
"1"
}
```
如:
```
java
public
List
<
String
>
getRoleTrightPKListByRoleId
(
String
roleId
)
{
return
this
.
query
(
String
.
class
,
GET_ROLE_TRIGHT_PKLIST_BY_ROLEID
,
roleId
);
}
```
# RoleDaoImpl
## 夏敏的函数请用load,可以删除
```
java
@Override
public
RoleVo
getRoleById
(
String
id
)
{
return
this
.
queryFirst
(
RoleVo
.
class
,
GET_ROLE_BY_ID
,
id
);
}
@Override
public
RoleVo
getRoleByName
(
String
name
)
{
return
this
.
queryFirst
(
RoleVo
.
class
,
GET_ROLE_BY_NAME
,
name
);
}
```
参见如下代码:
```
java
dao
.
load
({
id:
"1"
})
dao
.
load
({
name:
"1"
})
```
## 检测语句
```
java
table
.
add
(
CHECK_NAME_EXIST
,
"select count(r.id) from pd_role r where 1=1 "
)
.
add
(
"name"
,
"and r.name = ? "
)
.
add
(
"id"
,
"and r.id <> ?"
);
```
改成
```
java
table
.
addExist
(
CHECK_NAME_EXIST
,
"name"
);
```
调用时
```
java
this
.
checkExist
(
CHECK_NAME_EXIST
,
roleVo
,
"橘色名称已经存在"
);
```
# 请确定语句主表,比如说和 pd_role_authority表和pd_authority表的查询,请另外新建dao层,符合三层架构规范
```
java
table
.
add
(
GET_TRIGHTID_LIST
,
"select authority_id from pd_role_authority where 1=1 "
)
.
add
(
"roleId"
,
"and role_id = ?"
);
table
.
add
(
GET_TRIGHTNAME_BY_TRIGHTID
,
"select name from pd_authority where 1=1 "
)
.
add
(
"trightId"
,
"and id = ?"
);
```
# SQL语句合并
```
java
table
.
add
(
GET_ROLE_TRIGHT_PKLIST_BY_ROLEID
,
"select id from pd_role_authority where 1=1 "
)
.
add
(
"roleId"
,
"and role_id = ?"
);
table
.
add
(
GET_ROLE_TRIGHT_PKLIST_BY_TRIGHTID
,
"select id from pd_role_authority where 1=1 "
)
.
add
(
"trightId"
,
"and tright_id = ?"
);
```
可以合并为
```
java
table
.
add
(
GET_ROLE_TRIGHT_PKLIST_BY_ROLEID
,
"select id from pd_role_authority where 1=1 "
)
.
add
(
"roleId"
,
"and role_id = ?"
);
.
add
(
"trightId"
,
"and tright_id = ?"
);
```
# 更爱SQL语句
```
java
table
.
add
(
CHECK_VALID
,
"select count(a.id) from pd_authority a where 1=1 "
)
.
add
(
"name"
,
"and a.name = ? "
)
.
add
(
"url"
,
"and a.url = ? "
)
.
add
(
"id"
,
"and a.id <> ?"
);
```
改为:
```
java
table
.
addExist
(
CHECK_VALID
,
"name"
,
"url"
);
```
# 将如下SQL语句合并
```
java
table
.
add
(
GET_TRIGHT_BY_ID
,
"select * from pd_authority where 1=1 "
)
.
add
(
"id"
,
"and id = ?"
);
table
.
add
(
LIST_ALL
,
"select * from pd_authority where 1=1"
);
table
.
add
(
LIST_LEVEL_ONE
,
"select * from pd_authority where pid=null"
);
// 这句SQL语句可以去掉,本身没有意义
table
.
add
(
CHECK_CHILD
,
"select count(id) from pd_authority where 1=1 "
)
.
add
(
"id"
,
"and pid = ?"
);
table
.
add
(
GET_CHILDID_LIST
,
"select id from pd_authority where 1=1 "
)
.
add
(
"id"
,
"and pid = ?"
);
```
如:
is null, is not null , ifnull(field,'')=''
```
java
table
.
add
(
GET_TRIGHT_BY_ID
,
"select * from pd_authority where 1=1 "
)
.
add
(
"id"
,
"and id = ?"
)
.
add
(
"top"
,
"and ifnull(pid,'')= ''"
)
.
add
(
"pid"
,
"and pid = ?"
);
```
# 将如下SQL语句合并
```
java
table
.
add
(
GET_USER
,
"SELECT id,account,phone,status,remark,create_time,creator FROM pd_user WHERE 1=1 "
)
.
add
(
"account"
,
" AND account = ?"
);
table
.
add
(
GET_ALL_USERS
,
"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1"
);
table
.
add
(
GET_ROLE_IDS
,
"select role_id from pd_user_role where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
table
.
add
(
GET_USER_BY_ID
,
"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
table
.
add
(
GET_ROLE_BY_ROLEID
,
"select name from pd_role where 1=1 "
)
.
add
(
"roleId"
,
"and id = ?"
);
```
# 如下语句可以删除
```
java
table
.
add
(
DELETE_USER_ROLE
,
"delete from pd_user_role_relation where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
```
直接调用:
```
dao.remove({userId:"1"})
```
\ No newline at end of file
src/main/java/com/pangding/web/tright/controller/RoleController.java
View file @
13496897
...
...
@@ -2,17 +2,16 @@ package com.pangding.web.tright.controller;
import
com.pangding.web.tright.currency.Result
;
import
com.pangding.web.tright.dao.RoleDao
;
import
com.pangding.web.tright.dto.RoleDto
;
import
com.pangding.web.tright.service.RoleService
;
import
com.pangding.web.tright.vo.RoleVo
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
/**
* @author zhangjinyao
...
...
@@ -23,8 +22,7 @@ public class RoleController {
@Autowired
RoleService
roleServiceImpl
;
@Autowired
RoleDao
roleDao
;
/**
* 新增角色
* @param roleDto
...
...
@@ -32,16 +30,13 @@ public class RoleController {
*/
@RequestMapping
(
value
=
"/save"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
Object
saveRole
(
@RequestBody
RoleDto
roleDto
){
String
id
=
roleDto
.
getId
();
String
name
=
roleDto
.
getName
();
if
(
roleServiceImpl
.
getRoleById
(
id
)
!=
null
){
return
new
Result
(
4001
,
"该角色ID已存在"
,
null
);
}
if
(
roleServiceImpl
.
getRoleByName
(
name
)
!=
null
){
return
new
Result
(
4001
,
"该角色名已存在"
,
null
);
}
role
ServiceImpl
.
saveRole
((
RoleVo
)
roleDto
);
roleServiceImpl
.
roleAndTright
(
roleDto
);
role
Dto
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
);
roleServiceImpl
.
saveRole
(
roleDto
);
return
new
Result
(
0
,
"SUCCESS"
,
null
);
}
...
...
@@ -56,8 +51,7 @@ public class RoleController {
if
(!
roleServiceImpl
.
checkNameExist
(
roleVo
)){
return
new
Result
(
4001
,
"该角色名已存在"
,
null
);
}
roleServiceImpl
.
saveRole
(
roleVo
);
roleServiceImpl
.
roleAndTright
(
roleDto
);
roleServiceImpl
.
updateRole
(
roleDto
);
Result
result
=
new
Result
(
0
,
"SUCCESS"
,
null
);
return
result
;
}
...
...
@@ -116,15 +110,6 @@ public class RoleController {
@RequestMapping
(
value
=
"/delete/{roleId}"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
Object
delete
(
@PathVariable
String
roleId
){
roleServiceImpl
.
deleteRole
(
roleId
);
List
<
String
>
roleUserList
=
roleServiceImpl
.
getRoleUserPKListByRoleId
(
roleId
);
for
(
String
roleUserId:
roleUserList
)
{
roleServiceImpl
.
deleteRoleUser
(
roleUserId
);
}
List
<
String
>
roleTrightList
=
roleServiceImpl
.
getRoleTrightPKListByRoleId
(
roleId
);
for
(
String
roleTrightId:
roleTrightList
)
{
roleServiceImpl
.
deleteRoleTright
(
roleTrightId
);
}
Result
result
=
new
Result
(
0
,
"SUCCESS"
,
null
);
return
result
;
}
...
...
src/main/java/com/pangding/web/tright/controller/TrightController.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Lists
;
import
com.pangding.web.tright.currency.Result
;
import
com.pangding.web.tright.dao.TrightDao
;
import
com.pangding.web.tright.service.TrightService
;
import
com.pangding.web.tright.vo.TrightVo
;
import
org.bouncycastle.jcajce.provider.digest.MD5
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -24,8 +19,6 @@ public class TrightController {
@Autowired
TrightService
trightServiceImpl
;
@Autowired
TrightDao
trightDao
;
/**
* 新增权限
...
...
@@ -113,7 +106,7 @@ public class TrightController {
}
/**
* 删除权限
* 删除权限
及其子权限
* @param id
* @return
*/
...
...
@@ -126,11 +119,6 @@ public class TrightController {
}
}
trightServiceImpl
.
deleteTrightById
(
id
);
List
<
String
>
roleTrightList
=
trightServiceImpl
.
getRoleTrightPKListByTrightId
(
id
);
for
(
String
roleTrightId:
roleTrightList
)
{
trightServiceImpl
.
deleteRoleTright
(
roleTrightId
);
}
return
new
Result
(
0
,
"SUCCESS"
,
null
);
}
}
...
...
src/main/java/com/pangding/web/tright/controller/UserController.java
View file @
13496897
...
...
@@ -2,18 +2,16 @@ package com.pangding.web.tright.controller;
import
com.pangding.web.tright.currency.Result
;
import
com.pangding.web.tright.dao.UserDao
;
import
com.pangding.web.tright.dto.UserDto
;
import
com.pangding.web.tright.service.UserService
;
import
com.pangding.web.tright.vo.
UserVo
;
import
com.pangding.web.tright.vo.
*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.UUID
;
/**
* @author zhangjinyao
...
...
@@ -24,8 +22,7 @@ public class UserController {
@Autowired
UserService
userServiceImpl
;
@Autowired
private
UserDao
userDao
;
/**
* 新增用户
* @param userDto
...
...
@@ -37,18 +34,13 @@ public class UserController {
UserVo
u
=
userServiceImpl
.
getUser
(
userDto
);
if
(
u
!=
null
)
{
return
new
Result
(
4001
,
"该用户已存在"
,
null
);
return
new
Result
(
4001
,
"该用户
名
已存在"
,
null
);
}
String
saltPassword
=
userServiceImpl
.
passwordEncoder
(
userDto
.
getPassword
());
userDto
.
setPassword
(
saltPassword
);
userDao
.
create
(
userDto
);
if
(
userDto
.
getRoleIds
()!=
null
&&
userDto
.
getRoleIds
().
size
()!=
0
){
userServiceImpl
.
userAndRole
(
userDto
);
}
userDto
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
userServiceImpl
.
saveUser
(
userDto
);
Result
result
=
new
Result
(
0
,
"SUCCESS"
,
null
);
return
result
;
}
...
...
@@ -59,10 +51,12 @@ public class UserController {
*/
@RequestMapping
(
value
=
"/update"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
Object
updateUser
(
@RequestBody
UserDto
userDto
){
UserVo
u
=
userDto
;
u
.
setPassword
(
userServiceImpl
.
passwordEncoder
(
u
.
getPassword
()));
userDao
.
update
(
u
);
userServiceImpl
.
userAndRole
(
userDto
);
UserVo
u
=
userServiceImpl
.
getUser
(
userDto
);
if
(
u
!=
null
&&
!
u
.
getId
().
equals
(
userDto
.
getId
()))
{
return
new
Result
(
4001
,
"该用户名已存在"
,
null
);
}
userDto
.
setPassword
(
userServiceImpl
.
passwordEncoder
(
userDto
.
getPassword
()));
userServiceImpl
.
updateUser
(
userDto
);
Result
result
=
new
Result
(
0
,
"SUCCESS"
,
null
);
return
result
;
}
...
...
@@ -77,15 +71,23 @@ public class UserController {
List
<
UserVo
>
userVoList
=
userServiceImpl
.
listUserVo
();
List
<
UserDto
>
userDtoList
=
new
ArrayList
(
userVoList
.
size
());
for
(
int
var1
=
0
;
var1
<
userVoList
.
size
();
var1
++){
UserVo
userVo
=
userVoList
.
get
(
var1
);
List
<
String
>
roleIdList
=
userServiceImpl
.
listRoleIdList
(
userVo
);
List
<
String
>
roleList
=
new
ArrayList
(
roleIdList
.
size
());
for
(
int
var2
=
0
;
var2
<
roleIdList
.
size
();++
var2
){
String
role
=
userServiceImpl
.
getRoleNameByRoleId
(
roleIdList
.
get
(
var2
));
roleList
.
add
(
role
);
for
(
int
index1
=
0
;
index1
<
userVoList
.
size
();
index1
++){
UserVo
userVo
=
userVoList
.
get
(
index1
);
GetUserRoleListByUserIdReqVo
reqVo
=
new
GetUserRoleListByUserIdReqVo
();
reqVo
.
setUserId
(
userVo
.
getId
());
List
<
UserRoleRelation
>
userRole
=
userServiceImpl
.
listUserRoleListByUserId
(
reqVo
);
List
<
String
>
roleIdList
=
new
ArrayList
(
userRole
.
size
());
for
(
UserRoleRelation
userRoleRelation:
userRole
)
{
roleIdList
.
add
(
userRoleRelation
.
getRoleId
());
}
List
<
String
>
roleNameList
=
new
ArrayList
(
roleIdList
.
size
());
for
(
int
index2
=
0
;
index2
<
roleIdList
.
size
();
index2
++){
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
=
new
GetRoleByRoleIdReqVo
();
getRoleByRoleIdReqVo
.
setId
(
roleIdList
.
get
(
index2
));
RoleVo
role
=
userServiceImpl
.
getRoleByRoleId
(
getRoleByRoleIdReqVo
);
roleNameList
.
add
(
role
.
getName
());
}
UserDto
userDto
=
userServiceImpl
.
makeUserDto
(
userVo
,
roleIdList
,
roleList
);
UserDto
userDto
=
userServiceImpl
.
makeUserDto
(
userVo
,
roleIdList
,
role
Name
List
);
userDtoList
.
add
(
userDto
);
}
...
...
@@ -98,22 +100,29 @@ public class UserController {
* @param //id
* @return
*/
@RequestMapping
(
value
=
"/user"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
Object
user
(
String
userId
){
//@PathVariable Long id
@RequestMapping
(
value
=
"/user
/{userId}
"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
Object
user
(
@PathVariable
String
userId
){
UserVo
userVo
=
userServiceImpl
.
getUserById
(
userId
);
if
(
userVo
==
null
){
return
new
Result
(
4001
,
"该用户不存在"
,
null
);
}
List
<
String
>
roleIdList
=
userServiceImpl
.
listRoleIdList
(
userVo
);
List
<
String
>
roleList
=
new
ArrayList
(
roleIdList
.
size
());
for
(
int
var2
=
0
;
var2
<
roleIdList
.
size
();
var2
++){
String
role
=
userServiceImpl
.
getRoleNameByRoleId
(
roleIdList
.
get
(
var2
));
roleList
.
add
(
role
);
GetUserRoleListByUserIdReqVo
reqVo
=
new
GetUserRoleListByUserIdReqVo
();
reqVo
.
setUserId
(
userVo
.
getId
());
List
<
UserRoleRelation
>
userRole
=
userServiceImpl
.
listUserRoleListByUserId
(
reqVo
);
List
<
String
>
roleIdList
=
new
ArrayList
(
userRole
.
size
());
for
(
UserRoleRelation
userRoleRelation:
userRole
)
{
roleIdList
.
add
(
userRoleRelation
.
getRoleId
());
}
UserDto
userDto
=
userServiceImpl
.
makeUserDto
(
userVo
,
roleIdList
,
roleList
);
Result
result
=
new
Result
(
0
,
"SUCCESS"
,
userDto
);
return
result
;
List
<
String
>
roleNameList
=
new
ArrayList
(
roleIdList
.
size
());
for
(
int
index2
=
0
;
index2
<
roleIdList
.
size
();
index2
++){
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
=
new
GetRoleByRoleIdReqVo
();
getRoleByRoleIdReqVo
.
setId
(
roleIdList
.
get
(
index2
));
RoleVo
role
=
userServiceImpl
.
getRoleByRoleId
(
getRoleByRoleIdReqVo
);
roleNameList
.
add
(
role
.
getName
());
}
UserDto
userDto
=
userServiceImpl
.
makeUserDto
(
userVo
,
roleIdList
,
roleNameList
);
return
new
Result
(
0
,
"SUCCESS"
,
userDto
);
}
}
src/main/java/com/pangding/web/tright/dao/RoleDao.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
;
import
com.pangding.web.tright.
dto.RoleDt
o
;
import
com.pangding.web.tright.vo.
RoleTrightRelation
;
import
com.pangding.web.tright.
vo.GetRoleByRoleIdReqV
o
;
import
com.pangding.web.tright.vo.
GetRoleByRoleNameReqVo
;
import
com.pangding.web.tright.vo.RoleVo
;
import
com.yanzuoguang.dao.BaseDao
;
...
...
@@ -15,18 +15,18 @@ public interface RoleDao extends BaseDao {
/**
* 通过主键id获取RoleVo对象
*
* @param
id 主键
* @param
getRoleByRoleIdReqVo getRoleByRoleIdReqVo对象
* @return RoleVo对象
*/
RoleVo
getRoleById
(
String
id
);
RoleVo
getRoleById
(
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
);
/**
* 通过角色名查询RoleVo对象
*
* @param
name
角色名
* @param
getRoleByRoleNameReqVo
角色名
* @return RoleVo对象
*/
RoleVo
getRoleBy
Name
(
String
name
);
RoleVo
getRoleBy
RoleName
(
GetRoleByRoleNameReqVo
getRoleByRoleNameReqVo
);
/**
* 检查用户名是否已存在
...
...
src/main/java/com/pangding/web/tright/dao/UserDao.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
;
import
com.pangding.web.tright.
dto.UserDt
o
;
import
com.pangding.web.tright.vo.
UserRoleRelation
;
import
com.pangding.web.tright.
vo.GetUserByAccountReqV
o
;
import
com.pangding.web.tright.vo.
GetUserByIdReqVo
;
import
com.pangding.web.tright.vo.UserVo
;
import
com.yanzuoguang.dao.BaseDao
;
...
...
@@ -14,12 +14,12 @@ public interface UserDao extends BaseDao {
/**
* 通过
UserVo对象
获取相同的UserVo对象
* 通过
账户名
获取相同的UserVo对象
*
* @param
userVo UserVo对象
* @param
account 账户名
* @return UserVo对象
*/
UserVo
getUser
(
UserVo
userVo
);
UserVo
getUser
ByAccount
(
GetUserByAccountReqVo
account
);
/**
* 获取UserVo对象列表
...
...
@@ -50,5 +50,5 @@ public interface UserDao extends BaseDao {
* @param userId 用户id
* @return UserVo对象
*/
UserVo
getUserById
(
String
userI
d
);
UserVo
getUserById
(
GetUserByIdReqVo
i
d
);
}
src/main/java/com/pangding/web/tright/dao/UserRoleDao.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
;
import
com.pangding.web.tright.vo.GetUserRoleListByUserIdReqVo
;
import
com.pangding.web.tright.vo.UserRoleRelation
;
import
com.yanzuoguang.dao.BaseDao
;
import
java.util.List
;
...
...
@@ -10,10 +12,10 @@ import java.util.List;
public
interface
UserRoleDao
extends
BaseDao
{
/**
* 通过
角色id获取角色用户表主键
列表
* 通过
userId查询用户角色对应关系
列表
*
* @param
roleId 角色
id
* @return
角色用户表主键
列表
* @param
userId 用户
id
* @return
user和role对应关系对象
列表
*/
List
<
String
>
getRoleUserPKListByRoleId
(
String
role
Id
);
List
<
UserRoleRelation
>
getUserRoleListByUserId
(
GetUserRoleListByUserIdReqVo
user
Id
);
}
src/main/java/com/pangding/web/tright/dao/impl/RoleDaoImpl.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
.
impl
;
import
com.pangding.web.tright.dao.RoleDao
;
import
com.pangding.web.tright.vo.GetRoleByRoleIdReqVo
;
import
com.pangding.web.tright.vo.GetRoleByRoleNameReqVo
;
import
com.pangding.web.tright.vo.RoleVo
;
import
com.yanzuoguang.dao.impl.BaseDaoImpl
;
import
org.springframework.stereotype.Component
;
import
javax.management.relation.Role
;
import
java.util.List
;
/**
...
...
@@ -24,12 +27,6 @@ public class RoleDaoImpl extends BaseDaoImpl implements RoleDao {
protected
void
init
()
{
register
(
RoleVo
.
class
);
table
.
add
(
GET_ROLE_BY_ID
,
"select r.* from pd_role r where 1=1 "
)
.
add
(
"id"
,
"and r.id = ?"
);
table
.
add
(
GET_ROLE_BY_NAME
,
"select r.* from pd_role r where 1=1 "
)
.
add
(
"name"
,
"and r.name = ?"
);
table
.
add
(
CHECK_NAME_EXIST
,
"select count(r.id) from pd_role r where 1=1 "
)
.
add
(
"name"
,
"and r.name = ? "
)
.
add
(
"id"
,
"and r.id <> ?"
);
...
...
@@ -45,13 +42,13 @@ public class RoleDaoImpl extends BaseDaoImpl implements RoleDao {
}
@Override
public
RoleVo
getRoleById
(
String
id
)
{
return
this
.
queryFirst
(
RoleVo
.
class
,
GET_ROLE_BY_ID
,
id
);
public
RoleVo
getRoleById
(
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
)
{
return
this
.
load
(
getRoleByRoleIdReqVo
,
RoleVo
.
class
);
}
@Override
public
RoleVo
getRoleBy
Name
(
String
name
)
{
return
this
.
queryFirst
(
RoleVo
.
class
,
GET_ROLE_BY_NAME
,
name
);
public
RoleVo
getRoleBy
RoleName
(
GetRoleByRoleNameReqVo
getRoleByRoleNameReqVo
)
{
return
this
.
load
(
getRoleByRoleNameReqVo
,
RoleVo
.
class
);
}
@Override
...
...
src/main/java/com/pangding/web/tright/dao/impl/UserDaoImpl.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
.
impl
;
import
com.pangding.web.tright.dao.UserDao
;
import
com.pangding.web.tright.
dto.UserDt
o
;
import
com.pangding.web.tright.vo.
UserRoleRelation
;
import
com.pangding.web.tright.
vo.GetUserByAccountReqV
o
;
import
com.pangding.web.tright.vo.
GetUserByIdReqVo
;
import
com.pangding.web.tright.vo.UserVo
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.impl.BaseDaoImpl
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.PageSizeData
;
import
com.yanzuoguang.util.vo.PageSizeReqVo
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* @author zhangjinyao
...
...
@@ -22,7 +16,7 @@ import java.util.UUID;
public
class
UserDaoImpl
extends
BaseDaoImpl
implements
UserDao
{
private
static
final
String
GET_USER
=
"GET_USER
"
;
private
static
final
String
SELECT
=
"SELECT
"
;
private
static
final
String
DELETE_USER_ROLE
=
"deleteUserRole"
;
private
static
final
String
SAVE_USER_ROLE
=
"saveUserRoles"
;
private
static
final
String
GET_ALL_USERS
=
"GET_ALL_USERS"
;
...
...
@@ -34,28 +28,13 @@ public class UserDaoImpl extends BaseDaoImpl implements UserDao {
protected
void
init
()
{
register
(
UserVo
.
class
);
table
.
add
(
GET_USER
,
"SELECT id,account,phone,status,remark,create_time,creator FROM pd_user WHERE 1=1 "
)
.
add
(
"account"
,
" AND account = ?"
);
table
.
add
(
DELETE_USER_ROLE
,
"delete from pd_user_role_relation where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
table
.
add
(
GET_ALL_USERS
,
"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1"
);
table
.
add
(
GET_ROLE_IDS
,
"select role_id from pd_user_role where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
table
.
add
(
GET_USER_BY_ID
,
"select id,account,phone,status,remark,create_time,creator from pd_user where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
);
table
.
add
(
GET_ROLE_BY_ROLEID
,
"select name from pd_role where 1=1 "
)
.
add
(
"roleId"
,
"and id = ?"
);
}
@Override
public
UserVo
getUser
(
UserVo
userVo
)
{
return
this
.
queryFirst
(
UserVo
.
class
,
GET_USER
,
userVo
);
public
UserVo
getUser
ByAccount
(
GetUserByAccountReqVo
account
)
{
return
this
.
load
(
account
,
UserVo
.
class
);
}
...
...
@@ -77,7 +56,7 @@ public class UserDaoImpl extends BaseDaoImpl implements UserDao {
}
@Override
public
UserVo
getUserById
(
String
userI
d
)
{
return
this
.
queryFirst
(
UserVo
.
class
,
GET_USER_BY_ID
,
userId
);
public
UserVo
getUserById
(
GetUserByIdReqVo
i
d
)
{
return
this
.
load
(
id
,
UserVo
.
class
);
}
}
src/main/java/com/pangding/web/tright/dao/impl/UserRoleDaoImpl.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
dao
.
impl
;
import
com.pangding.web.tright.dao.UserRoleDao
;
import
com.pangding.web.tright.vo.GetUserRoleListByUserIdReqVo
;
import
com.pangding.web.tright.vo.UserRoleRelation
;
import
com.yanzuoguang.dao.impl.BaseDaoImpl
;
import
org.springframework.stereotype.Component
;
...
...
@@ -13,20 +14,21 @@ import java.util.List;
@Component
public
class
UserRoleDaoImpl
extends
BaseDaoImpl
implements
UserRoleDao
{
private
static
final
String
GET_
ROLE_USER_PK_BY_ROLEID
=
"GET_ROLE_USER_PK_BY_ROLEID
"
;
private
static
final
String
GET_
USER_ROLE_LIST
=
"GET_USER_ROLE_LIST
"
;
@Override
protected
void
init
()
{
register
(
UserRoleRelation
.
class
);
table
.
add
(
GET_ROLE_USER_PK_BY_ROLEID
,
"select id from pd_user_role where 1=1 "
)
table
.
add
(
GET_USER_ROLE_LIST
,
"select * from pd_user_role where 1=1 "
)
.
add
(
"userId"
,
"and user_id = ?"
)
.
add
(
"roleId"
,
"and role_id = ?"
);
}
@Override
public
List
<
String
>
getRoleUserPKListByRoleId
(
String
role
Id
)
{
return
this
.
query
(
String
.
class
,
GET_ROLE_USER_PK_BY_ROLEID
,
role
Id
);
public
List
<
UserRoleRelation
>
getUserRoleListByUserId
(
GetUserRoleListByUserIdReqVo
user
Id
)
{
return
this
.
query
(
UserRoleRelation
.
class
,
GET_USER_ROLE_LIST
,
user
Id
);
}
}
src/main/java/com/pangding/web/tright/service/RoleService.java
View file @
13496897
...
...
@@ -11,11 +11,18 @@ import java.util.List;
public
interface
RoleService
{
/**
* 保存Role
Vo对象
* 保存Role
Dto对象,并保存角色权限的对应关系
*
* @param roleVo RoleVo对象
* @param roleDto RoleDto对象
*/
void
saveRole
(
RoleDto
roleDto
);
/**
* 更新RoleDto对象,并更新角色权限的对应关系
*
* @param roleDto RoleDto对象
*/
void
saveRole
(
RoleVo
roleV
o
);
void
updateRole
(
RoleDto
roleDt
o
);
/**
* 通过主键id查询RoleVo对象
...
...
@@ -33,13 +40,6 @@ public interface RoleService {
*/
RoleVo
getRoleByName
(
String
name
);
/**
* 保存角色与权限的对应关系
*
* @param roleDto RoleDto对象
*/
void
roleAndTright
(
RoleDto
roleDto
);
/**
* 检查角色名是否已存在
*
...
...
@@ -82,39 +82,10 @@ public interface RoleService {
RoleDto
makeRoleDto
(
RoleVo
roleVo
,
List
<
String
>
trightIdList
,
List
<
String
>
trightNameList
);
/**
* 通过角色id删除角色
* 通过角色id删除角色
,并删除角色和用户的对应关系一级角色和权限的对应关系
*
* @param roleId 角色id
*/
void
deleteRole
(
String
roleId
);
/**
* 通过角色id删除角色与用户的对应关系
*
* @param roleId 角色id
*/
void
deleteRoleUser
(
String
roleId
);
/**
* 通过角色id删除角色权限的对应关系
*
* @param roleId 角色id
*/
void
deleteRoleTright
(
String
roleId
);
/**
* 通过角色id获取角色用户关系表主键列表
*
* @param roleId 角色id
* @return 角色用户关系表主键列表
*/
List
<
String
>
getRoleUserPKListByRoleId
(
String
roleId
);
/**
* 通过角色id获取角色权限主键列表
*
* @param roleId 角色id
* @return 角色权限主键列表
*/
List
<
String
>
getRoleTrightPKListByRoleId
(
String
roleId
);
}
src/main/java/com/pangding/web/tright/service/TrightService.java
View file @
13496897
...
...
@@ -31,7 +31,7 @@ public interface TrightService {
TrightVo
getTrightById
(
String
id
);
/**
* 通过权限表主键删除TrightVo对象
* 通过权限表主键删除TrightVo对象
,并删除权限和角色的对应关系
*
* @param id 主键
*/
...
...
@@ -75,18 +75,4 @@ public interface TrightService {
*/
List
<
String
>
getChildIdList
(
String
id
);
/**
* 通过权限id获取角色权限表主键列表
*
* @param id 权限id
* @return 角色权限表主键列表
*/
List
<
String
>
getRoleTrightPKListByTrightId
(
String
id
);
/**
* 通过角色权限表主键删除角色权限对应关系
*
* @param roleTrightId 角色权限表主键
*/
void
deleteRoleTright
(
String
roleTrightId
);
}
src/main/java/com/pangding/web/tright/service/UserService.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
service
;
import
com.pangding.web.tright.dto.UserDto
;
import
com.pangding.web.tright.vo.
UserVo
;
import
com.pangding.web.tright.vo.
*
;
import
java.lang.reflect.Array
;
import
java.util.List
;
/**
...
...
@@ -12,11 +11,18 @@ import java.util.List;
public
interface
UserService
{
/**
* 保存用户和角色的对应关系
* 保存用户
信息,并保存用户
和角色的对应关系
*
* @param userDto UserDto对象
*/
void
userAndRole
(
UserDto
userDto
);
void
saveUser
(
UserDto
userDto
);
/**
* 保存更新后的用户信息,并更新用户和角色的对应关系
*
* @param userDto UserDto对象
*/
void
updateUser
(
UserDto
userDto
);
/**
* 通过UserVo对象获取相同的UserVo对象
...
...
@@ -41,22 +47,6 @@ public interface UserService {
*/
List
<
UserVo
>
listUserVo
();
/**
* 通过UserVo对象获取该用户的角色ID列表
*
* @param userVo UserVo对象
* @return 角色id列表
*/
List
<
String
>
listRoleIdList
(
UserVo
userVo
);
/**
* 通过角色id获取角色名
*
* @param roleId 角色id
* @return 角色名
*/
String
getRoleNameByRoleId
(
String
roleId
);
/**
* 将UserVo对象添加角色id列表和角色名列表封装成UserDto对象
*
...
...
@@ -74,4 +64,20 @@ public interface UserService {
* @return UserVo对象
*/
UserVo
getUserById
(
String
userId
);
/**
* 通过userId查询user和role对应关系对象列表
*
* @param reqVo GetUserRoleListByUserIdReqVo对象
* @return UserRole对应关系对象列表
*/
List
<
UserRoleRelation
>
listUserRoleListByUserId
(
GetUserRoleListByUserIdReqVo
reqVo
);
/**
* 根据roleId查询RoleVo对象
*
* @param getRoleByRoleIdReqVo GetRoleByRoleIdReqVo对象
* @return RoleVo对象
*/
RoleVo
getRoleByRoleId
(
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
);
}
src/main/java/com/pangding/web/tright/service/impl/RoleServiceImpl.java
View file @
13496897
...
...
@@ -5,15 +5,13 @@ import com.pangding.web.tright.dao.RoleTrightDao;
import
com.pangding.web.tright.dao.UserRoleDao
;
import
com.pangding.web.tright.dto.RoleDto
;
import
com.pangding.web.tright.service.RoleService
;
import
com.pangding.web.tright.vo.GetRoleByRoleNameReqVo
;
import
com.pangding.web.tright.vo.RoleTrightRelation
;
import
com.pangding.web.tright.vo.RoleVo
;
import
com.pangding.web.tright.vo.UserRoleRelation
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.
util.CollectionUtils
;
import
org.springframework.
transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
...
...
@@ -33,32 +31,53 @@ public class RoleServiceImpl implements RoleService {
RoleTrightDao
roleTrightDaoImpl
;
@Override
public
void
saveRole
(
RoleVo
roleVo
)
{
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
saveRole
(
RoleDto
roleDto
)
{
RoleVo
roleVo
=
roleDto
;
roleDao
.
create
(
roleVo
);
List
<
String
>
trightIds
=
roleDto
.
getTrightIds
();
for
(
String
trightId
:
trightIds
)
{
RoleTrightRelation
roleTrightRelation
=
new
RoleTrightRelation
();
roleTrightRelation
.
setTrightId
(
trightId
);
roleTrightRelation
.
setRoleId
(
roleDto
.
getId
());
roleTrightRelation
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
roleTrightDaoImpl
.
create
(
roleTrightRelation
);
}
}
@Override
public
RoleVo
getRoleById
(
String
id
)
{
return
roleDao
.
getRoleById
(
id
);
}
@Override
public
RoleVo
getRoleByName
(
String
name
)
{
return
roleDao
.
getRoleByName
(
name
);
}
@Override
public
void
roleAndTright
(
RoleDto
roleDto
)
{
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateRole
(
RoleDto
roleDto
)
{
RoleVo
roleVo
=
roleDto
;
roleDao
.
update
(
roleVo
);
List
<
String
>
roleTrightIdList
=
roleTrightDaoImpl
.
getRoleTrightPKListByRoleId
(
roleDto
.
getId
());
if
(
roleTrightIdList
!=
null
&&
roleTrightIdList
.
size
()
!=
0
){
for
(
String
roleTrightId:
roleTrightIdList
)
{
roleTrightDaoImpl
.
remove
(
roleTrightId
);
}
}
List
<
String
>
trightIds
=
roleDto
.
getTrightIds
();
for
(
String
trightId
:
trightIds
)
{
RoleTrightRelation
roleTrightRelation
=
new
RoleTrightRelation
();
roleTrightRelation
.
setTrightId
(
trightId
);
roleTrightRelation
.
setRoleId
(
roleDto
.
getId
());
roleTrightRelation
.
setId
(
UUID
.
randomUUID
().
toString
());
roleTrightDaoImpl
.
cre
ate
(
roleTrightRelation
);
roleTrightRelation
.
setId
(
UUID
.
randomUUID
().
toString
()
.
replace
(
"-"
,
""
)
);
roleTrightDaoImpl
.
upd
ate
(
roleTrightRelation
);
}
}
@Override
public
RoleVo
getRoleById
(
String
id
)
{
return
roleDao
.
getRoleById
(
id
);
}
@Override
public
RoleVo
getRoleByName
(
String
name
)
{
GetRoleByRoleNameReqVo
getRoleByRoleNameReqVo
=
new
GetRoleByRoleNameReqVo
();
getRoleByRoleNameReqVo
.
setName
(
name
);
return
roleDao
.
getRoleByRoleName
(
getRoleByRoleNameReqVo
);
}
@Override
public
Boolean
checkNameExist
(
RoleVo
roleVo
)
{
if
(
roleDao
.
checkNameExist
(
roleVo
)
>
0
){
return
false
;}
...
...
@@ -89,32 +108,21 @@ public class RoleServiceImpl implements RoleService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteRole
(
String
roleId
)
{
roleDao
.
remove
(
roleId
);
}
@Override
public
void
deleteRoleUser
(
String
id
)
{
if
(
id
!=
null
&&
id
!=
""
)
{
userRoleDaoImpl
.
remove
(
id
);
roleDao
.
remove
(
roleId
);
List
<
String
>
roleUserList
=
userRoleDaoImpl
.
getRoleUserPKListByRoleId
(
roleId
);
for
(
String
roleUserId:
roleUserList
)
{
if
(
roleUserId
!=
null
&&
roleUserId
!=
""
)
{
userRoleDaoImpl
.
remove
(
roleUserId
);
}
}
}
@Override
public
void
deleteRoleTright
(
String
id
)
{
if
(
id
!=
null
&&
id
!=
""
)
{
roleTrightDaoImpl
.
remove
(
id
);
List
<
String
>
roleTrightList
=
roleTrightDaoImpl
.
getRoleTrightPKListByRoleId
(
roleId
);
for
(
String
roleTrightId:
roleTrightList
)
{
if
(
roleTrightId
!=
null
&&
roleTrightId
!=
""
)
{
roleTrightDaoImpl
.
remove
(
roleTrightId
);
}
}
}
@Override
public
List
<
String
>
getRoleUserPKListByRoleId
(
String
roleId
)
{
return
userRoleDaoImpl
.
getRoleUserPKListByRoleId
(
roleId
);
}
@Override
public
List
<
String
>
getRoleTrightPKListByRoleId
(
String
roleId
)
{
return
roleTrightDaoImpl
.
getRoleTrightPKListByRoleId
(
roleId
);
}
}
src/main/java/com/pangding/web/tright/service/impl/TrightServiceImpl.java
View file @
13496897
...
...
@@ -6,8 +6,10 @@ import com.pangding.web.tright.service.TrightService;
import
com.pangding.web.tright.vo.TrightVo
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
import
java.util.UUID
;
/**
* @author zhangjinyao
...
...
@@ -23,6 +25,7 @@ public class TrightServiceImpl implements TrightService {
@Override
public
void
save
(
TrightVo
trightVo
)
{
trightVo
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
trightDao
.
create
(
trightVo
);
}
...
...
@@ -45,8 +48,13 @@ public class TrightServiceImpl implements TrightService {
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
deleteTrightById
(
String
id
)
{
trightDao
.
remove
(
id
);
List
<
String
>
roleTrightList
=
roleTrightDao
.
getRoleTrightPKListByTrightId
(
id
);
for
(
String
roleTrightId:
roleTrightList
)
{
roleTrightDao
.
remove
(
roleTrightId
);
}
}
@Override
...
...
@@ -72,16 +80,4 @@ public class TrightServiceImpl implements TrightService {
return
trightDao
.
getChildIdList
(
id
);
}
@Override
public
List
<
String
>
getRoleTrightPKListByTrightId
(
String
id
)
{
return
roleTrightDao
.
getRoleTrightPKListByTrightId
(
id
);
}
@Override
public
void
deleteRoleTright
(
String
roleTrightId
)
{
roleTrightDao
.
remove
(
roleTrightId
);
}
}
src/main/java/com/pangding/web/tright/service/impl/UserServiceImpl.java
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
service
.
impl
;
import
com.pangding.web.tright.dao.RoleDao
;
import
com.pangding.web.tright.dao.UserDao
;
import
com.pangding.web.tright.dao.UserRoleDao
;
import
com.pangding.web.tright.dto.UserDto
;
import
com.pangding.web.tright.service.UserService
;
import
com.pangding.web.tright.utils.Md5AndSalt
;
import
com.pangding.web.tright.vo.UserRoleRelation
;
import
com.pangding.web.tright.vo.UserVo
;
import
com.pangding.web.tright.vo.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.
util.CollectionUtils
;
import
org.springframework.
transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -23,56 +24,107 @@ public class UserServiceImpl implements UserService {
@Autowired
UserDao
userDao
;
@
Override
public
List
<
UserVo
>
listUserVo
()
{
@
Autowired
UserRoleDao
userRoleDao
;
return
userDao
.
listUserVo
();
}
@Autowired
RoleDao
roleDao
;
@Override
public
void
userAndRole
(
UserDto
userDto
)
{
List
<
String
>
roleIds
=
userDto
.
getRoleIds
();
for
(
String
roleId
:
roleIds
)
{
UserRoleRelation
userRoleRelation
=
new
UserRoleRelation
();
userRoleRelation
.
setRoleId
(
roleId
);
userRoleRelation
.
setUserId
(
userDto
.
getId
());
userRoleRelation
.
setId
(
UUID
.
randomUUID
().
toString
());
userDao
.
create
(
userRoleRelation
);
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
saveUser
(
UserDto
userDto
)
{
UserVo
userVo
=
userDto
;
userDao
.
create
(
userVo
);
if
(
userDto
.
getRoleIds
()!=
null
&&
userDto
.
getRoleIds
().
size
()!=
0
){
List
<
String
>
roleIds
=
userDto
.
getRoleIds
();
for
(
String
roleId
:
roleIds
)
{
UserRoleRelation
userRoleRelation
=
new
UserRoleRelation
();
userRoleRelation
.
setRoleId
(
roleId
);
userRoleRelation
.
setUserId
(
userDto
.
getId
());
userRoleRelation
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
userRoleDao
.
create
(
userRoleRelation
);
}
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateUser
(
UserDto
userDto
)
{
UserVo
userVo
=
userDto
;
userDao
.
update
(
userVo
);
GetUserRoleListByUserIdReqVo
userId
=
new
GetUserRoleListByUserIdReqVo
();
userId
.
setUserId
(
userDto
.
getId
());
List
<
UserRoleRelation
>
userRoleList
=
userRoleDao
.
getUserRoleListByUserId
(
userId
);
List
<
String
>
userRoleIdList
=
new
ArrayList
(
userRoleList
.
size
());
for
(
UserRoleRelation
userRole:
userRoleList
)
{
userRoleIdList
.
add
(
userRole
.
getId
());
}
if
(
userRoleIdList
!=
null
&&
userRoleIdList
.
size
()
!=
0
){
for
(
String
userRoleId:
userRoleIdList
){
UserRoleDaoRemoveReqVo
userRole
=
new
UserRoleDaoRemoveReqVo
();
userRole
.
setId
(
userRoleId
);
userRoleDao
.
remove
(
userRole
);
}
}
if
(
userDto
.
getRoleIds
()!=
null
&&
userDto
.
getRoleIds
().
size
()!=
0
){
List
<
String
>
roleIds
=
userDto
.
getRoleIds
();
for
(
String
roleId
:
roleIds
)
{
UserRoleRelation
userRoleRelation
=
new
UserRoleRelation
();
userRoleRelation
.
setRoleId
(
roleId
);
userRoleRelation
.
setUserId
(
userDto
.
getId
());
userRoleRelation
.
setId
(
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
userRoleDao
.
create
(
userRoleRelation
);
}
}
}
@Override
public
List
<
UserVo
>
listUserVo
()
{
return
userDao
.
listUserVo
();
}
@Override
public
UserVo
getUser
(
UserVo
userVo
)
{
return
userDao
.
getUser
(
userVo
);
GetUserByAccountReqVo
account
=
new
GetUserByAccountReqVo
();
account
.
setAccount
(
userVo
.
getAccount
());
return
userDao
.
getUserByAccount
(
account
);
}
@Override
public
String
passwordEncoder
(
String
password
)
{
return
Md5AndSalt
.
generate
(
password
);
}
@Override
public
List
<
String
>
listRoleIdList
(
UserVo
userVo
)
{
return
userDao
.
getRoleIdList
(
userVo
);
}
@Override
public
UserDto
makeUserDto
(
UserVo
userVo
,
List
<
String
>
roleIdList
,
List
<
String
>
roleList
)
{
UserDto
userDto
=
(
UserDto
)
userVo
;
public
UserDto
makeUserDto
(
UserVo
userVo
,
List
<
String
>
roleIdList
,
List
<
String
>
roleNameList
)
{
UserDto
userDto
=
new
UserDto
();
userDto
.
setPassword
(
userVo
.
getPassword
());
userDto
.
setAccount
(
userVo
.
getAccount
());
userDto
.
setCreateTime
(
userVo
.
getCreateTime
());
userDto
.
setCreator
(
userVo
.
getCreator
());
userDto
.
setId
(
userVo
.
getId
());
userDto
.
setPhone
(
userVo
.
getPhone
());
userDto
.
setRemark
(
userVo
.
getRemark
());
userDto
.
setStatus
(
userVo
.
getStatus
());
userDto
.
setRoleIds
(
roleIdList
);
userDto
.
setRoles
(
roleList
);
userDto
.
setRoles
(
role
Name
List
);
return
userDto
;
}
@Override
public
String
getRoleNameByRoleId
(
String
roleId
)
{
return
userDao
.
getRoleNameByRoleId
(
roleId
);
public
UserVo
getUserById
(
String
userId
)
{
GetUserByIdReqVo
id
=
new
GetUserByIdReqVo
();
id
.
setId
(
userId
);
return
userDao
.
getUserById
(
id
);
}
@Override
public
UserVo
getUserById
(
String
userId
)
{
return
userDao
.
getUserById
(
userId
);
public
List
<
UserRoleRelation
>
listUserRoleListByUserId
(
GetUserRoleListByUserIdReqVo
reqVo
)
{
return
userRoleDao
.
getUserRoleListByUserId
(
reqVo
);
}
@Override
public
RoleVo
getRoleByRoleId
(
GetRoleByRoleIdReqVo
getRoleByRoleIdReqVo
)
{
return
roleDao
.
getRoleById
(
getRoleByRoleIdReqVo
);
}
}
src/main/java/com/pangding/web/tright/vo/GetRoleByRoleIdReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
/**
* @Author zhangjinyao
* @create 2019/5/10 20:09
*/
public
class
GetRoleByRoleIdReqVo
{
private
String
id
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
src/main/java/com/pangding/web/tright/vo/GetRoleByRoleNameReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
/**
* @Author zhangjinyao
* @create 2019/5/10 20:27
*/
public
class
GetRoleByRoleNameReqVo
{
private
String
name
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
src/main/java/com/pangding/web/tright/vo/GetUserByAccountReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
import
org.springframework.context.annotation.Bean
;
/**
* @Author zhangjinyao
* @create 2019/5/10 17:17
*/
public
class
GetUserByAccountReqVo
{
private
String
account
;
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
}
src/main/java/com/pangding/web/tright/vo/GetUserByIdReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
/**
* @Author zhangjinyao
* @create 2019/5/10 17:21
*/
public
class
GetUserByIdReqVo
{
private
String
id
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
src/main/java/com/pangding/web/tright/vo/GetUserRoleListByUserIdReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
/**
* @Author zhangjinyao
* @create 2019/5/10 19:34
*/
public
class
GetUserRoleListByUserIdReqVo
{
private
String
userId
;
public
String
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
String
userId
)
{
this
.
userId
=
userId
;
}
}
src/main/java/com/pangding/web/tright/vo/UserRoleDaoRemoveReqVo.java
0 → 100644
View file @
13496897
package
com
.
pangding
.
web
.
tright
.
vo
;
/**
* @Author zhangjinyao
* @create 2019/5/10 19:47
*/
public
class
UserRoleDaoRemoveReqVo
{
private
String
id
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
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