From 0eec3251f712b3888cef1a845aabcebf3565a498 Mon Sep 17 00:00:00 2001
From: zhongzb <972627721@qq.com>
Date: Tue, 10 Oct 2023 21:06:44 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mallchat-chat-server/pom.xml | 14 ++++++
.../common/config/SensitiveWordConfig.java | 6 +--
.../{IWordDeny.java => IWordFactory.java} | 6 +--
.../utils/sensitiveWord/SensitiveWordBs.java | 12 ++---
.../{MyWordDeny.java => MyWordFactory.java} | 6 +--
.../src/main/resources/application.yml | 2 +-
.../com/abin/mallchat/common/DaoTest.java | 17 +++++++
.../abin/mallchat/common/SensitiveTest.java | 47 +++++++++++++++++++
.../mallchat-common-starter/pom.xml | 15 ------
.../mallchat-frequency-control/pom.xml | 5 ++
mallchat-tools/mallchat-oss-starter/pom.xml | 18 +++++++
.../abin/mallchat/oss/MinIOConfiguration.java | 6 ++-
.../com/abin/mallchat/oss/MinIOTemplate.java | 3 +-
pom.xml | 6 ---
14 files changed, 122 insertions(+), 41 deletions(-)
rename mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/{IWordDeny.java => IWordFactory.java} (69%)
rename mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/{MyWordDeny.java => MyWordFactory.java} (86%)
create mode 100644 mallchat-chat-server/src/test/java/com/abin/mallchat/common/SensitiveTest.java
diff --git a/mallchat-chat-server/pom.xml b/mallchat-chat-server/pom.xml
index aa4620d..513d81c 100644
--- a/mallchat-chat-server/pom.xml
+++ b/mallchat-chat-server/pom.xml
@@ -34,6 +34,20 @@
p6spy
3.9.1
+
+ junit
+ junit
+ ${junit.version}
+
+
+ org.springframework
+ spring-test
+ 5.3.19
+
+
+ org.springframework.boot
+ spring-boot-test
+
diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/config/SensitiveWordConfig.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/config/SensitiveWordConfig.java
index 6220d51..262c880 100644
--- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/config/SensitiveWordConfig.java
+++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/config/SensitiveWordConfig.java
@@ -2,7 +2,7 @@ package com.abin.mallchat.common.common.config;
import com.abin.mallchat.common.common.utils.sensitiveWord.DFAFilter;
import com.abin.mallchat.common.common.utils.sensitiveWord.SensitiveWordBs;
-import com.abin.mallchat.common.sensitive.MyWordDeny;
+import com.abin.mallchat.common.sensitive.MyWordFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration;
public class SensitiveWordConfig {
@Autowired
- private MyWordDeny myWordDeny;
+ private MyWordFactory myWordFactory;
/**
* 初始化引导类
@@ -23,7 +23,7 @@ public class SensitiveWordConfig {
public SensitiveWordBs sensitiveWordBs() {
return SensitiveWordBs.newInstance()
.filterStrategy(DFAFilter.getInstance())
- .sensitiveWord(myWordDeny)
+ .sensitiveWord(myWordFactory)
.init();
}
diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordDeny.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordFactory.java
similarity index 69%
rename from mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordDeny.java
rename to mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordFactory.java
index a3b6822..7aed4ea 100644
--- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordDeny.java
+++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/IWordFactory.java
@@ -8,12 +8,12 @@ import java.util.List;
* @author zhaoyuhang
* @date 2023/07/09
*/
-public interface IWordDeny {
+public interface IWordFactory {
/**
- * 获取结果
+ * 返回敏感词数据源
*
* @return 结果
* @since 0.0.13
*/
- List deny();
+ List getWordList();
}
diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/SensitiveWordBs.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/SensitiveWordBs.java
index 44917f6..b49faf4 100644
--- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/SensitiveWordBs.java
+++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/common/utils/sensitiveWord/SensitiveWordBs.java
@@ -24,7 +24,7 @@ public class SensitiveWordBs {
/**
* 敏感词列表
*/
- private IWordDeny wordDeny;
+ private IWordFactory wordDeny;
public static SensitiveWordBs newInstance() {
return new SensitiveWordBs();
@@ -40,7 +40,7 @@ public class SensitiveWordBs {
*/
public SensitiveWordBs init() {
- List words = wordDeny.deny();
+ List words = wordDeny.getWordList();
loadWord(words);
return this;
}
@@ -60,11 +60,11 @@ public class SensitiveWordBs {
return this;
}
- public SensitiveWordBs sensitiveWord(IWordDeny wordDeny) {
- if (wordDeny == null) {
- throw new IllegalArgumentException("wordDeny can not be null");
+ public SensitiveWordBs sensitiveWord(IWordFactory wordFactory) {
+ if (wordFactory == null) {
+ throw new IllegalArgumentException("wordFactory can not be null");
}
- this.wordDeny = wordDeny;
+ this.wordDeny = wordFactory;
return this;
}
diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordDeny.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordFactory.java
similarity index 86%
rename from mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordDeny.java
rename to mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordFactory.java
index a47d623..8d9fef3 100644
--- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordDeny.java
+++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/sensitive/MyWordFactory.java
@@ -1,6 +1,6 @@
package com.abin.mallchat.common.sensitive;
-import com.abin.mallchat.common.common.utils.sensitiveWord.IWordDeny;
+import com.abin.mallchat.common.common.utils.sensitiveWord.IWordFactory;
import com.abin.mallchat.common.sensitive.dao.SensitiveWordDao;
import com.abin.mallchat.common.sensitive.domain.SensitiveWord;
import org.springframework.beans.factory.annotation.Autowired;
@@ -10,12 +10,12 @@ import java.util.List;
import java.util.stream.Collectors;
@Component
-public class MyWordDeny implements IWordDeny {
+public class MyWordFactory implements IWordFactory {
@Autowired
private SensitiveWordDao sensitiveWordDao;
@Override
- public List deny() {
+ public List getWordList() {
return sensitiveWordDao.list()
.stream()
.map(SensitiveWord::getWord)
diff --git a/mallchat-chat-server/src/main/resources/application.yml b/mallchat-chat-server/src/main/resources/application.yml
index ee78bd5..88a3e29 100644
--- a/mallchat-chat-server/src/main/resources/application.yml
+++ b/mallchat-chat-server/src/main/resources/application.yml
@@ -11,7 +11,7 @@ mybatis-plus:
spring:
profiles:
#运行的环境
- active: my-prod
+ active: my-test
application:
name: mallchat
datasource:
diff --git a/mallchat-chat-server/src/test/java/com/abin/mallchat/common/DaoTest.java b/mallchat-chat-server/src/test/java/com/abin/mallchat/common/DaoTest.java
index ec397c9..4651baf 100644
--- a/mallchat-chat-server/src/test/java/com/abin/mallchat/common/DaoTest.java
+++ b/mallchat-chat-server/src/test/java/com/abin/mallchat/common/DaoTest.java
@@ -5,6 +5,9 @@ import com.abin.mallchat.common.common.utils.JwtUtils;
import com.abin.mallchat.common.user.domain.enums.ItemEnum;
import com.abin.mallchat.common.user.service.IUserBackpackService;
import com.abin.mallchat.common.user.service.LoginService;
+import com.abin.mallchat.oss.MinIOTemplate;
+import com.abin.mallchat.oss.domain.OssReq;
+import com.abin.mallchat.oss.domain.OssResp;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
@@ -39,6 +42,20 @@ public class DaoTest {
@Autowired
private RocketMQTemplate rocketMQTemplate;
+ @Autowired
+ private MinIOTemplate minIOTemplate;
+
+ @Test
+ public void getUploadUrl() {
+ OssReq ossReq = OssReq.builder()
+ .fileName("test.jpeg")
+ .filePath("/test")
+ .autoPath(false)
+ .build();
+ OssResp preSignedObjectUrl = minIOTemplate.getPreSignedObjectUrl(ossReq);
+ System.out.println(preSignedObjectUrl);
+ }
+
@Test
public void sendMQ() {
Message build = MessageBuilder.withPayload("123").build();
diff --git a/mallchat-chat-server/src/test/java/com/abin/mallchat/common/SensitiveTest.java b/mallchat-chat-server/src/test/java/com/abin/mallchat/common/SensitiveTest.java
new file mode 100644
index 0000000..784b6e8
--- /dev/null
+++ b/mallchat-chat-server/src/test/java/com/abin/mallchat/common/SensitiveTest.java
@@ -0,0 +1,47 @@
+package com.abin.mallchat.common;
+
+import com.abin.mallchat.common.common.utils.sensitiveWord.ACFilter;
+import com.abin.mallchat.common.common.utils.sensitiveWord.DFAFilter;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Description:
+ * Author: abin
+ * Date: 2023-10-08
+ */
+public class SensitiveTest {
+ @Test
+ public void DFA() {
+ List sensitiveList = Arrays.asList("abcd", "abcbba", "adabca");
+ DFAFilter instance = DFAFilter.getInstance();
+ instance.loadWord(sensitiveList);
+ System.out.println(instance.hasSensitiveWord("adabcd"));
+ }
+
+ @Test
+ public void AC() {
+ List sensitiveList = Arrays.asList("abcd", "abcbba", "adabca");
+ ACFilter instance = new ACFilter();
+ instance.loadWord(sensitiveList);
+ instance.hasSensitiveWord("adabcd");
+ }
+
+ @Test
+ public void DFAMulti() {
+ List sensitiveList = Arrays.asList("白痴", "你是白痴", "白痴吗");
+ DFAFilter instance = DFAFilter.getInstance();
+ instance.loadWord(sensitiveList);
+ System.out.println(instance.filter("你是白痴吗"));
+ }
+
+ @Test
+ public void ACMulti() {
+ List sensitiveList = Arrays.asList("白痴", "你是白痴", "白痴吗");
+ ACFilter instance = new ACFilter();
+ instance.loadWord(sensitiveList);
+ System.out.println(instance.filter("你是白痴吗"));
+ }
+}
diff --git a/mallchat-tools/mallchat-common-starter/pom.xml b/mallchat-tools/mallchat-common-starter/pom.xml
index 4681d7c..5c47a1a 100644
--- a/mallchat-tools/mallchat-common-starter/pom.xml
+++ b/mallchat-tools/mallchat-common-starter/pom.xml
@@ -104,21 +104,6 @@
org.redisson
redisson-spring-boot-starter
-
-
- junit
- junit
- ${junit.version}
-
-
- org.springframework
- spring-test
- 5.3.19
-
-
- org.springframework.boot
- spring-boot-test
-
org.apache.rocketmq
rocketmq-spring-boot-starter
diff --git a/mallchat-tools/mallchat-frequency-control/pom.xml b/mallchat-tools/mallchat-frequency-control/pom.xml
index d7c6e85..3d0f6f7 100644
--- a/mallchat-tools/mallchat-frequency-control/pom.xml
+++ b/mallchat-tools/mallchat-frequency-control/pom.xml
@@ -40,6 +40,11 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ none
+ execute
+
+
diff --git a/mallchat-tools/mallchat-oss-starter/pom.xml b/mallchat-tools/mallchat-oss-starter/pom.xml
index b44a662..ca5f301 100644
--- a/mallchat-tools/mallchat-oss-starter/pom.xml
+++ b/mallchat-tools/mallchat-oss-starter/pom.xml
@@ -21,4 +21,22 @@
minio
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.4.3
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ none
+ execute
+
+
+
+
+
\ No newline at end of file
diff --git a/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOConfiguration.java b/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOConfiguration.java
index 2508799..f56664e 100644
--- a/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOConfiguration.java
+++ b/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOConfiguration.java
@@ -2,13 +2,15 @@ package com.abin.mallchat.oss;
import io.minio.MinioClient;
import lombok.SneakyThrows;
-import org.springframework.boot.autoconfigure.condition.*;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass({MinioClient.class})
@EnableConfigurationProperties(OssProperties.class)
@ConditionalOnExpression("${oss.enabled}")
@ConditionalOnProperty(value = "oss.type", havingValue = "minio")
diff --git a/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOTemplate.java b/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOTemplate.java
index 370cfa9..5eca8c7 100644
--- a/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOTemplate.java
+++ b/mallchat-tools/mallchat-oss-starter/src/main/java/com/abin/mallchat/oss/MinIOTemplate.java
@@ -65,7 +65,6 @@ public class MinIOTemplate {
public void makeBucket(String bucketName) {
if (!bucketExists(bucketName)) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
-
}
}
@@ -80,7 +79,7 @@ public class MinIOTemplate {
}
/**
- * 返回临时带签名、过期时间一天、Get请求方式的访问URL
+ * 返回临时带签名、过期时间一天、PUT请求方式的访问URL
*/
@SneakyThrows
public OssResp getPreSignedObjectUrl(OssReq req) {
diff --git a/pom.xml b/pom.xml
index 36f8bef..50f6fcb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,6 @@
8.0.29
2.7.5
0.9.1
- 3.16.0
7.2
8.4.5
2.3.1
@@ -124,11 +123,6 @@
${jjwt.version}
-
- com.aliyun.oss
- aliyun-sdk-oss
- ${aliyun-oss.version}
-
io.minio
minio