各种空指针 bugfix 及 优化
This commit is contained in:
@@ -140,17 +140,22 @@ public class CommonServiceImpl implements CommonService {
|
|||||||
// 常量指标
|
// 常量指标
|
||||||
// 常量JOSN指标直接获取定义好的常量的value
|
// 常量JOSN指标直接获取定义好的常量的value
|
||||||
String value = field.getJsonValue();
|
String value = field.getJsonValue();
|
||||||
inputParam.put(field.getFieldEn(), JSONObject.parseObject(value));
|
// inputParam.put(field.getFieldEn(), JSONObject.parseObject(value));
|
||||||
|
putValue(inputParam,field.getFieldEn(), value);
|
||||||
|
|
||||||
remainFields.remove(field);
|
remainFields.remove(field);
|
||||||
} else if (field.getIsUseSql()) {
|
} else if (field.getIsUseSql()) {
|
||||||
// 通过sql方式获取指标
|
// 通过sql方式获取指标
|
||||||
Object value = getFieldValueBySql(field, inputParam);
|
Object value = getFieldValueBySql(field, inputParam);
|
||||||
inputParam.put(field.getFieldEn(), value);
|
// inputParam.put(field.getFieldEn(), value);
|
||||||
|
putValue(inputParam,field.getFieldEn(), value);
|
||||||
|
|
||||||
remainFields.remove(field);
|
remainFields.remove(field);
|
||||||
} else if (field.getIsInterface()) {
|
} else if (field.getIsInterface()) {
|
||||||
// 解析接口指标
|
// 解析接口指标
|
||||||
String value = getFieldValueByInterface(field, inputParam);
|
String value = getFieldValueByInterface(field, inputParam);
|
||||||
inputParam.put(field.getFieldEn(), value);
|
// inputParam.put(field.getFieldEn(), value);
|
||||||
|
putValue(inputParam,field.getFieldEn(), value);
|
||||||
remainFields.remove(field);
|
remainFields.remove(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +174,14 @@ public class CommonServiceImpl implements CommonService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putValue(Map map,String key,Object value){
|
||||||
|
// ConcurrentHashMap key value 不能为 null
|
||||||
|
if(key==null || value==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
map.put(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getFields(List<Field> fields, Map<String, Object> inputParam) {
|
public Map<String, Object> getFields(List<Field> fields, Map<String, Object> inputParam) {
|
||||||
logger.info("start getEngineField, fields:{},inputParam:{}", JSONObject.toJSONString(fields), JSONObject.toJSONString(inputParam));
|
logger.info("start getEngineField, fields:{},inputParam:{}", JSONObject.toJSONString(fields), JSONObject.toJSONString(inputParam));
|
||||||
@@ -355,9 +368,12 @@ public class CommonServiceImpl implements CommonService {
|
|||||||
} else if (jedis != null) {
|
} else if (jedis != null) {
|
||||||
resultValue = jedis.eval(parameterMap.get("sqlStr").toString());
|
resultValue = jedis.eval(parameterMap.get("sqlStr").toString());
|
||||||
}
|
}
|
||||||
if (resultValue == null) {
|
|
||||||
throw new ApiException(ErrorCodeEnum.GET_DATABASE_FIELD_ERROR.getCode(), ErrorCodeEnum.GET_DATABASE_FIELD_ERROR.getMessage());
|
// 20250213 获取不到值 不报错 !!
|
||||||
}
|
// com.fibo.ddp.common.utils.exception.ApiException: 获取数据库指标失败
|
||||||
|
// if (resultValue == null) {
|
||||||
|
// throw new ApiException(ErrorCodeEnum.GET_DATABASE_FIELD_ERROR.getCode(), ErrorCodeEnum.GET_DATABASE_FIELD_ERROR.getMessage());
|
||||||
|
// }
|
||||||
} finally {
|
} finally {
|
||||||
// 执行完成后切换到系统数据源
|
// 执行完成后切换到系统数据源
|
||||||
DataSourceContextHolder.setDBType("default");
|
DataSourceContextHolder.setDBType("default");
|
||||||
@@ -367,12 +383,24 @@ public class CommonServiceImpl implements CommonService {
|
|||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
fieldCallLogService.save(new FieldCallLog(field.getId(), FieldTypeConsts.DATABASE,dataSource.getType(),dataSource.getId().longValue(),JSON.toJSONString(parameterMap),
|
fieldCallLogService.save(new FieldCallLog(field.getId(), FieldTypeConsts.DATABASE,dataSource.getType(),dataSource.getId().longValue(),JSON.toJSONString(parameterMap),
|
||||||
JSON.toJSONString(resultValue),(end - start),field.getOrganId()));
|
toJSONString(resultValue),(end - start),field.getOrganId()));
|
||||||
logger.info("【获取数据库指标】fieldEn:{}, 耗时:{}, result:{}, parameterMap:{}", field.getFieldEn(), (end - start), resultValue, parameterMap);
|
logger.info("【获取数据库指标】fieldEn:{}, 耗时:{}, result:{}, parameterMap:{}", field.getFieldEn(), (end - start), resultValue, parameterMap);
|
||||||
return resultValue;
|
return resultValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String toJSONString(Object resultValue){
|
||||||
|
if(resultValue==null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
return JSON.toJSONString(resultValue);
|
||||||
|
}catch(Throwable e){
|
||||||
|
logger.error("toJSONString_error,"+e);
|
||||||
|
return resultValue.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析接口指标
|
* 解析接口指标
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -157,8 +157,13 @@ public class JevalUtil {
|
|||||||
}
|
}
|
||||||
//2代表字符串
|
//2代表字符串
|
||||||
if(value == 2){
|
if(value == 2){
|
||||||
String variableValue = CommonConst.SYMBOL_SINGLE_QUOTA+variablesMap.get(key).toString()+CommonConst.SYMBOL_SINGLE_QUOTA;
|
// 20250213 空指针修复
|
||||||
variablesMap.put(key, variableValue);
|
// String variableValue = CommonConst.SYMBOL_SINGLE_QUOTA+variablesMap.get(key).toString()+CommonConst.SYMBOL_SINGLE_QUOTA;
|
||||||
|
Object v = variablesMap.get(key);
|
||||||
|
if(v!=null) {
|
||||||
|
String variableValue = CommonConst.SYMBOL_SINGLE_QUOTA+v.toString()+CommonConst.SYMBOL_SINGLE_QUOTA;
|
||||||
|
variablesMap.put(key, variableValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user