commit 6621b5f0bfea97b55b10543cb410cf4753d52750
Author: 55007 <55007@maojian>
Date: Tue Jan 7 17:20:24 2025 +0800
过滤器应用
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cf60db2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,34 @@
+HELP.md
+target/
+logs/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..943dfea
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+过滤器
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..0786b12
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,130 @@
+
+
+ 4.0.0
+ com.bfd.crawl
+ dataFilter
+ 0.0.1-SNAPSHOT
+ dataFilter
+ dataFilter
+
+ 1.8
+ UTF-8
+ UTF-8
+ 2.2.4.RELEASE
+
+
+
+
+ de.codecentric
+ spring-boot-admin-client
+ 2.2.4
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.kafka
+ spring-kafka
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.redisson
+ redisson-spring-boot-starter
+ 3.13.6
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ mysql
+ mysql-connector-java
+ runtime
+
+
+
+ com.alibaba
+ fastjson
+ 2.0.17
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.kafka
+ spring-kafka-test
+ test
+
+
+ com.bfd.util
+ pauseTool
+ 1.0
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring-boot.version}
+ pom
+ import
+
+
+
+
+
+ dataFilter-0.0.1-SNAPSHOT
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 2.4.1
+
+ true
+
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+
+
diff --git a/src/main/java/com/bfd/crawl/datafilter/DataFilterApplication.java b/src/main/java/com/bfd/crawl/datafilter/DataFilterApplication.java
new file mode 100644
index 0000000..340e21a
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/DataFilterApplication.java
@@ -0,0 +1,24 @@
+package com.bfd.crawl.datafilter;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@SpringBootApplication
+@EnableAsync
+@EnableScheduling
+/**
+ * @author:jinming
+ * @className:DataFilterApplication
+ * @version:1.0
+ * @description:
+ * @Date:2023/7/31 17:53
+ */
+public class DataFilterApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(DataFilterApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/bfd/crawl/datafilter/bean/Constants.java b/src/main/java/com/bfd/crawl/datafilter/bean/Constants.java
new file mode 100644
index 0000000..17424bc
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/bean/Constants.java
@@ -0,0 +1,36 @@
+package com.bfd.crawl.datafilter.bean;
+
+/**
+ * @author:jinming
+ * @className:Constants
+ * @version:1.0
+ * @description:
+ * @Date:2023/7/14 10:41
+ */
+public class Constants {
+ /**
+ * 查询数据时间
+ */
+ public static String TIME = "time";
+
+ /**
+ * 查询数据开始时间
+ */
+ public static String START_TIME = "startTime";
+
+ /**
+ * 查询数据结束时间
+ */
+ public static String END_TIME = "endTime";
+
+ /**
+ * 查询排除词
+ */
+ public static String EXCLUSION_WORDS = "exclusionWords";
+
+ /**
+ * 查询包含命中关键词
+ */
+ public static String INCLUD_WORDS = "includWords";
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/bean/ResponsePo.java b/src/main/java/com/bfd/crawl/datafilter/bean/ResponsePo.java
new file mode 100644
index 0000000..7677269
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/bean/ResponsePo.java
@@ -0,0 +1,59 @@
+package com.bfd.crawl.datafilter.bean;
+
+
+import com.bfd.crawl.datafilter.enums.ResponseCode;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author:jinming
+ * @className:ResponsePo
+ * @version:1.0
+ * @description:
+ * @Date:2023/4/3 17:23
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ResponsePo {
+ /**
+ * 响应码
+ */
+ private int code;
+
+ /**
+ * 正常放 返回数据 的JSON串
+ */
+ private Object data;
+
+ /**
+ * 提示消息
+ */
+ private String message;
+
+ public static ResponsePo success() {
+ return setStatus(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage());
+ }
+
+ public static ResponsePo error() {
+ return setStatus(ResponseCode.FAILURE.getCode(), ResponseCode.FAILURE.getMessage());
+ }
+
+ public static ResponsePo setStatus(int code, String message) {
+ ResponsePo resultBean = new ResponsePo();
+ resultBean.code = code;
+ resultBean.message = message;
+ return resultBean;
+ }
+ public ResponsePo(int code, String message) {
+ this.code = code;
+ this.message = message;
+ this.data = data;
+ }
+ public ResponsePo(ResponseCode responseCode){
+ this.code = responseCode.getCode();
+ this.message = responseCode.getMessage();
+ this.data = data;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/config/AsyncThreadConfiguration.java b/src/main/java/com/bfd/crawl/datafilter/config/AsyncThreadConfiguration.java
new file mode 100644
index 0000000..08a5aef
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/config/AsyncThreadConfiguration.java
@@ -0,0 +1,48 @@
+package com.bfd.crawl.datafilter.config;
+
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+/**
+ * @author jinming
+ * @version 1.0
+ * @className AsyncThreadConfiguration
+ * @Date 2022/2/17 18:37
+ */
+@Configuration
+@EnableAsync
+public class AsyncThreadConfiguration {
+ @Bean(name = "asyncExecutor")
+ public Executor asyncExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ // 核心线程数
+ executor.setCorePoolSize(500);
+ // 并发线程的数量限制为2
+ executor.setMaxPoolSize(500);
+ // 线程队列
+ executor.setQueueCapacity(500);
+ executor.setThreadNamePrefix("dataFilter-");
+ executor.initialize();
+ executor.setWaitForTasksToCompleteOnShutdown(true);
+ return executor;
+ }
+ @Bean(name = "sendExecutor")
+ public Executor sendExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ // 核心线程数
+ executor.setCorePoolSize(500);
+ // 并发线程的数量限制为2
+ executor.setMaxPoolSize(500);
+ // 线程队列
+ executor.setQueueCapacity(500);
+ executor.setThreadNamePrefix("sendData-");
+ executor.initialize();
+ executor.setWaitForTasksToCompleteOnShutdown(true);
+ return executor;
+ }
+}
diff --git a/src/main/java/com/bfd/crawl/datafilter/controller/DataFilterController.java b/src/main/java/com/bfd/crawl/datafilter/controller/DataFilterController.java
new file mode 100644
index 0000000..67ed787
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/controller/DataFilterController.java
@@ -0,0 +1,39 @@
+package com.bfd.crawl.datafilter.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.bfd.crawl.datafilter.bean.ResponsePo;
+import com.bfd.crawl.datafilter.enums.ResponseCode;
+import com.bfd.crawl.datafilter.util.QueueUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * @author:jinming
+ * @className:DataFilterController
+ * @version:1.0
+ * @description:
+ * @Date:2023/7/26 11:21
+ */
+@RestController
+@RequestMapping("/handlerdata")
+@Slf4j
+public class DataFilterController {
+ @PostMapping("/filter")
+ public ResponsePo documentFeedback(@RequestBody String dataJson) {
+
+ ResponsePo responsePo = ResponsePo.success();
+ log.info("新增任务:" + dataJson);
+ try {
+ QueueUtil.taskQueue.put(dataJson);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ return responsePo;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/dao/FilterTypeDao.java b/src/main/java/com/bfd/crawl/datafilter/dao/FilterTypeDao.java
new file mode 100644
index 0000000..2c344ff
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/dao/FilterTypeDao.java
@@ -0,0 +1,14 @@
+package com.bfd.crawl.datafilter.dao;
+
+import com.bfd.crawl.datafilter.entity.FilterType;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author jinming
+ * @version 1.0
+ * @className FilterTypeDao
+ * @Date 2023/7/26 16:28
+ */
+public interface FilterTypeDao extends JpaRepository {
+ FilterType getFilterTypeById(int id);
+}
diff --git a/src/main/java/com/bfd/crawl/datafilter/entity/FilterType.java b/src/main/java/com/bfd/crawl/datafilter/entity/FilterType.java
new file mode 100644
index 0000000..16ef305
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/entity/FilterType.java
@@ -0,0 +1,49 @@
+package com.bfd.crawl.datafilter.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+
+/**
+ * @author:jinming
+ * @className:FilterType
+ * @version:1.0
+ * @description:
+ * @Date:2023/7/26 10:58
+ */
+@Entity
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Table(name = "filter_type")
+public class FilterType {
+ /**
+ * 自增主键ID
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private Integer id;
+ /**
+ * 类型(66运算方式,67运算条件)
+ */
+ @Column(name = "type")
+ private String type;
+ /**
+ * 描述
+ */
+ @Column(name = "describe")
+ private String describe;
+ /**
+ * 上级id
+ */
+ @Column(name = "parent_id")
+ private Integer parentId;
+ /**
+ * 等级
+ */
+ @Column(name = "level")
+ private String level;
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/enums/ResponseCode.java b/src/main/java/com/bfd/crawl/datafilter/enums/ResponseCode.java
new file mode 100644
index 0000000..a80635f
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/enums/ResponseCode.java
@@ -0,0 +1,32 @@
+package com.bfd.crawl.datafilter.enums;
+
+/**
+ * @author:jinming
+ * @className:ResponseCodeEnum
+ * @version:1.0
+ * @description:响应结果码枚举类
+ * @Date:2023/2/28 11:40
+ */
+public enum ResponseCode {
+ //返回结果码枚举类
+ SUCCESS(200, "操作成功"),
+ FAILURE(400, "参数错误"),
+ INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
+ TYPE_NOT_SUPPORT(601,"文件类型不支持");
+
+ private int code;
+ private String message;
+
+ ResponseCode(int code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/exception/GlobalExceptionHandler.java b/src/main/java/com/bfd/crawl/datafilter/exception/GlobalExceptionHandler.java
new file mode 100644
index 0000000..c7d0921
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/exception/GlobalExceptionHandler.java
@@ -0,0 +1,32 @@
+package com.bfd.crawl.datafilter.exception;
+
+
+
+import com.bfd.crawl.datafilter.bean.ResponsePo;
+import com.bfd.crawl.datafilter.enums.ResponseCode;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+/**
+ * @author:jinming
+ * @className:GlobalExceptionHandler
+ * @version:1.0
+ * @description: 异常处理类
+ * @Date:2023/2/28 16:29
+ */
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(value = {IllegalArgumentException.class})
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ public ResponsePo handleBadRequest(Exception ex) {
+ return new ResponsePo(ResponseCode.FAILURE.getCode(), ex.getMessage());
+ }
+ @ExceptionHandler(value = {Exception.class})
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ public ResponsePo handleException(Exception ex) {
+ return new ResponsePo(ResponseCode.INTERNAL_SERVER_ERROR.getCode(), ex.getMessage());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/bfd/crawl/datafilter/service/HandlerService.java b/src/main/java/com/bfd/crawl/datafilter/service/HandlerService.java
new file mode 100644
index 0000000..2b22030
--- /dev/null
+++ b/src/main/java/com/bfd/crawl/datafilter/service/HandlerService.java
@@ -0,0 +1,331 @@
+package com.bfd.crawl.datafilter.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONPath;
+import com.bfd.crawl.datafilter.dao.FilterTypeDao;
+import com.bfd.crawl.datafilter.entity.FilterType;
+import com.bfd.crawl.datafilter.util.DataUtil;
+import com.bfd.crawl.datafilter.util.DateUtil;
+import com.bfd.crawl.datafilter.util.QueueUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author:jinming
+ * @className:HandlerService
+ * @version:1.0
+ * @description:
+ * @Date:2023/7/26 11:29
+ */
+@Service
+@Slf4j
+public class HandlerService {
+ @Autowired
+ private FilterTypeDao filterTypeDao;
+
+
+ @Async("asyncExecutor")
+ public void run() {
+ while (true) {
+ if (QueueUtil.taskQueue.size() > 0) {
+ String dataJson = null;
+ try {
+ dataJson = QueueUtil.taskQueue.take();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ Map parse = null;
+ try {
+ parse = (Map) JSON.parse(dataJson);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ try {
+ Map data = (Map) parse.get("data");
+ int id = (int) parse.get("id");
+ log.info("任务:" + id + "已开始处理");
+ boolean needSend = false;
+ Map admin = (Map) parse.get("input");
+ Map dataMap = (Map) parse.get("data");
+ log.info("任务:" + id + "的判断条件为:" + JSON.toJSONString(admin));
+ boolean caseSensitive = true;
+ try {
+ caseSensitive = (boolean) admin.get("caseSensitive");
+ } catch (Exception e) {
+
+ }
+ List> conditions = (List>) admin.get("or");
+ for (List