Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lemos1235 committed Jun 15, 2021
1 parent 4bb729b commit af7c67c
Show file tree
Hide file tree
Showing 40 changed files with 1,524 additions and 897 deletions.
14 changes: 4 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>club.lemos</groupId>
<artifactId>jtool</artifactId>
<version>1.0.0-RC1</version>
<version>1.1.0</version>
<packaging>jar</packaging>
<name>jtool</name>

Expand Down Expand Up @@ -36,10 +36,9 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<encoding>UTF-8</encoding>
<spring.boot.version>2.3.2.RELEASE</spring.boot.version>
<lombok.version>1.18.12</lombok.version>
<commons-text.version>1.9</commons-text.version>
<mybatis-plus.version>3.3.2</mybatis-plus.version>
<spring.boot.version>2.5.1</spring.boot.version>
<lombok.version>1.18.20</lombok.version>
<mybatis-plus.version>3.4.3</mybatis-plus.version>
<swagger.version>3.0.0</swagger.version>
<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
Expand Down Expand Up @@ -69,11 +68,6 @@
</build>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/club/lemos/common/api/ApiCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package club.lemos.common.api;

import lombok.Data;

/**
* Api错误码
* <p>
* 统一格式:A-BB-CCC
* A:错误级别,如1代表系统级错误,2代表服务级错误;
* B:项目或模块名称
* C:具体错误编号
*/
@Data
public class ApiCode implements IResultCode {

private static final long serialVersionUID = 1L;

private int code;

private String msg;

private String errorDescription;

public ApiCode() {
}

public ApiCode(int code, String msg) {
this.code = code;
this.msg = msg;
}

public ApiCode(int code, String msg, String errorDescription) {
this.code = code;
this.msg = msg;
this.errorDescription = errorDescription;
}

public static final ApiCode SERVER_ERROR = new ApiCode(100001, "服务内部错误");
public static final ApiCode SERVER_BUSY = new ApiCode(100002, "服务器繁忙,请稍后再试");
public static final ApiCode OPT_DISABLED = new ApiCode(100004, "操作被禁用");

public static final ApiCode PARAM_VALID_ERROR = new ApiCode(100011, "参数校验错误");
public static final ApiCode PARAM_MISS = new ApiCode(100012, "缺少参数");
public static final ApiCode PARAM_TYPE_ERROR = new ApiCode(100013, "参数类型不匹配");
public static final ApiCode MYBATIS_ERROR = new ApiCode(100021, "Mybatis错误");
public static final ApiCode LOGGING_REPORT_ERROR = new ApiCode(100031, "日志上报错误");
}
44 changes: 31 additions & 13 deletions src/main/java/club/lemos/common/api/ApiException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package club.lemos.common.api;

