parent
49a871c972
commit
5f5dfcd7c4
@ -0,0 +1,27 @@
|
||||
package com.mashibing.common.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Getter
|
||||
public enum MobileOperatorEnum {
|
||||
|
||||
CHINA_MOBILE(1,"移动"),
|
||||
CHINA_UNICOM(2,"联通"),
|
||||
CHINA_TELECOM(3,"电信"),
|
||||
UNKNOWN(0,"未知");
|
||||
|
||||
private Integer operatorId;
|
||||
|
||||
private String operatorName;
|
||||
|
||||
|
||||
|
||||
MobileOperatorEnum(Integer operatorId, String operatorName) {
|
||||
this.operatorId = operatorId;
|
||||
this.operatorName = operatorName;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.mashibing.common.util;
|
||||
|
||||
import com.mashibing.common.enums.MobileOperatorEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public class OperatorUtil {
|
||||
|
||||
private static Map<String,Integer> operators = new HashMap<>();
|
||||
|
||||
static{
|
||||
MobileOperatorEnum[] operatorEnums = MobileOperatorEnum.values();
|
||||
for (MobileOperatorEnum operatorEnum : operatorEnums) {
|
||||
operators.put(operatorEnum.getOperatorName(),operatorEnum.getOperatorId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过运营商名称获取运营商Id
|
||||
* @param operatorName
|
||||
* @return
|
||||
*/
|
||||
public static Integer getOperatorIdByOperatorName(String operatorName){
|
||||
return operators.get(operatorName);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.mashibing.strategy.config;
|
||||
|
||||
import com.mashibing.common.constant.RabbitMQConstants;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 构建队列&交换机信息
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
/**
|
||||
* 接口模块发送消息到策略模块的队列
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue preSendQueue(){
|
||||
return QueueBuilder.durable(RabbitMQConstants.MOBILE_AREA_OPERATOR).build();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.mashibing.strategy.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.aspectj.apache.bcel.generic.ObjectType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 获取手机号归属地和运营商的工具
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Component
|
||||
public class MobileOperatorUtil {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private final String url1 = "https://cx.shouji.360.cn/phonearea.php?number=";
|
||||
|
||||
private final String CODE = "code";
|
||||
private final String DATA = "data";
|
||||
private final String PROVINCE = "province";
|
||||
private final String CITY = "city";
|
||||
private final String SP = "sp";
|
||||
private final String SPACE = " ";
|
||||
private final String SEPARATE = ",";
|
||||
|
||||
/**
|
||||
* 获取手机号信息
|
||||
* @param mobile 手机号前7位即可
|
||||
* @return
|
||||
*/
|
||||
public String getMobileInfoBy360(String mobile){
|
||||
String url = url1;
|
||||
//1、发送请求获取信息
|
||||
String mobileInfoJSON = restTemplate.getForObject(url + mobile, String.class);
|
||||
// {"code":0,"data":{"province":"\u4e91\u5357","city":"\u6606\u660e","sp":"\u79fb\u52a8"}}
|
||||
//2、解析JSON
|
||||
Map map = null;
|
||||
try {
|
||||
map = objectMapper.readValue(mobileInfoJSON, Map.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Integer code = (Integer) map.get(CODE);
|
||||
if(code != 0){
|
||||
return null;
|
||||
}
|
||||
Map<String, String> areaAndOperator = (Map<String, String>) map.get(DATA);
|
||||
String province = areaAndOperator.get(PROVINCE);
|
||||
String city = areaAndOperator.get(CITY);
|
||||
String sp = areaAndOperator.get(SP);
|
||||
//3、封装为 省 市,运营商 的格式返回
|
||||
return province + SPACE +city + SEPARATE + sp;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.mashibing.test.entity;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public class MobileArea {
|
||||
|
||||
private String mobileNumber;
|
||||
|
||||
private String mobileArea;
|
||||
|
||||
private String mobileType;
|
||||
|
||||
public String getMobileNumber() {
|
||||
return mobileNumber;
|
||||
}
|
||||
|
||||
public void setMobileNumber(String mobileNumber) {
|
||||
this.mobileNumber = mobileNumber;
|
||||
}
|
||||
|
||||
public String getMobileArea() {
|
||||
return mobileArea;
|
||||
}
|
||||
|
||||
public void setMobileArea(String mobileArea) {
|
||||
this.mobileArea = mobileArea;
|
||||
}
|
||||
|
||||
public String getMobileType() {
|
||||
return mobileType;
|
||||
}
|
||||
|
||||
public void setMobileType(String mobileType) {
|
||||
this.mobileType = mobileType;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.entity.ClientBalance;
|
||||
import com.mashibing.test.entity.MobileArea;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface MobileAreaMapper {
|
||||
|
||||
@Select("select mobile_number,mobile_area,mobile_type from mobile_area")
|
||||
List<MobileArea> findAll();
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.entity.MobileArea;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface MobileDirtyWordMapper {
|
||||
|
||||
@Select("select dirtyword from mobile_dirtyword")
|
||||
List<String> findDirtyWord();
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import com.mashibing.test.entity.MobileArea;
|
||||
import org.junit.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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class MobileAreaMapperTest {
|
||||
|
||||
@Autowired
|
||||
private MobileAreaMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
|
||||
@Test
|
||||
public void findAll() {
|
||||
List<MobileArea> list = mapper.findAll();
|
||||
Map map = new HashMap(list.size());
|
||||
for (MobileArea mobileArea : list) {
|
||||
map.put("phase:" + mobileArea.getMobileNumber(),mobileArea.getMobileArea() + "," + mobileArea.getMobileType());
|
||||
}
|
||||
cacheClient.pipelineString(map);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.mashibing.test.mapper;
|
||||
|
||||
import com.mashibing.test.client.CacheClient;
|
||||
import com.mashibing.test.entity.MobileArea;
|
||||
import org.junit.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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class MobileDirtyWordMapperTest {
|
||||
|
||||
@Autowired
|
||||
private MobileDirtyWordMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CacheClient cacheClient;
|
||||
|
||||
|
||||
@Test
|
||||
public void findAll() {
|
||||
List<String> dirtyWords = mapper.findDirtyWord();
|
||||
|
||||
cacheClient.saddStr("dirty_word",dirtyWords.toArray(new String[]{}));
|
||||
}
|
||||
}
|
Loading…
Reference in new issue