|
|
@ -1,18 +1,22 @@
|
|
|
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
|
|
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.CacheConstant;
|
|
|
|
import com.mashibing.common.constant.CacheConstant;
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.RabbitMQConstant;
|
|
|
|
|
|
|
|
import com.mashibing.common.constant.SMSConstant;
|
|
|
|
|
|
|
|
import com.mashibing.common.enums.ExceptionEnums;
|
|
|
|
|
|
|
|
import com.mashibing.common.exception.StrategyException;
|
|
|
|
|
|
|
|
import com.mashibing.common.pojo.StandardReport;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.common.pojo.StandardSubmit;
|
|
|
|
import com.mashibing.strategy.feignclient.CacheClient;
|
|
|
|
import com.mashibing.strategy.feignclient.CacheClient;
|
|
|
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
|
|
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
|
|
|
import com.mashibing.strategy.utils.DirtyWordTree;
|
|
|
|
import com.mashibing.strategy.utils.DirtyWordTree;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
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.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
@ -30,21 +34,44 @@ public class DFADirtyWordStrategyFilter implements StrategyFilter {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
CacheClient cacheClient;
|
|
|
|
CacheClient cacheClient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void strategy(StandardSubmit submit) {
|
|
|
|
public void strategy(StandardSubmit submit) {
|
|
|
|
log.info("【策略模块-敏感词校验】开始====================================");
|
|
|
|
log.info("【策略模块-敏感词校验】开始====================================");
|
|
|
|
String text = submit.getText();
|
|
|
|
String text = submit.getText();
|
|
|
|
Set<String> set = new HashSet<>();
|
|
|
|
Set<String> set = new HashSet<>();
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】通过敏感词树校验敏感词");
|
|
|
|
log.info("【策略模块-敏感词校验】使用敏感词树校验敏感词");
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
Set<String> result = DirtyWordTree.getDirtyWord(text);
|
|
|
|
Set<String> result = DirtyWordTree.getDirtyWord(text);
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】使用敏感词树校验敏感词耗时:{}ms", end - start);
|
|
|
|
|
|
|
|
|
|
|
|
if (!result.isEmpty()) {
|
|
|
|
if (!result.isEmpty()) {
|
|
|
|
log.error("【策略模块-敏感词校验】短信内容包含敏感词:{}", result);
|
|
|
|
log.error("【策略模块-敏感词校验】短信内容包含敏感词:{}", result);
|
|
|
|
return;
|
|
|
|
submit.setReportState(SMSConstant.REPORT_STATE_FAILED);
|
|
|
|
// throw new RuntimeException("短信内容包含敏感词");
|
|
|
|
submit.setErrorMsg(ExceptionEnums.HAVE_DIRTY_WORD.getMsg() + result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送消息到写日志队列
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConstant.SMS_WRITE_LOG, submit);
|
|
|
|
|
|
|
|
log.error("【策略模块-敏感词校验】发送写日志消息到{}队列,消息:{}", RabbitMQConstant.SMS_WRITE_LOG, submit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送消息到推送状态报告队列
|
|
|
|
|
|
|
|
Integer isCallback = cacheClient.hgetInteger(CacheConstant.CLIENT_BUSINESS + submit.getApikey(), CacheConstant.IS_CALLBACK);
|
|
|
|
|
|
|
|
if (isCallback != null && isCallback == 1) {
|
|
|
|
|
|
|
|
String callbackUrl = cacheClient.hgetString(CacheConstant.CLIENT_BUSINESS + submit.getApikey(), CacheConstant.CALLBACK_URL);
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(callbackUrl)) {
|
|
|
|
|
|
|
|
StandardReport report = new StandardReport();
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(submit, report);
|
|
|
|
|
|
|
|
report.setIsCallback(isCallback);
|
|
|
|
|
|
|
|
report.setCallbackUrl(callbackUrl);
|
|
|
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConstant.SMS_PUSH_REPORT, report);
|
|
|
|
|
|
|
|
log.info("【策略模块-敏感词校验】发送短信状态报告消息到{}队列,消息:{}", RabbitMQConstant.SMS_PUSH_REPORT, report);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new StrategyException(ExceptionEnums.HAVE_DIRTY_WORD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.info("【策略模块-敏感词校验】敏感词校验通过");
|
|
|
|
log.info("【策略模块-敏感词校验】敏感词校验通过");
|
|
|
|
}
|
|
|
|
}
|
|
|
|