Browse Source

添加访问日志记录过滤器

Arc 5 năm trước cách đây
mục cha
commit
375c8f08f9
18 tập tin đã thay đổi với 147 bổ sung20 xóa
  1. 11 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/WebMvcConfiguration.java
  2. 101 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/interceptors/BrowseLogHandelInterceptor.java
  3. 0 1
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml
  4. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceAdvertisePlanController.java
  5. 2 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceAdvertiserController.java
  6. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCampaignController.java
  7. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeController.java
  8. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeMaterialController.java
  9. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceVideoInfoController.java
  10. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAdvertiserDailyReportController.java
  11. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAdvertiserHourlyReportController.java
  12. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCampaignDailyReportController.java
  13. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCampaignHourlyReportController.java
  14. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCreativeDailyReportController.java
  15. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCreativeHourlyReportController.java
  16. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedancePlanDailyReportController.java
  17. 2 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedancePlanHourlyReportController.java
  18. 7 6
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

+ 11 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/WebMvcConfiguration.java

@@ -1,12 +1,15 @@
 package org.jeecg.config;
 
 import cn.com.ctop.common.module.utils.StringUtils;
+import org.jeecg.config.interceptors.BrowseLogHandelInterceptor;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -20,6 +23,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 @Configuration
 public class WebMvcConfiguration implements WebMvcConfigurer {
 
+	@Autowired
+	BrowseLogHandelInterceptor browseLogHandelInterceptor;
+
 	@Value("${jeecg.path.upload}")
 	private String upLoadPath;
 	@Value("${jeecg.path.webapp}")
@@ -27,6 +33,11 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
 	@Value("${spring.resource.static-locations}")
 	private String staticLocations;
 
+	@Override
+	public void addInterceptors(InterceptorRegistry registry) {
+		registry.addInterceptor(browseLogHandelInterceptor);
+	}
+
 	@Bean
 	public CorsFilter corsFilter() {
 		final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();

+ 101 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/interceptors/BrowseLogHandelInterceptor.java

@@ -0,0 +1,101 @@
+package org.jeecg.config.interceptors;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.system.util.JwtUtil;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Created by JQ.bi on 2020.5.8
+ */
+@Component
+@Slf4j
+public class BrowseLogHandelInterceptor extends HandlerInterceptorAdapter {
+
+    private static final String REQUEST_METHOD = "GET_POST_PUT_DELETE_OPTIONS";
+
+    private final static ExecutorService executorServicePool;
+
+    //加载一次
+    static {
+        int threadCount = Runtime.getRuntime().availableProcessors();
+        ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
+        builder.setNameFormat("BrowseLogHandlerFactory");
+        builder.setDaemon(true);
+        builder.setUncaughtExceptionHandler((t, e) -> {
+        });//忽略异常
+        builder.setPriority(Thread.MIN_PRIORITY);
+        executorServicePool = new ThreadPoolExecutor(threadCount, threadCount,
+                0L, TimeUnit.MILLISECONDS,
+                new LinkedBlockingQueue<Runnable>(100000), builder.build(), new ThreadPoolExecutor.DiscardPolicy());
+    }
+
+
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
+
+        if (REQUEST_METHOD.contains(request.getMethod())) {
+            if (request.getRequestURI().endsWith("/getEncryptedString")||request.getRequestURI().endsWith("/login")) {
+                return;
+            }
+            boolean isSuccess = true;
+            if (response.getStatus() != 200) {
+                isSuccess = false;
+            }
+            String userName = JwtUtil.getUserNameByToken(request);
+            if (StringUtils.isEmpty(userName)) {
+                log.warn("登陆账号用户名为空");
+            }
+            String token = request.getHeader("X-Access-Token");
+            String uri = request.getRequestURI();
+            String currentDate = DateUtils.now();
+            BrowseLogRunnable runnable = new BrowseLogRunnable(userName, isSuccess,token, uri, currentDate);
+            executorServicePool.submit(runnable);
+        }
+    }
+
+
+    private static class BrowseLogRunnable implements Runnable {
+
+        String userName;
+        Boolean isSuccess;
+        String token;
+        String uri;
+        String currentDate;
+
+
+        BrowseLogRunnable(String userName, boolean isSuccess, String token, String uri, String currentDate) {
+            this.userName = userName;
+            this.isSuccess = isSuccess;
+            this.token = token;
+            this.uri = uri;
+            this.currentDate = currentDate;
+        }
+
+        @Override
+        public void run() {
+            try {
+                if (!StringUtils.isEmpty(token)) {
+                    if(isSuccess){
+                        log.info("-SUCCESS " + currentDate + " 用户:" + userName + " 访问了[" + uri + "]?token=\"" + token + "\"");
+                    }else {
+                        log.info("-FALSE " + currentDate + " 用户:" + userName + "” 访问了[" + uri + "]?token=\"" + token + "\"");
+                    }
+                }
+            } catch (Exception e) {
+                log.error(e.toString());
+            }
+        }
+    }
+}
+

+ 0 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml

@@ -94,7 +94,6 @@
         on t1.account_id = t2.account_id
         where t2.account_status = 0
         and t1.media_id = 1
-        and user_id != 'e9ca23d68d884d4ebb19d07889727dae' <!-- 去掉管理员 -->
         group by account_id
     </select>
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceAdvertisePlanController.java

@@ -110,9 +110,10 @@ public class ByteDanceAdvertisePlanController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = byteDanceAdvertisePlanService.updateById(byteDanceAdvertisePlan);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceAdvertiserController.java

@@ -113,6 +113,8 @@ public class ByteDanceAdvertiserController {
             //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            } else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCampaignController.java

@@ -110,9 +110,10 @@ public class ByteDanceCampaignController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = byteDanceCampaignService.updateById(byteDanceCampaign);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeController.java

@@ -110,9 +110,10 @@ public class ByteDanceCreativeController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = byteDanceCreativeService.updateById(byteDanceCreative);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            } else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeMaterialController.java

@@ -110,9 +110,10 @@ public class ByteDanceCreativeMaterialController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = byteDanceCreativeMaterialService.updateById(byteDanceCreativeMaterial);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceVideoInfoController.java

@@ -109,9 +109,10 @@ public class ByteDanceVideoInfoController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = byteDanceVideoInfoService.updateById(byteDanceVideoInfo);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAdvertiserDailyReportController.java

@@ -109,9 +109,10 @@ public class BytedanceAdvertiserDailyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceAdvertiserDailyReportService.updateById(bytedanceAdvertiserDailyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAdvertiserHourlyReportController.java

@@ -110,9 +110,10 @@ public class BytedanceAdvertiserHourlyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceAdvertiserHourlyReportService.updateById(bytedanceAdvertiserHourlyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            } else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCampaignDailyReportController.java

@@ -110,9 +110,10 @@ public class BytedanceCampaignDailyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceCampaignDailyReportService.updateById(bytedanceCampaignDailyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCampaignHourlyReportController.java

@@ -109,9 +109,10 @@ public class BytedanceCampaignHourlyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceCampaignHourlyReportService.updateById(bytedanceCampaignHourlyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCreativeDailyReportController.java

@@ -110,9 +110,10 @@ public class BytedanceCreativeDailyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceCreativeDailyReportService.updateById(bytedanceCreativeDailyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceCreativeHourlyReportController.java

@@ -109,9 +109,10 @@ public class BytedanceCreativeHourlyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedanceCreativeHourlyReportService.updateById(bytedanceCreativeHourlyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedancePlanDailyReportController.java

@@ -114,9 +114,10 @@ public class BytedancePlanDailyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedancePlanDailyReportService.updateById(bytedancePlanDailyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 2 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedancePlanHourlyReportController.java

@@ -109,9 +109,10 @@ public class BytedancePlanHourlyReportController {
             result.error500("未找到对应实体");
         } else {
             boolean ok = bytedancePlanHourlyReportService.updateById(bytedancePlanHourlyReport);
-            //TODO 返回false说明什么?
             if (ok) {
                 result.success("修改成功!");
+            }else {
+                result.error500("未知错误");
             }
         }
 

+ 7 - 6
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceReportController.java

@@ -132,7 +132,7 @@ public class BytedanceReportController {
             result.error500("开始时间和结束时间不能为空");
             return result;
         }
-
+        final ExecutorService  executorService = Executors.newFixedThreadPool(8);
         try {
             log.info("头条获取素材报表数据任务执行开始");
             Long starttime = System.currentTimeMillis();
@@ -141,14 +141,12 @@ public class BytedanceReportController {
                 log.info("头条获取素材报表数据任务执行失败:未获取到可用的token");
                 return result;
             }
-
-            final ExecutorService executorService = Executors.newFixedThreadPool(8);
             tokens.forEach(token -> {
                 executorService.submit(new Runnable() {
                     @Override
                     public void run() {
                         try {
-                            Long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
+                            long days = DateUtils.getDiscrepantDays(startDate, endDate); //间隔天数
                             String start = null;
                             String end = null;
                             for(int i=0; i<=days; i++){
@@ -159,7 +157,6 @@ public class BytedanceReportController {
                             }
                         } catch (Exception e) {
                             e.printStackTrace();
-                        } finally {
                         }
                     }
                 });
@@ -171,6 +168,8 @@ public class BytedanceReportController {
             log.error("头条获取素材报表数据任务执行结失败");
             e.printStackTrace();
             result.setSuccess(false);
+        }finally {
+            executorService.shutdownNow();
         }
         return result;
     }
@@ -179,10 +178,10 @@ public class BytedanceReportController {
     public Result bytedanceMaterialReportRetry() {
         log.info("头条获取素材报表失败数据任务重试开始");
         Result result = new Result<>();
+        final ExecutorService executorService = Executors.newFixedThreadPool(8);
         try {
             List<BytedanceReportMaterialRetry> retryList = bytedanceReportService.getRetryList();
                 //多线程
-            final ExecutorService executorService = Executors.newFixedThreadPool(8);
             retryList.forEach(retry -> {
                 executorService.submit(new Runnable() {
                     @Override
@@ -202,6 +201,8 @@ public class BytedanceReportController {
             log.error("条获取素材报表失败数据任务重试失败");
             e.printStackTrace();
             result.setSuccess(false);
+        }finally {
+            executorService.shutdownNow();
         }
 
         log.info("头条获取素材报表数据任务重试结束");