lihong 2 年之前
父节点
当前提交
85fcbc6080

+ 41 - 0
src/main/java/cn/hnthyy/thmz/Utils/AssertUtil.java

@@ -0,0 +1,41 @@
+package cn.hnthyy.thmz.Utils;
+
+import cn.hnthyy.thmz.common.exception.BizException;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @Description:断言工具类
+ * @Author:lihong
+ */
+public class AssertUtil {
+
+    /**
+     * @description: 不能为空  支持集合 ,字符串 ,Map
+     * @author: lihong
+     * @param: object
+     * @param: message
+     **/
+    public static void isNotBlank(Object object,String message){
+        if (object == null) {
+            throw new BizException(message,-1);
+        }
+       else if (object instanceof Collection) {
+            if(CollUtil.isEmpty((Collection)object)){
+                throw new BizException(message,-1);
+            }
+        }
+        else if (object instanceof Map) {
+            if(CollUtil.isEmpty((Map)object)){
+                throw new BizException(message,-1);
+            }
+        }else {
+            if (StrUtil.isBlank(object.toString())) {
+                throw new BizException(message,-1);
+            }
+        }
+    }
+}

+ 57 - 0
src/main/java/cn/hnthyy/thmz/common/exception/BizException.java

@@ -0,0 +1,57 @@
+
+
+package cn.hnthyy.thmz.common.exception;
+
+import java.io.Serializable;
+
+/**
+ * 自定义异常
+ *
+ * @author lihong
+ */
+public class BizException extends RuntimeException implements Serializable {
+	private static final long serialVersionUID = 1L;
+	
+    private String msg;
+    private int code = -1;
+    
+    public BizException(String msg) {
+		super(msg);
+		this.msg = msg;
+	}
+	
+	public BizException(String msg, Throwable e) {
+		super(msg, e);
+		this.msg = msg;
+	}
+	
+	public BizException(String msg, int code) {
+		super(msg);
+		this.msg = msg;
+		this.code = code;
+	}
+	
+	public BizException(String msg, int code, Throwable e) {
+		super(msg, e);
+		this.msg = msg;
+		this.code = code;
+	}
+
+	public String getMsg() {
+		return msg;
+	}
+
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+
+	public int getCode() {
+		return code;
+	}
+
+	public void setCode(int code) {
+		this.code = code;
+	}
+	
+	
+}

+ 2 - 6
src/main/java/cn/hnthyy/thmz/controller/mz/MzyReqrecController.java

@@ -908,12 +908,8 @@ public class MzyReqrecController {
     @UserLoginToken
     @PostMapping("/validFurtherVisit")
     public R validFurtherVisit(@RequestBody MzyReqrec reqrec, HttpServletRequest httpServletRequest){
-        if(StrUtil.isBlank(reqrec.getPatientId())){
-          return   R.error("门诊号不能为空");
-        }
-        if(StrUtil.isBlank(reqrec.getVisitDept())){
-            return  R.error("就诊科室不能为空");
-        }
+        AssertUtil.isNotBlank(reqrec.getPatientId(),"门诊号不能为空");
+        AssertUtil.isNotBlank(reqrec.getVisitDept(),"就诊科室不能为空");
         return mzyReqrecService.validFurtherVisit(reqrec);
     }
 

+ 9 - 0
src/main/java/cn/hnthyy/thmz/interceptor/GlobalExceptionHandler.java

@@ -1,12 +1,15 @@
 package cn.hnthyy.thmz.interceptor;
 
 
+import cn.hnthyy.thmz.Utils.R;
+import cn.hnthyy.thmz.common.exception.BizException;
 import cn.hnthyy.thmz.entity.AuthException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
@@ -42,4 +45,10 @@ public class GlobalExceptionHandler {
         }
         return null;
     }
+
+    @ExceptionHandler(BizException.class)
+    @ResponseBody
+    public R handleRRException(BizException e){
+       return R.error(e.getCode(),e.getMessage());
+    }
 }