Просмотр исходного кода

增加分页查询默认参数

lixing 4 лет назад
Родитель
Сommit
d3a2c8b82b

+ 59 - 0
fm-common/src/main/java/com/persagy/fm/common/config/FeignExceptionHandler.java

@@ -0,0 +1,59 @@
+package com.persagy.fm.common.config;
+
+import com.persagy.common.enums.ResponseCode;
+import com.persagy.fm.common.exception.RpcException;
+import com.persagy.fm.common.response.FmResponseContent;
+import com.persagy.fm.common.response.FmResponseItem;
+import com.persagy.fm.common.response.FmResponseMsg;
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+
+/**
+ * feign调用接口,如果接口返回了报错信息,将报错信息抛出
+ *
+ * @author lixing
+ * @version V1.0 2021/3/24 4:55 下午
+ **/
+@Aspect
+@Component
+public class FeignExceptionHandler {
+
+    @Pointcut("@within(org.springframework.cloud.openfeign.FeignClient)")
+    private void pointCutMethod() {
+    }
+
+    @AfterReturning(pointcut = "pointCutMethod()", returning = "res")
+    public void process(Object res) {
+        String respCode = null;
+        String resultMsg = null;
+        if (res instanceof FmResponseMsg) {
+            FmResponseMsg response = (FmResponseMsg) res;
+            respCode = response.getRespCode();
+            resultMsg = response.getRespMsg();
+        }
+
+        if (res instanceof FmResponseContent) {
+            FmResponseContent response = (FmResponseContent) res;
+            respCode = response.getRespCode();
+            resultMsg = response.getRespMsg();
+        }
+
+        if (res instanceof FmResponseItem) {
+            FmResponseItem response = (FmResponseItem) res;
+            respCode = response.getRespCode();
+            resultMsg = response.getRespMsg();
+        }
+
+        if (!ResponseCode.A00000.getCode().equals(respCode)) {
+            throw new RpcException(resultMsg);
+        }
+    }
+
+    @Before("pointCutMethod()")
+    public void test() {
+        System.out.println("test test test");
+    }
+}

+ 18 - 0
fm-common/src/main/java/com/persagy/fm/common/constant/PageQueryConstants.java

@@ -0,0 +1,18 @@
+package com.persagy.fm.common.constant;
+
+/**
+ * 分页查询常量
+ *
+ * @author lixing
+ * @version V1.0 2021/3/24 3:05 下午
+ **/
+public class PageQueryConstants {
+    /**
+     * 默认查询第一页
+     */
+    public static final int DEFAULT_PAGE = 1;
+    /**
+     * 默认查询10条
+     */
+    public static final int DEFAULT_SIZE = 10;
+}

+ 5 - 0
fm-common/src/main/java/com/persagy/fm/common/response/FmResponseContent.java

@@ -35,6 +35,11 @@ public class FmResponseContent<T> {
     @JSONField(name = "Count")
     private Integer count;
 
+    /**
+     * 错误信息
+     */
+    private String respMsg;
+
     public FmResponseContent(String respCode, T content, Integer count) {
         this.respCode = respCode;
         this.content = content;

+ 5 - 0
fm-common/src/main/java/com/persagy/fm/common/response/FmResponseItem.java

@@ -28,6 +28,11 @@ public class FmResponseItem<T> {
     @JSONField(name = "Item")
     private T item;
 
+    /**
+     * 错误信息
+     */
+    private String respMsg;
+
     public FmResponseItem(String respCode, T item) {
         this.respCode = respCode;
         this.item = item;

+ 3 - 3
fm-common/src/main/java/com/persagy/fm/common/response/FmResponseMsg.java

@@ -23,10 +23,10 @@ public class FmResponseMsg {
     /**
      * 错误信息
      */
-    private String resultMsg;
+    private String respMsg;
 
-    public FmResponseMsg(String respCode, String resultMsg) {
+    public FmResponseMsg(String respCode, String respMsg) {
         this.respCode = respCode;
-        this.resultMsg = resultMsg;
+        this.respMsg = respMsg;
     }
 }

+ 1 - 1
fm-server/src/main/java/com/persagy/ServerApplication.java

@@ -25,7 +25,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableDiscoveryClient
 @Configuration
 @EnableScheduling
-@SpringBootApplication(exclude = AopAutoConfiguration.class)
+@SpringBootApplication
 @MapperScan(value = "com.persagy.fm.*.dao")
 @EnableSpringUtil
 public class ServerApplication {