parent
51a80b9099
commit
9c0e6cb4e3
@ -0,0 +1,44 @@
|
|||||||
|
package com.mashibing.strategy.feignclient;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: BeaconCacheClient
|
||||||
|
* @Description: 缓存模块openFeignClient接口
|
||||||
|
* @date 2025/6/7 20:16
|
||||||
|
*/
|
||||||
|
|
||||||
|
@FeignClient("beacon-cache")
|
||||||
|
public interface CacheClient {
|
||||||
|
@GetMapping("/cache/get/{key}")
|
||||||
|
String get(@PathVariable String key);
|
||||||
|
|
||||||
|
@GetMapping("/cache/set/{key}/{value}")
|
||||||
|
void set(@PathVariable String key, @PathVariable String value);
|
||||||
|
|
||||||
|
@GetMapping("/cache/hget/{key}")
|
||||||
|
Map hget(@PathVariable String key);
|
||||||
|
|
||||||
|
@GetMapping("/cache/hget/{key}/{field}")
|
||||||
|
Object hget(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field);
|
||||||
|
|
||||||
|
@GetMapping("/cache/hget/{key}/{field}")
|
||||||
|
String hgetString(@PathVariable(value = "key") String key, @PathVariable(value = "field") String field);
|
||||||
|
|
||||||
|
@PostMapping("/cache/hset/{key}")
|
||||||
|
void hset(@PathVariable String key, @RequestBody Map hash);
|
||||||
|
|
||||||
|
@PostMapping("/cache/sadd/{key}")
|
||||||
|
void sadd(@PathVariable(value = "key") String key, @RequestBody Map<String, Object>... maps);
|
||||||
|
|
||||||
|
@PostMapping("/cache/smember/{key}")
|
||||||
|
Set<Map> smember(@PathVariable(value = "key") String key);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter;
|
||||||
|
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: StrategyFilter
|
||||||
|
* @Description: 策略校验父接口
|
||||||
|
* @date 2025/6/7 20:24
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface StrategyFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 策略校验
|
||||||
|
*/
|
||||||
|
void strategy(StandardSubmit standardSubmit);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter;
|
||||||
|
|
||||||
|
import com.mashibing.common.constant.CacheConstant;
|
||||||
|
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.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: StrategyFilterContext
|
||||||
|
* @Description: 策略模块校验链的执行
|
||||||
|
* @date 2025/6/7 20:32
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class StrategyFilterContext {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Map<String, StrategyFilter> strategyFilters;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CacheClient cacheClient;
|
||||||
|
|
||||||
|
private final String CLIENT_FILTERS = "clientFilters";
|
||||||
|
|
||||||
|
public void strategy(StandardSubmit standardSubmit) {
|
||||||
|
String s = cacheClient.hgetString(CacheConstant.CLIENT_BUSINESS + standardSubmit.getApikey(), CLIENT_FILTERS);
|
||||||
|
if (StringUtils.isBlank(s)) {
|
||||||
|
log.info("【策略模块-策略为空】没有校验。。。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] strategyFilterArr = s.split(",");
|
||||||
|
for (String strategyFilter : strategyFilterArr) {
|
||||||
|
StrategyFilter check = strategyFilters.get(strategyFilter);
|
||||||
|
if (check != null) {
|
||||||
|
check.strategy(standardSubmit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
||||||
|
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: BlackStrategyFilter
|
||||||
|
* @Description: 黑名单校验
|
||||||
|
* @date 2025/6/7 20:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service(value = "black")
|
||||||
|
public class BlackStrategyFilter implements StrategyFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strategy(StandardSubmit standardSubmit) {
|
||||||
|
log.info("【策略模块-黑名单校验】。。。");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
||||||
|
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: DirtyWordStrategyFilter
|
||||||
|
* @Description: 敏感词校验
|
||||||
|
* @date 2025/6/7 20:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service(value = "dirtyword")
|
||||||
|
public class DirtyWordStrategyFilter implements StrategyFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strategy(StandardSubmit standardSubmit) {
|
||||||
|
log.info("【策略模块-敏感词校验】。。。");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
||||||
|
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: PhaseStrategyFilter
|
||||||
|
* @Description: 号段补全
|
||||||
|
* @date 2025/6/7 20:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service(value = "phase")
|
||||||
|
public class PhaseStrategyFilter implements StrategyFilter {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strategy(StandardSubmit standardSubmit) {
|
||||||
|
log.info("【策略模块-号段补全】。。。");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.mashibing.strategy.service.strategyfilter.impl;
|
||||||
|
|
||||||
|
import com.mashibing.common.pojo.StandardSubmit;
|
||||||
|
import com.mashibing.strategy.service.strategyfilter.StrategyFilter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: RouteStrategyFilter
|
||||||
|
* @Description: 路由校验
|
||||||
|
* @date 2025/6/7 20:26
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service(value = "route")
|
||||||
|
public class RouteStrategyFilter implements StrategyFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strategy(StandardSubmit standardSubmit) {
|
||||||
|
log.info("【策略模块-路由校验】。。。");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,165 @@
|
|||||||
|
package com.mashibing.test.entity;
|
||||||
|
|
||||||
|
public class MobileArea {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private String mobileNumber;
|
||||||
|
|
||||||
|
private String mobileArea;
|
||||||
|
|
||||||
|
private String mobileType;
|
||||||
|
|
||||||
|
private String areaCode;
|
||||||
|
|
||||||
|
private String postCode;
|
||||||
|
|
||||||
|
private String provinceCode;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAreaCode() {
|
||||||
|
return areaCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAreaCode(String areaCode) {
|
||||||
|
this.areaCode = areaCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPostCode() {
|
||||||
|
return postCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostCode(String postCode) {
|
||||||
|
this.postCode = postCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProvinceCode() {
|
||||||
|
return provinceCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProvinceCode(String provinceCode) {
|
||||||
|
this.provinceCode = provinceCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.mashibing.test.mapper;
|
||||||
|
|
||||||
|
import com.mashibing.test.entity.MobileArea;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: MobileAreaMapper
|
||||||
|
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||||
|
* @date 2025/6/8 14:47
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface MobileAreaMapper {
|
||||||
|
|
||||||
|
@Select("select mobile_number,mobile_area,mobile_type from mobile_area ")
|
||||||
|
List<MobileArea> findAllMobileArea();
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.mashibing.test.mapper;
|
||||||
|
|
||||||
|
import com.mashibing.test.entity.MobileArea;
|
||||||
|
import com.mashibing.test.feignClient.BeaconCacheClient;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
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.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
class MobileAreaMapperTest {
|
||||||
|
@Autowired
|
||||||
|
BeaconCacheClient beaconCacheClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MobileAreaMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findAllMobileArea() {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
List<MobileArea> allMobileArea = mapper.findAllMobileArea();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
log.info("【数据库查询耗时】: {} ms", endTime - startTime);
|
||||||
|
Map<String, String> map = new HashMap<>(allMobileArea.size());
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
allMobileArea.forEach(mobileArea -> {
|
||||||
|
map.put(mobileArea.getMobileNumber(),
|
||||||
|
mobileArea.getMobileArea() + "," + mobileArea.getMobileType());
|
||||||
|
});
|
||||||
|
endTime = System.currentTimeMillis();
|
||||||
|
log.info("【List转Map耗时】: {} ms", endTime - startTime);
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
beaconCacheClient.pipelineString(map);
|
||||||
|
endTime = System.currentTimeMillis();
|
||||||
|
log.info("【写入Redis耗时】: {} ms", endTime - startTime);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue