抽取策略校验失败后发送消息到队列的代码到工具类中,方便其他策略失败也能调用

main
heqijun 3 months ago
parent d9cd915f73
commit a19770bfab

@ -10,6 +10,7 @@ import com.mashibing.common.pojo.StandardSubmit;
import com.mashibing.strategy.feignclient.CacheClient;
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
import com.mashibing.strategy.utils.DirtyWordTree;
import com.mashibing.strategy.utils.StrategyCheckFailedUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@ -32,10 +33,9 @@ import java.util.Set;
public class DFADirtyWordStrategyFilter implements StrategyFilter {
@Autowired
CacheClient cacheClient;
StrategyCheckFailedUtil strategyCheckFailedUtil;
@Autowired
RabbitTemplate rabbitTemplate;
private static final String STRATEGY_NAME = "敏感词";
@Override
public void strategy(StandardSubmit submit) {
@ -55,22 +55,10 @@ public class DFADirtyWordStrategyFilter implements StrategyFilter {
submit.setErrorMsg(ExceptionEnums.HAVE_DIRTY_WORD.getMsg() + result);
//发送消息到写日志队列
rabbitTemplate.convertAndSend(RabbitMQConstant.SMS_WRITE_LOG, submit);
log.error("【策略模块-敏感词校验】发送写日志消息到{}队列,消息:{}", RabbitMQConstant.SMS_WRITE_LOG, submit);
strategyCheckFailedUtil.smsSendLog(submit, STRATEGY_NAME);
//发送消息到推送状态报告队列
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);
}
}
strategyCheckFailedUtil.smsPushReport(submit, STRATEGY_NAME);
throw new StrategyException(ExceptionEnums.HAVE_DIRTY_WORD);
}
log.info("【策略模块-敏感词校验】敏感词校验通过");

@ -0,0 +1,63 @@
package com.mashibing.strategy.utils;
import com.mashibing.common.constant.CacheConstant;
import com.mashibing.common.constant.RabbitMQConstant;
import com.mashibing.common.pojo.StandardReport;
import com.mashibing.common.pojo.StandardSubmit;
import com.mashibing.strategy.feignclient.CacheClient;
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.stereotype.Component;
/**
* @author heqijun
* @ClassName: StrategyCheckFailedUtil
* @Description: mq
* @date 2025/6/10 16:17
*/
@Component
@Slf4j
public class StrategyCheckFailedUtil {
@Autowired
CacheClient cacheClient;
@Autowired
RabbitTemplate rabbitTemplate;
/**
*
*
* @param submit
* @param strategyName
*/
public void smsPushReport(StandardSubmit submit, String strategyName) {
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("【策略模块-{}校验】发送短信状态报告消息到{}队列,消息:{}", strategyName, RabbitMQConstant.SMS_PUSH_REPORT, report);
}
}
}
/**
*
*
* @param submit
* @param strategyName
*/
public void smsSendLog(StandardSubmit submit, String strategyName) {
rabbitTemplate.convertAndSend(RabbitMQConstant.SMS_WRITE_LOG, submit);
log.error("【策略模块-{}校验】发送写日志消息到{}队列,消息:{}", strategyName, RabbitMQConstant.SMS_WRITE_LOG, submit);
}
}
Loading…
Cancel
Save