Skip to content

Commit d9337b6

Browse files
🚔 优化用户角色权限
1 parent 206b218 commit d9337b6

39 files changed

+496
-214
lines changed

README-zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
<p align="center">
1111
<a href="https://github.com/geekidea/spring-boot-plus/">
12-
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-1.3.1.RELEASE-blue">
12+
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-1.4.0-blue">
1313
</a>
1414
<a href="https://github.com/spring-projects/spring-boot">
15-
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.1.9.RELEASE-brightgreen">
15+
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.2.0.RELEASE-brightgreen">
1616
</a>
1717
<a href="https://www.apache.org/licenses/LICENSE-2.0">
1818
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
<p align="center">
1111
<a href="https://github.com/geekidea/spring-boot-plus/">
12-
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-1.3.1.RELEASE-blue">
12+
<img alt="spring-boot-plus version" src="https://img.shields.io/badge/spring--boot--plus-1.4.0-blue">
1313
</a>
1414
<a href="https://github.com/spring-projects/spring-boot">
15-
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.1.9.RELEASE-brightgreen">
15+
<img alt="spring boot version" src="https://img.shields.io/badge/spring%20boot-2.2.0.RELEASE-brightgreen">
1616
</a>
1717
<a href="https://www.apache.org/licenses/LICENSE-2.0">
1818
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">

src/main/java/io/geekidea/springbootplus/aop/LogAop.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package io.geekidea.springbootplus.aop;
1818

1919
import io.geekidea.springbootplus.core.aop.AbstractLogAop;
20-
import lombok.Data;
2120
import lombok.extern.slf4j.Slf4j;
2221
import org.aspectj.lang.ProceedingJoinPoint;
2322
import org.aspectj.lang.annotation.Around;
2423
import org.aspectj.lang.annotation.Aspect;
25-
26-
import java.util.Map;
24+
import org.springframework.stereotype.Component;
2725

