mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
fix:优化
This commit is contained in:
@@ -34,6 +34,20 @@
|
||||
<artifactId>p6spy</artifactId>
|
||||
<version>3.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.3.19</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> deny();
|
||||
List<String> getWordList();
|
||||
}
|
||||
@@ -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<String> words = wordDeny.deny();
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> deny() {
|
||||
public List<String> getWordList() {
|
||||
return sensitiveWordDao.list()
|
||||
.stream()
|
||||
.map(SensitiveWord::getWord)
|
||||
@@ -11,7 +11,7 @@ mybatis-plus:
|
||||
spring:
|
||||
profiles:
|
||||
#运行的环境
|
||||
active: my-prod
|
||||
active: my-test
|
||||
application:
|
||||
name: mallchat
|
||||
datasource:
|
||||
|
||||
@@ -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<String> build = MessageBuilder.withPayload("123").build();
|
||||
|
||||
@@ -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: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-10-08
|
||||
*/
|
||||
public class SensitiveTest {
|
||||
@Test
|
||||
public void DFA() {
|
||||
List<String> sensitiveList = Arrays.asList("abcd", "abcbba", "adabca");
|
||||
DFAFilter instance = DFAFilter.getInstance();
|
||||
instance.loadWord(sensitiveList);
|
||||
System.out.println(instance.hasSensitiveWord("adabcd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void AC() {
|
||||
List<String> sensitiveList = Arrays.asList("abcd", "abcbba", "adabca");
|
||||
ACFilter instance = new ACFilter();
|
||||
instance.loadWord(sensitiveList);
|
||||
instance.hasSensitiveWord("adabcd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void DFAMulti() {
|
||||
List<String> sensitiveList = Arrays.asList("白痴", "你是白痴", "白痴吗");
|
||||
DFAFilter instance = DFAFilter.getInstance();
|
||||
instance.loadWord(sensitiveList);
|
||||
System.out.println(instance.filter("你是白痴吗"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ACMulti() {
|
||||
List<String> sensitiveList = Arrays.asList("白痴", "你是白痴", "白痴吗");
|
||||
ACFilter instance = new ACFilter();
|
||||
instance.loadWord(sensitiveList);
|
||||
System.out.println(instance.filter("你是白痴吗"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user