import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ApiException extends RuntimeException {

/**
Expand All @@ -11,27 +15,41 @@ public class ApiException extends RuntimeException {
/**
* 错误码
*/
private IErrorCode errorCode;
private int code = 400;

public ApiException(IErrorCode errorCode) {
super(errorCode.getMsg());
this.errorCode = errorCode;
}
private String msg = "";

private String errorDescription;

public ApiException(String message) {
super(message);
/**
* @deprecated 请使用 ApiException(IResultCode resultCode)
*
* @param msg 错误信息
*/
@Deprecated
public ApiException(String msg) {
super(msg);
this.msg = msg;
}

public ApiException(Throwable cause) {
super(cause);
public ApiException(int code, String msg) {
super(msg);
this.code = code;
this.msg = msg;
}

public ApiException(String message, Throwable cause) {
super(message, cause);
public ApiException(IResultCode resultCode) {
super(resultCode.getMsg());
this.code = resultCode.getCode();
this.msg = resultCode.getMsg();
this.errorDescription = resultCode.getErrorDescription();
}

public IErrorCode getErrorCode() {
return errorCode;
public ApiException(R<?> result) {
super(result.getMsg());
this.code = result.getCode();
this.msg = result.getMsg();
this.errorDescription = result.getErrorDescription();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import javax.servlet.http.HttpServletResponse;

/**
* 业务代码枚举
* 一般型错误码
*/
@Getter
@AllArgsConstructor
public enum ResultCode implements IResultCode {
public enum HttpCode implements IResultCode {

/**
* 操作成功
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/club/lemos/common/api/IErrorCode.java

This file was deleted.

30 changes: 18 additions & 12 deletions src/main/java/club/lemos/common/api/IResultCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
*/
public interface IResultCode extends Serializable {

/**
* 消息
*
* @return String
*/
String getMsg();
/**
* 状态码
*
* @return int
*/
int getCode();

/**
* 状态码
*
* @return int
*/
int getCode();
/**
* 消息
*
* @return String
*/
String getMsg();

/**
* 消息描述
*/
default String getErrorDescription() {
return null;
}
}
43 changes: 38 additions & 5 deletions src/main/java/club/lemos/common/api/R.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package club.lemos.common.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -26,12 +28,20 @@ public class R<T> implements Serializable {
private static final String DEFAULT_NULL_MESSAGE = "暂无承载数据!";

private int code;

private boolean success;

@JsonInclude(JsonInclude.Include.NON_NULL)
private T data;

private String msg;

@JsonProperty("error_description")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String errorDescription;

private R(IResultCode resultCode) {
this(resultCode, null, resultCode.getMsg());
this(resultCode.getCode(), null, resultCode.getMsg(), resultCode.getErrorDescription());
}

private R(IResultCode resultCode, String msg) {
Expand All @@ -50,7 +60,12 @@ private R(int code, T data, String msg) {
this.code = code;
this.data = data;
this.msg = msg;
this.success = ResultCode.SUCCESS.code == code;
this.success = HttpCode.SUCCESS.code == code;
}

private R(int code, T data, String msg, String errorDescription) {
this(code, data, msg);
this.errorDescription = errorDescription;
}

/**
Expand All @@ -61,7 +76,7 @@ private R(int code, T data, String msg) {
*/
public static boolean isSuccess(@Nullable R<?> result) {
return Optional.ofNullable(result)
.map(x -> ObjectUtils.nullSafeEquals(ResultCode.SUCCESS.code, x.code))
.map(x -> ObjectUtils.nullSafeEquals(HttpCode.SUCCESS.code, x.code))
.orElse(Boolean.FALSE);
}

Expand Down Expand Up @@ -119,7 +134,7 @@ public static <T> R<T> data(int code, T data, String msg) {
* @return R
*/
public static <T> R<T> success(String msg) {
return new R<>(ResultCode.SUCCESS, msg);
return new R<>(HttpCode.SUCCESS, msg);
}

/**
Expand Down Expand Up @@ -153,7 +168,7 @@ public static <T> R<T> success(IResultCode resultCode, String msg) {
* @return R
*/
public static <T> R<T> fail(String msg) {
return new R<>(ResultCode.FAILURE, msg);
return new R<>(HttpCode.FAILURE, msg);
}


Expand All @@ -169,6 +184,11 @@ public static <T> R<T> fail(int code, String msg) {
return new R<>(code, null, msg);
}


public static <T> R<T> fail(int code, String msg, String error_description) {
return new R<>(code, null, msg, error_description);
}

/**
* 返回R
*
Expand All @@ -192,6 +212,19 @@ public static <T> R<T> fail(IResultCode resultCode, String msg) {
return new R<>(resultCode, msg);
}


/**
* 返回R
*
* @param resultCode 业务代码
* @param data 数据
* @param <T> T 泛型标记
* @return R
*/
public static <T> R<T> fail(IResultCode resultCode, T data) {
return new R<>(resultCode, data);
}

/**
* 返回R
*
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/club/lemos/common/api/RException.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/club/lemos/common/constant/CommonConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public interface CommonConstant {
* 开发环境相关
*/
String DEV_CODE = "dev";
String HOME_CODE = "home";
String PROD_CODE = "prod";
String TEST_CODE = "test";

Expand All @@ -45,13 +44,15 @@ public interface CommonConstant {
String DB_CREATE_TIME_FIELD_NAME ="createTime";
String DB_UPDATE_TIME_FIELD_NAME ="updateTime";
String DB_IS_DELETED_FIELD_NAME ="isDeleted";
String DB_ENABLED_FIELD_NAME ="enabled";
String DATETIME_MIN ="1000-01-01T00:00:00";
String DATETIME_MAX ="9999-12-31T23:59:59";

String DB_CREATE_USER_COLUMN_NAME ="create_user";
String DB_CREATE_TIME_COLUMN_NAME ="create_time";
String DB_UPDATE_USER_COLUMN_NAME ="update_user";
String DB_UPDATE_TIME_COLUMN_NAME ="update_time";
String DB_IS_DELETED_COLUMN_NAME ="is_deleted";
String DB_ENABLED_COLUMN_NAME ="enabled";

String DB_TENANT_ID = "tenant_id";
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/club/lemos/common/enums/AdminState.java

This file was deleted.

Loading

0 comments on commit af7c67c

Please sign in to comment.