Compare commits

...

2 Commits

@ -33,6 +33,9 @@ public interface BeaconCacheClient {
@GetMapping("cache/hgetString/{key}/{field}")
String hgetString(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field);
@GetMapping("cache/hget/{key}/{field}")
Integer hgetInteger(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field);
@PostMapping("cache/hset/{key}")
void hset(@PathVariable String key, @RequestBody Map hash);

@ -31,4 +31,11 @@ public class CacheConstant {
@Description("敏感词key")
public static final String DIRTY_WORD = "dirty_word";
@Description("客户信息-是否需要回调")
public static final String IS_CALLBACK = "isCallback";
@Description("客户信息-回调地址")
public static final String CALLBACK_URL = "callbackUrl";
}

@ -17,4 +17,14 @@ public interface RabbitMQConstant {
*
*/
String MOBILE_AREA_OPERATOR = "mobile_area_operator_topic";
/**
* ES
*/
String SMS_WRITE_LOG = "sms_write_log_topic";
/**
*
*/
String SMS_PUSH_REPORT = "sms_push_report_topic";
}

@ -1,5 +1,7 @@
package com.mashibing.common.constant;
import com.mashibing.common.annotation.Description;
/**
* @author heqijun
* @ClassName: Constant
@ -19,4 +21,13 @@ public class SMSConstant {
public static final Long SINGLE_FEE = 50L;
@Description("短信的发送状态, 0-等待ing1-成功2-失败")
public static final int REPORT_STATE_WAITING = 0;
@Description("短信的发送状态, 0-等待ing1-成功2-失败")
public static final int REPORT_STATE_SUCCESS = 1;
@Description("短信的发送状态, 0-等待ing1-成功2-失败")
public static final int REPORT_STATE_FAILED = 2;
}

@ -0,0 +1,51 @@
package com.mashibing.common.pojo;
import com.mashibing.common.annotation.Description;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author heqijun
* @ClassName: StandardReport
* @Description:
* @date 2025/6/10 15:45
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StandardReport implements Serializable {
@Description("针对当前短信的唯一标识,雪花算法(保留)")
private Long sequenceId;
@Description("客户端ID基于apikey查询缓存模块得到客户的ID")
private Long clientId;
@Description("客户业务内的uid客户请求传递的")
private String uid;
@Description("目标手机号,客户请求传递的")
private String mobile;
@Description("短信的发送时间,当前系统时间")
private LocalDateTime sendTime;
@Description("短信的发送状态, 0-等待/发送ing1-成功2-失败 默认情况就是0")
private int reportState;
@Description("短信发送失败的原因是什么,记录在当前属性")
private String errorMsg;
@Description("是否需要回调")
private Integer isCallback;
@Description("回调url")
private String callbackUrl;
}

@ -17,10 +17,26 @@ import org.springframework.context.annotation.Configuration;
public class RabbitMQConfig {
/**
*
*
*/
@Bean
public Queue preSendQueue() {
return QueueBuilder.durable(RabbitMQConstant.MOBILE_AREA_OPERATOR).build();
}
/**
* ES
*/
@Bean
public Queue writeLogQueue() {
return QueueBuilder.durable(RabbitMQConstant.SMS_WRITE_LOG).build();
}
/**
*
*/
@Bean
public Queue pushReportQueue() {
return QueueBuilder.durable(RabbitMQConstant.SMS_PUSH_REPORT).build();
}
}

@ -36,7 +36,7 @@ public class PreSendListener {
log.info("【策略模块-接收消息】消息消费完毕手动ack");
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
} catch (StrategyException e) {
log.info("【策略模块-接收消息】消息消费失败!!!错误信息:{}", e.getMessage());
log.error("【策略模块-接收消息】消息消费失败!!!错误信息:{}", e.getMessage());
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
}

@ -1,18 +1,23 @@
package com.mashibing.strategy.service.strategyfilter.impl;
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.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;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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;
@ -28,23 +33,33 @@ import java.util.Set;
public class DFADirtyWordStrategyFilter implements StrategyFilter {
@Autowired
CacheClient cacheClient;
StrategyCheckFailedUtil strategyCheckFailedUtil;
private static final String STRATEGY_NAME = "敏感词";
@Override
public void strategy(StandardSubmit submit) {
log.info("【策略模块-敏感词校验】开始====================================");
String text = submit.getText();
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);
long end = System.currentTimeMillis();
log.info("【策略模块-敏感词校验】使用敏感词树校验敏感词耗时:{}ms", end - start);
if (!result.isEmpty()) {
log.error("【策略模块-敏感词校验】短信内容包含敏感词:{}", result);
return;
// throw new RuntimeException("短信内容包含敏感词");
submit.setReportState(SMSConstant.REPORT_STATE_FAILED);
submit.setErrorMsg(ExceptionEnums.HAVE_DIRTY_WORD.getMsg() + result);
//发送消息到写日志队列
strategyCheckFailedUtil.smsSendLog(submit, STRATEGY_NAME);
//发送消息到推送状态报告队列
strategyCheckFailedUtil.smsPushReport(submit, STRATEGY_NAME);
throw new StrategyException(ExceptionEnums.HAVE_DIRTY_WORD);
}
log.info("【策略模块-敏感词校验】敏感词校验通过");
}

@ -21,7 +21,7 @@ public class DirtyWordTree {
static {
//通过SpringUtil获取Spring中的CacheClient对象
CacheClient cacheClient = (CacheClient) StringUtil.getBeanByClass(CacheClient.class);
CacheClient cacheClient = (CacheClient) SpringUtil.getBeanByClass(CacheClient.class);
//调用缓存模块接口获取全部敏感词
Set<String> dirtyWords = cacheClient.smember(CacheConstant.DIRTY_WORD);
//构建敏感词树

@ -13,13 +13,13 @@ import org.springframework.stereotype.Component;
*/
@Component
public class StringUtil implements ApplicationContextAware {
public class SpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
StringUtil.applicationContext = applicationContext;
SpringUtil.applicationContext = applicationContext;
}
public static Object getBeanByName(String beanName) {

@ -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);
}
}

@ -17,4 +17,7 @@ public interface MobileAreaMapper {
@Select("select mobile_number,mobile_area,mobile_type from mobile_area ")
List<MobileArea> findAllMobileArea();
@Select("select mobile_number,mobile_area,mobile_type from mobile_area where mobile_number = #{mobileNumber}")
MobileArea findOneMobileAreaByMobileNumber(@Param("mobileNumber") String mobileNumber);
}

@ -3,6 +3,7 @@ package com.mashibing.test.mapper;
import com.mashibing.test.entity.MobileArea;
import com.mashibing.test.feignClient.CacheClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -42,4 +43,14 @@ class MobileAreaMapperTest {
endTime = System.currentTimeMillis();
log.info("【写入Redis耗时】: {} ms", endTime - startTime);
}
@Test
void findOneMobileAreaByMobileNumber() {
MobileArea mobileArea = mapper.findOneMobileAreaByMobileNumber("1322409");
cacheClient.set("phase:" + mobileArea.getMobileNumber(),
mobileArea.getMobileArea() + "," + mobileArea.getMobileType());
}
}
Loading…
Cancel
Save