From a19770bfabe84c5fda129245f3eab4a638fd85cf Mon Sep 17 00:00:00 2001 From: heqijun Date: Tue, 10 Jun 2025 16:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E7=AD=96=E7=95=A5=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E5=A4=B1=E8=B4=A5=E5=90=8E=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=88=B0=E9=98=9F=E5=88=97=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=B0=E5=B7=A5=E5=85=B7=E7=B1=BB=E4=B8=AD=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E5=85=B6=E4=BB=96=E7=AD=96=E7=95=A5=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=B9=9F=E8=83=BD=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DFADirtyWordStrategyFilter.java | 22 ++----- .../utils/StrategyCheckFailedUtil.java | 63 +++++++++++++++++++ 2 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 beacon-strategy/src/main/java/com/mashibing/strategy/utils/StrategyCheckFailedUtil.java diff --git a/beacon-strategy/src/main/java/com/mashibing/strategy/service/strategyfilter/impl/DFADirtyWordStrategyFilter.java b/beacon-strategy/src/main/java/com/mashibing/strategy/service/strategyfilter/impl/DFADirtyWordStrategyFilter.java index ebd99e6..7c863fa 100644 --- a/beacon-strategy/src/main/java/com/mashibing/strategy/service/strategyfilter/impl/DFADirtyWordStrategyFilter.java +++ b/beacon-strategy/src/main/java/com/mashibing/strategy/service/strategyfilter/impl/DFADirtyWordStrategyFilter.java @@ -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("【策略模块-敏感词校验】敏感词校验通过"); diff --git a/beacon-strategy/src/main/java/com/mashibing/strategy/utils/StrategyCheckFailedUtil.java b/beacon-strategy/src/main/java/com/mashibing/strategy/utils/StrategyCheckFailedUtil.java new file mode 100644 index 0000000..4745914 --- /dev/null +++ b/beacon-strategy/src/main/java/com/mashibing/strategy/utils/StrategyCheckFailedUtil.java @@ -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); + } +}