diff --git a/bonus-common-biz/pom.xml b/bonus-common-biz/pom.xml new file mode 100644 index 00000000..2bfe51cb --- /dev/null +++ b/bonus-common-biz/pom.xml @@ -0,0 +1,173 @@ + + + + com.bonus + bonus + 24.8.0 + + 4.0.0 + + bonus-common-biz + + + bonus-material-common核心模块 + + + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.freemarker + freemarker + 2.3.30 + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + + org.springframework + spring-context-support + + + + + org.springframework + spring-web + + + + + com.alibaba + transmittable-thread-local + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + + + org.springframework.boot + spring-boot-starter-validation + + + + + com.fasterxml.jackson.core + jackson-databind + + + + + com.alibaba.fastjson2 + fastjson2 + + + + + io.jsonwebtoken + jjwt + + + + + javax.xml.bind + jaxb-api + + + + + org.apache.commons + commons-lang3 + + + + + commons-io + commons-io + + + + cn.hutool + hutool-all + 5.8.22 + + + + org.apache.poi + poi-ooxml + + + + + javax.servlet + javax.servlet-api + + + + + io.swagger + swagger-annotations + + + org.projectlombok + lombok + + + com.alibaba.nacos + nacos-client + + + junit + junit + 4.13.2 + test + + + + + org.jfree + jfreechart + 1.5.3 + + + + com.itextpdf + itextpdf + 5.5.9 + + + com.itextpdf + itext-asian + 5.2.0 + + + com.google.code.gson + gson + 2.8.9 + + + org.mockito + mockito-core + 1.10.19 + test + + + org.apache.commons + commons-lang3 + + + + diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/Constants.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/Constants.java new file mode 100644 index 00000000..8034da7e --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/Constants.java @@ -0,0 +1,22 @@ +package com.bonus.common.biz.constant; + +/** + * 通用常量信息 + * + * @author bonus + */ +public class Constants +{ + private Constants(){} + + /** + * 成功标记 + */ + public static final Integer SUCCESS = 200; + + /** + * 失败标记 + */ + public static final Integer FAIL = 500; + +} diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/R.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/R.java new file mode 100644 index 00000000..b3b1a739 --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/R.java @@ -0,0 +1,116 @@ +package com.bonus.common.biz.domain; + +import com.bonus.common.biz.constant.Constants; + +import java.io.Serializable; + +/** + * 响应信息主体 + * + * @author bonus + */ +public class R implements Serializable +{ + private static final long serialVersionUID = 1L; + + /** 成功 */ + public static final int SUCCESS = Constants.SUCCESS; + + /** 失败 */ + public static final int FAIL = Constants.FAIL; + + private int code; + + private String msg; + + private T data; + + public static R ok() + { + return restResult(null, SUCCESS, null); + } + + public static R ok(T data) + { + return restResult(data, SUCCESS, null); + } + + public static R ok(T data, String msg) + { + return restResult(data, SUCCESS, msg); + } + + public static R fail() + { + return restResult(null, FAIL, null); + } + + public static R fail(String msg) + { + return restResult(null, FAIL, msg); + } + + public static R fail(T data) + { + return restResult(data, FAIL, null); + } + + public static R fail(T data, String msg) + { + return restResult(data, FAIL, msg); + } + + public static R fail(int code, String msg) + { + return restResult(null, code, msg); + } + + private static R restResult(T data, int code, String msg) + { + R apiResult = new R<>(); + apiResult.setCode(code); + apiResult.setData(data); + apiResult.setMsg(msg); + return apiResult; + } + + public int getCode() + { + return code; + } + + public void setCode(int code) + { + this.code = code; + } + + public String getMsg() + { + return msg; + } + + public void setMsg(String msg) + { + this.msg = msg; + } + + public T getData() + { + return data; + } + + public void setData(T data) + { + this.data = data; + } + + public static Boolean isError(R ret) + { + return !isSuccess(ret); + } + + public static Boolean isSuccess(R ret) + { + return R.SUCCESS == ret.getCode(); + } +} diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/UserStatus.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/UserStatus.java new file mode 100644 index 00000000..db6b533b --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/enums/UserStatus.java @@ -0,0 +1,35 @@ +package com.bonus.common.biz.enums; + +/** + * 用户状态 + * + * @author bonus + */ +public enum UserStatus +{ + //正常 + OK("0", "正常"), + //停用 + DISABLE("1", "停用"), + //删除 + DELETED("2", "删除"); + + private final String code; + private final String info; + + UserStatus(String code, String info) + { + this.code = code; + this.info = info; + } + + public String getCode() + { + return code; + } + + public String getInfo() + { + return info; + } +} diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/ExceptionUtil.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/ExceptionUtil.java new file mode 100644 index 00000000..9e7b6e94 --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/ExceptionUtil.java @@ -0,0 +1,54 @@ +package com.bonus.common.biz.utils; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * 错误信息处理类。 + * 提供获取异常详细信息和根本错误信息的工具方法。 + * 作者: bonus + */ +public class ExceptionUtil { + + /** + * 获取异常的详细错误信息。 + * + * @param e 需要处理的异常 + * @return 异常的详细错误信息字符串 + */ + public static String getExceptionMessage(Throwable e) { + // 使用StringWriter来保存异常的堆栈信息 + StringWriter sw = new StringWriter(); + // 将异常的堆栈信息打印到StringWriter中 + e.printStackTrace(new PrintWriter(sw, true)); + // 返回异常的详细信息 + return sw.toString(); + } + + /** + * 获取异常的根本错误信息。 + * + * @param e 需要处理的异常 + * @return 根本错误信息字符串,如果没有错误信息返回空字符串 + */ + public static String getRootErrorMessage(Exception e) { + // 获取异常的根本原因 + Throwable root = ExceptionUtils.getRootCause(e); + // 如果没有根本原因,则使用原始异常 + root = (root == null ? e : root); + // 如果根本原因为空,返回空字符串 + if (root == null) { + return ""; + } + // 获取根本原因的错误信息 + String msg = root.getMessage(); + // 如果错误信息为空,返回"null" + if (msg == null) { + return "null"; + } + // 使用StringUtils.defaultString确保返回的错误信息不是null + return StringUtils.defaultString(msg); + } +} diff --git a/pom.xml b/pom.xml index 5d2b46fa..53a72aaf 100644 --- a/pom.xml +++ b/pom.xml @@ -241,6 +241,7 @@ bonus-api bonus-common bonus-modules + bonus-common-biz pom