实现策略模块号段补全功能

main
heqijun 4 months ago
parent 7f38c0bf75
commit af29eb818c

@ -25,4 +25,7 @@ public class CacheConstant {
@Description("客户信息ip白名单ipAddress")
public static final String CLIENT_BUSINESS_IPADDRESS = "ipAddress";
@Description("号段前缀")
public static final String PHASE = "phase:";
}

@ -12,4 +12,9 @@ public interface RabbitMQConstant {
*
*/
String SMS_PRE_SEND = "sms_pre_send_topic";
/**
*
*/
String MOBILE_AREA_OPERATOR = "mobile_area_operator_topic";
}

@ -0,0 +1,21 @@
package com.mashibing.strategy.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
* @author heqijun
* @ClassName: RestTemplateConfig
* @Description: TODO()
* @date 2025/6/8 16:33
*/
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

@ -35,8 +35,8 @@ public class PreSendListener {
log.info("【策略模块-接收消息】消息消费完毕手动ack");
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
} catch (IOException e) {
e.printStackTrace();
log.info("【策略模块-接收消息】消息消费失败!!!!!!!");
e.printStackTrace();
}
}
}

@ -0,0 +1,31 @@
package com.mashibing.strategy.pojo;
import com.mashibing.common.annotation.Description;
import lombok.Data;
/**
* @author heqijun
* @ClassName: PhasePOJO
* @Description: TODO()
* @date 2025/6/8 16:39
*/
@Data
public class PhasePojo {
@Description("目标手机号的运营商id")
private Integer operatorId;
@Description("目标手机号的运营商na")
private String operatorNa;
@Description("目标手机号的归属地 哈尔滨, 绥化~")
private String area;
public PhasePojo unknown() {
this.operatorId = 0;
this.operatorNa = "未知";
this.area = "未知 未知";
return this;
}
}

@ -1,9 +1,16 @@
package com.mashibing.strategy.service.strategyfilter.impl;
import com.mashibing.common.constant.CacheConstant;
import com.mashibing.common.pojo.StandardSubmit;
import com.mashibing.strategy.feignclient.CacheClient;
import com.mashibing.strategy.pojo.PhasePojo;
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
import com.mashibing.strategy.utils.PhaseUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
/**
* @author heqijun
@ -16,11 +23,32 @@ import org.springframework.stereotype.Service;
@Service(value = "phase")
public class PhaseStrategyFilter implements StrategyFilter {
@Autowired
private CacheClient cacheClient;
@Autowired
private RestTemplate restTemplate;
@Override
public void strategy(StandardSubmit standardSubmit) {
log.info("【策略模块-号段补全】。。。");
log.info("【策略模块-号段补全】开始===============================");
String mobile7 = standardSubmit.getMobile().substring(0, 7);
//缓存中查询号段。如果查询不到,则在三方接口中查询
String s = cacheClient.get(CacheConstant.PHASE + mobile7);
PhasePojo phasePojo = new PhasePojo();
if (StringUtils.isBlank(s)) {
log.info("【策略模块-号段补全】缓存中未查询到信息,需要三方查询。。。");
phasePojo = PhaseUtil.phaseMobile360(restTemplate, mobile7);
log.info("【策略模块-号段补全】三方查询结果:{}", phasePojo);
} else {
log.info("【策略模块-号段补全】缓存中查询到信息:{}", s);
String[] split = s.split(",");
phasePojo.setArea(split[0]);
phasePojo.setOperatorNa(split[1]);
}
//查询到号段之后补全standardSubmit中运营商信息
standardSubmit.setArea(phasePojo.getArea());
standardSubmit.setOperatorId(PhaseUtil.getOperatorId(phasePojo.getOperatorNa()));
log.info("【策略模块-号段补全】结束===============================");
}
}

@ -0,0 +1,101 @@
package com.mashibing.strategy.utils;
import com.alibaba.nacos.common.utils.MapUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mashibing.common.annotation.Description;
import com.mashibing.strategy.pojo.PhasePojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
/**
* @author heqijun
* @ClassName: PhaseUtil
* @Description:
* @date 2025/6/8 16:24
*/
@Slf4j
public class PhaseUtil {
private final static String URL1 = "https://cx.shouji.360.cn/phonearea.php?number=";
public static PhasePojo phaseMobile360(RestTemplate restTemplate, String mobile7) {
Map map;
//调360的接口获取结果
//坑爹接口返回的居然是text不是json
String s = restTemplate.getForObject(URL1 + mobile7, String.class);
//String转map
ObjectMapper objectMapper = new ObjectMapper();
try {
map = objectMapper.readValue(s, Map.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
if (MapUtils.isEmpty(map)) {
return new PhasePojo().unknown();
}
Phase360 phase360 = objectMapper.convertValue(map.get("data"), Phase360.class);
if (phase360 == null||StringUtils.isBlank(phase360.getProvince())) {
return new PhasePojo().unknown();
}
// 处理直辖市
if (StringUtils.isBlank(phase360.getCity())) {
phase360.setCity(phase360.getProvince());
}
PhasePojo phasePojo = new PhasePojo();
phasePojo.setArea(phase360.getProvince() + " " + phase360.getCity());
phasePojo.setOperatorNa(phase360.getSp());
return phasePojo;
}
public static Integer getOperatorId(String operatorNa) {
if ("移动".equals(operatorNa)) {
return 1;
}
if ("联通".equals(operatorNa)) {
return 2;
}
if ("电信".equals(operatorNa)) {
return 3;
}
return 0;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class Phase360 {
@Description("运营商id")
private int operatorId;
@Description("运营商名称")
private String sp;
@Description("号码归属地省")
private String province;
@Description("号码归属地市")
private String city;
public Phase360 unknuwn() {
this.operatorId = 0;
this.sp = "未知";
this.province = "未知";
this.city = "未知";
return this;
}
}
}

@ -34,7 +34,7 @@ class MobileAreaMapperTest {
Map<String, String> map = new HashMap<>(allMobileArea.size());
startTime = System.currentTimeMillis();
allMobileArea.forEach(mobileArea -> {
map.put(mobileArea.getMobileNumber(),
map.put("phase:" + mobileArea.getMobileNumber(),
mobileArea.getMobileArea() + "," + mobileArea.getMobileType());
});
endTime = System.currentTimeMillis();

Loading…
Cancel
Save