Compare commits

..

No commits in common. '506bc39114b8747b7be6516b651fd8d4852dc5aa' and '48f03f1bbe5e5150c4f34597bedf27f4bff1c7e7' have entirely different histories.

@ -98,7 +98,7 @@ public class CacheController {
return result;
}
@GetMapping("smember/{key}")
@PostMapping("smember/{key}")
public Set smember(@PathVariable(value = "key") String key) {
log.info("【缓存模块】smember: key = {}", key);
Set value = redisClient.sMembers(key);

@ -52,7 +52,7 @@ public interface BeaconCacheClient {
@PostMapping("cache/sinterstr/{key}/{sinterkey}")
Set<Object> sinterStr(@PathVariable String key, @PathVariable String sinterkey, @RequestBody String... value);
@GetMapping("cache/smember/{key}")
@PostMapping("cache/smember/{key}")
Set smember(@PathVariable String key);
@PostMapping("cache/zadd/{key}/{member}/{score}")

@ -55,10 +55,4 @@ public class CacheConstant {
@Description("小时限流规则前缀")
public static final String LIMIT_HOUR = "limit_hour:";
@Description("通道channel前缀")
public static final String CHANNEL = "channel:";
@Description("客户和通道绑定信息前缀")
public static final String CLIENT_CHANNEL = "client_channel:";
}

@ -27,9 +27,4 @@ public interface RabbitMQConstant {
*
*/
String SMS_PUSH_REPORT = "sms_push_report_topic";
/**
*
*/
String SMS_GATEWAY = "sms_gateway_topic_";
}

@ -11,7 +11,6 @@ import lombok.Getter;
@Getter
public enum ExceptionEnums {
UNKNOWN_ERROR(-999, "未知的错误!!!"),
ERROR_APIKEY(-1, "非法的apikey"),
IP_NOT_WHITE(-2, "请求的ip不在白名单内"),
ERROR_SIGN(-3, "无可用签名"),
@ -26,8 +25,6 @@ public enum ExceptionEnums {
BLACK_CLIENT(-15, "手机号是客户黑名单!!"),
LIMIT_MINUTE(-16, "达到分钟限流阈值!!"),
LIMIT_HOUR(-17, "达到小时限流阈值!!"),
NO_CHANNEL(-18, "没有可用通道!!!"),
;
private final int code;

@ -1,27 +1,10 @@
package com.mashibing.strategy.service.strategyfilter.impl;
import com.mashibing.common.constant.CacheConstant;
import com.mashibing.common.constant.RabbitMQConstant;
import com.mashibing.common.enums.ExceptionEnums;
import com.mashibing.common.exception.StrategyException;
import com.mashibing.common.pojo.StandardSubmit;
import com.mashibing.strategy.feignclient.CacheClient;
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
import com.mashibing.strategy.utils.ChannelTransferUtil;
import com.mashibing.strategy.utils.StrategyCheckFailedUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
* @author heqijun
* @ClassName: RouteStrategyFilter
@ -33,99 +16,8 @@ import java.util.TreeSet;
@Service(value = "route")
public class RouteStrategyFilter implements StrategyFilter {
@Autowired
CacheClient cacheClient;
@Autowired
StrategyCheckFailedUtil strategyCheckFailedUtil;
@Autowired
private AmqpAdmin amqpAdmin;
@Autowired
private RabbitTemplate rabbitTemplate;
private static final String STRATEGY_NAME = "路由";
@Override
public void strategy(StandardSubmit submit) {
log.info("【策略模块-路由策略】开始====================================");
//1、拿到客户id
Long clientId = submit.getClientId();
//2、基于redis获取当前客户绑定的所有通道信息
Set<Map> clientChannels = cacheClient.smember(CacheConstant.CLIENT_CHANNEL + clientId);
//3、将获取到的客户通道信息根据权重做好排序
TreeSet<Map> clientWeightChannels = new TreeSet<>(new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
int o1Weight = Integer.parseInt(o1.get("clientChannelWeight") + "");
int o2Weight = Integer.parseInt(o2.get("clientChannelWeight") + "");
return o2Weight - o1Weight;
}
});
clientWeightChannels.addAll(clientChannels);
boolean ok = false;
Map channel = null;
Map clientChannel = null;
//4、基于排好序的通道选择权重更高的
for (Map clientWeightChannel : clientWeightChannels) {
//5、如果客户和通道的绑定关系可用直接去基于Redis查询具体的通道信息
if ((int) (clientWeightChannel.get("isAvailable")) != 0) {
// 当前关系不可用,直接进行下次循环,选择权重相对更低一点的
continue;
}
//6、如果通道信息查询后判断通道睡否可用其次运营商可以匹配。
channel = cacheClient.hget(CacheConstant.CHANNEL + clientWeightChannel.get("channelId"));
if ((int) (channel.get("isAvailable")) != 0) {
// 当前通道不可用,选择权重更低的通道~
continue;
}
// 获取通道的通讯方式
Integer channelType = (Integer) channel.get("channelType");
if (channelType != 0 && submit.getOperatorId() != channelType) {
// 通道不是全网通,并且和当前手机号运营商不匹配
continue;
}
//7、如果后期涉及到的通道的转换这里留一个口子
Map transferChannel = ChannelTransferUtil.transfer(submit, channel);
// 找到可以使用的通道了
ok = true;
clientChannel = clientWeightChannel;
break;
}
if (!ok) {
log.info("【策略模块-路由策略】没有选择到可用的通道!!");
submit.setErrorMsg(ExceptionEnums.NO_CHANNEL.getMsg());
strategyCheckFailedUtil.smsSendLog(submit, STRATEGY_NAME);
strategyCheckFailedUtil.smsPushReport(submit, STRATEGY_NAME);
throw new StrategyException(ExceptionEnums.NO_CHANNEL);
}
//8、基于选择的通道封装submit的信息
submit.setChannelId(Long.parseLong(channel.get("id") + ""));
submit.setSrcNumber("" + channel.get("channelNumber") + clientChannel.get("clientChannelNumber"));
try {
//9、声明好队列名称并构建队列
String queueName = RabbitMQConstant.SMS_GATEWAY + submit.getChannelId();
amqpAdmin.declareQueue(QueueBuilder.durable(queueName).build());
//10、发送消息到声明好的队列中
rabbitTemplate.convertAndSend(queueName, submit);
} catch (AmqpException e) {
log.error("【策略模块-路由策略】声明通道对应队列以及发送消息时出现了问题!");
submit.setErrorMsg(e.getMessage());
strategyCheckFailedUtil.smsSendLog(submit, STRATEGY_NAME);
strategyCheckFailedUtil.smsPushReport(submit, STRATEGY_NAME);
throw new StrategyException(ExceptionEnums.UNKNOWN_ERROR.getCode(), e.getMessage());
}
log.info("【策略模块-路由策略】路由完毕!!!");
log.info("【策略模块-路由校验】。。。");
}
}

@ -1,27 +0,0 @@
package com.mashibing.strategy.utils;
import com.mashibing.common.pojo.StandardSubmit;
import java.util.Map;
/**
* @author heqijun
* @ClassName: ChannelTransferUtil
* @Description:
* @date 2025/6/11 19:34
*/
public class ChannelTransferUtil {
/**
*
*
* @param submit submit
* @param channel
* @return
*/
public static Map transfer(StandardSubmit submit, Map channel) {
return channel;
}
}

@ -73,6 +73,7 @@ public class DirtyWordTree {
*/
public static Set<String> getDirtyWord(String text) {
//拿到敏感词树
Map currentMap;
Set<String> result = new HashSet<>();

@ -1,227 +0,0 @@
package com.mashibing.test.entity;
public class Channel {
private long id;
private String channelName;
private long channelType;
private String channelArea;
private String channelAreaCode;
private long channelPrice;
private long channelProtocal;
private String channelIp;
private long channelPort;
private String channelUsername;
private String channelPassword;
private String channelNumber;
private long isAvailable;
private java.sql.Timestamp created;
private long createId;
private java.sql.Timestamp updated;
private long updateId;
private long isDelete;
private String extend1;
private String extend2;
private String extend3;
private String extend4;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getChannelName() {
return channelName;
}
public void setChannelName(String channelName) {
this.channelName = channelName;
}
public long getChannelType() {
return channelType;
}
public void setChannelType(long channelType) {
this.channelType = channelType;
}
public String getChannelArea() {
return channelArea;
}
public void setChannelArea(String channelArea) {
this.channelArea = channelArea;
}
public String getChannelAreaCode() {
return channelAreaCode;
}
public void setChannelAreaCode(String channelAreaCode) {
this.channelAreaCode = channelAreaCode;
}
public long getChannelPrice() {
return channelPrice;
}
public void setChannelPrice(long channelPrice) {
this.channelPrice = channelPrice;
}
public long getChannelProtocal() {
return channelProtocal;
}
public void setChannelProtocal(long channelProtocal) {
this.channelProtocal = channelProtocal;
}
public String getChannelIp() {
return channelIp;
}
public void setChannelIp(String channelIp) {
this.channelIp = channelIp;
}
public long getChannelPort() {
return channelPort;
}
public void setChannelPort(long channelPort) {
this.channelPort = channelPort;
}
public String getChannelUsername() {
return channelUsername;
}
public void setChannelUsername(String channelUsername) {
this.channelUsername = channelUsername;
}
public String getChannelPassword() {
return channelPassword;
}
public void setChannelPassword(String channelPassword) {
this.channelPassword = channelPassword;
}
public String getChannelNumber() {
return channelNumber;
}
public void setChannelNumber(String channelNumber) {
this.channelNumber = channelNumber;
}
public long getIsAvailable() {
return isAvailable;
}
public void setIsAvailable(long isAvailable) {
this.isAvailable = isAvailable;
}
public java.sql.Timestamp getCreated() {
return created;
}
public void setCreated(java.sql.Timestamp created) {
this.created = created;
}
public long getCreateId() {
return createId;
}
public void setCreateId(long createId) {
this.createId = createId;
}
public java.sql.Timestamp getUpdated() {
return updated;
}
public void setUpdated(java.sql.Timestamp updated) {
this.updated = updated;
}
public long getUpdateId() {
return updateId;
}
public void setUpdateId(long updateId) {
this.updateId = updateId;
}
public long getIsDelete() {
return isDelete;
}
public void setIsDelete(long isDelete) {
this.isDelete = isDelete;
}
public String getExtend1() {
return extend1;
}
public void setExtend1(String extend1) {
this.extend1 = extend1;
}
public String getExtend2() {
return extend2;
}
public void setExtend2(String extend2) {
this.extend2 = extend2;
}
public String getExtend3() {
return extend3;
}
public void setExtend3(String extend3) {
this.extend3 = extend3;
}
public String getExtend4() {
return extend4;
}
public void setExtend4(String extend4) {
this.extend4 = extend4;
}
}

@ -1,167 +0,0 @@
package com.mashibing.test.entity;
public class ClientChannel {
private long id;
private long clientId;
private long channelId;
private long clientChannelWeight;
private long clientChannelPrice;
private String clientChannelNumber;
private long isAvailable;
private java.sql.Timestamp created;
private long createId;
private java.sql.Timestamp updated;
private long updateId;
private long isDelete;
private String extend1;
private String extend2;
private String extend3;
private String extend4;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getClientId() {
return clientId;
}
public void setClientId(long clientId) {
this.clientId = clientId;
}
public long getChannelId() {
return channelId;
}
public void setChannelId(long channelId) {
this.channelId = channelId;
}
public long getClientChannelWeight() {
return clientChannelWeight;
}
public void setClientChannelWeight(long clientChannelWeight) {
this.clientChannelWeight = clientChannelWeight;
}
public long getClientChannelPrice() {
return clientChannelPrice;
}
public void setClientChannelPrice(long clientChannelPrice) {
this.clientChannelPrice = clientChannelPrice;
}
public String getClientChannelNumber() {
return clientChannelNumber;
}
public void setClientChannelNumber(String clientChannelNumber) {
this.clientChannelNumber = clientChannelNumber;
}
public long getIsAvailable() {
return isAvailable;
}
public void setIsAvailable(long isAvailable) {
this.isAvailable = isAvailable;
}
public java.sql.Timestamp getCreated() {
return created;
}
public void setCreated(java.sql.Timestamp created) {
this.created = created;
}
public long getCreateId() {
return createId;
}
public void setCreateId(long createId) {
this.createId = createId;
}
public java.sql.Timestamp getUpdated() {
return updated;
}
public void setUpdated(java.sql.Timestamp updated) {
this.updated = updated;
}
public long getUpdateId() {
return updateId;
}
public void setUpdateId(long updateId) {
this.updateId = updateId;
}
public long getIsDelete() {
return isDelete;
}
public void setIsDelete(long isDelete) {
this.isDelete = isDelete;
}
public String getExtend1() {
return extend1;
}
public void setExtend1(String extend1) {
this.extend1 = extend1;
}
public String getExtend2() {
return extend2;
}
public void setExtend2(String extend2) {
this.extend2 = extend2;
}
public String getExtend3() {
return extend3;
}
public void setExtend3(String extend3) {
this.extend3 = extend3;
}
public String getExtend4() {
return extend4;
}
public void setExtend4(String extend4) {
this.extend4 = extend4;
}
}

@ -1,22 +0,0 @@
package com.mashibing.test.mapper;
import com.mashibing.test.entity.Channel;
import com.mashibing.test.entity.ClientBalance;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author heqijun
* @ClassName: ChannelMapper
* @Description: TODO()
* @date 2025/6/11 18:11
*/
public interface ChannelMapper {
@Select("select * from channel where is_delete = 0")
List<Channel> findAll();
}

@ -1,22 +0,0 @@
package com.mashibing.test.mapper;
import com.mashibing.test.entity.Channel;
import com.mashibing.test.entity.ClientBusiness;
import com.mashibing.test.entity.ClientChannel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author heqijun
* @ClassName: ClientChannelMapper
* @Description: TODO()
* @date 2025/6/11 18:20
*/
public interface ClientChannelMapper {
@Select("select * from client_channel where is_delete = 0")
List<ClientChannel> findAll();
}

@ -1,38 +0,0 @@
package com.mashibing.test.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.mashibing.test.entity.Channel;
import com.mashibing.test.feignClient.CacheClient;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@RunWith(SpringRunner.class)
class ChannelMapperTest {
@Autowired
CacheClient cacheClient;
@Autowired
ChannelMapper mapper;
@Test
void findAll() throws JsonProcessingException {
List<Channel> channelList = mapper.findAll();
ObjectMapper objectMapper = new ObjectMapper();
for (Channel channel : channelList) {
Map map = objectMapper.readValue(objectMapper.writeValueAsString(channel), Map.class);
cacheClient.hset("channel:" + channel.getId(), map);
}
}
}

@ -1,37 +0,0 @@
package com.mashibing.test.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashibing.test.entity.ClientChannel;
import com.mashibing.test.feignClient.CacheClient;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@RunWith(SpringRunner.class)
class ClientChannelMapperTest {
@Autowired
CacheClient cacheClient;
@Autowired
ClientChannelMapper mapper;
@Test
void findAll() throws JsonProcessingException {
List<ClientChannel> clientChannelList = mapper.findAll();
ObjectMapper objectMapper = new ObjectMapper();
for (ClientChannel clientChannel : clientChannelList) {
Map map = objectMapper.readValue(objectMapper.writeValueAsString(clientChannel), Map.class);
cacheClient.sadd("client_channel:" + clientChannel.getClientId(), map);
}
}
}
Loading…
Cancel
Save