init
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.houbb.heaven.support.handler.IHandler;
|
||||
import com.github.houbb.heaven.util.util.CollectionUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordAllow;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class MyDdWordAllow implements IWordAllow {
|
||||
|
||||
@Autowired
|
||||
private WordService wordService;
|
||||
|
||||
@Override
|
||||
public List<String> allow() {
|
||||
List<Word> wordList = wordService.list(Wrappers.lambdaQuery(Word.class)
|
||||
.select(Word::getWord)
|
||||
.eq(Word::getEnableStatus,1)
|
||||
.eq(Word::getType, 1));
|
||||
return CollectionUtil.toList(wordList, new IHandler<Word, String>() {
|
||||
@Override
|
||||
public String handle(Word word) {
|
||||
return word.getWord();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.houbb.heaven.support.handler.IHandler;
|
||||
import com.github.houbb.heaven.util.util.CollectionUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import com.ruoyi.sensitive.domain.Word;
|
||||
import com.ruoyi.sensitive.service.WordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Component
|
||||
public class MyDdWordDeny implements IWordDeny {
|
||||
|
||||
@Autowired
|
||||
private WordService wordService;
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
List<Word> wordList = wordService.list(Wrappers.lambdaQuery(Word.class)
|
||||
.select(Word::getWord)
|
||||
.eq(Word::getEnableStatus,1)
|
||||
.eq(Word::getType, 2));
|
||||
|
||||
return CollectionUtil.toList(wordList, new IHandler<Word, String>() {
|
||||
@Override
|
||||
public String handle(Word word) {
|
||||
return word.getWord();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.ruoyi.sensitive.cache.LastUpdateTimeCache;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MySensitiveWordScheduleRefresh {
|
||||
|
||||
@Autowired
|
||||
private SensitiveWordBs sensitiveWordBs;
|
||||
@Autowired
|
||||
private LastUpdateTimeCache cache;
|
||||
|
||||
@Scheduled(fixedDelay = 20,timeUnit = TimeUnit.SECONDS)
|
||||
public void job(){
|
||||
try {
|
||||
LocalDateTime time = cache.getUpdateTime();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if(time == null || time.isBefore(now)){
|
||||
return;
|
||||
}
|
||||
refresh();
|
||||
} catch (Exception e) {
|
||||
log.error("MySensitiveWordScheduleRefresh meet ex", e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
sensitiveWordBs.init();
|
||||
cache.setRefreshTime();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.ruoyi.sensitive.config;
|
||||
|
||||
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||
import com.github.houbb.sensitive.word.support.allow.WordAllows;
|
||||
import com.github.houbb.sensitive.word.support.deny.WordDenys;
|
||||
import com.ruoyi.sensitive.cache.SensitiveWordConfigCache;
|
||||
import com.ruoyi.sensitive.dto.SensitiveConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author binbin.hou
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class SensitiveWordConfig {
|
||||
|
||||
@Autowired
|
||||
private MyDdWordAllow myDdWordAllow;
|
||||
|
||||
@Autowired
|
||||
private MyDdWordDeny myDdWordDeny;
|
||||
@Autowired
|
||||
private SensitiveWordConfigCache sensitiveWordConfigCache;
|
||||
|
||||
/**
|
||||
* 初始化引导类
|
||||
* @return 初始化引导类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Bean
|
||||
public SensitiveWordBs sensitiveWordBs() {
|
||||
SensitiveConfig sensitiveConfig = sensitiveWordConfigCache.getConfig();
|
||||
if(sensitiveConfig == null){
|
||||
sensitiveConfig = new SensitiveConfig();
|
||||
}
|
||||
return SensitiveWordBs.newInstance()
|
||||
.wordAllow(WordAllows.chains(WordAllows.defaults(), myDdWordAllow))
|
||||
.wordDeny(WordDenys.chains(WordDenys.defaults(), myDdWordDeny))
|
||||
// 各种其他配置
|
||||
.ignoreCase(sensitiveConfig.isIgnoreCase())
|
||||
.ignoreWidth(sensitiveConfig.isIgnoreWidth())
|
||||
.ignoreNumStyle(sensitiveConfig.isIgnoreNumStyle())
|
||||
.ignoreChineseStyle(sensitiveConfig.isIgnoreChineseStyle())
|
||||
.ignoreEnglishStyle(sensitiveConfig.isIgnoreEnglishStyle())
|
||||
.ignoreRepeat(sensitiveConfig.isIgnoreRepeat())
|
||||
.enableNumCheck(sensitiveConfig.isEnableNumCheck())
|
||||
.enableEmailCheck(sensitiveConfig.isEnableEmailCheck())
|
||||
.enableUrlCheck(sensitiveConfig.isEnableUrlCheck())
|
||||
.enableWordCheck(sensitiveConfig.isEnableWordCheck())
|
||||
.numCheckLen(sensitiveConfig.getNumCheckLen())
|
||||
.init();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user