Skip to content

Commit

Permalink
fix:优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zongzibinbin committed Oct 10, 2023
1 parent 5f15e1f commit 0eec325
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 41 deletions.
14 changes: 14 additions & 0 deletions mallchat-chat-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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;
Expand All @@ -11,7 +11,7 @@
public class SensitiveWordConfig {

@Autowired
private MyWordDeny myWordDeny;
private MyWordFactory myWordFactory;

/**
* 初始化引导类
Expand All @@ -23,7 +23,7 @@ public class SensitiveWordConfig {
public SensitiveWordBs sensitiveWordBs() {
return SensitiveWordBs.newInstance()
.filterStrategy(DFAFilter.getInstance())
.sensitiveWord(myWordDeny)
.sensitiveWord(myWordFactory)
.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* @author zhaoyuhang
* @date 2023/07/09
*/
public interface IWordDeny {
public interface IWordFactory {
/**
* 获取结果
* 返回敏感词数据源
*
* @return 结果
* @since 0.0.13
*/
List<String> deny();
List<String> getWordList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private SensitiveWordBs() {
/**
* 敏感词列表
*/
private IWordDeny wordDeny;
private IWordFactory wordDeny;

public static SensitiveWordBs newInstance() {
return new SensitiveWordBs();
Expand All @@ -40,7 +40,7 @@ public static SensitiveWordBs newInstance() {
*/
public SensitiveWordBs init() {

List<String> words = wordDeny.deny();
List<String> words = wordDeny.getWordList();
loadWord(words);
return this;
}
Expand All @@ -60,11 +60,11 @@ public SensitiveWordBs filterStrategy(SensitiveWordFilter filter) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,12 +10,12 @@
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)
Expand Down
2 changes: 1 addition & 1 deletion mallchat-chat-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mybatis-plus:
spring:
profiles:
#运行的环境
active: my-prod
active: my-test
application:
name: mallchat
datasource:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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("你是白痴吗"));
}
}
15 changes: 0 additions & 15 deletions mallchat-tools/mallchat-common-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions mallchat-tools/mallchat-frequency-control/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 18 additions & 0 deletions mallchat-tools/mallchat-oss-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public boolean bucketExists(String bucketName) {
public void makeBucket(String bucketName) {
if (!bucketExists(bucketName)) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());

}
}

Expand All @@ -80,7 +79,7 @@ public void removeBucket(String bucketName) {
}

/**
* 返回临时带签名、过期时间一天、Get请求方式的访问URL
* 返回临时带签名、过期时间一天、PUT请求方式的访问URL
*/
@SneakyThrows
public OssResp getPreSignedObjectUrl(OssReq req) {
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 0eec325

Please sign in to comment.