|
@@ -23,17 +23,20 @@ public class TreeUtils {
|
|
// 处理sql语句,返回拼接sql
|
|
// 处理sql语句,返回拼接sql
|
|
public static String reSql(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
public static String reSql(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
String sql;
|
|
String sql;
|
|
- //判断是否为逻辑
|
|
|
|
|
|
+ //判断是否为规则,是的话则返回为“”,不对其他sql条件产生影响
|
|
if (jsonObject.get("nodeType").equals("logic")) {
|
|
if (jsonObject.get("nodeType").equals("logic")) {
|
|
sql = "";
|
|
sql = "";
|
|
}
|
|
}
|
|
//符合二叉树形式
|
|
//符合二叉树形式
|
|
else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
|
|
+ //将二叉树转换为sql条件
|
|
sql = recursionTree(jsonObject, dataSource, personnelVO);
|
|
sql = recursionTree(jsonObject, dataSource, personnelVO);
|
|
}
|
|
}
|
|
// 不符合二叉树形式(单条数据)
|
|
// 不符合二叉树形式(单条数据)
|
|
else {
|
|
else {
|
|
|
|
+ //获得规则的field字段,作为sql条件的栏位
|
|
String field = jsonObject.get("field").toString();
|
|
String field = jsonObject.get("field").toString();
|
|
|
|
+ //获得规则的栏位值,并且要对值进行识别操作
|
|
String value = distinguishFields(jsonObject.get("value").toString(), dataSource, personnelVO);
|
|
String value = distinguishFields(jsonObject.get("value").toString(), dataSource, personnelVO);
|
|
if (jsonObject.get("opr").toString().equals("FIND_IN_SET")) {
|
|
if (jsonObject.get("opr").toString().equals("FIND_IN_SET")) {
|
|
sql = "FIND_IN_SET(" + value + "," + field + ")";
|
|
sql = "FIND_IN_SET(" + value + "," + field + ")";
|
|
@@ -54,21 +57,27 @@ public class TreeUtils {
|
|
* @param personnelVO 登录人的信息
|
|
* @param personnelVO 登录人的信息
|
|
* @return 拼接的sql
|
|
* @return 拼接的sql
|
|
*/
|
|
*/
|
|
|
|
+ // 处理规则
|
|
public static String reCompute(JSONObject jsonObject, Object[] object, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
public static String reCompute(JSONObject jsonObject, Object[] object, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
String sql;
|
|
String sql;
|
|
- //判断是否为sql类型规则
|
|
|
|
|
|
+ //判断是否为sql类型规则,是的话规则转换为1==1,不对其他规则产生影响
|
|
if (jsonObject.get("nodeType").equals("sql")) {
|
|
if (jsonObject.get("nodeType").equals("sql")) {
|
|
sql = "1==1";
|
|
sql = "1==1";
|
|
}
|
|
}
|
|
- //判断是否为单条数据
|
|
|
|
|
|
+ //符合二叉树形式
|
|
else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
|
|
+ //将二叉树转换为规则判断
|
|
sql = cRecursionTree(jsonObject, object, dataSource, personnelVO);
|
|
sql = cRecursionTree(jsonObject, object, dataSource, personnelVO);
|
|
}
|
|
}
|
|
- // 不为sql类型的二叉树形式
|
|
|
|
|
|
+ // 不符合二叉树形式(单条数据)
|
|
else {
|
|
else {
|
|
|
|
+ //获得规则的 field字段,并进行识别操作
|
|
String field = distinguishFields(jsonObject.get("field").toString(), object, dataSource, personnelVO);
|
|
String field = distinguishFields(jsonObject.get("field").toString(), object, dataSource, personnelVO);
|
|
|
|
+ //获得规则的 value字段,并进行识别操作
|
|
String value = distinguishValues(jsonObject.get("value").toString(), object);
|
|
String value = distinguishValues(jsonObject.get("value").toString(), object);
|
|
|
|
+ //获得规则的 运算符字段,并进行识别操作
|
|
String opr = distinguishLogic(jsonObject.getString("nodeType"), jsonObject.getString("opr"));
|
|
String opr = distinguishLogic(jsonObject.getString("nodeType"), jsonObject.getString("opr"));
|
|
|
|
+ //field 和value若为以,隔开的数组时,将被拆开,并合成为新的规则
|
|
sql = arrayEqlToString(field, value, opr);
|
|
sql = arrayEqlToString(field, value, opr);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,16 +90,22 @@ public class TreeUtils {
|
|
*
|
|
*
|
|
* @param jsonObject jsonObject
|
|
* @param jsonObject jsonObject
|
|
*/
|
|
*/
|
|
|
|
+ //将二叉树转换为sql条件
|
|
public static String recursionTree(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
public static String recursionTree(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
String str1;
|
|
String str1;
|
|
String str2;
|
|
String str2;
|
|
|
|
+ // 获得规则左边
|
|
JSONObject jsonLeft = jsonObject.getJSONObject("left");
|
|
JSONObject jsonLeft = jsonObject.getJSONObject("left");
|
|
|
|
+ // 获得规则右边
|
|
JSONObject jsonRight = jsonObject.getJSONObject("right");
|
|
JSONObject jsonRight = jsonObject.getJSONObject("right");
|
|
- //判断是否含有left分支
|
|
|
|
|
|
+ //判断是否含有left分支,有的话进行递归
|
|
if (jsonLeft.containsKey("left")) {
|
|
if (jsonLeft.containsKey("left")) {
|
|
str1 = recursionTree(jsonLeft, dataSource, personnelVO);//递归
|
|
str1 = recursionTree(jsonLeft, dataSource, personnelVO);//递归
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ //没有的话解析字符串拼接成子sql
|
|
|
|
+ else {
|
|
String field = jsonLeft.get("field").toString();
|
|
String field = jsonLeft.get("field").toString();
|
|
|
|
+ //获得规则的 value字段,并进行识别操作
|
|
String value = distinguishFields(jsonLeft.get("value").toString(), dataSource, personnelVO); //没有的话解析字符串拼接成子sql
|
|
String value = distinguishFields(jsonLeft.get("value").toString(), dataSource, personnelVO); //没有的话解析字符串拼接成子sql
|
|
if (jsonLeft.get("opr").toString().equals("FIND_IN_SET")) {
|
|
if (jsonLeft.get("opr").toString().equals("FIND_IN_SET")) {
|
|
str1 = "FIND_IN_SET(" + value + "," + field + ")";
|
|
str1 = "FIND_IN_SET(" + value + "," + field + ")";
|
|
@@ -114,20 +129,27 @@ public class TreeUtils {
|
|
return "(" + str1 + ") " + jsonObject.get("logicOpr") + " (" + str2 + ")";
|
|
return "(" + str1 + ") " + jsonObject.get("logicOpr") + " (" + str2 + ")";
|
|
}
|
|
}
|
|
|
|
|
|
- //json规则判断
|
|
|
|
|
|
+ //将二叉树转换为规则判断
|
|
public static String cRecursionTree(JSONObject jsonObject, Object[] object, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
public static String cRecursionTree(JSONObject jsonObject, Object[] object, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
String str1;
|
|
String str1;
|
|
String str2;
|
|
String str2;
|
|
|
|
+ // 获得规则左边
|
|
JSONObject jsonLeft = jsonObject.getJSONObject("left");
|
|
JSONObject jsonLeft = jsonObject.getJSONObject("left");
|
|
|
|
+ // 获得规则右边
|
|
JSONObject jsonRight = jsonObject.getJSONObject("right");
|
|
JSONObject jsonRight = jsonObject.getJSONObject("right");
|
|
|
|
+ //判断是否含有left分支,有的话进行递归
|
|
if (jsonLeft.containsKey("left")) {
|
|
if (jsonLeft.containsKey("left")) {
|
|
str1 = cRecursionTree(jsonLeft, object, dataSource, personnelVO);
|
|
str1 = cRecursionTree(jsonLeft, object, dataSource, personnelVO);
|
|
} else {
|
|
} else {
|
|
|
|
+ //获得规则的 field字段,并进行识别操作
|
|
String field = distinguishFields(jsonLeft.get("field").toString(), object, dataSource, personnelVO);
|
|
String field = distinguishFields(jsonLeft.get("field").toString(), object, dataSource, personnelVO);
|
|
|
|
+ //获得规则的 value字段,并进行识别操作
|
|
String value = distinguishValues(jsonLeft.get("value").toString(), object);
|
|
String value = distinguishValues(jsonLeft.get("value").toString(), object);
|
|
|
|
+ //获得规则的 opr字段,并进行识别操作
|
|
String opr = distinguishLogic(jsonLeft.getString("nodeType"), jsonLeft.getString("opr"));
|
|
String opr = distinguishLogic(jsonLeft.getString("nodeType"), jsonLeft.getString("opr"));
|
|
str1 = arrayEqlToString(field, value, opr);
|
|
str1 = arrayEqlToString(field, value, opr);
|
|
}
|
|
}
|
|
|
|
+ //同上部分处理right分支
|
|
if (jsonRight.containsKey("right")) {
|
|
if (jsonRight.containsKey("right")) {
|
|
str2 = cRecursionTree(jsonRight, object, dataSource, personnelVO);
|
|
str2 = cRecursionTree(jsonRight, object, dataSource, personnelVO);
|
|
} else {
|
|
} else {
|