mirror of
https://gitee.com/freshday/radar.git
synced 2026-03-22 12:47:16 +08:00
在配置抽象处理时,如果搜索字段或统计字段选择了预处理字段,在测试的时候就会报错 feihu wang
This commit is contained in:
@@ -14,6 +14,7 @@ import com.pgmmers.radar.service.engine.vo.AdaptationResult;
|
||||
import com.pgmmers.radar.service.engine.vo.HitObject;
|
||||
import com.pgmmers.radar.service.engine.vo.RiskObject;
|
||||
import com.pgmmers.radar.service.impl.dnn.EstimatorContainer;
|
||||
import com.pgmmers.radar.service.impl.util.JsonParserUtil;
|
||||
import com.pgmmers.radar.service.model.AbstractionService;
|
||||
import com.pgmmers.radar.service.model.ActivationService;
|
||||
import com.pgmmers.radar.service.model.DataListsService;
|
||||
@@ -149,6 +150,9 @@ public class AntiFraudEngineImpl implements AntiFraudEngine {
|
||||
Object searchFieldVal = data.get("fields").get(searchField);
|
||||
if (searchFieldVal == null) {
|
||||
searchFieldVal = data.get("preItems").get(searchField);
|
||||
if (searchFieldVal == null) {
|
||||
searchFieldVal = JsonParserUtil.value(data.get("preItems"), searchField, null);
|
||||
}
|
||||
}
|
||||
if (searchFieldVal == null) {
|
||||
result.setMsg("search field value eq null!");
|
||||
@@ -168,8 +172,11 @@ public class AntiFraudEngineImpl implements AntiFraudEngine {
|
||||
}
|
||||
}
|
||||
if (functionFieldType == null) {
|
||||
result.setMsg("function field type is null");
|
||||
return result;
|
||||
// 如果field字段里面没有改字段,因为预处理字段没有字段类型,暂时设置为String
|
||||
// TODO: 目前只有高级函数使用了 functionFieldType。
|
||||
//result.setMsg("function field type is null");
|
||||
//return result;
|
||||
functionFieldType = FieldType.valueOf("STRING");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.pgmmers.radar.service.impl.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* @author 爱好者提供.
|
||||
* @since 2020-10-18
|
||||
*/
|
||||
public class JsonParserUtil {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(JsonParserUtil.class);
|
||||
|
||||
private static final String AQL_SEPARATOR = ".";
|
||||
|
||||
/**
|
||||
* 获取方法链的值
|
||||
*/
|
||||
public static JSONObject jsonObject(JSONObject json, String aql) {
|
||||
logger.debug("#获取 json 节点 safety ".concat(aql));
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
json = json.getJSONObject(args_string);
|
||||
}
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
logger.warn("解析 json 节点".concat(aql).concat("错误:"), e);
|
||||
}
|
||||
return new JSONObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取安全方法链的 JSONArray
|
||||
*/
|
||||
public static JSONArray array(JSONObject json, String aql) {
|
||||
logger.debug("#获取 json 节点组 safety ".concat(aql));
|
||||
JSONArray json_array = new JSONArray();
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
if (token.hasMoreElements()) {
|
||||
json = json.getJSONObject(args_string);
|
||||
} else {
|
||||
json_array = json.getJSONArray(args_string);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("解析 json 节点".concat(aql).concat("错误:"), e);
|
||||
}
|
||||
if (json_array == null) {
|
||||
json_array = new JSONArray();
|
||||
}
|
||||
return json_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取安全方法链的值,方法中出现错误返回传入的 value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T value(String jsonStr, String aql, T default_result) {
|
||||
logger.debug("#获取 json 节点 safety ".concat(aql));
|
||||
JSONObject json_object = JSONObject.parseObject(jsonStr);
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
T tmp_result = null;
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
if (token.hasMoreElements()) {
|
||||
json_object = json_object.getJSONObject(args_string);
|
||||
} else {
|
||||
tmp_result = (T) json_object.get(args_string);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String message = "解析 json 节点".concat(aql).concat("错误:");
|
||||
logger.warn(message, e);
|
||||
}
|
||||
default_result = (tmp_result == null) ? default_result : tmp_result;
|
||||
return default_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取安全方法链的值,方法中出现错误返回传入的 value
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T value(Object javaObject, String aql, T defaultValue) {
|
||||
logger.debug("#获取 json 节点 safety ".concat(aql));
|
||||
JSONObject json_object = (JSONObject) JSONObject.toJSON(javaObject);
|
||||
StringTokenizer token = new StringTokenizer(aql, AQL_SEPARATOR);
|
||||
T tmp_result = null;
|
||||
try {
|
||||
while (token.hasMoreElements()) {
|
||||
String args_string = token.nextToken();
|
||||
if (token.hasMoreElements()) {
|
||||
json_object = json_object.getJSONObject(args_string);
|
||||
} else {
|
||||
tmp_result = (T) json_object.get(args_string);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("解析 json 节点".concat(aql).concat("错误:"), e);
|
||||
}
|
||||
defaultValue = (tmp_result == null) ? defaultValue : tmp_result;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONObject jsonObject = JSONObject.parseObject("{\"a\":{\"b\":{\"c\":1}}}");
|
||||
System.out.println(JsonParserUtil.jsonObject(jsonObject, "a.b"));
|
||||
Integer value = JsonParserUtil.value(jsonObject, "a.b.c", null);
|
||||
System.out.println(value);
|
||||
Integer value1 = JsonParserUtil.value("{\"a\":{\"b\":{\"c\":1}}}", "a.b.c", null);
|
||||
System.out.println(value1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user