first commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
/.idea/
|
||||||
|
/aos-common-spring-boot-starter.iml
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.aos</groupId>
|
||||||
|
<artifactId>aos-common-domain</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.aos.common.domain.exception;
|
||||||
|
|
||||||
|
import com.aos.common.domain.result.ResultCodeInterface;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: BizException
|
||||||
|
* @Function: 统一异常
|
||||||
|
* @Date: 2020/4/12 20:13
|
||||||
|
* @author wyl
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BizException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
protected Integer errorCode;
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
protected String errorMsg;
|
||||||
|
|
||||||
|
public BizException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(ResultCodeInterface resultCode) {
|
||||||
|
super(resultCode.getCode()
|
||||||
|
.toString());
|
||||||
|
this.errorCode = resultCode.getCode();
|
||||||
|
this.errorMsg = resultCode.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(ResultCodeInterface resultCode, Throwable cause) {
|
||||||
|
super(resultCode.getCode()
|
||||||
|
.toString(), cause);
|
||||||
|
this.errorCode = resultCode.getCode();
|
||||||
|
this.errorMsg = resultCode.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(String errorMsg) {
|
||||||
|
super(errorMsg);
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(Integer errorCode, String errorMsg) {
|
||||||
|
super(errorCode.toString());
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BizException(Integer errorCode, String errorMsg, Throwable cause) {
|
||||||
|
super(errorCode.toString(), cause);
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMsg = errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Throwable fillInStackTrace() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.aos.common.domain.result;
|
||||||
|
|
||||||
|
public enum ResultCode implements ResultCodeInterface {
|
||||||
|
SUCCEED(200, "成功"), FAILED(-1, "系统异常");
|
||||||
|
private Integer code;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
ResultCode(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* @Author wangyl
|
||||||
|
* @E-mail wangyl0629@foxmail.com
|
||||||
|
**/
|
||||||
|
package com.aos.common.domain.result;
|
||||||
|
|
||||||
|
public interface ResultCodeInterface {
|
||||||
|
/**
|
||||||
|
* @Description 获取错误码
|
||||||
|
* @param
|
||||||
|
* @return java.lang.Integer
|
||||||
|
* @Date 2020/11/8 15:37
|
||||||
|
* @Author wangyl
|
||||||
|
* @Version V1.0
|
||||||
|
*/
|
||||||
|
Integer getCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 获取错误信息
|
||||||
|
* @param
|
||||||
|
* @return java.lang.String
|
||||||
|
* @Date 2020/11/8 15:38
|
||||||
|
* @Author wangyl
|
||||||
|
* @Version V1.0
|
||||||
|
*/
|
||||||
|
String getMsg();
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.aos.common.domain.result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: WebResponse
|
||||||
|
* @Function: 返回结果工具
|
||||||
|
* @Date: 2020/4/12 19:58
|
||||||
|
* @author wangyl
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
public enum WebResponse {
|
||||||
|
WebResponse;
|
||||||
|
|
||||||
|
public <T> WebResult<T,ResultCode> ok() {
|
||||||
|
return new WebResult(ResultCode.SUCCEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult ok(ResultCode resultCode, T data) {
|
||||||
|
return new WebResult(resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult ok(T data) {
|
||||||
|
return new WebResult(ResultCode.SUCCEED, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult error() {
|
||||||
|
return new WebResult(ResultCode.FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult error(T data) {
|
||||||
|
return new WebResult(ResultCode.FAILED, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult error(ResultCode resultCode, T data) {
|
||||||
|
return new WebResult(resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult error(ResultCode resultCode) {
|
||||||
|
return new WebResult(resultCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> WebResult error(Integer code, String msg) {
|
||||||
|
return new WebResult(code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> WebResult WebResponse(Integer code, String msg, T data) {
|
||||||
|
return new WebResult(code, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> WebResult WebResponse(Integer code, String msg) {
|
||||||
|
return new WebResult(code, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.aos.common.domain.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: WebResult
|
||||||
|
* @Function: 返回对象
|
||||||
|
* @Date: 2020/3/27 10:49
|
||||||
|
* @author wangyl
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WebResult<T,R extends ResultCodeInterface> {
|
||||||
|
/**
|
||||||
|
* 返回码
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
/**
|
||||||
|
* 描述信息
|
||||||
|
*/
|
||||||
|
private String msg;
|
||||||
|
/**
|
||||||
|
* 返回数据
|
||||||
|
*/
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public WebResult() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebResult(Integer code, String msg, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebResult(R resultCode) {
|
||||||
|
this(resultCode, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebResult(R resultCode, T data) {
|
||||||
|
this(resultCode.getCode(), resultCode.getMsg(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebResult(Integer code, String msg) {
|
||||||
|
this(code, msg, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user