mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-13 21:53:41 +08:00
fix:优化
This commit is contained in:
@@ -34,6 +34,20 @@
|
|||||||
<artifactId>p6spy</artifactId>
|
<artifactId>p6spy</artifactId>
|
||||||
<version>3.9.1</version>
|
<version>3.9.1</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<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.DFAFilter;
|
||||||
import com.abin.mallchat.common.common.utils.sensitiveWord.SensitiveWordBs;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -11,7 +11,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
public class SensitiveWordConfig {
|
public class SensitiveWordConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MyWordDeny myWordDeny;
|
private MyWordFactory myWordFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化引导类
|
* 初始化引导类
|
||||||
@@ -23,7 +23,7 @@ public class SensitiveWordConfig {
|
|||||||
public SensitiveWordBs sensitiveWordBs() {
|
public SensitiveWordBs sensitiveWordBs() {
|
||||||
return SensitiveWordBs.newInstance()
|
return SensitiveWordBs.newInstance()
|
||||||
.filterStrategy(DFAFilter.getInstance())
|
.filterStrategy(DFAFilter.getInstance())
|
||||||
.sensitiveWord(myWordDeny)
|
.sensitiveWord(myWordFactory)
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import java.util.List;
|
|||||||
* @author zhaoyuhang
|
* @author zhaoyuhang
|
||||||
* @date 2023/07/09
|
* @date 2023/07/09
|
||||||
*/
|
*/
|
||||||
public interface IWordDeny {
|
public interface IWordFactory {
|
||||||
/**
|
/**
|
||||||
* 获取结果
|
* 返回敏感词数据源
|
||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
* @since 0.0.13
|
* @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() {
|
public static SensitiveWordBs newInstance() {
|
||||||
return new SensitiveWordBs();
|
return new SensitiveWordBs();
|
||||||
@@ -40,7 +40,7 @@ public class SensitiveWordBs {
|
|||||||
*/
|
*/
|
||||||
public SensitiveWordBs init() {
|
public SensitiveWordBs init() {
|
||||||
|
|
||||||
List<String> words = wordDeny.deny();
|
List<String> words = wordDeny.getWordList();
|
||||||
loadWord(words);
|
loadWord(words);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -60,11 +60,11 @@ public class SensitiveWordBs {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensitiveWordBs sensitiveWord(IWordDeny wordDeny) {
|
public SensitiveWordBs sensitiveWord(IWordFactory wordFactory) {
|
||||||
if (wordDeny == null) {
|
if (wordFactory == null) {
|
||||||
throw new IllegalArgumentException("wordDeny can not be null");
|
throw new IllegalArgumentException("wordFactory can not be null");
|
||||||
}
|
}
|
||||||
this.wordDeny = wordDeny;
|
this.wordDeny = wordFactory;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.abin.mallchat.common.sensitive;
|
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.dao.SensitiveWordDao;
|
||||||
import com.abin.mallchat.common.sensitive.domain.SensitiveWord;
|
import com.abin.mallchat.common.sensitive.domain.SensitiveWord;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -10,12 +10,12 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class MyWordDeny implements IWordDeny {
|
public class MyWordFactory implements IWordFactory {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensitiveWordDao sensitiveWordDao;
|
private SensitiveWordDao sensitiveWordDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> deny() {
|
public List<String> getWordList() {
|
||||||
return sensitiveWordDao.list()
|
return sensitiveWordDao.list()
|
||||||
.stream()
|
.stream()
|
||||||
.map(SensitiveWord::getWord)
|
.map(SensitiveWord::getWord)
|
||||||
@@ -11,7 +11,7 @@ mybatis-plus:
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
#运行的环境
|
#运行的环境
|
||||||
active: my-prod
|
active: my-test
|
||||||
application:
|
application:
|
||||||
name: mallchat
|
name: mallchat
|
||||||
datasource:
|
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.domain.enums.ItemEnum;
|
||||||
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
import com.abin.mallchat.common.user.service.IUserBackpackService;
|
||||||
import com.abin.mallchat.common.user.service.LoginService;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
@@ -39,6 +42,20 @@ public class DaoTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RocketMQTemplate rocketMQTemplate;
|
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
|
@Test
|
||||||
public void sendMQ() {
|
public void sendMQ() {
|
||||||
Message<String> build = MessageBuilder.withPayload("123").build();
|
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("你是白痴吗"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -104,21 +104,6 @@
|
|||||||
<groupId>org.redisson</groupId>
|
<groupId>org.redisson</groupId>
|
||||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Used for unit testing -->
|
|
||||||
<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>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||||
|
|||||||
@@ -40,6 +40,11 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>none</mainClass> <!-- 取消查找本项目下的Main方法:为了解决Unable to find main class的问题 -->
|
||||||
|
<classifier>execute
|
||||||
|
</classifier> <!-- 解决maven-plugin插件打的Jar包可以运行,但依赖方打包找不到此模块中的类或属性的问题(程序包xxx不存在) -->
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@@ -21,4 +21,22 @@
|
|||||||
<artifactId>minio</artifactId>
|
<artifactId>minio</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>none</mainClass> <!-- 取消查找本项目下的Main方法:为了解决Unable to find main class的问题 -->
|
||||||
|
<classifier>execute
|
||||||
|
</classifier> <!-- 解决maven-plugin插件打的Jar包可以运行,但依赖方打包找不到此模块中的类或属性的问题(程序包xxx不存在) -->
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -2,13 +2,15 @@ package com.abin.mallchat.oss;
|
|||||||
|
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import lombok.SneakyThrows;
|
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.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({MinioClient.class})
|
|
||||||
@EnableConfigurationProperties(OssProperties.class)
|
@EnableConfigurationProperties(OssProperties.class)
|
||||||
@ConditionalOnExpression("${oss.enabled}")
|
@ConditionalOnExpression("${oss.enabled}")
|
||||||
@ConditionalOnProperty(value = "oss.type", havingValue = "minio")
|
@ConditionalOnProperty(value = "oss.type", havingValue = "minio")
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ public class MinIOTemplate {
|
|||||||
public void makeBucket(String bucketName) {
|
public void makeBucket(String bucketName) {
|
||||||
if (!bucketExists(bucketName)) {
|
if (!bucketExists(bucketName)) {
|
||||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +79,7 @@ public class MinIOTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回临时带签名、过期时间一天、Get请求方式的访问URL
|
* 返回临时带签名、过期时间一天、PUT请求方式的访问URL
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public OssResp getPreSignedObjectUrl(OssReq req) {
|
public OssResp getPreSignedObjectUrl(OssReq req) {
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -34,7 +34,6 @@
|
|||||||
<mysql-connector.version>8.0.29</mysql-connector.version>
|
<mysql-connector.version>8.0.29</mysql-connector.version>
|
||||||
<spring-data-commons.version>2.7.5</spring-data-commons.version>
|
<spring-data-commons.version>2.7.5</spring-data-commons.version>
|
||||||
<jjwt.version>0.9.1</jjwt.version>
|
<jjwt.version>0.9.1</jjwt.version>
|
||||||
<aliyun-oss.version>3.16.0</aliyun-oss.version>
|
|
||||||
<logstash-logback.version>7.2</logstash-logback.version>
|
<logstash-logback.version>7.2</logstash-logback.version>
|
||||||
<minio.version>8.4.5</minio.version>
|
<minio.version>8.4.5</minio.version>
|
||||||
<jaxb-api.version>2.3.1</jaxb-api.version>
|
<jaxb-api.version>2.3.1</jaxb-api.version>
|
||||||
@@ -124,11 +123,6 @@
|
|||||||
<version>${jjwt.version}</version>
|
<version>${jjwt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 阿里云OSS -->
|
<!-- 阿里云OSS -->
|
||||||
<dependency>
|
|
||||||
<groupId>com.aliyun.oss</groupId>
|
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
|
||||||
<version>${aliyun-oss.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.minio</groupId>
|
<groupId>io.minio</groupId>
|
||||||
<artifactId>minio</artifactId>
|
<artifactId>minio</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user