Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
7faffe54
Commit
7faffe54
authored
Sep 30, 2018
by
zhh
Browse files
添加权限管理功能
parent
207a72d1
Changes
39
Hide whitespace changes
Inline
Side-by-side
mall-admin/pom.xml
View file @
7faffe54
...
...
@@ -97,6 +97,12 @@
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
<!--lombok依赖-->
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
<build>
<plugins>
...
...
mall-admin/src/main/java/com/macro/mall/bo/AdminUserDetails.java
View file @
7faffe54
...
...
@@ -52,6 +52,6 @@ public class AdminUserDetails implements UserDetails {
@Override
public
boolean
isEnabled
()
{
return
true
;
return
umsAdmin
.
getStatus
().
equals
(
1
)
;
}
}
mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java
View file @
7faffe54
...
...
@@ -7,8 +7,6 @@ import com.macro.mall.model.PmsProductCategory;
import
com.macro.mall.service.PmsProductCategoryService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.BindingResult
;
...
...
@@ -75,7 +73,7 @@ public class PmsProductCategoryController {
}
@ApiOperation
(
"删除商品分类"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GE
T
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POS
T
)
@ResponseBody
public
Object
delete
(
@PathVariable
Long
id
)
{
int
count
=
productCategoryService
.
delete
(
id
);
...
...
mall-admin/src/main/java/com/macro/mall/controller/UmsAdminController.java
View file @
7faffe54
...
...
@@ -9,18 +9,15 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.security.Principal
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -59,9 +56,9 @@ public class UmsAdminController {
if
(
token
==
null
)
{
return
new
CommonResult
().
validateFailed
(
"用户名或密码错误"
);
}
Map
<
String
,
String
>
tokenMap
=
new
HashMap
<>();
tokenMap
.
put
(
"token"
,
token
);
tokenMap
.
put
(
"tokenHead"
,
tokenHead
);
Map
<
String
,
String
>
tokenMap
=
new
HashMap
<>();
tokenMap
.
put
(
"token"
,
token
);
tokenMap
.
put
(
"tokenHead"
,
tokenHead
);
return
new
CommonResult
().
success
(
tokenMap
);
}
...
...
@@ -74,28 +71,69 @@ public class UmsAdminController {
if
(
refreshToken
==
null
)
{
return
new
CommonResult
().
failed
();
}
Map
<
String
,
String
>
tokenMap
=
new
HashMap
<>();
tokenMap
.
put
(
"token"
,
token
);
tokenMap
.
put
(
"tokenHead"
,
tokenHead
);
Map
<
String
,
String
>
tokenMap
=
new
HashMap
<>();
tokenMap
.
put
(
"token"
,
token
);
tokenMap
.
put
(
"tokenHead"
,
tokenHead
);
return
new
CommonResult
().
success
(
tokenMap
);
}
@ApiOperation
(
value
=
"获取用户信息"
)
@RequestMapping
(
value
=
"/info"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"获取
当前登录
用户信息"
)
@RequestMapping
(
value
=
"/info"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getAdminInfo
(
Principal
principal
){
public
Object
getAdminInfo
(
Principal
principal
)
{
String
username
=
principal
.
getName
();
UmsAdmin
umsAdmin
=
adminService
.
getAdminByUsername
(
username
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"username"
,
umsAdmin
.
getUsername
());
data
.
put
(
"roles"
,
new
String
[]{
"TEST"
});
data
.
put
(
"icon"
,
umsAdmin
.
getIcon
());
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"username"
,
umsAdmin
.
getUsername
());
data
.
put
(
"roles"
,
new
String
[]{
"TEST"
});
data
.
put
(
"icon"
,
umsAdmin
.
getIcon
());
return
new
CommonResult
().
success
(
data
);
}
@ApiOperation
(
value
=
"登出功能"
)
@RequestMapping
(
value
=
"/logout"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/logout"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
logout
(){
public
Object
logout
()
{
return
new
CommonResult
().
success
(
null
);
}
@ApiOperation
(
"根据用户名或姓名分页获取用户列表"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
list
(
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
){
List
<
UmsAdmin
>
adminList
=
adminService
.
list
(
name
,
pageSize
,
pageNum
);
return
new
CommonResult
().
pageSuccess
(
adminList
);
}
@ApiOperation
(
"获取指定用户信息"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getItem
(
@PathVariable
Long
id
){
UmsAdmin
admin
=
adminService
.
getItem
(
id
);
return
new
CommonResult
().
success
(
admin
);
}
@ApiOperation
(
"获取指定用户信息"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
update
(
@PathVariable
Long
id
,
@RequestBody
UmsAdmin
admin
){
int
count
=
adminService
.
update
(
id
,
admin
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"删除指定用户信息"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
delete
(
@PathVariable
Long
id
){
int
count
=
adminService
.
delete
(
id
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
}
mall-admin/src/main/java/com/macro/mall/controller/UmsPermissionController.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.controller
;
import
com.macro.mall.dto.CommonResult
;
import
com.macro.mall.dto.UmsPermissionNode
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.service.UmsPermissionService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 后台用户权限管理
* Created by macro on 2018/9/29.
*/
@Controller
@Api
(
tags
=
"UmsPermissionController"
,
description
=
"后台用户权限管理"
)
@RequestMapping
(
"/admin/permission"
)
public
class
UmsPermissionController
{
@Autowired
private
UmsPermissionService
permissionService
;
@ApiOperation
(
"添加权限"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
create
(
@RequestBody
UmsPermission
permission
)
{
int
count
=
permissionService
.
create
(
permission
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"修改权限"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
update
(
@PathVariable
Long
id
,
@RequestBody
UmsPermission
permission
)
{
int
count
=
permissionService
.
update
(
id
,
permission
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"根据id批量删除权限"
)
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
int
count
=
permissionService
.
delete
(
ids
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"以层级结构返回所有权限"
)
@RequestMapping
(
value
=
"/treeList"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
treeList
()
{
List
<
UmsPermissionNode
>
permissionNodeList
=
permissionService
.
treeList
();
return
new
CommonResult
().
success
(
permissionNodeList
);
}
}
mall-admin/src/main/java/com/macro/mall/controller/UmsRoleController.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.controller
;
import
com.macro.mall.dto.CommonResult
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
import
com.macro.mall.service.UmsRoleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 后台用户角色管理
* Created by macro on 2018/9/30.
*/
@Controller
@Api
(
tags
=
"UmsRoleController"
,
description
=
"后台用户角色管理"
)
@RequestMapping
(
"/admin/role"
)
public
class
UmsRoleController
{
@Autowired
private
UmsRoleService
roleService
;
@ApiOperation
(
"添加角色"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
create
(
@RequestBody
UmsRole
role
)
{
int
count
=
roleService
.
create
(
role
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"修改角色"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
update
(
@PathVariable
Long
id
,
@RequestBody
UmsRole
role
)
{
int
count
=
roleService
.
update
(
id
,
role
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"批量删除角色"
)
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
delete
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
int
count
=
roleService
.
delete
(
ids
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
@ApiOperation
(
"获取相应角色权限"
)
@RequestMapping
(
value
=
"/permission/{roleId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
getPermissionList
(
@PathVariable
Long
roleId
)
{
List
<
UmsPermission
>
permissionList
=
roleService
.
getPermissionList
(
roleId
);
return
new
CommonResult
().
success
(
permissionList
);
}
@ApiOperation
(
"修改角色权限"
)
@RequestMapping
(
value
=
"/permission/update"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
updatePermission
(
@RequestParam
Long
roleId
,
@RequestParam
(
"permissionIds"
)
List
<
Long
>
permissionIds
)
{
int
count
=
roleService
.
updatePermission
(
roleId
,
permissionIds
);
if
(
count
>
0
){
return
new
CommonResult
().
success
(
count
);
}
return
new
CommonResult
().
failed
();
}
}
mall-admin/src/main/java/com/macro/mall/dao/UmsRolePermissionRelationDao.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.dao
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRolePermissionRelation
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* 后台用户角色管理自定义Dao
* Created by macro on 2018/9/30.
*/
public
interface
UmsRolePermissionRelationDao
{
/**
* 批量插入角色和权限关系
*/
int
insertList
(
@Param
(
"list"
)
List
<
UmsRolePermissionRelation
>
list
);
/**
* 根据角色获取权限
*/
List
<
UmsPermission
>
getPermissionList
(
@Param
(
"roleId"
)
Long
roleId
);
}
mall-admin/src/main/java/com/macro/mall/dto/UmsAdminParam.java
View file @
7faffe54
package
com.macro.mall.dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.hibernate.validator.constraints.Email
;
import
org.hibernate.validator.constraints.NotEmpty
;
...
...
@@ -8,6 +10,8 @@ import org.hibernate.validator.constraints.NotEmpty;
* 用户登录参数
* Created by macro on 2018/4/26.
*/
@Getter
@Setter
public
class
UmsAdminParam
{
@ApiModelProperty
(
value
=
"用户名"
,
required
=
true
)
@NotEmpty
(
message
=
"用户名不能为空"
)
...
...
@@ -20,36 +24,8 @@ public class UmsAdminParam {
@ApiModelProperty
(
value
=
"邮箱"
)
@Email
(
message
=
"邮箱格式不合法"
)
private
String
email
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getIcon
()
{
return
icon
;
}
public
void
setIcon
(
String
icon
)
{
this
.
icon
=
icon
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
@ApiModelProperty
(
value
=
"用户昵称"
)
private
String
nickName
;
@ApiModelProperty
(
value
=
"备注"
)
private
String
note
;
}
mall-admin/src/main/java/com/macro/mall/dto/UmsPermissionNode.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.dto
;
import
com.macro.mall.model.UmsPermission
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* Created by macro on 2018/9/30.
*/
public
class
UmsPermissionNode
extends
UmsPermission
{
@Getter
@Setter
private
List
<
UmsPermissionNode
>
children
;
}
mall-admin/src/main/java/com/macro/mall/service/UmsAdminService.java
View file @
7faffe54
...
...
@@ -3,6 +3,8 @@ package com.macro.mall.service;
import
com.macro.mall.dto.UmsAdminParam
;
import
com.macro.mall.model.UmsAdmin
;
import
java.util.List
;
/**
* 后台管理员Service
* Created by macro on 2018/4/26.
...
...
@@ -31,4 +33,24 @@ public interface UmsAdminService {
* @param oldToken 旧的token
*/
String
refreshToken
(
String
oldToken
);
/**
* 根据用户id获取用户
*/
UmsAdmin
getItem
(
Long
id
);
/**
* 根据用户名或昵称分页查询用户
*/
List
<
UmsAdmin
>
list
(
String
name
,
Integer
pageSize
,
Integer
pageNum
);
/**
* 修改指定用户信息
*/
int
update
(
Long
id
,
UmsAdmin
admin
);
/**
* 删除指定用户
*/
int
delete
(
Long
id
);
}
mall-admin/src/main/java/com/macro/mall/service/UmsPermissionService.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.service
;
import
com.macro.mall.dto.UmsPermissionNode
;
import
com.macro.mall.model.UmsPermission
;
import
java.util.List
;
/**
* 后台用户权限管理Service
* Created by macro on 2018/9/29.
*/
public
interface
UmsPermissionService
{
/**
* 添加权限
*/
int
create
(
UmsPermission
permission
);
/**
* 修改权限
*/
int
update
(
Long
id
,
UmsPermission
permission
);
/**
* 批量删除权限
*/
int
delete
(
List
<
Long
>
ids
);
/**
* 以层级结构返回所有权限
*/
List
<
UmsPermissionNode
>
treeList
();
}
mall-admin/src/main/java/com/macro/mall/service/UmsRoleService.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.service
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* 后台角色管理Service
* Created by macro on 2018/9/30.
*/
public
interface
UmsRoleService
{
/**
* 添加角色
*/
int
create
(
UmsRole
role
);
/**
* 修改角色信息
*/
int
update
(
Long
id
,
UmsRole
role
);
/**
* 批量删除角色
*/
int
delete
(
List
<
Long
>
ids
);
/**
* 获取指定角色权限
*/
List
<
UmsPermission
>
getPermissionList
(
Long
roleId
);
/**
* 修改指定角色的权限
*/
@Transactional
int
updatePermission
(
Long
roleId
,
List
<
Long
>
permissionIds
);
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
View file @
7faffe54
package
com.macro.mall.service.impl
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.dto.UmsAdminParam
;
import
com.macro.mall.mapper.UmsAdminMapper
;
import
com.macro.mall.model.UmsAdmin
;
...
...
@@ -20,6 +21,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
...
...
@@ -96,4 +98,31 @@ public class UmsAdminServiceImpl implements UmsAdminService{
}
return
null
;
}
@Override
public
UmsAdmin
getItem
(
Long
id
)
{
return
adminMapper
.
selectByPrimaryKey
(
id
);
}
@Override
public
List
<
UmsAdmin
>
list
(
String
name
,
Integer
pageSize
,
Integer
pageNum
)
{
PageHelper
.
startPage
(
pageNum
,
pageSize
);
UmsAdminExample
example
=
new
UmsAdminExample
();
UmsAdminExample
.
Criteria
criteria
=
example
.
createCriteria
();
if
(!
StringUtils
.
isEmpty
(
name
)){
criteria
.
andUsernameLike
(
"%"
+
name
+
"%"
);
example
.
or
(
example
.
createCriteria
().
andNickNameLike
(
"%"
+
name
+
"%"
));
}
return
adminMapper
.
selectByExample
(
example
);
}
@Override
public
int
update
(
Long
id
,
UmsAdmin
admin
)
{
return
0
;
}
@Override
public
int
delete
(
Long
id
)
{
return
0
;
}
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsPermissionServiceImpl.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.service.impl
;
import
com.macro.mall.dto.UmsPermissionNode
;
import
com.macro.mall.mapper.UmsPermissionMapper
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsPermissionExample
;
import
com.macro.mall.service.UmsPermissionService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 后台用户权限管理Service实现类
* Created by macro on 2018/9/29.
*/
@Service
public
class
UmsPermissionServiceImpl
implements
UmsPermissionService
{
@Autowired
private
UmsPermissionMapper
permissionMapper
;
@Override
public
int
create
(
UmsPermission
permission
)
{
permission
.
setStatus
(
1
);
permission
.
setCreateTime
(
new
Date
());
permission
.
setSort
(
0
);
return
permissionMapper
.
insert
(
permission
);
}
@Override
public
int
update
(
Long
id
,
UmsPermission
permission
)
{
permission
.
setId
(
id
);
return
permissionMapper
.
updateByPrimaryKey
(
permission
);
}
@Override
public
int
delete
(
List
<
Long
>
ids
)
{
UmsPermissionExample
example
=
new
UmsPermissionExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
permissionMapper
.
deleteByExample
(
example
);
}
@Override
public
List
<
UmsPermissionNode
>
treeList
()
{
List
<
UmsPermission
>
permissionList
=
permissionMapper
.
selectByExample
(
new
UmsPermissionExample
());
List
<
UmsPermissionNode
>
result
=
permissionList
.
stream
()
.
filter
(
permission
->
permission
.
getPid
().
equals
(
0L
))
.
map
(
permission
->
covert
(
permission
,
permissionList
)).
collect
(
Collectors
.
toList
());
return
result
;
}
/**
* 将权限转换为带有子级的权限对象
* 当找不到子级权限的时候map操作不会再递归调用covert
*/
private
UmsPermissionNode
covert
(
UmsPermission
permission
,
List
<
UmsPermission
>
permissionList
){
UmsPermissionNode
node
=
new
UmsPermissionNode
();
BeanUtils
.
copyProperties
(
permission
,
node
);
List
<
UmsPermissionNode
>
children
=
permissionList
.
stream
()
.
filter
(
subPermission
->
subPermission
.
getPid
().
equals
(
permission
.
getId
()))
.
map
(
subPermission
->
covert
(
subPermission
,
permissionList
)).
collect
(
Collectors
.
toList
());
node
.
setChildren
(
children
);
return
node
;
}
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsRoleServiceImpl.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.service.impl
;
import
com.macro.mall.dao.UmsRolePermissionRelationDao
;
import
com.macro.mall.mapper.UmsRoleMapper
;
import
com.macro.mall.mapper.UmsRolePermissionRelationMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.service.UmsRoleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
* 后台角色管理Service实现类
* Created by macro on 2018/9/30.
*/
@Service
public
class
UmsRoleServiceImpl
implements
UmsRoleService
{
@Autowired
private
UmsRoleMapper
roleMapper
;
@Autowired
private
UmsRolePermissionRelationMapper
rolePermissionRelationMapper
;
@Autowired
private
UmsRolePermissionRelationDao
rolePermissionRelationDao
;
@Override
public
int
create
(
UmsRole
role
)
{
role
.
setCreateTime
(
new
Date
());
role
.
setStatus
(
1
);
role
.
setAdminCount
(
0
);
role
.
setSort
(
0
);
return
roleMapper
.
insert
(
role
);
}
@Override
public
int
update
(
Long
id
,
UmsRole
role
)
{
role
.
setId
(
id
);
return
roleMapper
.
updateByPrimaryKey
(
role
);
}
@Override
public
int
delete
(
List
<
Long
>
ids
)
{
UmsRoleExample
example
=
new
UmsRoleExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
roleMapper
.
deleteByExample
(
example
);
}
@Override
public
List
<
UmsPermission
>
getPermissionList
(
Long
roleId
)
{
return
rolePermissionRelationDao
.
getPermissionList
(
roleId
);
}
@Override
public
int
updatePermission
(
Long
roleId
,
List
<
Long
>
permissionIds
)
{
//先删除原有关系
UmsRolePermissionRelationExample
example
=
new
UmsRolePermissionRelationExample
();
example
.
createCriteria
().
andRoleIdEqualTo
(
roleId
);
rolePermissionRelationMapper
.
deleteByExample
(
example
);
//批量插入新关系
List
<
UmsRolePermissionRelation
>
relationList
=
new
ArrayList
<>();
for
(
Long
permissionId
:
permissionIds
)
{
UmsRolePermissionRelation
relation
=
new
UmsRolePermissionRelation
();
relation
.
setRoleId
(
roleId
);
relation
.
setPermissionId
(
permissionId
);
relationList
.
add
(
relation
);
}
return
rolePermissionRelationDao
.
insertList
(
relationList
);
}
}
mall-admin/src/main/resources/dao/UmsRolePermissionRelationDao.xml
0 → 100644
View file @
7faffe54
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.macro.mall.dao.UmsRolePermissionRelationDao"
>
<!--批量新增回写主键支持-->
<insert
id=
"insertList"
>
INSERT INTO ums_role_permission_relation (role_id, permission_id) VALUES
<foreach
collection=
"list"
separator=
","
item=
"item"
index=
"index"
>
(#{item.roleId,jdbcType=BIGINT},
#{item.permissionId,jdbcType=BIGINT})
</foreach>
</insert>
<select
id=
"getPermissionList"
resultMap=
"com.macro.mall.mapper.UmsPermissionMapper.BaseResultMap"
>
SELECT
p.*
FROM
ums_role_permission_relation r
LEFT JOIN ums_permission p ON r.permission_id = p.id
WHERE
r.role_id = #{roleId};
</select>
</mapper>
\ No newline at end of file
mall-mbg/src/main/java/com/macro/mall/mapper/UmsAdminPermissionRelationMapper.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.mapper
;
import
com.macro.mall.model.UmsAdminPermissionRelation
;
import
com.macro.mall.model.UmsAdminPermissionRelationExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
UmsAdminPermissionRelationMapper
{
int
countByExample
(
UmsAdminPermissionRelationExample
example
);
int
deleteByExample
(
UmsAdminPermissionRelationExample
example
);
int
deleteByPrimaryKey
(
Long
id
);
int
insert
(
UmsAdminPermissionRelation
record
);
int
insertSelective
(
UmsAdminPermissionRelation
record
);
List
<
UmsAdminPermissionRelation
>
selectByExample
(
UmsAdminPermissionRelationExample
example
);
UmsAdminPermissionRelation
selectByPrimaryKey
(
Long
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
UmsAdminPermissionRelation
record
,
@Param
(
"example"
)
UmsAdminPermissionRelationExample
example
);
int
updateByExample
(
@Param
(
"record"
)
UmsAdminPermissionRelation
record
,
@Param
(
"example"
)
UmsAdminPermissionRelationExample
example
);
int
updateByPrimaryKeySelective
(
UmsAdminPermissionRelation
record
);
int
updateByPrimaryKey
(
UmsAdminPermissionRelation
record
);
}
\ No newline at end of file
mall-mbg/src/main/java/com/macro/mall/mapper/UmsAdminRoleRelationMapper.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.mapper
;
import
com.macro.mall.model.UmsAdminRoleRelation
;
import
com.macro.mall.model.UmsAdminRoleRelationExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
UmsAdminRoleRelationMapper
{
int
countByExample
(
UmsAdminRoleRelationExample
example
);
int
deleteByExample
(
UmsAdminRoleRelationExample
example
);
int
deleteByPrimaryKey
(
Long
id
);
int
insert
(
UmsAdminRoleRelation
record
);
int
insertSelective
(
UmsAdminRoleRelation
record
);
List
<
UmsAdminRoleRelation
>
selectByExample
(
UmsAdminRoleRelationExample
example
);
UmsAdminRoleRelation
selectByPrimaryKey
(
Long
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
UmsAdminRoleRelation
record
,
@Param
(
"example"
)
UmsAdminRoleRelationExample
example
);
int
updateByExample
(
@Param
(
"record"
)
UmsAdminRoleRelation
record
,
@Param
(
"example"
)
UmsAdminRoleRelationExample
example
);
int
updateByPrimaryKeySelective
(
UmsAdminRoleRelation
record
);
int
updateByPrimaryKey
(
UmsAdminRoleRelation
record
);
}
\ No newline at end of file
mall-mbg/src/main/java/com/macro/mall/mapper/UmsPermissionMapper.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.mapper
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsPermissionExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
UmsPermissionMapper
{
int
countByExample
(
UmsPermissionExample
example
);
int
deleteByExample
(
UmsPermissionExample
example
);
int
deleteByPrimaryKey
(
Long
id
);
int
insert
(
UmsPermission
record
);
int
insertSelective
(
UmsPermission
record
);
List
<
UmsPermission
>
selectByExample
(
UmsPermissionExample
example
);
UmsPermission
selectByPrimaryKey
(
Long
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
UmsPermission
record
,
@Param
(
"example"
)
UmsPermissionExample
example
);
int
updateByExample
(
@Param
(
"record"
)
UmsPermission
record
,
@Param
(
"example"
)
UmsPermissionExample
example
);
int
updateByPrimaryKeySelective
(
UmsPermission
record
);
int
updateByPrimaryKey
(
UmsPermission
record
);
}
\ No newline at end of file
mall-mbg/src/main/java/com/macro/mall/mapper/UmsRoleMapper.java
0 → 100644
View file @
7faffe54
package
com.macro.mall.mapper
;
import
com.macro.mall.model.UmsRole
;
import
com.macro.mall.model.UmsRoleExample
;
import
java.util.List
;
import
org.apache.ibatis.annotations.Param
;
public
interface
UmsRoleMapper
{
int
countByExample
(
UmsRoleExample
example
);
int
deleteByExample
(
UmsRoleExample
example
);
int
deleteByPrimaryKey
(
Long
id
);
int
insert
(
UmsRole
record
);
int
insertSelective
(
UmsRole
record
);
List
<
UmsRole
>
selectByExample
(
UmsRoleExample
example
);
UmsRole
selectByPrimaryKey
(
Long
id
);
int
updateByExampleSelective
(
@Param
(
"record"
)
UmsRole
record
,
@Param
(
"example"
)
UmsRoleExample
example
);
int
updateByExample
(
@Param
(
"record"
)
UmsRole
record
,
@Param
(
"example"
)
UmsRoleExample
example
);
int
updateByPrimaryKeySelective
(
UmsRole
record
);
int
updateByPrimaryKey
(
UmsRole
record
);
}
\ No newline at end of file
Prev
1
2
Next
Write
Preview
Supports
Markdown
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