package com.changhong.epc.zuul.filter;
|
|
import com.changhong.epc.constter.base.BaseConst;
|
import com.changhong.epc.rely.api.tool.HttpContextTool;
|
import com.changhong.epc.zuul.filter.version.MasterVersion;
|
import com.changhong.epc.zuul.filter.version.NormVersion;
|
import com.changhong.epc.zuul.filter.version.Version;
|
import com.iemsoft.framework.cloud.redis.service.CacheUtils;
|
import com.iemsoft.framework.cloud.zuul.filter.url.UrlFilter;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Collections;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 版本号过滤器
|
*/
|
@Slf4j
|
@Service
|
public class VersionFilter implements UrlFilter, BaseConst {
|
|
protected static final Map<String, Version> VERSION_ENTITY_MAP;
|
|
static {
|
Map<String, Version> version = new HashMap<>(2);
|
/**
|
* 主数据版本控制
|
*/
|
version.put("master", new MasterVersion());
|
|
/**
|
* 补助标准版本控制
|
*/
|
version.put("norm", new NormVersion());
|
|
VERSION_ENTITY_MAP = Collections.unmodifiableMap(version);
|
}
|
|
@Override
|
public void filter(HttpServletRequest request) {
|
log.debug("版本号拦截url:{}", HttpContextTool.getRequestUIR(request));
|
VERSION_ENTITY_MAP.entrySet()
|
.stream()
|
.filter(entityEntry -> HttpContextTool.getRequestUIR(request).endsWith(entityEntry.getValue().getUpdateUrl()))
|
.forEach(entityEntry ->{
|
String key;
|
log.debug("更新版本号:{}", key = entityEntry.getValue().getUpdateKey());
|
CacheUtils.set(key, System.currentTimeMillis(), 0);
|
});
|
}
|
|
public static Version getVersion(String key){
|
return VERSION_ENTITY_MAP.get(key);
|
}
|
|
@Override
|
public String getRegExp() {
|
return ".+";
|
}
|
|
}
|