2826
/**
2927
* <p>
@@ -34,9 +32,9 @@
3432
* @author geekidea
3533
* @date 2019-10-23
3634
*/
37-
@Data
3835
@Slf4j
3936
@Aspect
37+
@Component
4038
public class LogAop extends AbstractLogAop {
4139

4240
/**
@@ -50,14 +48,4 @@ public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
5048
return super.handle(joinPoint);
5149
}
5250

53-
@Override
54-
protected void handleRequestInfo(Map<String, Object> map) {
55-
super.handleRequestInfo(map);
56-
}
57-
58-
@Override
59-
protected void handleResponseInfo(Object result) {
60-
super.handleResponseInfo(result);
61-
}
62-
6351
}

src/main/java/io/geekidea/springbootplus/common/api/ApiCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public enum ApiCode {
5656

5757
VERIFICATION_CODE_EXCEPTION(5103, "验证码校验异常"),
5858

59+
AUTHENTICATION_EXCEPTION(5104, "登陆授权异常"),
60+
5961

6062
;
6163

src/main/java/io/geekidea/springbootplus/common/exception/GlobalExceptionHandler.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.geekidea.springbootplus.common.api.ApiResult;
2222
import io.geekidea.springbootplus.system.exception.VerificationCodeException;
2323
import lombok.extern.slf4j.Slf4j;
24+
import org.apache.shiro.authc.AuthenticationException;
2425
import org.springframework.http.HttpStatus;
2526
import org.springframework.http.converter.HttpMessageNotReadableException;
2627
import org.springframework.validation.BindingResult;
@@ -130,6 +131,22 @@ public ApiResult springBootPlusExceptionHandler(SpringBootPlusException exceptio
130131
.setMsg(exception.getMessage());
131132
}
132133

134+
135+
/**
136+
* 登陆授权异常处理
137+
*
138+
* @param exception
139+
* @return
140+
*/
141+
@ExceptionHandler(value = AuthenticationException.class)
142+
@ResponseStatus(HttpStatus.OK)
143+
public ApiResult authenticationExceptionHandler(AuthenticationException exception) {
144+
log.error("authenticationException:", exception);
145+
return new ApiResult()
146+
.setCode(ApiCode.AUTHENTICATION_EXCEPTION.getCode())
147+
.setMsg(exception.getMessage());
148+
}
149+
133150
/**
134151
* 默认的异常处理
135152
*

src/main/java/io/geekidea/springbootplus/core/aop/AbstractLogAop.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.aspectj.lang.Signature;
3232
import org.aspectj.lang.reflect.MethodSignature;
3333
import org.fusesource.jansi.Ansi;
34+
import org.springframework.beans.factory.annotation.Autowired;
3435
import org.springframework.web.bind.annotation.RequestBody;
3536
import org.springframework.web.context.request.RequestContextHolder;
3637
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -86,8 +87,12 @@ public abstract class AbstractLogAop {
8687
/**
8788
* AOP配置
8889
*/
89-
protected SpringBootPlusAopProperties.LogAopConfig logAopConfig = new SpringBootPlusAopProperties.LogAopConfig();
90+
protected SpringBootPlusAopProperties.LogAopConfig logAopConfig;
9091

92+
@Autowired
93+
public void setSpringBootPlusAopProperties(SpringBootPlusAopProperties springBootPlusAopProperties) {
94+
logAopConfig = springBootPlusAopProperties.getLog();
95+
}
9196

9297
/**
9398
* 环绕通知
@@ -424,5 +429,4 @@ protected JSONObject getJsonForParamMap(Map<String, String[]> paramsMap) {
424429
}
425430

426431

427-
428432
}

src/main/java/io/geekidea/springbootplus/core/config/SpringBootPlusConfig.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package io.geekidea.springbootplus.core.config;
1717

18-
import io.geekidea.springbootplus.aop.LogAop;
1918
import io.geekidea.springbootplus.core.properties.*;
2019
import io.geekidea.springbootplus.interceptor.PermissionInterceptor;
2120
import io.geekidea.springbootplus.resource.interceptor.DownloadInterceptor;
@@ -44,20 +43,6 @@
4443
})
4544
public class SpringBootPlusConfig {
4645

47-
/**
48-
* 配置日志AOP
49-
*
50-
* @param aopProperties
51-
* @return
52-
*/
53-
@Bean
54-
public LogAop logAop(SpringBootPlusAopProperties aopProperties) {
55-
LogAop logAop = new LogAop();
56-
logAop.setLogAopConfig(aopProperties.getLog());
57-
log.debug("init LogAop success");
58-
return logAop;
59-
}
60-
6146
/**
6247
* 权限拦截器
6348
*

src/main/java/io/geekidea/springbootplus/system/controller/SysPermissionController.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,34 @@ public ApiResult<SysPermissionTreeVo> getAllMenuTree() throws Exception {
120120
return ApiResult.ok(list);
121121
}
122122

123+
124+
/**
125+
* 根据用户id获取菜单列表
126+
*/
127+
@PostMapping("/getMenuListByUserId/{userId}")
128+
@ApiOperation(value = "根据用户id获取菜单列表", notes = "根据用户id获取菜单列表", response = SysPermissionTreeVo.class)
129+
public ApiResult<SysPermissionTreeVo> getMenuListByUserId(@PathVariable("userId") Long userId) throws Exception {
130+
List<SysPermission> list = sysPermissionService.getMenuListByUserId(userId);
131+
return ApiResult.ok(list);
132+
}
133+
134+
/**
135+
* 根据用户id获取菜单树形列表
136+
*/
137+
@PostMapping("/getMenuTreeByUserId/{userId}")
138+
@ApiOperation(value = "根据用户id获取菜单树形列表", notes = "根据用户id获取菜单树形列表", response = SysPermissionTreeVo.class)
139+
public ApiResult<SysPermissionTreeVo> getMenuTreeByUserId(@PathVariable("userId") Long userId) throws Exception {
140+
List<SysPermissionTreeVo> list = sysPermissionService.getMenuTreeByUserId(userId);
141+
return ApiResult.ok(list);
142+
}
143+
123144
/**
124145
* 根据用户id获取该用户所有权限编码
125146
*/
126-
@GetMapping("/getPermissionCodeByUserId/{userId}")
147+
@GetMapping("/getPermissionCodesByUserId/{userId}")
127148
@ApiOperation(value = "根据用户id获取该用户所有权限编码", notes = "根据用户id获取该用户所有权限编码", response = ApiResult.class)
128-
public ApiResult<String> getPermissionCodeByUserId(@PathVariable("userId") Long userId) throws Exception {
129-
List<String> list = sysPermissionService.getPermissionCodeByUserId(userId);
149+
public ApiResult<String> getPermissionCodesByUserId(@PathVariable("userId") Long userId) throws Exception {
150+
List<String> list = sysPermissionService.getPermissionCodesByUserId(userId);
130151
return ApiResult.ok(list);
131152
}
132153

src/main/java/io/geekidea/springbootplus/system/controller/SysUserController.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
import io.geekidea.springbootplus.common.api.ApiResult;
2020
import io.geekidea.springbootplus.common.controller.BaseController;
2121
import io.geekidea.springbootplus.common.vo.Paging;
22+
import io.geekidea.springbootplus.core.properties.SpringBootPlusProperties;
2223
import io.geekidea.springbootplus.system.entity.SysUser;
2324
import io.geekidea.springbootplus.system.param.SysUserQueryParam;
25+
import io.geekidea.springbootplus.system.param.UpdatePasswordParam;
2426
import io.geekidea.springbootplus.system.service.SysUserService;
2527
import io.geekidea.springbootplus.system.vo.SysUserQueryVo;
28+
import io.geekidea.springbootplus.util.UploadUtil;
2629
import io.swagger.annotations.Api;
2730
import io.swagger.annotations.ApiOperation;
2831
import lombok.extern.slf4j.Slf4j;
2932
import org.springframework.beans.factory.annotation.Autowired;
3033
import org.springframework.web.bind.annotation.*;
34+
import org.springframework.web.multipart.MultipartFile;
3135

3236
import javax.validation.Valid;
3337

@@ -48,14 +52,17 @@ public class SysUserController extends BaseController {
4852
@Autowired
4953
private SysUserService sysUserService;
5054

55+
@Autowired
56+
private SpringBootPlusProperties springBootPlusProperties;
57+
5158
/**
5259
* 添加系统用户
5360
*/
5461
@PostMapping("/add")
5562
@ApiOperation(value = "添加SysUser对象", notes = "添加系统用户", response = ApiResult.class)
5663
public ApiResult<Boolean> addSysUser(@Valid @RequestBody SysUser sysUser) throws Exception {
57-
boolean flag = sysUserService.saveSysUser(sysUser);
58-
return ApiResult.result(flag);
64+
boolean flag = sysUserService.saveSysUser(sysUser);
65+
return ApiResult.result(flag);
5966
}
6067

6168
/**
@@ -64,8 +71,8 @@ public ApiResult<Boolean> addSysUser(@Valid @RequestBody SysUser sysUser) throws
6471
@PostMapping("/update")
6572
@ApiOperation(value = "修改SysUser对象", notes = "修改系统用户", response = ApiResult.class)
6673
public ApiResult<Boolean> updateSysUser(@Valid @RequestBody SysUser sysUser) throws Exception {
67-
boolean flag = sysUserService.updateSysUser(sysUser);
68-
return ApiResult.result(flag);
74+
boolean flag = sysUserService.updateSysUser(sysUser);
75+
return ApiResult.result(flag);
6976
}
7077

7178
/**
@@ -74,8 +81,8 @@ public ApiResult<Boolean> updateSysUser(@Valid @RequestBody SysUser sysUser) thr
7481
@PostMapping("/delete/{id}")
7582
@ApiOperation(value = "删除SysUser对象", notes = "删除系统用户", response = ApiResult.class)
7683
public ApiResult<Boolean> deleteSysUser(@PathVariable("id") Long id) throws Exception {
77-
boolean flag = sysUserService.deleteSysUser(id);
78-
return ApiResult.result(flag);
84+
boolean flag = sysUserService.deleteSysUser(id);
85+
return ApiResult.result(flag);
7986
}
8087

8188
/**
@@ -98,5 +105,44 @@ public ApiResult<Paging<SysUserQueryVo>> getSysUserPageList(@Valid @RequestBody
98105
return ApiResult.ok(paging);
99106
}
100107

108+
/**
109+
* 修改密码
110+
*/
111+
@PostMapping("/updatePassword")
112+
@ApiOperation(value = "修改密码", notes = "修改密码", response = ApiResult.class)
113+
public ApiResult<Boolean> updatePassword(@Valid @RequestBody UpdatePasswordParam updatePasswordParam) throws Exception {
114+
boolean flag = sysUserService.updatePassword(updatePasswordParam);
115+
return ApiResult.result(flag);
116+
}
117+
118+
/**
119+
* 修改头像
120+
*/
121+
@PostMapping("/uploadHead/{id}")
122+
@ApiOperation(value = "修改头像",notes = "修改头像",response = ApiResult.class)
123+
public ApiResult<Boolean> uploadHead(@PathVariable("id") Long id,
124+
@RequestParam("head") MultipartFile multipartFile) throws Exception{
125+
log.info("multipartFile = " + multipartFile);
126+
log.info("ContentType = " + multipartFile.getContentType());
127+
log.info("OriginalFilename = " + multipartFile.getOriginalFilename());
128+
log.info("Name = " + multipartFile.getName());
129+
log.info("Size = " + multipartFile.getSize());
130+
131+
// 上传文件,返回保存的文件名称
132+
String uploadPath = springBootPlusProperties.getUploadPath();
133+
String saveFileName = UploadUtil.upload(uploadPath, multipartFile);
134+
// 上传成功之后,返回访问路径,请根据实际情况设置
135+
String headPath = springBootPlusProperties.getResourceAccessUrl() + saveFileName;
136+
log.info("headPath:{}",headPath);
137+
138+
boolean flag = sysUserService.updateSysUserHead(id,headPath);
139+
if (flag){
140+
return ApiResult.ok(headPath);
141+
}
142+
143+
// 删除图片文件
144+
UploadUtil.deleteQuietly(uploadPath,saveFileName);
145+
return ApiResult.fail();
146+
}
101147
}
102148

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.geekidea.springbootplus.system.convert;
18+
19+
import io.geekidea.springbootplus.system.entity.SysRole;
20+
import io.geekidea.springbootplus.system.param.sysrole.AddSysRoleParam;
21+
import org.mapstruct.Mapper;
22+
import org.mapstruct.factory.Mappers;
23+
24+
/**
25+
* 系统角色转换器
26+
*
27+
* @author geekidea
28+
* @date 2019-10-05
29+
**/
30+
@Mapper
31+
public interface SysRoleConvert {
32+
33+
SysRoleConvert INSTANCE = Mappers.getMapper(SysRoleConvert.class);
34+
35+
/**
36+
* AddSysRoleParam转SysRole
37+
*
38+
* @param addSysRoleParam
39+
* @return
40+
*/
41+
SysRole addSysRoleParamToSysRole(AddSysRoleParam addSysRoleParam);
42+
}

0 commit comments

Comments
 (0)