|
@@ -0,0 +1,93 @@
|
|
|
+package com.gis.exception;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class BaseRuntimeException extends RuntimeException{
|
|
|
+
|
|
|
+ private static final long serialVersionUID = -1518945670203783450L;
|
|
|
+ private Integer code;
|
|
|
+ private String msg;
|
|
|
+
|
|
|
+ public BaseRuntimeException(String msg){
|
|
|
+ super(msg);
|
|
|
+ this.code = -1;
|
|
|
+ this.msg = msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param code 允许为null
|
|
|
+ * @param msg
|
|
|
+ */
|
|
|
+ public BaseRuntimeException(Integer code, String msg){
|
|
|
+ super(msg);
|
|
|
+ this.code = code == null? -1 : code;
|
|
|
+ this.msg = msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Integer getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCode(Integer code) {
|
|
|
+ this.code = code;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMsg() {
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMsg(String msg) {
|
|
|
+ this.msg = msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void isNull(Object obj, Integer code, String msg){
|
|
|
+ if (obj == null){
|
|
|
+ getExc(code, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void isBlank(Object obj, Integer code, String msg){
|
|
|
+ if (obj == null){
|
|
|
+ getExc(code, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (obj instanceof String && StrUtil.isBlank(obj.toString())){
|
|
|
+ getExc(code, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param obj 存在抛异常
|
|
|
+ * @param code 允许为null
|
|
|
+ * @param msg
|
|
|
+ */
|
|
|
+ public static void isTrue(boolean obj, Integer code, String msg){
|
|
|
+ if (obj){
|
|
|
+ getExc(code, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getExc(Integer code, String msg){
|
|
|
+ throw new BaseRuntimeException(code, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void isEmpty(List obj, Integer code, String msg){
|
|
|
+ if (CollectionUtils.isEmpty(obj)){
|
|
|
+ getExc(code, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|