@Data
public class TagV2MatchContext {
private TagV2MatchInfo matchInfo;
private TagV2InterfaceInfo interfaceInfo;
private TagV2ReturnValue returnValue;
private UserRequestContext userRequestContext;
public static TagV2MatchContext from(RealtimeTagValue realtimeTagValue, RealtimeTagInfo realtimeTagInfo, UserRequestContext requestContext) {
TagV2InterfaceInfo interfaceInfo = TagV2InterfaceInfo.form(realtimeTagInfo);
TagV2MatchInfo matchInfo = TagV2MatchInfo.from(realtimeTagValue);
TagV2MatchContext context = new TagV2MatchContext();
context.setInterfaceInfo(interfaceInfo);
context.setMatchInfo(matchInfo);
context.setUserRequestContext(requestContext);
return context;
}
}
TagV2MatchContext(matchInfo=TagV2MatchInfo(category=addNumbers, tagValue=5,7,9,15,21, extValue={"matchType":"4","vipRuleOptionValue":""}, matchType=4, hasRuleOption=false, ruleOption=null), interfaceInfo=TagV2InterfaceInfo(tagName=addNumbers, tagZhName=整型数组, interfaceProvider=, interfaceExtInfo={"signStrategy":"","timeout":"100"}, interfaceProtocol=INTERNAL, interfaceAddress=UserRequestContext.bizParamMap.addNumbers, interfaceType=NUMBER[]), returnValue=null, userRequestContext=UserRequestContext(userId=2087321718, deviceId=868610049930933, rewriteDeviceIdAlready=false, deviceInfo=null, brand=null, myOppoAppVersion=700, country=null, push=false, isClientSupportSigning=false, phoneModel=PDEM30, categoryInternalMap={"addNumbers":[5,15]}, bizParamMap={"addNumbers":[5,15]}, getBrandFromOnlineDeviceIfAbsent=true, getDeviceIdFromOnlineDeviceIfAbsent=true, sourcePackage=null, requestScopeObjectHolder=RequestScopeObjectHolder{}, requestSource=null, osVersion=null, payInfo=null, themeVouContext=null, version=null, transactionId=null, udid=null, vaid=null, aaid=null, oaid=null, userGroupId=5001040, hardwareType=null))
interfaceAddress=UserRequestContext.bizParamMap.addNumbers
public static final ConcurrentHashMap<Class<?>, BeanResolver> RESOLVER_MAP = new ConcurrentHashMap<>();
private Object getValue(TagV2MatchContext matchContext, String interfaceAddress) {
Iterator<String> propChain = Arrays.stream(interfaceAddress.split("[.]")).iterator();
if (!propChain.hasNext()) {
throw new IllegalArgumentException("配置错误,interfaceAddress 格式错误");
}
Object root;
String rootName = propChain.next();
if (REQUEST_CONTEXT.equalsIgnoreCase(rootName)) {
root = RequestContextManager.get();
} else if (USER_REQUEST_CONTEXT.equalsIgnoreCase(rootName)) {
root = matchContext.getUserRequestContext();
} else {
throw new IllegalArgumentException("配置错误,interfaceAddress 不支持此配置 " + rootName);
}
log.debug("interfaceAddress:{} root:{} ", interfaceAddress, root);
return getValue(root, propChain);
}
private Object getValue(Object object, Iterator<String> propChain) {
BeanResolver beanResolver;
while (propChain.hasNext() && object != null) {
String propName = propChain.next();
beanResolver = RESOLVER_MAP.computeIfAbsent(object.getClass(), BeanResolver::newInstance);
object = beanResolver.get(object, propName);
}
return object;
}