修改依赖
parent
125f75b7bf
commit
ebf8d3bb9b
@ -0,0 +1,33 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package core.exception;
|
||||||
|
|
||||||
|
public class BizException extends RuntimeException {
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public BizException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.message = message;
|
||||||
|
this.code = 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(Integer code, String message) {
|
||||||
|
this.message = message;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package core.exception;
|
||||||
|
|
||||||
|
import core.pojo.HttpStatus;
|
||||||
|
import core.pojo.Result;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class BizExceptionHandler {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(BizExceptionHandler.class);
|
||||||
|
|
||||||
|
public BizExceptionHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({BizException.class})
|
||||||
|
@ResponseBody
|
||||||
|
public Result<String> bussException(BizException e) {
|
||||||
|
log.warn("message:{},{}", e.getMessage(), e);
|
||||||
|
Result<String> result = new Result();
|
||||||
|
result.setMessage(e.getMessage());
|
||||||
|
result.setCode(e.getCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({Exception.class})
|
||||||
|
@ResponseBody
|
||||||
|
public Result<String> exception(Exception e) {
|
||||||
|
log.error("{}:{}", e.getMessage(), e);
|
||||||
|
Result<String> result = new Result();
|
||||||
|
result.setMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
|
||||||
|
result.setCode(HttpStatus.INTERNAL_SERVER_ERROR.getCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package core.pojo;
|
||||||
|
|
||||||
|
public enum HttpStatus {
|
||||||
|
SUCCESS(200, "SUCCESS"),
|
||||||
|
UNAUTHORIZED(401, "未认证"),
|
||||||
|
INTERNAL_SERVER_ERROR(500, "内部异常,请联系管理员");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String reasonPhrase;
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReasonPhrase() {
|
||||||
|
return this.reasonPhrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpStatus(int code, String reasonPhrase) {
|
||||||
|
this.code = code;
|
||||||
|
this.reasonPhrase = reasonPhrase;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,182 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package core.pojo;
|
||||||
|
|
||||||
|
public class Result<T> {
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public Result(T data) {
|
||||||
|
this.code = HttpStatus.SUCCESS.getCode();
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
Result<T> result = new Result();
|
||||||
|
result.setData(data);
|
||||||
|
result.setCode(HttpStatus.SUCCESS.getCode());
|
||||||
|
result.setMessage("SUCCESS");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success(T data, String msg) {
|
||||||
|
Result<T> result = new Result();
|
||||||
|
result.setData(data);
|
||||||
|
result.setCode(HttpStatus.SUCCESS.getCode());
|
||||||
|
result.setMessage(msg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result success() {
|
||||||
|
return builder().code(HttpStatus.SUCCESS.getCode()).message("SUCCESS").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error(Integer code, String message) {
|
||||||
|
Result<T> result = new Result();
|
||||||
|
result.setCode(code);
|
||||||
|
result.setMessage(message);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> ResultBuilder<T> builder() {
|
||||||
|
return new ResultBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
} else if (!(o instanceof Result)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Result<?> other = (Result)o;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
label47: {
|
||||||
|
Object this$code = this.getCode();
|
||||||
|
Object other$code = other.getCode();
|
||||||
|
if (this$code == null) {
|
||||||
|
if (other$code == null) {
|
||||||
|
break label47;
|
||||||
|
}
|
||||||
|
} else if (this$code.equals(other$code)) {
|
||||||
|
break label47;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$message = this.getMessage();
|
||||||
|
Object other$message = other.getMessage();
|
||||||
|
if (this$message == null) {
|
||||||
|
if (other$message != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$message.equals(other$message)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object this$data = this.getData();
|
||||||
|
Object other$data = other.getData();
|
||||||
|
if (this$data == null) {
|
||||||
|
if (other$data != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!this$data.equals(other$data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return other instanceof Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
int result = 1;
|
||||||
|
Object $code = this.getCode();
|
||||||
|
result = result * 59 + ($code == null ? 43 : $code.hashCode());
|
||||||
|
Object $message = this.getMessage();
|
||||||
|
result = result * 59 + ($message == null ? 43 : $message.hashCode());
|
||||||
|
Object $data = this.getData();
|
||||||
|
result = result * 59 + ($data == null ? 43 : $data.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Result(code=" + this.getCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(Integer code, String message, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ResultBuilder<T> {
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
ResultBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultBuilder<T> code(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultBuilder<T> message(String message) {
|
||||||
|
this.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultBuilder<T> data(T data) {
|
||||||
|
this.data = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result<T> build() {
|
||||||
|
return new Result(this.code, this.message, this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Result.ResultBuilder(code=" + this.code + ", message=" + this.message + ", data=" + this.data + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package core.util;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import core.exception.BizException;
|
||||||
|
import core.pojo.HttpStatus;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
public class Assert {
|
||||||
|
public Assert() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void isTrue(boolean expression, String message) {
|
||||||
|
if (!expression) {
|
||||||
|
throw new BizException(HttpStatus.INTERNAL_SERVER_ERROR.getCode(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notEmpty(@Nullable Collection<?> collection, String message) {
|
||||||
|
if (CollectionUtils.isEmpty(collection)) {
|
||||||
|
throw new BizException(HttpStatus.INTERNAL_SERVER_ERROR.getCode(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notEmpty(@Nullable Collection<?> collection, Integer code, String message) {
|
||||||
|
if (CollectionUtils.isEmpty(collection)) {
|
||||||
|
throw new BizException(code, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void isNull(@Nullable Object object, String message) {
|
||||||
|
if (object != null) {
|
||||||
|
throw new BizException(HttpStatus.INTERNAL_SERVER_ERROR.getCode(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notNull(@Nullable Object object, String message) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new BizException(HttpStatus.INTERNAL_SERVER_ERROR.getCode(), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void isTrue(boolean expression, Integer code, String message) {
|
||||||
|
if (!expression) {
|
||||||
|
throw new BizException(code, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void isNull(@Nullable Object object, Integer code, String message) {
|
||||||
|
if (object != null) {
|
||||||
|
throw new BizException(code, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notNull(@Nullable Object object, Integer code, String message) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new BizException(code, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue