Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
restful
Project
Project
Details
Activity
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
李永强
restful
Commits
48b5f522
Commit
48b5f522
authored
Oct 24, 2019
by
张明杰
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/developer' into developer
parents
4d8149f0
10957a02
Pipeline
#216
canceled with stages
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
50 deletions
+43
-50
JurisdictionController.java
...n/java/com/restful/controller/JurisdictionController.java
+14
-20
JurisdictionDao.java
src/main/java/com/restful/dao/JurisdictionDao.java
+4
-4
JurisdictionService.java
src/main/java/com/restful/service/JurisdictionService.java
+18
-26
Operation.java
src/main/java/com/restful/subject/Operation.java
+7
-0
No files found.
src/main/java/com/restful/controller/JurisdictionController.java
View file @
48b5f522
...
@@ -6,17 +6,15 @@ import com.restful.common.Constants;
...
@@ -6,17 +6,15 @@ import com.restful.common.Constants;
import
com.restful.common.entity.ServiceException
;
import
com.restful.common.entity.ServiceException
;
import
com.restful.domain.Menu
;
import
com.restful.domain.Menu
;
import
com.restful.domain.Role
;
import
com.restful.domain.Role
;
import
com.restful.dto.Authority
;
import
com.restful.service.JurisdictionService
;
import
com.restful.service.JurisdictionService
;
import
com.restful.subject.Operation
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.beanutils.ConvertUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.List
;
...
@@ -24,7 +22,7 @@ import java.util.List;
...
@@ -24,7 +22,7 @@ import java.util.List;
@RequestMapping
(
"jurisdiction"
)
@RequestMapping
(
"jurisdiction"
)
public
class
JurisdictionController
{
public
class
JurisdictionController
{
@
Autowired
@
Resource
JurisdictionService
jurisdictionService
;
JurisdictionService
jurisdictionService
;
@ApiOperation
(
value
=
"查看所有菜单"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiOperation
(
value
=
"查看所有菜单"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
@@ -33,7 +31,7 @@ public class JurisdictionController {
...
@@ -33,7 +31,7 @@ public class JurisdictionController {
@ApiImplicitParam
(
name
=
Constants
.
PAGE_NUM
,
value
=
"页码,从1开始, 默认第一页"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
Constants
.
PAGE_NUM
,
value
=
"页码,从1开始, 默认第一页"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
Constants
.
PAGE_SIZE
,
value
=
"每页的数量"
,
paramType
=
"query"
,
dataType
=
"int"
)
@ApiImplicitParam
(
name
=
Constants
.
PAGE_SIZE
,
value
=
"每页的数量"
,
paramType
=
"query"
,
dataType
=
"int"
)
})
})
@RequestMapping
(
value
=
"/
findM
enus"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/
m
enus"
,
method
=
RequestMethod
.
GET
)
public
Object
findMenus
(
HttpServletRequest
request
,
public
Object
findMenus
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
remark
,
@RequestParam
(
required
=
false
)
String
remark
,
@RequestParam
(
required
=
false
)
String
url
)
{
@RequestParam
(
required
=
false
)
String
url
)
{
...
@@ -53,7 +51,7 @@ public class JurisdictionController {
...
@@ -53,7 +51,7 @@ public class JurisdictionController {
@ApiImplicitParam
(
name
=
Constants
.
PAGE_NUM
,
value
=
"页码,从1开始, 默认第一页"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
Constants
.
PAGE_NUM
,
value
=
"页码,从1开始, 默认第一页"
,
paramType
=
"query"
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
Constants
.
PAGE_SIZE
,
value
=
"每页的数量"
,
paramType
=
"query"
,
dataType
=
"int"
)
@ApiImplicitParam
(
name
=
Constants
.
PAGE_SIZE
,
value
=
"每页的数量"
,
paramType
=
"query"
,
dataType
=
"int"
)
})
})
@RequestMapping
(
value
=
"/
findR
oles"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/
r
oles"
,
method
=
RequestMethod
.
GET
)
public
Object
findRoles
(
HttpServletRequest
request
)
throws
ServiceException
{
public
Object
findRoles
(
HttpServletRequest
request
)
throws
ServiceException
{
Integer
pageNum
=
(
Integer
)
request
.
getAttribute
(
Constants
.
PAGE_NUM
);
Integer
pageNum
=
(
Integer
)
request
.
getAttribute
(
Constants
.
PAGE_NUM
);
Integer
pageSize
=
(
Integer
)
request
.
getAttribute
(
Constants
.
PAGE_SIZE
);
Integer
pageSize
=
(
Integer
)
request
.
getAttribute
(
Constants
.
PAGE_SIZE
);
...
@@ -64,27 +62,23 @@ public class JurisdictionController {
...
@@ -64,27 +62,23 @@ public class JurisdictionController {
@ApiOperation
(
value
=
"给角色授权"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiOperation
(
value
=
"给角色授权"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@RequestMapping
(
value
=
"/addAuthority"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/authority/{roleId}/{menuIds}"
,
method
=
RequestMethod
.
POST
)
public
Object
addAuthority
(
@RequestBody
Authority
authority
)
throws
ServiceException
{
public
Object
addAuthority
(
@PathVariable
Long
roleId
,
@PathVariable
String
menuIds
)
throws
ServiceException
{
if
(!
StringUtils
.
isBlank
(
authority
.
menus
))
return
jurisdictionService
.
authority
(
roleId
,
menuIds
,
Operation
.
add
);
authority
.
menuIds
=
(
Long
[])
ConvertUtils
.
convert
(
authority
.
menus
.
split
(
","
),
Long
.
class
);
return
jurisdictionService
.
authority
(
authority
.
roleId
,
authority
.
menuIds
,
"add"
);
}
}
@ApiOperation
(
value
=
"取消授权"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiOperation
(
value
=
"取消授权"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@RequestMapping
(
value
=
"/delAuthority"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/authority/{roleId}/{menuIds}"
,
method
=
RequestMethod
.
DELETE
)
public
Object
delAuthority
(
@RequestBody
Authority
authority
)
throws
ServiceException
{
public
Object
delAuthority
(
@PathVariable
Long
roleId
,
@PathVariable
String
menuIds
)
throws
ServiceException
{
if
(!
StringUtils
.
isBlank
(
authority
.
menus
))
return
jurisdictionService
.
authority
(
roleId
,
menuIds
,
Operation
.
del
);
authority
.
menuIds
=
(
Long
[])
ConvertUtils
.
convert
(
authority
.
menus
.
split
(
","
),
Long
.
class
);
return
jurisdictionService
.
authority
(
authority
.
roleId
,
authority
.
menuIds
,
"del"
);
}
}
@ApiOperation
(
value
=
"给用户赋予角色"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiOperation
(
value
=
"给用户赋予角色"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@ApiImplicitParam
(
name
=
Constants
.
ACCESS_TOKEN
,
required
=
true
,
paramType
=
"header"
,
dataType
=
"String"
)
@RequestMapping
(
value
=
"/role
ToUser
"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/role
/{roleIds}/user/{userId}
"
,
method
=
RequestMethod
.
POST
)
public
Object
roleToUser
(
@
RequestBody
Authority
authority
)
throws
ServiceException
{
public
Object
roleToUser
(
@
PathVariable
String
roleIds
,
@PathVariable
Long
userId
)
throws
ServiceException
{
jurisdictionService
.
roleToUser
(
authority
.
roleId
,
authority
.
userId
);
jurisdictionService
.
roleToUser
(
roleIds
,
userId
);
return
null
;
return
null
;
}
}
}
}
src/main/java/com/restful/dao/JurisdictionDao.java
View file @
48b5f522
...
@@ -10,16 +10,16 @@ public interface JurisdictionDao {
...
@@ -10,16 +10,16 @@ public interface JurisdictionDao {
List
<
Menu
>
findMenus
(
Menu
menu
);
List
<
Menu
>
findMenus
(
Menu
menu
);
Menu
getMenu
(
Long
id
);
Menu
getMenu
(
Long
[]
id
);
List
<
Role
>
findRoles
();
List
<
Role
>
findRoles
();
Role
getRole
(
Long
id
);
Role
getRole
(
Long
id
);
void
addAuthority
(
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"menuId"
)
Long
menuId
);
void
addAuthority
(
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"menuId"
)
Long
[]
menuId
);
void
delAuthority
(
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"menuId"
)
Long
menuId
);
void
delAuthority
(
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"menuId"
)
Long
[]
menuId
);
void
roleToUser
(
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"userId"
)
Long
userId
);
void
roleToUser
(
@Param
(
"roleId"
)
Long
[]
roleId
,
@Param
(
"userId"
)
Long
userId
);
}
}
src/main/java/com/restful/service/JurisdictionService.java
View file @
48b5f522
...
@@ -5,7 +5,9 @@ import com.restful.common.entity.ServiceException;
...
@@ -5,7 +5,9 @@ import com.restful.common.entity.ServiceException;
import
com.restful.dao.JurisdictionDao
;
import
com.restful.dao.JurisdictionDao
;
import
com.restful.domain.Menu
;
import
com.restful.domain.Menu
;
import
com.restful.domain.Role
;
import
com.restful.domain.Role
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.restful.subject.Operation
;
import
org.apache.commons.beanutils.ConvertUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.dao.DuplicateKeyException
;
import
org.springframework.dao.DuplicateKeyException
;
...
@@ -21,8 +23,6 @@ public class JurisdictionService {
...
@@ -21,8 +23,6 @@ public class JurisdictionService {
@Resource
@Resource
JurisdictionDao
jurisdictionDao
;
JurisdictionDao
jurisdictionDao
;
@Autowired
UserService
userService
;
public
List
<
Menu
>
findMenus
(
Menu
menu
)
{
public
List
<
Menu
>
findMenus
(
Menu
menu
)
{
return
jurisdictionDao
.
findMenus
(
menu
);
return
jurisdictionDao
.
findMenus
(
menu
);
...
@@ -38,45 +38,37 @@ public class JurisdictionService {
...
@@ -38,45 +38,37 @@ public class JurisdictionService {
}
}
@CachePut
(
value
=
Constants
.
JURISDICTION
,
key
=
"#roleId"
,
unless
=
"#result==null"
)
@CachePut
(
value
=
Constants
.
JURISDICTION
,
key
=
"#roleId"
,
unless
=
"#result==null"
)
public
Role
authority
(
Long
roleId
,
Long
[]
menuIds
,
String
operation
)
throws
ServiceException
{
public
Role
authority
(
Long
roleId
,
String
menuIds
,
Operation
operation
)
throws
ServiceException
{
if
(
roleId
==
null
)
if
(
roleId
==
null
)
throw
new
ServiceException
(
"角色id不能为空"
);
throw
new
ServiceException
(
"角色id不能为空"
);
Role
role
=
jurisdictionDao
.
getRole
(
roleId
);
Role
role
=
jurisdictionDao
.
getRole
(
roleId
);
if
(
role
==
null
)
if
(
role
==
null
)
throw
new
ServiceException
(
"角色不存在"
);
throw
new
ServiceException
(
"角色不存在"
);
for
(
Long
menuId
:
menuIds
)
{
Long
[]
menuIdArr
=
(
Long
[])
ConvertUtils
.
convert
(
menuIds
.
split
(
","
),
Long
.
class
);
Menu
menu
=
jurisdictionDao
.
getMenu
(
menuId
);
Menu
menu
=
jurisdictionDao
.
getMenu
(
menuIdArr
);
if
(
menu
==
null
)
if
(
Operation
.
add
==
operation
)
{
throw
new
ServiceException
(
"菜单不存在"
);
switch
(
operation
)
{
case
"add"
:
{
try
{
try
{
jurisdictionDao
.
addAuthority
(
roleId
,
menuId
);
jurisdictionDao
.
addAuthority
(
roleId
,
menuIdArr
);
}
catch
(
DuplicateKeyException
e
)
{
}
catch
(
DuplicateKeyException
e
)
{
throw
new
ServiceException
(
"已经存在该权限"
);
throw
new
ServiceException
(
"已经存在该权限"
);
}
}
role
.
getMenuList
().
add
(
menu
);
role
.
getMenuList
().
add
(
menu
);
break
;
}
else
if
(
Operation
.
del
==
operation
)
{
}
jurisdictionDao
.
delAuthority
(
roleId
,
menuIdArr
);
case
"del"
:
{
jurisdictionDao
.
delAuthority
(
roleId
,
menuId
);
role
.
getMenuList
().
removeIf
(
e
->
menu
.
getId
().
equals
(
e
.
getId
()));
role
.
getMenuList
().
removeIf
(
e
->
menu
.
getId
().
equals
(
e
.
getId
()));
break
;
}
}
}
}
return
role
;
return
role
;
}
}
public
void
roleToUser
(
Long
roleId
,
Long
userId
)
throws
ServiceException
{
public
void
roleToUser
(
String
roleIds
,
Long
userId
)
throws
ServiceException
{
if
(
roleId
==
null
)
{
if
(
StringUtils
.
isBlank
(
roleIds
)
)
{
throw
new
ServiceException
(
"角色id不能为空"
);
throw
new
ServiceException
(
"角色id不能为空"
);
}
}
if
(
userId
==
null
)
{
if
(
userId
==
null
)
{
throw
new
ServiceException
(
"用户id不能为空"
);
throw
new
ServiceException
(
"用户id不能为空"
);
}
}
try
{
try
{
jurisdictionDao
.
roleToUser
(
roleId
,
userId
);
jurisdictionDao
.
roleToUser
(
(
Long
[])
ConvertUtils
.
convert
(
roleIds
.
split
(
","
),
Long
.
class
)
,
userId
);
}
catch
(
DuplicateKeyException
e
)
{
}
catch
(
DuplicateKeyException
e
)
{
throw
new
ServiceException
(
"已经存在"
);
throw
new
ServiceException
(
"已经存在"
);
}
}
...
...
src/main/java/com/restful/subject/Operation.java
0 → 100644
View file @
48b5f522
package
com
.
restful
.
subject
;
public
enum
Operation
{
add
,
del
}
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