|
@@ -51,9 +51,18 @@ public class TreeUtils {
|
|
|
* @param personnelVO 登录人的信息
|
|
|
* @return 拼接的sql
|
|
|
*/
|
|
|
- public static String reCompute(JSONObject jsonObject,Integer id,Object[] object) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ public static String reCompute(JSONObject jsonObject,Object[] object,List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ String sql="";
|
|
|
|
|
|
- String sql= cRecursionTree(jsonObject,id,object);
|
|
|
+ if (jsonObject.containsKey("left")&&jsonObject.containsKey("right")){
|
|
|
+ sql= cRecursionTree(jsonObject,object,dataSource,personnelVO);}
|
|
|
+ // 不符合二叉树形式(单条数据)
|
|
|
+ else{
|
|
|
+ String field = distinguishFields(jsonObject.get("field").toString(),object,dataSource,personnelVO);
|
|
|
+ String value= distinguishValues(jsonObject.get("value").toString(),object);
|
|
|
+ String opr = distinguishLogic(jsonObject.getString("nodeType"),jsonObject.getString("opr"));
|
|
|
+ sql = ArryEqlToString(field,value,opr);
|
|
|
+ }
|
|
|
return sql;
|
|
|
|
|
|
}
|
|
@@ -102,28 +111,28 @@ public class TreeUtils {
|
|
|
};
|
|
|
|
|
|
//json规则判断
|
|
|
- public static String cRecursionTree(JSONObject jsonObject,Integer id, Object[] object) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ public static String cRecursionTree(JSONObject jsonObject, Object[] object, List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
String str1 = "";
|
|
|
String str2 = "";
|
|
|
JSONObject jsonLeft =jsonObject.getJSONObject("left");
|
|
|
JSONObject jsonRight =jsonObject.getJSONObject("right");
|
|
|
if(jsonLeft.containsKey("left")){
|
|
|
- str1 = cRecursionTree(jsonLeft,id,object);
|
|
|
+ str1 = cRecursionTree(jsonLeft,object,dataSource,personnelVO);
|
|
|
}
|
|
|
else{
|
|
|
- String field = distinguishFields(jsonLeft.get("field").toString(),object);
|
|
|
+ String field = distinguishFields(jsonLeft.get("field").toString(),object,dataSource,personnelVO);
|
|
|
String value= distinguishValues(jsonLeft.get("value").toString(),object);
|
|
|
String opr = distinguishLogic(jsonLeft.getString("nodeType"),jsonLeft.getString("opr"));
|
|
|
- str1 = field+opr+value;
|
|
|
+ str1 = ArryEqlToString(field,value,opr);
|
|
|
}
|
|
|
if(jsonRight.containsKey("right")){
|
|
|
- str2= cRecursionTree( jsonRight,id,object);
|
|
|
+ str2= cRecursionTree( jsonRight,object,dataSource,personnelVO);
|
|
|
}
|
|
|
else{
|
|
|
- String field =distinguishFields(jsonRight.get("field").toString(),object);
|
|
|
+ String field =distinguishFields(jsonRight.get("field").toString(),object,dataSource,personnelVO);
|
|
|
String value=distinguishValues(jsonRight.get("value").toString(),object);
|
|
|
String opr = distinguishLogic(jsonRight.getString("nodeType"),jsonRight.getString("opr"));
|
|
|
- str2 =field+opr+value;
|
|
|
+ str2 = ArryEqlToString(field,value,opr);
|
|
|
}
|
|
|
String sql ="("+ str1+") "+distinguishLogic(jsonObject.getString("nodeType"),jsonObject.getString("logicOpr"))+" ("+str2+")";
|
|
|
|
|
@@ -184,7 +193,7 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
}
|
|
|
|
|
|
//对field部分进行计算
|
|
|
- public static String distinguishFields(String field, Object[] object) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ public static String distinguishFields(String field, Object[] object,List<DataSource> dataSources,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
String reField ="'"+field+"'";
|
|
|
//反射获方法的参数值
|
|
|
Class jsonClass = object[0].getClass();
|
|
@@ -197,13 +206,59 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ //获得登录用户部门列表信息
|
|
|
+ List<PersonnelVO.DP> dps =personnelVO.getDpList();
|
|
|
+ //获得登录用户角色列表信息
|
|
|
+ List<PersonnelVO.PerRole> perRoles =personnelVO.getRList();
|
|
|
+ String tem ="";
|
|
|
+ //遍历字典数据
|
|
|
+ for(DataSource dataSource :dataSources){
|
|
|
+ // 如果匹配上字典字段则进行处理
|
|
|
+ if(field.equals(dataSource.getDataSourceField())){
|
|
|
+ // 判断是否是部门信息
|
|
|
+ if(field.contains("DP.")){
|
|
|
+ // 分割字符串获得部门字段
|
|
|
+ String Fields= field.split("\\.")[1];
|
|
|
+ // 遍历部门信息,用反射将对应字段转换成(*,*,...)格式
|
|
|
+ for(PersonnelVO.DP dp : dps){
|
|
|
+ Class DPClass =dp.getClass();
|
|
|
+ Field dataField = DPClass.getDeclaredField(Fields);
|
|
|
+ dataField.setAccessible(true);
|
|
|
+ tem =dataField.get(dp).toString()+"," ;
|
|
|
+
|
|
|
+ }
|
|
|
+ reField = tem.substring(0,tem.length() - 1);
|
|
|
+ }
|
|
|
+ //判断是否是角色信息(处理过程同部门信息处理过程)
|
|
|
+ else if(field.contains("PerRole.")){
|
|
|
+ String Fields= field.split("\\.")[1];
|
|
|
+ for(PersonnelVO.PerRole perRole : perRoles){
|
|
|
+ Class DPClass =perRole.getClass();
|
|
|
+ Field dataField = DPClass.getDeclaredField(Fields);
|
|
|
+ dataField.setAccessible(true);
|
|
|
+ tem =dataField.get(perRole).toString()+"," ;
|
|
|
+ }
|
|
|
+ reField = tem.substring(0,tem.length() - 1);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ Class personClass =personnelVO.getClass();
|
|
|
+ Field dataField = personClass.getDeclaredField(field);
|
|
|
+ dataField.setAccessible(true);
|
|
|
+ reField =dataField.get(personnelVO).toString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }}
|
|
|
|
|
|
return reField;
|
|
|
}
|
|
|
|
|
|
//对value部分进行计算
|
|
|
public static String distinguishValues(String value, Object[] object) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- String reValue ="'"+value+"'";
|
|
|
+ String reValue =""+value+"";
|
|
|
//反射获得参数值
|
|
|
Class jsonClass = object[0].getClass();
|
|
|
for(Field field1: jsonClass.getDeclaredFields()){
|
|
@@ -219,7 +274,7 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
return reValue;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ //对应改变运算逻辑
|
|
|
public static String distinguishLogic(String nodeType ,String opr) {
|
|
|
if(nodeType .equals("logic")){
|
|
|
switch (opr){
|
|
@@ -237,4 +292,19 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
return opr;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ // 将x,y=z,w 形式改为 x=z||x=w||y=z||y=w形式
|
|
|
+ public static String ArryEqlToString(String field,String value,String opr){
|
|
|
+ String reStr ="";
|
|
|
+ String[] fields =field.split(",");
|
|
|
+ String[] values =value.split(",");
|
|
|
+ for (int i=0; i<fields.length;i++) {
|
|
|
+ for(int t=0; t<values.length;t++){
|
|
|
+ reStr+= i==fields.length-1&&t==values.length-1? fields[i]+opr+values[t]:fields[i]+opr+values[t]+"||";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return reStr;
|
|
|
+ }
|
|
|
}
|