|
|
@ -1,9 +1,19 @@
|
|
|
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
|
|
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.CacheConstant;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
|
|
|
|
import com.mashibing.strategy.feignclient.CacheClient;
|
|
|
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
|
|
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.wltea.analyzer.core.IKSegmenter;
|
|
|
|
|
|
|
|
import org.wltea.analyzer.core.Lexeme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author heqijun
|
|
|
|
* @author heqijun
|
|
|
@ -16,8 +26,41 @@ import org.springframework.stereotype.Service;
|
|
|
|
@Service(value = "dirtyword")
|
|
|
|
@Service(value = "dirtyword")
|
|
|
|
public class DirtyWordStrategyFilter implements StrategyFilter {
|
|
|
|
public class DirtyWordStrategyFilter implements StrategyFilter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
CacheClient cacheClient;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void strategy(StandardSubmit standardSubmit) {
|
|
|
|
public void strategy(StandardSubmit submit) {
|
|
|
|
log.info("【策略模块-敏感词校验】。。。");
|
|
|
|
log.info("【策略模块-敏感词校验】开始====================================");
|
|
|
|
|
|
|
|
Set<String> set = new HashSet<>();
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
StringReader reader = new StringReader(submit.getText());
|
|
|
|
|
|
|
|
IKSegmenter ik = new IKSegmenter(reader, false);
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】分词器读取短信耗时:{}ms", end - start);
|
|
|
|
|
|
|
|
Lexeme lexeme = null;
|
|
|
|
|
|
|
|
start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
lexeme = ik.next();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("【策略模块-敏感词校验】IK分词器处理短信内容异常" + "\n e={}", e.getMessage());
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lexeme == null) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
set.add(lexeme.getLexemeText());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】分词耗时:{}ms", end - start);
|
|
|
|
|
|
|
|
//交集
|
|
|
|
|
|
|
|
Set<Object> result = cacheClient.sinterStr(submit.getSequenceId().toString(), CacheConstant.DIRTY_WORD, set.toArray(new String[0]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result != null && !result.isEmpty()) {
|
|
|
|
|
|
|
|
log.error("【策略模块-敏感词校验】短信内容包含敏感词:{}", result);
|
|
|
|
|
|
|
|
throw new RuntimeException("短信内容包含敏感词");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】敏感词校验通过");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|