Kaynağa Gözat

2022-10-27 13:41 RMS报告管理系统提交 补充日志打印信息配置

沈永艺 2 yıl önce
ebeveyn
işleme
cc411c53e8

+ 29 - 29
RMS/src/main/java/cn/cslg/report/common/config/SaTokenConfigure.java

@@ -15,34 +15,34 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 @Configuration
 public class SaTokenConfigure implements WebMvcConfigurer {
 
-    @Bean
-    public SaServletFilter getSaServletFilter() {
-        return new SaServletFilter()
-                .addInclude(Constants.REPORT_API + "/**")
-                .addExclude("/favicon.ico")
-                .setAuth(obj -> {
-                    SaRouter.match(Constants.REPORT_API + "/**")
-                            .notMatch(
-                                    Constants.REPORT_API + "/ws/**",
-                                    Constants.REPORT_API + "/test/**",
-                                    Constants.REPORT_API + "/oauth2/**",
-                                    Constants.REPORT_API + "/admin/**",
-                                    Constants.REPORT_API + "/common/download",
-                                    Constants.REPORT_API + "/common/export",
-                                    Constants.REPORT_API + "/common/download",
-                                    Constants.REPORT_API + "/admin/login",
-                                    Constants.REPORT_API + "/system/**"
-                            ).check(StpUtil::checkLogin);
-                    //SaRouter.match(Constants.PERMISSION_API + "/admin/**", Constants.PERMISSION_API + "/admin/login", StpAdminUtil::checkLogin);
-                })
-                .setError(e -> Response.error(ResponseEnum.UNAUTHORIZED));
-    }
-
-    // 注册Sa-Token的注解拦截器,打开注解式鉴权功能
-    @Override
-    public void addInterceptors(InterceptorRegistry registry) {
-        // 注册注解拦截器,并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
-        registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
-    }
+//    @Bean
+//    public SaServletFilter getSaServletFilter() {
+//        return new SaServletFilter()
+//                .addInclude(Constants.REPORT_API + "/**")
+//                .addExclude("/favicon.ico")
+//                .setAuth(obj -> {
+//                    SaRouter.match(Constants.REPORT_API + "/**")
+//                            .notMatch(
+//                                    Constants.REPORT_API + "/ws/**",
+//                                    Constants.REPORT_API + "/test/**",
+//                                    Constants.REPORT_API + "/oauth2/**",
+//                                    Constants.REPORT_API + "/admin/**",
+//                                    Constants.REPORT_API + "/common/download",
+//                                    Constants.REPORT_API + "/common/export",
+//                                    Constants.REPORT_API + "/common/download",
+//                                    Constants.REPORT_API + "/admin/login",
+//                                    Constants.REPORT_API + "/system/**"
+//                            ).check(StpUtil::checkLogin);
+//                    //SaRouter.match(Constants.PERMISSION_API + "/admin/**", Constants.PERMISSION_API + "/admin/login", StpAdminUtil::checkLogin);
+//                })
+//                .setError(e -> Response.error(ResponseEnum.UNAUTHORIZED));
+//    }
+//
+//    // 注册Sa-Token的注解拦截器,打开注解式鉴权功能
+//    @Override
+//    public void addInterceptors(InterceptorRegistry registry) {
+//        // 注册注解拦截器,并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
+//        registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
+//    }
 
 }

+ 32 - 0
RMS/src/main/java/cn/cslg/report/common/utils/LogExceptionUtil.java

@@ -0,0 +1,32 @@
+package cn.cslg.report.common.utils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class LogExceptionUtil {
+    public static String getMessage(Exception e) {
+        StringWriter sw = null;
+        PrintWriter pw = null;
+        try {
+            sw = new StringWriter();
+            pw = new PrintWriter(sw);
+            //将出错的栈信息输出到printWriter中
+            e.printStackTrace(pw);
+            pw.flush();
+            sw.flush();
+        } finally {
+            if (sw != null) {
+                try {
+                    sw.close();
+                } catch (IOException e1) {
+                    e1.printStackTrace();
+                }
+            }
+            if (pw != null) {
+                pw.close();
+            }
+        }
+        return sw.toString();
+    }
+}

+ 8 - 0
RMS/src/main/java/cn/cslg/report/controller/ReportController.java

@@ -1,9 +1,11 @@
 package cn.cslg.report.controller;
 
 import cn.cslg.report.common.core.base.Constants;
+import cn.cslg.report.service.ReportService;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -12,4 +14,10 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping(Constants.REPORT_API + "/report")
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class ReportController {
+    private final ReportService reportService;
+
+    @GetMapping( "/test")
+    public void test() {
+        reportService.testMethod();
+    }
 }

+ 12 - 0
RMS/src/main/java/cn/cslg/report/service/ReportService.java

@@ -1,10 +1,22 @@
 package cn.cslg.report.service;
 
+import cn.cslg.report.common.utils.LogExceptionUtil;
 import cn.cslg.report.entity.Report;
 import cn.cslg.report.mapper.ReportMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 @Service
+@Slf4j
 public class ReportService extends ServiceImpl<ReportMapper, Report> {
+    public void testMethod() {
+        try {
+            throw new Exception();
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(LogExceptionUtil.getMessage(e));
+        }
+
+    }
 }