Browse Source

fix bug

master
刘力 3 years ago
parent
commit
feb6fb304b
  1. 33
      common/src/main/java/com/canvas/web/exception/CustomException.java
  2. 20
      common/src/main/java/com/canvas/web/exception/GlobalExceptionHandler.java
  3. 14
      common/src/main/java/com/canvas/web/exception/user/CaptchaException.java
  4. 14
      common/src/main/java/com/canvas/web/exception/user/UserException.java
  5. 12
      common/src/main/java/com/canvas/web/exception/user/UserNotExistsException.java
  6. 34
      common/src/main/java/com/canvas/web/utils/Response.java
  7. 3
      system/src/main/java/com/canvas/web/modules/system/controller/UserController.java

33
common/src/main/java/com/canvas/web/exception/CustomException.java

@ -1,33 +0,0 @@
package com.canvas.web.exception;
//自定义异常类
public class CustomException extends RuntimeException {
private static final long serialVersionUID = 1L;
private Integer code;
private String message;
public CustomException(String message) { this.message=message;}
public CustomException(String message ,Integer code){
this.message=message;
this.code=code;
}
public CustomException(String message,Throwable e){
super(message,e);
this.message=message;
}
@Override
public String getMessage() {
return message;
}
public Integer getCode() {
return code;
}
}

20
common/src/main/java/com/canvas/web/exception/GlobalExceptionHandler.java

@ -0,0 +1,20 @@
package com.canvas.web.exception;
import com.canvas.web.utils.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import javax.servlet.http.HttpServletRequest;
@ControllerAdvice
public class GlobalExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
// public Response baseExceptionHandler(HttpServletRequest req,BaseException e){
// logger.error("发生业务异常!原因是:{}",e.getDefaultMessage());
// return Response.error(e.getCode(),e.getDefaultMessage());
// }
}

14
common/src/main/java/com/canvas/web/exception/user/CaptchaException.java

@ -1,14 +0,0 @@
package com.canvas.web.exception.user;
import com.canvas.web.exception.BaseException;
//验证码处理异常
public class CaptchaException extends UserException {
private static final long seriaVersionUID = 1L;
public CaptchaException() {
super("user.jcaptcha.error", null);
}
}

14
common/src/main/java/com/canvas/web/exception/user/UserException.java

@ -1,14 +0,0 @@
package com.canvas.web.exception.user;
import com.canvas.web.exception.BaseException;
//用户处理异常
public class UserException extends BaseException {
private static final long serialVersionUID = 1L;
public UserException(String code, Object[] args) {
super("user", code, args, null);
}
}

12
common/src/main/java/com/canvas/web/exception/user/UserNotExistsException.java

@ -1,12 +0,0 @@
package com.canvas.web.exception.user;
//用户不存在异常
public class UserNotExistsException extends UserException {
private static final long seriaVersionUID = 1L;
public UserNotExistsException() {
super("user.not.exits",null);
}
}

34
common/src/main/java/com/canvas/web/utils/Response.java

@ -18,15 +18,21 @@ public class Response<T> {
private long timestamp;
public Response(){
this.timestamp=System.currentTimeMillis();
}
private Response(T data){
public Response(T data) {
this.code = ResponseEnum.SUCCESS.getCode();
this.msg = ResponseEnum.SUCCESS.getMessage();
this.timestamp = System.currentTimeMillis();
this.data = data;
}
private Response(ResponseEnum responseEnum){
public Response(ResponseEnum responseEnum) {
if (null == responseEnum) {
return;
}
@ -38,9 +44,16 @@ public class Response<T> {
public static <T> Response<T> success() {
return success(null);
}
//成功时调用
public static <T> Response<T> success(T data) {
return new Response<T>(data);
Response<T> response=new Response<>();
response.setCode(ResponseEnum.SUCCESS.getCode());
response.setMsg(ResponseEnum.SUCCESS.getMessage());
response.setData(data);
return response;
}
public static <T> Response error() {
@ -51,6 +64,17 @@ public class Response<T> {
return new Response<T>(responseEnum);
}
public static <T> Response<T> error(Integer code,String message){
Response<T> response=new Response<>();
response.setCode(code);
response.setMsg(message);
return response;
}
public Integer getCode() {
return code;
}
@ -69,7 +93,9 @@ public class Response<T> {
return this;
}
public T getData() {return data;}
public T getData() {
return data;
}
public Response<T> setData(T data) {
this.data = data;

3
system/src/main/java/com/canvas/web/modules/system/controller/UserController.java

@ -49,10 +49,13 @@ public class UserController {
//如果当前用户角色级别低于创建用户的角色级别抛出权限不足
private void checkLevel(User resources){
Integer currentLevel= Collections.min(roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()));
Integer optLevel = roleService.findByRoles(resources.getRoles());
if (currentLevel > optLevel){
throw new BaseException("权限不足");
}
}
}
Loading…
Cancel
Save