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
ecc50c4b
"...src/main/resources/template/front/index.ftl" did not exist on "6bc2a8ada15dc699fa98e794a12b888c9d4aa9ca"
Commit
ecc50c4b
authored
Feb 16, 2020
by
macro
Browse files
添加权限管理相关接口
parent
f1bec5df
Changes
26
Hide whitespace changes
Inline
Side-by-side
mall-admin/src/main/java/com/macro/mall/bo/AdminUserDetails.java
View file @
ecc50c4b
package
com.macro.mall.bo
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.Ums
Permission
;
import
com.macro.mall.model.Ums
Resource
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.security.core.userdetails.UserDetails
;
...
...
@@ -16,18 +16,17 @@ import java.util.stream.Collectors;
*/
public
class
AdminUserDetails
implements
UserDetails
{
private
UmsAdmin
umsAdmin
;
private
List
<
Ums
Permission
>
permission
List
;
public
AdminUserDetails
(
UmsAdmin
umsAdmin
,
List
<
Ums
Permission
>
permission
List
)
{
private
List
<
Ums
Resource
>
resource
List
;
public
AdminUserDetails
(
UmsAdmin
umsAdmin
,
List
<
Ums
Resource
>
resource
List
)
{
this
.
umsAdmin
=
umsAdmin
;
this
.
permissionList
=
permission
List
;
this
.
resourceList
=
resource
List
;
}
@Override
public
Collection
<?
extends
GrantedAuthority
>
getAuthorities
()
{
//返回当前用户的权限
return
permissionList
.
stream
()
.
filter
(
permission
->
permission
.
getValue
()!=
null
)
.
map
(
permission
->
new
SimpleGrantedAuthority
(
permission
.
getValue
()))
//返回当前用户的角色
return
resourceList
.
stream
()
.
map
(
role
->
new
SimpleGrantedAuthority
(
role
.
getId
()+
":"
+
role
.
getName
()))
.
collect
(
Collectors
.
toList
());
}
...
...
mall-admin/src/main/java/com/macro/mall/config/MallSecurityConfig.java
View file @
ecc50c4b
package
com.macro.mall.config
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.security.component.DynamicSecurityService
;
import
com.macro.mall.security.config.SecurityConfig
;
import
com.macro.mall.service.UmsAdminService
;
import
com.macro.mall.service.UmsResourceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.security.access.ConfigAttribute
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* mall-security模块相关配置
* Created by macro on 2019/11/9.
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
@EnableGlobalMethodSecurity
(
prePostEnabled
=
true
)
public
class
MallSecurityConfig
extends
SecurityConfig
{
@Autowired
private
UmsAdminService
adminService
;
@Autowired
private
UmsResourceService
resourceService
;
@Bean
public
UserDetailsService
userDetailsService
()
{
//获取登录用户信息
return
username
->
adminService
.
loadUserByUsername
(
username
);
}
@Bean
public
DynamicSecurityService
dynamicSecurityService
()
{
return
new
DynamicSecurityService
()
{
@Override
public
Map
<
String
,
ConfigAttribute
>
loadDataSource
()
{
Map
<
String
,
ConfigAttribute
>
map
=
new
ConcurrentHashMap
<>();
List
<
UmsResource
>
resourceList
=
resourceService
.
listAll
();
for
(
UmsResource
resource
:
resourceList
)
{
map
.
put
(
resource
.
getUrl
(),
new
org
.
springframework
.
security
.
access
.
SecurityConfig
(
resource
.
getId
()
+
":"
+
resource
.
getName
()));
}
return
map
;
}
};
}
}
mall-admin/src/main/java/com/macro/mall/controller/PmsBrandController.java
View file @
ecc50c4b
...
...
@@ -8,7 +8,6 @@ import com.macro.mall.service.PmsBrandService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -30,7 +29,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"获取全部品牌列表"
)
@RequestMapping
(
value
=
"/listAll"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:read')"
)
public
CommonResult
<
List
<
PmsBrand
>>
getList
()
{
return
CommonResult
.
success
(
brandService
.
listAllBrand
());
}
...
...
@@ -38,7 +36,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"添加品牌"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:create')"
)
public
CommonResult
create
(
@Validated
@RequestBody
PmsBrandParam
pmsBrand
,
BindingResult
result
)
{
CommonResult
commonResult
;
int
count
=
brandService
.
createBrand
(
pmsBrand
);
...
...
@@ -53,7 +50,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"更新品牌"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:update')"
)
public
CommonResult
update
(
@PathVariable
(
"id"
)
Long
id
,
@Validated
@RequestBody
PmsBrandParam
pmsBrandParam
,
BindingResult
result
)
{
...
...
@@ -70,7 +66,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"删除品牌"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:delete')"
)
public
CommonResult
delete
(
@PathVariable
(
"id"
)
Long
id
)
{
int
count
=
brandService
.
deleteBrand
(
id
);
if
(
count
==
1
)
{
...
...
@@ -83,7 +78,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"根据品牌名称分页获取品牌列表"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:read')"
)
public
CommonResult
<
CommonPage
<
PmsBrand
>>
getList
(
@RequestParam
(
value
=
"keyword"
,
required
=
false
)
String
keyword
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
)
{
...
...
@@ -94,7 +88,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"根据编号查询品牌信息"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:read')"
)
public
CommonResult
<
PmsBrand
>
getItem
(
@PathVariable
(
"id"
)
Long
id
)
{
return
CommonResult
.
success
(
brandService
.
getBrand
(
id
));
}
...
...
@@ -102,7 +95,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"批量删除品牌"
)
@RequestMapping
(
value
=
"/delete/batch"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:delete')"
)
public
CommonResult
deleteBatch
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
)
{
int
count
=
brandService
.
deleteBrand
(
ids
);
if
(
count
>
0
)
{
...
...
@@ -115,7 +107,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"批量更新显示状态"
)
@RequestMapping
(
value
=
"/update/showStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:update')"
)
public
CommonResult
updateShowStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"showStatus"
)
Integer
showStatus
)
{
int
count
=
brandService
.
updateShowStatus
(
ids
,
showStatus
);
...
...
@@ -129,7 +120,6 @@ public class PmsBrandController {
@ApiOperation
(
value
=
"批量更新厂家制造商状态"
)
@RequestMapping
(
value
=
"/update/factoryStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:brand:update')"
)
public
CommonResult
updateFactoryStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"factoryStatus"
)
Integer
factoryStatus
)
{
int
count
=
brandService
.
updateFactoryStatus
(
ids
,
factoryStatus
);
...
...
mall-admin/src/main/java/com/macro/mall/controller/PmsProductCategoryController.java
View file @
ecc50c4b
...
...
@@ -9,7 +9,6 @@ import com.macro.mall.service.PmsProductCategoryService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -31,7 +30,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"添加产品分类"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:create')"
)
public
CommonResult
create
(
@Validated
@RequestBody
PmsProductCategoryParam
productCategoryParam
,
BindingResult
result
)
{
int
count
=
productCategoryService
.
create
(
productCategoryParam
);
...
...
@@ -45,7 +43,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"修改商品分类"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:update')"
)
public
CommonResult
update
(
@PathVariable
Long
id
,
@Validated
@RequestBody
PmsProductCategoryParam
productCategoryParam
,
...
...
@@ -61,7 +58,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"分页查询商品分类"
)
@RequestMapping
(
value
=
"/list/{parentId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:read')"
)
public
CommonResult
<
CommonPage
<
PmsProductCategory
>>
getList
(
@PathVariable
Long
parentId
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
...
...
@@ -72,7 +68,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"根据id获取商品分类"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:read')"
)
public
CommonResult
<
PmsProductCategory
>
getItem
(
@PathVariable
Long
id
)
{
PmsProductCategory
productCategory
=
productCategoryService
.
getItem
(
id
);
return
CommonResult
.
success
(
productCategory
);
...
...
@@ -81,7 +76,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"删除商品分类"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:delete')"
)
public
CommonResult
delete
(
@PathVariable
Long
id
)
{
int
count
=
productCategoryService
.
delete
(
id
);
if
(
count
>
0
)
{
...
...
@@ -94,7 +88,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"修改导航栏显示状态"
)
@RequestMapping
(
value
=
"/update/navStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:update')"
)
public
CommonResult
updateNavStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"navStatus"
)
Integer
navStatus
)
{
int
count
=
productCategoryService
.
updateNavStatus
(
ids
,
navStatus
);
if
(
count
>
0
)
{
...
...
@@ -107,7 +100,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"修改显示状态"
)
@RequestMapping
(
value
=
"/update/showStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:update')"
)
public
CommonResult
updateShowStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"showStatus"
)
Integer
showStatus
)
{
int
count
=
productCategoryService
.
updateShowStatus
(
ids
,
showStatus
);
if
(
count
>
0
)
{
...
...
@@ -120,7 +112,6 @@ public class PmsProductCategoryController {
@ApiOperation
(
"查询所有一级分类及子分类"
)
@RequestMapping
(
value
=
"/list/withChildren"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:productCategory:read')"
)
public
CommonResult
<
List
<
PmsProductCategoryWithChildrenItem
>>
listWithChildren
()
{
List
<
PmsProductCategoryWithChildrenItem
>
list
=
productCategoryService
.
listWithChildren
();
return
CommonResult
.
success
(
list
);
...
...
mall-admin/src/main/java/com/macro/mall/controller/PmsProductController.java
View file @
ecc50c4b
...
...
@@ -10,7 +10,6 @@ import com.macro.mall.service.PmsProductService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -31,7 +30,6 @@ public class PmsProductController {
@ApiOperation
(
"创建商品"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:create')"
)
public
CommonResult
create
(
@RequestBody
PmsProductParam
productParam
,
BindingResult
bindingResult
)
{
int
count
=
productService
.
create
(
productParam
);
if
(
count
>
0
)
{
...
...
@@ -44,7 +42,6 @@ public class PmsProductController {
@ApiOperation
(
"根据商品id获取商品编辑信息"
)
@RequestMapping
(
value
=
"/updateInfo/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:read')"
)
public
CommonResult
<
PmsProductResult
>
getUpdateInfo
(
@PathVariable
Long
id
)
{
PmsProductResult
productResult
=
productService
.
getUpdateInfo
(
id
);
return
CommonResult
.
success
(
productResult
);
...
...
@@ -53,7 +50,6 @@ public class PmsProductController {
@ApiOperation
(
"更新商品"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:update')"
)
public
CommonResult
update
(
@PathVariable
Long
id
,
@RequestBody
PmsProductParam
productParam
,
BindingResult
bindingResult
)
{
int
count
=
productService
.
update
(
id
,
productParam
);
if
(
count
>
0
)
{
...
...
@@ -66,7 +62,6 @@ public class PmsProductController {
@ApiOperation
(
"查询商品"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:read')"
)
public
CommonResult
<
CommonPage
<
PmsProduct
>>
getList
(
PmsProductQueryParam
productQueryParam
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
...
...
@@ -85,7 +80,6 @@ public class PmsProductController {
@ApiOperation
(
"批量修改审核状态"
)
@RequestMapping
(
value
=
"/update/verifyStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:update')"
)
public
CommonResult
updateVerifyStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"verifyStatus"
)
Integer
verifyStatus
,
@RequestParam
(
"detail"
)
String
detail
)
{
...
...
@@ -100,7 +94,6 @@ public class PmsProductController {
@ApiOperation
(
"批量上下架"
)
@RequestMapping
(
value
=
"/update/publishStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:update')"
)
public
CommonResult
updatePublishStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"publishStatus"
)
Integer
publishStatus
)
{
int
count
=
productService
.
updatePublishStatus
(
ids
,
publishStatus
);
...
...
@@ -114,7 +107,6 @@ public class PmsProductController {
@ApiOperation
(
"批量推荐商品"
)
@RequestMapping
(
value
=
"/update/recommendStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:update')"
)
public
CommonResult
updateRecommendStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"recommendStatus"
)
Integer
recommendStatus
)
{
int
count
=
productService
.
updateRecommendStatus
(
ids
,
recommendStatus
);
...
...
@@ -128,7 +120,6 @@ public class PmsProductController {
@ApiOperation
(
"批量设为新品"
)
@RequestMapping
(
value
=
"/update/newStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:update')"
)
public
CommonResult
updateNewStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"newStatus"
)
Integer
newStatus
)
{
int
count
=
productService
.
updateNewStatus
(
ids
,
newStatus
);
...
...
@@ -142,7 +133,6 @@ public class PmsProductController {
@ApiOperation
(
"批量修改删除状态"
)
@RequestMapping
(
value
=
"/update/deleteStatus"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@PreAuthorize
(
"hasAuthority('pms:product:delete')"
)
public
CommonResult
updateDeleteStatus
(
@RequestParam
(
"ids"
)
List
<
Long
>
ids
,
@RequestParam
(
"deleteStatus"
)
Integer
deleteStatus
)
{
int
count
=
productService
.
updateDeleteStatus
(
ids
,
deleteStatus
);
...
...
mall-admin/src/main/java/com/macro/mall/controller/UmsAdminController.java
View file @
ecc50c4b
...
...
@@ -9,6 +9,7 @@ import com.macro.mall.model.UmsAdmin;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
import
com.macro.mall.service.UmsAdminService
;
import
com.macro.mall.service.UmsRoleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -31,12 +32,14 @@ import java.util.Map;
@Api
(
tags
=
"UmsAdminController"
,
description
=
"后台用户管理"
)
@RequestMapping
(
"/admin"
)
public
class
UmsAdminController
{
@Autowired
private
UmsAdminService
adminService
;
@Value
(
"${jwt.tokenHeader}"
)
private
String
tokenHeader
;
@Value
(
"${jwt.tokenHead}"
)
private
String
tokenHead
;
@Autowired
private
UmsAdminService
adminService
;
@Autowired
private
UmsRoleService
roleService
;
@ApiOperation
(
value
=
"用户注册"
)
@RequestMapping
(
value
=
"/register"
,
method
=
RequestMethod
.
POST
)
...
...
@@ -82,11 +85,15 @@ public class UmsAdminController {
@RequestMapping
(
value
=
"/info"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
getAdminInfo
(
Principal
principal
)
{
if
(
principal
==
null
){
return
CommonResult
.
unauthorized
(
null
);
}
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
(
"menus"
,
roleService
.
getMenuList
(
umsAdmin
.
getId
()));
data
.
put
(
"icon"
,
umsAdmin
.
getIcon
());
return
CommonResult
.
success
(
data
);
}
...
...
@@ -101,10 +108,10 @@ public class UmsAdminController {
@ApiOperation
(
"根据用户名或姓名分页获取用户列表"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
UmsAdmin
>>
list
(
@RequestParam
(
value
=
"
name
"
,
required
=
false
)
String
name
,
public
CommonResult
<
CommonPage
<
UmsAdmin
>>
list
(
@RequestParam
(
value
=
"
keyword
"
,
required
=
false
)
String
keyword
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
UmsAdmin
>
adminList
=
adminService
.
list
(
name
,
pageSize
,
pageNum
);
List
<
UmsAdmin
>
adminList
=
adminService
.
list
(
keyword
,
pageSize
,
pageNum
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
adminList
));
}
...
...
@@ -156,6 +163,19 @@ public class UmsAdminController {
return
CommonResult
.
failed
();
}
@ApiOperation
(
"修改帐号状态"
)
@RequestMapping
(
value
=
"/updateStatus/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
updateStatus
(
@PathVariable
Long
id
,
@RequestParam
(
value
=
"status"
)
Integer
status
)
{
UmsAdmin
umsAdmin
=
new
UmsAdmin
();
umsAdmin
.
setStatus
(
status
);
int
count
=
adminService
.
update
(
id
,
umsAdmin
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
return
CommonResult
.
failed
();
}
@ApiOperation
(
"给用户分配角色"
)
@RequestMapping
(
value
=
"/role/update"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
...
...
mall-admin/src/main/java/com/macro/mall/controller/UmsMenuController.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.controller
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.dto.UmsMenuNode
;
import
com.macro.mall.model.UmsMenu
;
import
com.macro.mall.service.UmsMenuService
;
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
;
/**
* 后台菜单管理Controller
* Created by macro on 2020/2/4.
*/
@Controller
@Api
(
tags
=
"UmsMenuController"
,
description
=
"后台菜单管理"
)
@RequestMapping
(
"/menu"
)
public
class
UmsMenuController
{
@Autowired
private
UmsMenuService
menuService
;
@ApiOperation
(
"添加后台菜单"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
create
(
@RequestBody
UmsMenu
umsMenu
)
{
int
count
=
menuService
.
create
(
umsMenu
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"修改后台菜单"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
update
(
@PathVariable
Long
id
,
@RequestBody
UmsMenu
umsMenu
)
{
int
count
=
menuService
.
update
(
id
,
umsMenu
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"根据ID获取菜单详情"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
UmsMenu
>
getItem
(
@PathVariable
Long
id
)
{
UmsMenu
umsMenu
=
menuService
.
getItem
(
id
);
return
CommonResult
.
success
(
umsMenu
);
}
@ApiOperation
(
"根据ID删除后台菜单"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
delete
(
@PathVariable
Long
id
)
{
int
count
=
menuService
.
delete
(
id
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"分页查询后台菜单"
)
@RequestMapping
(
value
=
"/list/{parentId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
UmsMenu
>>
list
(
@PathVariable
Long
parentId
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
UmsMenu
>
menuList
=
menuService
.
list
(
parentId
,
pageSize
,
pageNum
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
menuList
));
}
@ApiOperation
(
"树形结构返回所有菜单列表"
)
@RequestMapping
(
value
=
"/treeList"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
UmsMenuNode
>>
treeList
()
{
List
<
UmsMenuNode
>
list
=
menuService
.
treeList
();
return
CommonResult
.
success
(
list
);
}
@ApiOperation
(
"修改菜单显示状态"
)
@RequestMapping
(
value
=
"/updateHidden/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
updateHidden
(
@PathVariable
Long
id
,
@RequestParam
(
"hidden"
)
Integer
hidden
)
{
int
count
=
menuService
.
updateHidden
(
id
,
hidden
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
}
mall-admin/src/main/java/com/macro/mall/controller/UmsResourceCategoryController.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.controller
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.UmsResourceCategory
;
import
com.macro.mall.service.UmsResourceCategoryService
;
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
;
/**
* 后台资源分类管理Controller
* Created by macro on 2020/2/5.
*/
@Controller
@Api
(
tags
=
"UmsResourceCategoryController"
,
description
=
"后台资源分类管理"
)
@RequestMapping
(
"/resourceCategory"
)
public
class
UmsResourceCategoryController
{
@Autowired
private
UmsResourceCategoryService
resourceCategoryService
;
@ApiOperation
(
"查询所有后台资源分类"
)
@RequestMapping
(
value
=
"/listAll"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
UmsResourceCategory
>>
listAll
()
{
List
<
UmsResourceCategory
>
resourceList
=
resourceCategoryService
.
listAll
();
return
CommonResult
.
success
(
resourceList
);
}
@ApiOperation
(
"添加后台资源分类"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
create
(
@RequestBody
UmsResourceCategory
umsResourceCategory
)
{
int
count
=
resourceCategoryService
.
create
(
umsResourceCategory
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"修改后台资源分类"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
update
(
@PathVariable
Long
id
,
@RequestBody
UmsResourceCategory
umsResourceCategory
)
{
int
count
=
resourceCategoryService
.
update
(
id
,
umsResourceCategory
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"根据ID删除后台资源"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
delete
(
@PathVariable
Long
id
)
{
int
count
=
resourceCategoryService
.
delete
(
id
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
}
mall-admin/src/main/java/com/macro/mall/controller/UmsResourceController.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.controller
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.security.component.DynamicSecurityMetadataSource
;
import
com.macro.mall.service.UmsResourceService
;
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
;
/**
* 后台资源管理Controller
* Created by macro on 2020/2/4.
*/
@Controller
@Api
(
tags
=
"UmsResourceController"
,
description
=
"后台资源管理"
)
@RequestMapping
(
"/resource"
)
public
class
UmsResourceController
{
@Autowired
private
UmsResourceService
resourceService
;
@Autowired
private
DynamicSecurityMetadataSource
dynamicSecurityMetadataSource
;
@ApiOperation
(
"添加后台资源"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
create
(
@RequestBody
UmsResource
umsResource
)
{
int
count
=
resourceService
.
create
(
umsResource
);
dynamicSecurityMetadataSource
.
clearDataSource
();
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"修改后台资源"
)
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
update
(
@PathVariable
Long
id
,
@RequestBody
UmsResource
umsResource
)
{
int
count
=
resourceService
.
update
(
id
,
umsResource
);
dynamicSecurityMetadataSource
.
clearDataSource
();
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"根据ID获取资源详情"
)
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
UmsResource
>
getItem
(
@PathVariable
Long
id
)
{
UmsResource
umsResource
=
resourceService
.
getItem
(
id
);
return
CommonResult
.
success
(
umsResource
);
}
@ApiOperation
(
"根据ID删除后台资源"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
delete
(
@PathVariable
Long
id
)
{
int
count
=
resourceService
.
delete
(
id
);
dynamicSecurityMetadataSource
.
clearDataSource
();
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"分页模糊查询后台资源"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
UmsResource
>>
list
(
@RequestParam
(
required
=
false
)
Long
categoryId
,
@RequestParam
(
required
=
false
)
String
nameKeyword
,
@RequestParam
(
required
=
false
)
String
urlKeyword
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
UmsResource
>
resourceList
=
resourceService
.
list
(
categoryId
,
nameKeyword
,
urlKeyword
,
pageSize
,
pageNum
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
resourceList
));
}
@ApiOperation
(
"查询所有后台资源"
)
@RequestMapping
(
value
=
"/listAll"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
UmsResource
>>
listAll
()
{
List
<
UmsResource
>
resourceList
=
resourceService
.
listAll
();
return
CommonResult
.
success
(
resourceList
);
}
}
mall-admin/src/main/java/com/macro/mall/controller/UmsRoleController.java
View file @
ecc50c4b
package
com.macro.mall.controller
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
import
com.macro.mall.model.*
;
import
com.macro.mall.service.UmsRoleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -77,11 +77,66 @@ public class UmsRoleController {
}
@ApiOperation
(
"获取所有角色"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/list
All
"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
list
()
{
public
CommonResult
<
List
<
UmsRole
>>
list
All
()
{
List
<
UmsRole
>
roleList
=
roleService
.
list
();
return
CommonResult
.
success
(
roleList
);
}
@ApiOperation
(
"根据角色名称分页获取角色列表"
)
@RequestMapping
(
value
=
"/list"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
UmsRole
>>
list
(
@RequestParam
(
value
=
"keyword"
,
required
=
false
)
String
keyword
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
UmsRole
>
roleList
=
roleService
.
list
(
keyword
,
pageSize
,
pageNum
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
roleList
));
}
@ApiOperation
(
"修改角色状态"
)
@RequestMapping
(
value
=
"/updateStatus/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
updateStatus
(
@PathVariable
Long
id
,
@RequestParam
(
value
=
"status"
)
Integer
status
)
{
UmsRole
umsRole
=
new
UmsRole
();
umsRole
.
setStatus
(
status
);
int
count
=
roleService
.
update
(
id
,
umsRole
);
if
(
count
>
0
)
{
return
CommonResult
.
success
(
count
);
}
return
CommonResult
.
failed
();
}
@ApiOperation
(
"获取角色相关菜单"
)
@RequestMapping
(
value
=
"/listMenu/{roleId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
UmsMenu
>>
listMenu
(
@PathVariable
Long
roleId
)
{
List
<
UmsMenu
>
roleList
=
roleService
.
listMenu
(
roleId
);
return
CommonResult
.
success
(
roleList
);
}
@ApiOperation
(
"获取角色相关资源"
)
@RequestMapping
(
value
=
"/listResource/{roleId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
UmsResource
>>
listResource
(
@PathVariable
Long
roleId
)
{
List
<
UmsResource
>
roleList
=
roleService
.
listResource
(
roleId
);
return
CommonResult
.
success
(
roleList
);
}
@ApiOperation
(
"给角色分配菜单"
)
@RequestMapping
(
value
=
"/allocMenu"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
allocMenu
(
@RequestParam
Long
roleId
,
@RequestParam
List
<
Long
>
menuIds
)
{
int
count
=
roleService
.
allocMenu
(
roleId
,
menuIds
);
return
CommonResult
.
success
(
count
);
}
@ApiOperation
(
"给角色分配资源"
)
@RequestMapping
(
value
=
"/allocResource"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
allocResource
(
@RequestParam
Long
roleId
,
@RequestParam
List
<
Long
>
resourceIds
)
{
int
count
=
roleService
.
allocResource
(
roleId
,
resourceIds
);
return
CommonResult
.
success
(
count
);
}
}
mall-admin/src/main/java/com/macro/mall/dao/UmsAdminRoleRelationDao.java
View file @
ecc50c4b
...
...
@@ -2,6 +2,7 @@ package com.macro.mall.dao;
import
com.macro.mall.model.UmsAdminRoleRelation
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.model.UmsRole
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -31,4 +32,9 @@ public interface UmsAdminRoleRelationDao {
* 获取用户所有权限(包括+-权限)
*/
List
<
UmsPermission
>
getPermissionList
(
@Param
(
"adminId"
)
Long
adminId
);
/**
* 获取用户所有可访问资源
*/
List
<
UmsResource
>
getResourceList
(
@Param
(
"adminId"
)
Long
adminId
);
}
mall-admin/src/main/java/com/macro/mall/dao/UmsRoleDao.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.dao
;
import
com.macro.mall.model.UmsMenu
;
import
com.macro.mall.model.UmsResource
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* 后台用户角色自定义Dao
* Created by macro on 2020/2/2.
*/
public
interface
UmsRoleDao
{
List
<
UmsMenu
>
getMenuList
(
@Param
(
"adminId"
)
Long
adminId
);
List
<
UmsMenu
>
getMenuListByRoleId
(
@Param
(
"roleId"
)
Long
roleId
);
List
<
UmsResource
>
getResourceListByRoleId
(
@Param
(
"roleId"
)
Long
roleId
);
}
mall-admin/src/main/java/com/macro/mall/dto/UmsMenuNode.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.dto
;
import
com.macro.mall.model.UmsMenu
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* Created by macro on 2020/2/4.
*/
@Getter
@Setter
public
class
UmsMenuNode
extends
UmsMenu
{
private
List
<
UmsMenuNode
>
children
;
}
mall-admin/src/main/java/com/macro/mall/service/UmsAdminService.java
View file @
ecc50c4b
...
...
@@ -4,6 +4,7 @@ import com.macro.mall.dto.UmsAdminParam;
import
com.macro.mall.dto.UpdateAdminPasswordParam
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.model.UmsRole
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -47,7 +48,7 @@ public interface UmsAdminService {
/**
* 根据用户名或昵称分页查询用户
*/
List
<
UmsAdmin
>
list
(
String
name
,
Integer
pageSize
,
Integer
pageNum
);
List
<
UmsAdmin
>
list
(
String
keyword
,
Integer
pageSize
,
Integer
pageNum
);
/**
* 修改指定用户信息
...
...
@@ -70,6 +71,11 @@ public interface UmsAdminService {
*/
List
<
UmsRole
>
getRoleList
(
Long
adminId
);
/**
* 获取指定用户的可访问资源
*/
List
<
UmsResource
>
getResourceList
(
Long
adminId
);
/**
* 修改用户的+-权限
*/
...
...
mall-admin/src/main/java/com/macro/mall/service/UmsMenuService.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.service
;
import
com.macro.mall.dto.UmsMenuNode
;
import
com.macro.mall.model.UmsMenu
;
import
java.util.List
;
/**
* 后台菜单管理Service
* Created by macro on 2020/2/2.
*/
public
interface
UmsMenuService
{
/**
* 创建后台菜单
*/
int
create
(
UmsMenu
umsMenu
);
/**
* 修改后台菜单
*/
int
update
(
Long
id
,
UmsMenu
umsMenu
);
/**
* 根据ID获取菜单详情
*/
UmsMenu
getItem
(
Long
id
);
/**
* 根据ID删除菜单
*/
int
delete
(
Long
id
);
/**
* 分页查询后台菜单
*/
List
<
UmsMenu
>
list
(
Long
parentId
,
Integer
pageSize
,
Integer
pageNum
);
/**
* 树形结构返回所有菜单列表
*/
List
<
UmsMenuNode
>
treeList
();
/**
* 修改菜单显示状态
*/
int
updateHidden
(
Long
id
,
Integer
hidden
);
}
mall-admin/src/main/java/com/macro/mall/service/UmsResourceCategoryService.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.service
;
import
com.macro.mall.model.UmsResourceCategory
;
import
java.util.List
;
/**
* 后台资源分类管理Service
* Created by macro on 2020/2/5.
*/
public
interface
UmsResourceCategoryService
{
List
<
UmsResourceCategory
>
listAll
();
int
create
(
UmsResourceCategory
umsResourceCategory
);
int
update
(
Long
id
,
UmsResourceCategory
umsResourceCategory
);
int
delete
(
Long
id
);
}
mall-admin/src/main/java/com/macro/mall/service/UmsResourceService.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.service
;
import
com.macro.mall.model.UmsResource
;
import
java.util.List
;
/**
* 后台资源管理Service
* Created by macro on 2020/2/2.
*/
public
interface
UmsResourceService
{
int
create
(
UmsResource
umsResource
);
int
update
(
Long
id
,
UmsResource
umsResource
);
UmsResource
getItem
(
Long
id
);
int
delete
(
Long
id
);
List
<
UmsResource
>
list
(
Long
categoryId
,
String
nameKeyword
,
String
urlKeyword
,
Integer
pageSize
,
Integer
pageNum
);
List
<
UmsResource
>
listAll
();
}
mall-admin/src/main/java/com/macro/mall/service/UmsRoleService.java
View file @
ecc50c4b
package
com.macro.mall.service
;
import
com.macro.mall.model.UmsMenu
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsResource
;
import
com.macro.mall.model.UmsRole
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -38,7 +40,39 @@ public interface UmsRoleService {
int
updatePermission
(
Long
roleId
,
List
<
Long
>
permissionIds
);
/**
* 获取角色列表
* 获取
所有
角色列表
*/
List
<
UmsRole
>
list
();
/**
* 分页获取角色列表
*/
List
<
UmsRole
>
list
(
String
keyword
,
Integer
pageSize
,
Integer
pageNum
);
/**
* 根据管理员ID获取对应菜单
*/
List
<
UmsMenu
>
getMenuList
(
Long
adminId
);
/**
* 获取角色相关菜单
*/
List
<
UmsMenu
>
listMenu
(
Long
roleId
);
/**
* 获取角色相关资源
*/
List
<
UmsResource
>
listResource
(
Long
roleId
);
/**
* 给角色分配菜单
*/
@Transactional
int
allocMenu
(
Long
roleId
,
List
<
Long
>
menuIds
);
/**
* 给角色分配资源
*/
@Transactional
int
allocResource
(
Long
roleId
,
List
<
Long
>
resourceIds
);
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
View file @
ecc50c4b
...
...
@@ -150,13 +150,13 @@ public class UmsAdminServiceImpl implements UmsAdminService {
}
@Override
public
List
<
UmsAdmin
>
list
(
String
name
,
Integer
pageSize
,
Integer
pageNum
)
{
public
List
<
UmsAdmin
>
list
(
String
keyword
,
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
+
"%"
));
if
(!
StringUtils
.
isEmpty
(
keyword
))
{
criteria
.
andUsernameLike
(
"%"
+
keyword
+
"%"
);
example
.
or
(
example
.
createCriteria
().
andNickNameLike
(
"%"
+
keyword
+
"%"
));
}
return
adminMapper
.
selectByExample
(
example
);
}
...
...
@@ -164,8 +164,18 @@ public class UmsAdminServiceImpl implements UmsAdminService {
@Override
public
int
update
(
Long
id
,
UmsAdmin
admin
)
{
admin
.
setId
(
id
);
//密码已经加密处理,需要单独修改
admin
.
setPassword
(
null
);
UmsAdmin
rawAdmin
=
adminMapper
.
selectByPrimaryKey
(
id
);
if
(
rawAdmin
.
getPassword
().
equals
(
admin
.
getPassword
())){
//与原加密密码相同的不需要修改
admin
.
setPassword
(
null
);
}
else
{
//与原加密密码不同的需要加密修改
if
(
StrUtil
.
isEmpty
(
admin
.
getPassword
())){
admin
.
setPassword
(
null
);
}
else
{
admin
.
setPassword
(
passwordEncoder
.
encode
(
admin
.
getPassword
()));
}
}
return
adminMapper
.
updateByPrimaryKeySelective
(
admin
);
}
...
...
@@ -200,6 +210,11 @@ public class UmsAdminServiceImpl implements UmsAdminService {
return
adminRoleRelationDao
.
getRoleList
(
adminId
);
}
@Override
public
List
<
UmsResource
>
getResourceList
(
Long
adminId
)
{
return
adminRoleRelationDao
.
getResourceList
(
adminId
);
}
@Override
public
int
updatePermission
(
Long
adminId
,
List
<
Long
>
permissionIds
)
{
//删除原所有权限关系
...
...
@@ -269,8 +284,8 @@ public class UmsAdminServiceImpl implements UmsAdminService {
//获取用户信息
UmsAdmin
admin
=
getAdminByUsername
(
username
);
if
(
admin
!=
null
)
{
List
<
Ums
Permission
>
permissionList
=
getPermission
List
(
admin
.
getId
());
return
new
AdminUserDetails
(
admin
,
permission
List
);
List
<
Ums
Resource
>
resourceList
=
getResource
List
(
admin
.
getId
());
return
new
AdminUserDetails
(
admin
,
resource
List
);
}
throw
new
UsernameNotFoundException
(
"用户名或密码错误"
);
}
...
...
mall-admin/src/main/java/com/macro/mall/service/impl/UmsMenuServiceImpl.java
0 → 100644
View file @
ecc50c4b
package
com.macro.mall.service.impl
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.dto.UmsMenuNode
;
import
com.macro.mall.mapper.UmsMenuMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.service.UmsMenuService
;
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 2020/2/2.
*/
@Service
public
class
UmsMenuServiceImpl
implements
UmsMenuService
{
@Autowired
private
UmsMenuMapper
menuMapper
;
@Override
public
int
create
(
UmsMenu
umsMenu
)
{
umsMenu
.
setCreateTime
(
new
Date
());
updateLevel
(
umsMenu
);
return
menuMapper
.
insert
(
umsMenu
);
}
/**
* 修改菜单层级
*/
private
void
updateLevel
(
UmsMenu
umsMenu
)
{
if
(
umsMenu
.
getParentId
()
==
0
)
{
//没有父菜单时为一级菜单
umsMenu
.
setLevel
(
0
);
}
else
{
//有父菜单时选择根据父菜单level设置
UmsMenu
parentMenu
=
menuMapper
.
selectByPrimaryKey
(
umsMenu
.
getParentId
());
if
(
parentMenu
!=
null
)
{
umsMenu
.
setLevel
(
parentMenu
.
getLevel
()
+
1
);
}
else
{
umsMenu
.
setLevel
(
0
);
}
}
}
@Override
public
int
update
(
Long
id
,
UmsMenu
umsMenu
)
{
umsMenu
.
setId
(
id
);
updateLevel
(
umsMenu
);
return
menuMapper
.
updateByPrimaryKeySelective
(
umsMenu
);
}
@Override
public
UmsMenu
getItem
(
Long
id
)
{
return
menuMapper
.
selectByPrimaryKey
(
id
);
}
@Override
public
int
delete
(
Long
id
)
{
return
menuMapper
.
deleteByPrimaryKey
(
id
);
}
@Override
public
List
<
UmsMenu
>
list
(
Long
parentId
,
Integer
pageSize
,
Integer
pageNum
)
{
PageHelper
.
startPage
(
pageNum
,
pageSize
);
UmsMenuExample
example
=
new
UmsMenuExample
();
example
.
setOrderByClause
(
"sort desc"
);
example
.
createCriteria
().
andParentIdEqualTo
(
parentId
);
return
menuMapper
.
selectByExample
(
example
);
}
@Override
public
List
<
UmsMenuNode
>
treeList
()
{
List
<
UmsMenu
>
menuList
=
menuMapper
.
selectByExample
(
new
UmsMenuExample
());
List
<
UmsMenuNode
>
result
=
menuList
.
stream
()
.
filter
(
menu
->
menu
.
getParentId
().
equals
(
0L
))
.
map
(
menu
->
covertMenuNode
(
menu
,
menuList
)).
collect
(
Collectors
.
toList
());
return
result
;
}
@Override
public
int
updateHidden
(
Long
id
,
Integer
hidden
)
{
UmsMenu
umsMenu
=
new
UmsMenu
();
umsMenu
.
setId
(
id
);
umsMenu
.
setHidden
(
hidden
);
return
menuMapper
.
updateByPrimaryKeySelective
(
umsMenu
);
}
/**
* 将UmsMenu转化为UmsMenuNode并设置children属性
*/
private
UmsMenuNode
covertMenuNode
(
UmsMenu
menu
,
List
<
UmsMenu
>
menuList
)
{
UmsMenuNode
node
=
new
UmsMenuNode
();
BeanUtils
.
copyProperties
(
menu
,
node
);
List
<
UmsMenuNode
>
children
=
menuList
.
stream
()
.
filter
(
subMenu
->
subMenu
.
getParentId
().
equals
(
menu
.
getId
()))
.
map
(
subMenu
->
covertMenuNode
(
subMenu
,
menuList
)).
collect
(
Collectors
.
toList
());
node
.
setChildren
(
children
);
return
node
;
}
}
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