mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2025-12-26 04:47:53 +08:00
fix:优化
This commit is contained in:
parent
5f15e1f5aa
commit
0eec3251f7
@ -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("你是白痴吗"));
|
||||
}
|
||||
}
|
||||
@ -104,21 +104,6 @@
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
</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>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
|
||||
@ -40,6 +40,11 @@
|
||||
<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>
|
||||
|
||||
@ -21,4 +21,22 @@
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
</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>
|
||||
@ -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")
|
||||
|
||||
@ -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) {
|
||||
|
||||
6
pom.xml
6
pom.xml
@ -34,7 +34,6 @@
|
||||
<mysql-connector.version>8.0.29</mysql-connector.version>
|
||||
<spring-data-commons.version>2.7.5</spring-data-commons.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>
|
||||
<minio.version>8.4.5</minio.version>
|
||||
<jaxb-api.version>2.3.1</jaxb-api.version>
|
||||
@ -124,11 +123,6 @@
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<!-- 阿里云OSS -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>${aliyun-oss.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user