|
@@ -2,14 +2,9 @@ package cn.cslg.pas.common.utils.auth;
|
|
|
|
|
|
import cn.cslg.pas.common.model.DataSource;
|
|
|
import cn.cslg.pas.common.model.PersonnelVO;
|
|
|
-import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
-import cn.cslg.pas.common.utils.RedisUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import org.apache.poi.ss.formula.functions.T;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -17,309 +12,291 @@ import java.util.List;
|
|
|
public class TreeUtils {
|
|
|
/**
|
|
|
* 将二叉树json对象转为sql where后的条件语句
|
|
|
- *liRJ
|
|
|
- * @param jsonObject 要处理的jsonObject对象
|
|
|
+ * liRJ
|
|
|
+ *
|
|
|
+ * @param jsonObject 要处理的jsonObject对象
|
|
|
* @param dataSource 要使用的数据字典
|
|
|
* @param personnelVO 登录人的信息
|
|
|
* @return 拼接的sql
|
|
|
*/
|
|
|
// 处理sql语句,返回拼接sql
|
|
|
- public static String reSql(JSONObject jsonObject,List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- String sql ="";
|
|
|
+ public static String reSql(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ String sql;
|
|
|
//判断是否为逻辑
|
|
|
- if (jsonObject.get("nodeType").equals("logic")){
|
|
|
- sql ="";
|
|
|
+ if (jsonObject.get("nodeType").equals("logic")) {
|
|
|
+ sql = "";
|
|
|
}
|
|
|
//符合二叉树形式
|
|
|
- else if (jsonObject.containsKey("left")&&jsonObject.containsKey("right")){
|
|
|
- sql= recursionTree(jsonObject,dataSource,personnelVO);}
|
|
|
- // 不符合二叉树形式(单条数据)
|
|
|
- else{
|
|
|
- String field =jsonObject.get("field").toString();
|
|
|
- String value=distinguishFields(jsonObject.get("value").toString(),dataSource,personnelVO);
|
|
|
- if(jsonObject.get("opr").toString().equals("FIND_IN_SET")){
|
|
|
- sql ="FIND_IN_SET("+value+","+field+")";
|
|
|
- }
|
|
|
- else{
|
|
|
- sql = field+" "+jsonObject.get("opr").toString()+" "+value;}
|
|
|
- }
|
|
|
+ else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
|
+ sql = recursionTree(jsonObject, dataSource, personnelVO);
|
|
|
+ }
|
|
|
+ // 不符合二叉树形式(单条数据)
|
|
|
+ else {
|
|
|
+ String field = jsonObject.get("field").toString();
|
|
|
+ String value = distinguishFields(jsonObject.get("value").toString(), dataSource, personnelVO);
|
|
|
+ if (jsonObject.get("opr").toString().equals("FIND_IN_SET")) {
|
|
|
+ sql = "FIND_IN_SET(" + value + "," + field + ")";
|
|
|
+ } else {
|
|
|
+ sql = field + " " + jsonObject.get("opr").toString() + " " + value;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return sql;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将二叉树json对象转为sql where后的条件语句
|
|
|
- *liRJ
|
|
|
- * @param jsonObject 要处理的jsonObject对象
|
|
|
+ * liRJ
|
|
|
+ *
|
|
|
+ * @param jsonObject 要处理的jsonObject对象
|
|
|
* @param dataSource 要使用的数据字典
|
|
|
* @param personnelVO 登录人的信息
|
|
|
* @return 拼接的sql
|
|
|
*/
|
|
|
- public static String reCompute(JSONObject jsonObject,Object[] object,List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- String sql="";
|
|
|
- //判断是否为sql类型规则
|
|
|
- if (jsonObject.get("nodeType").equals("sql")){
|
|
|
- sql ="1==1";
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否为单条数据
|
|
|
- else if (jsonObject.containsKey("left")&&jsonObject.containsKey("right")){
|
|
|
- sql= cRecursionTree(jsonObject,object,dataSource,personnelVO);}
|
|
|
+ public static String reCompute(JSONObject jsonObject, Object[] object, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ String sql;
|
|
|
+ //判断是否为sql类型规则
|
|
|
+ if (jsonObject.get("nodeType").equals("sql")) {
|
|
|
+ sql = "1==1";
|
|
|
+ }
|
|
|
+ //判断是否为单条数据
|
|
|
+ else if (jsonObject.containsKey("left") && jsonObject.containsKey("right")) {
|
|
|
+ sql = cRecursionTree(jsonObject, object, dataSource, personnelVO);
|
|
|
+ }
|
|
|
// 不为sql类型的二叉树形式
|
|
|
- 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);
|
|
|
+ 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 = arrayEqlToString(field, value, opr);
|
|
|
}
|
|
|
- return sql;
|
|
|
|
|
|
+ return sql;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 递归将二叉树转换为字符串
|
|
|
- *liRJ
|
|
|
- * @param jsonObject jsaonObject
|
|
|
- * @return
|
|
|
+ * liRJ
|
|
|
+ *
|
|
|
+ * @param jsonObject jsonObject
|
|
|
*/
|
|
|
- public static String recursionTree(JSONObject jsonObject, List<DataSource> dataSource,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- String str1 = "";
|
|
|
- String str2 = "";
|
|
|
- JSONObject jsonLeft =jsonObject.getJSONObject("left");
|
|
|
- JSONObject jsonRight =jsonObject.getJSONObject("right");
|
|
|
+ public static String recursionTree(JSONObject jsonObject, List<DataSource> dataSource, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ String str1;
|
|
|
+ String str2;
|
|
|
+ JSONObject jsonLeft = jsonObject.getJSONObject("left");
|
|
|
+ JSONObject jsonRight = jsonObject.getJSONObject("right");
|
|
|
//判断是否含有left分支
|
|
|
- if(jsonLeft.containsKey("left")){
|
|
|
- str1 = recursionTree(jsonLeft,dataSource,personnelVO);//递归
|
|
|
- }
|
|
|
- else{
|
|
|
- String field =jsonLeft.get("field").toString();
|
|
|
- String value=distinguishFields(jsonLeft.get("value").toString(),dataSource,personnelVO); //没有的话解析字符串拼接成子sql
|
|
|
- if(jsonLeft.get("opr").toString().equals("FIND_IN_SET")){
|
|
|
- str1 ="FIND_IN_SET("+value+","+field+")";
|
|
|
+ if (jsonLeft.containsKey("left")) {
|
|
|
+ str1 = recursionTree(jsonLeft, dataSource, personnelVO);//递归
|
|
|
+ } else {
|
|
|
+ String field = jsonLeft.get("field").toString();
|
|
|
+ String value = distinguishFields(jsonLeft.get("value").toString(), dataSource, personnelVO); //没有的话解析字符串拼接成子sql
|
|
|
+ if (jsonLeft.get("opr").toString().equals("FIND_IN_SET")) {
|
|
|
+ str1 = "FIND_IN_SET(" + value + "," + field + ")";
|
|
|
+ } else {
|
|
|
+ str1 = field + " " + jsonLeft.get("opr").toString() + " " + value;
|
|
|
}
|
|
|
- else{
|
|
|
- str1 = field+" "+jsonLeft.get("opr").toString()+" "+value;}
|
|
|
}
|
|
|
-
|
|
|
//同上部分处理left分支
|
|
|
- if(jsonRight.containsKey("right")){
|
|
|
- str2= recursionTree( jsonRight,dataSource,personnelVO);
|
|
|
- }
|
|
|
- else{
|
|
|
- String field =jsonRight.get("field").toString();
|
|
|
- String value=distinguishFields(jsonRight.get("value").toString(),dataSource,personnelVO);
|
|
|
- if(jsonRight.get("opr").toString().equals("FIND_IN_SET")){
|
|
|
- str2 ="FIND_IN_SET("+value+","+field+")";
|
|
|
+ if (jsonRight.containsKey("right")) {
|
|
|
+ str2 = recursionTree(jsonRight, dataSource, personnelVO);
|
|
|
+ } else {
|
|
|
+ String field = jsonRight.get("field").toString();
|
|
|
+ String value = distinguishFields(jsonRight.get("value").toString(), dataSource, personnelVO);
|
|
|
+ if (jsonRight.get("opr").toString().equals("FIND_IN_SET")) {
|
|
|
+ str2 = "FIND_IN_SET(" + value + "," + field + ")";
|
|
|
+ } else {
|
|
|
+ str2 = field + " " + jsonRight.get("opr").toString() + " " + value;
|
|
|
}
|
|
|
- else{
|
|
|
- str2 = field+" "+jsonRight.get("opr").toString()+" "+value;}
|
|
|
-
|
|
|
- }
|
|
|
- String sql ="("+ str1+") "+ jsonObject.get("logicOpr")+" ("+str2+")";
|
|
|
- return sql;
|
|
|
- };
|
|
|
-
|
|
|
- //json规则判断
|
|
|
- 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,object,dataSource,personnelVO);
|
|
|
- }
|
|
|
- else{
|
|
|
- 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 = ArryEqlToString(field,value,opr);
|
|
|
}
|
|
|
- if(jsonRight.containsKey("right")){
|
|
|
- str2= cRecursionTree( jsonRight,object,dataSource,personnelVO);
|
|
|
- }
|
|
|
- else{
|
|
|
- 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 = ArryEqlToString(field,value,opr);
|
|
|
- }
|
|
|
- String sql ="("+ str1+") "+distinguishLogic(jsonObject.getString("nodeType"),jsonObject.getString("logicOpr"))+" ("+str2+")";
|
|
|
-
|
|
|
- return sql;
|
|
|
- };
|
|
|
|
|
|
- //对field和value部分进行计算 sql查询
|
|
|
- public static String distinguishFields(String field, List<DataSource> dataSources,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- //获得登录用户部门列表信息
|
|
|
- List<PersonnelVO.DP> dps =personnelVO.getDpList();
|
|
|
- //获得登录用户角色列表信息
|
|
|
- List<PersonnelVO.PerRole> perRoles =personnelVO.getRList();
|
|
|
- String tem ="";
|
|
|
- String reField =field;
|
|
|
- //如果参数是sql语句
|
|
|
- if(field.contains("select")){
|
|
|
- for(DataSource dataSource :dataSources) {
|
|
|
- String sourceField=dataSource.getDataSourceField();
|
|
|
-if(field.contains("local."+sourceField)){
|
|
|
- // 判断是否是部门信息
|
|
|
- if(sourceField.contains("DP.")){
|
|
|
- // 分割字符串获得部门字段
|
|
|
- String Fields= sourceField.split("\\.")[1];
|
|
|
- // 遍历部门信息,用反射将对应字段转换成(*,*,...)格式
|
|
|
- for(PersonnelVO.DP dp : dps){
|
|
|
- Class DPClass =dp.getClass();
|
|
|
- Field dataField = DPClass.getDeclaredField(Fields);
|
|
|
- dataField.setAccessible(true);
|
|
|
- tem =dataField.get(dp).toString()+"," ;
|
|
|
+ return "(" + str1 + ") " + jsonObject.get("logicOpr") + " (" + str2 + ")";
|
|
|
+ }
|
|
|
|
|
|
+ //json规则判断
|
|
|
+ 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, object, dataSource, personnelVO);
|
|
|
+ } else {
|
|
|
+ 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 = arrayEqlToString(field, value, opr);
|
|
|
}
|
|
|
- reField = sourceField.replace("local."+sourceField,"("+tem.substring(0,tem.length() - 1)+")") ;
|
|
|
- }
|
|
|
- //判断是否是角色信息(处理过程同部门信息处理过程)
|
|
|
- else if(sourceField.contains("PerRole.")){
|
|
|
- String Fields= sourceField.split("\\.")[1];
|
|
|
- for(PersonnelVO.PerRole perRole : perRoles){
|
|
|
- Class DPClass =perRole.getClass();
|
|
|
- Field dataField = DPClass.getDeclaredField(Fields);
|
|
|
- dataField.setAccessible(true);
|
|
|
- tem =dataField.get(perRole).toString()+"," ;
|
|
|
+ if (jsonRight.containsKey("right")) {
|
|
|
+ str2 = cRecursionTree(jsonRight, object, dataSource, personnelVO);
|
|
|
+ } else {
|
|
|
+ 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 = arrayEqlToString(field, value, opr);
|
|
|
}
|
|
|
- reField = sourceField.replace("local."+sourceField,"("+tem.substring(0,tem.length() - 1)+")") ;
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
- else{
|
|
|
- Class personClass =personnelVO.getClass();
|
|
|
- Field dataField = personClass.getDeclaredField(sourceField);
|
|
|
- dataField.setAccessible(true);
|
|
|
- reField = field.replace("local."+sourceField,dataField.get(personnelVO).toString());
|
|
|
+ return "(" + str1 + ") " + distinguishLogic(jsonObject.getString("nodeType"), jsonObject.getString("logicOpr")) + " (" + str2 + ")";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-} }
|
|
|
-
|
|
|
+ //对field和value部分进行计算 sql查询
|
|
|
+ public static String distinguishFields(String field, List<DataSource> dataSources, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ //获得登录用户部门列表信息
|
|
|
+ List<PersonnelVO.DP> dps = personnelVO.getDpList();
|
|
|
+ //获得登录用户角色列表信息
|
|
|
+ List<PersonnelVO.PerRole> perRoles = personnelVO.getRList();
|
|
|
+ String tem = "";
|
|
|
+ String reField = field;
|
|
|
+ //如果参数是sql语句
|
|
|
+ if (field.contains("select")) {
|
|
|
+ for (DataSource dataSource : dataSources) {
|
|
|
+ String sourceField = dataSource.getDataSourceField();
|
|
|
+ if (field.contains("local." + sourceField)) {
|
|
|
+ // 判断是否是部门信息
|
|
|
+ if (sourceField.contains("DP.")) {
|
|
|
+ // 分割字符串获得部门字段
|
|
|
+ String Fields = sourceField.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 = sourceField.replace("local." + sourceField, "(" + tem.substring(0, tem.length() - 1) + ")");
|
|
|
+ }
|
|
|
+ //判断是否是角色信息(处理过程同部门信息处理过程)
|
|
|
+ else if (sourceField.contains("PerRole.")) {
|
|
|
+ String Fields = sourceField.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 = sourceField.replace("local." + sourceField, "(" + tem.substring(0, tem.length() - 1) + ")");
|
|
|
+ } else {
|
|
|
+ Class<?> personClass = personnelVO.getClass();
|
|
|
+ Field dataField = personClass.getDeclaredField(sourceField);
|
|
|
+ dataField.setAccessible(true);
|
|
|
+ reField = field.replace("local." + sourceField, dataField.get(personnelVO).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//遍历字典数据
|
|
|
- for(DataSource dataSource :dataSources){
|
|
|
+ for (DataSource dataSource : dataSources) {
|
|
|
// 如果匹配上字典字段则进行处理
|
|
|
- if(field.equals(dataSource.getDataSourceField())){
|
|
|
+ if (field.equals(dataSource.getDataSourceField())) {
|
|
|
// 判断是否是部门信息
|
|
|
- if(field.contains("DP.")){
|
|
|
+ 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()+"," ;
|
|
|
+ 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)+")";
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ 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()+"," ;
|
|
|
+ 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();
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
//对field部分进行计算
|
|
|
- public static String distinguishFields(String field, Object[] object,List<DataSource> dataSources,PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
- String reField ="'"+field+"'";
|
|
|
+ public static String distinguishFields(String field, Object[] object, List<DataSource> dataSources, PersonnelVO personnelVO) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ String reField = "'" + field + "'";
|
|
|
//反射获方法的参数值
|
|
|
- Class jsonClass = object[0].getClass();
|
|
|
- for(Field field1: jsonClass.getDeclaredFields()){
|
|
|
- if(field1.getName().equals(field)){ //判断field的值是否和参数名一样,一样的话变为参数值
|
|
|
- Field dataField = jsonClass.getDeclaredField(field);
|
|
|
- dataField.setAccessible(true);//设置data属性为可访问的
|
|
|
- String fie=dataField.get(object[0]).toString();
|
|
|
- reField ="'"+fie+"'";
|
|
|
- break;
|
|
|
- }
|
|
|
+ Class<?> jsonClass = object[0].getClass();
|
|
|
+ for (Field field1 : jsonClass.getDeclaredFields()) {
|
|
|
+ if (field1.getName().equals(field)) { //判断field的值是否和参数名一样,一样的话变为参数值
|
|
|
+ Field dataField = jsonClass.getDeclaredField(field);
|
|
|
+ dataField.setAccessible(true);//设置data属性为可访问的
|
|
|
+ String fie = dataField.get(object[0]).toString();
|
|
|
+ reField = "'" + fie + "'";
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
//获得登录用户部门列表信息
|
|
|
- List<PersonnelVO.DP> dps =personnelVO.getDpList();
|
|
|
+ List<PersonnelVO.DP> dps = personnelVO.getDpList();
|
|
|
//获得登录用户角色列表信息
|
|
|
- List<PersonnelVO.PerRole> perRoles =personnelVO.getRList();
|
|
|
- String tem ="";
|
|
|
+ List<PersonnelVO.PerRole> perRoles = personnelVO.getRList();
|
|
|
+ String tem = "";
|
|
|
//遍历字典数据
|
|
|
- for(DataSource dataSource :dataSources){
|
|
|
+ for (DataSource dataSource : dataSources) {
|
|
|
// 如果匹配上字典字段则进行处理
|
|
|
- if(field.equals(dataSource.getDataSourceField())){
|
|
|
+ if (field.equals(dataSource.getDataSourceField())) {
|
|
|
// 判断是否是部门信息
|
|
|
- if(field.contains("DP.")){
|
|
|
+ if (field.contains("DP.")) {
|
|
|
// 分割字符串获得部门字段
|
|
|
- String Fields= field.split("\\.")[1];
|
|
|
+ String Fields = field.split("\\.")[1];
|
|
|
// 遍历部门信息,用反射将对应字段转换成(*,*,...)格式
|
|
|
- for(PersonnelVO.DP dp : dps){
|
|
|
- Class DPClass =dp.getClass();
|
|
|
+ for (PersonnelVO.DP dp : dps) {
|
|
|
+ Class<?> DPClass = dp.getClass();
|
|
|
Field dataField = DPClass.getDeclaredField(Fields);
|
|
|
dataField.setAccessible(true);
|
|
|
- tem =dataField.get(dp).toString()+"," ;
|
|
|
+ tem = dataField.get(dp).toString() + ",";
|
|
|
|
|
|
}
|
|
|
- reField = tem.substring(0,tem.length() - 1);
|
|
|
+ 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();
|
|
|
+ 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()+"," ;
|
|
|
+ tem = dataField.get(perRole).toString() + ",";
|
|
|
}
|
|
|
- reField = tem.substring(0,tem.length() - 1);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- else{
|
|
|
- Class personClass =personnelVO.getClass();
|
|
|
+ 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()+"'";
|
|
|
+ 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()){
|
|
|
- if(field1.getName().equals(value)){ //判断value的值是否和参数名一样,一样的话变为参数值
|
|
|
+ Class<?> jsonClass = object[0].getClass();
|
|
|
+ for (Field field1 : jsonClass.getDeclaredFields()) {
|
|
|
+ if (field1.getName().equals(value)) { //判断value的值是否和参数名一样,一样的话变为参数值
|
|
|
Field dataField = jsonClass.getDeclaredField(value);
|
|
|
dataField.setAccessible(true);//设置data属性为可访问的
|
|
|
- String fie=dataField.get(object[0]).toString();
|
|
|
- reValue ="'"+fie+"'";
|
|
|
+ String fie = dataField.get(object[0]).toString();
|
|
|
+ reValue = "'" + fie + "'";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -328,9 +305,9 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
}
|
|
|
|
|
|
//对应改变运算逻辑
|
|
|
- public static String distinguishLogic(String nodeType ,String opr) {
|
|
|
- if(nodeType .equals("logic")){
|
|
|
- switch (opr){
|
|
|
+ public static String distinguishLogic(String nodeType, String opr) {
|
|
|
+ if (nodeType.equals("logic")) {
|
|
|
+ switch (opr) {
|
|
|
case "=":
|
|
|
opr = "==";
|
|
|
break;
|
|
@@ -342,22 +319,21 @@ reField = "("+tem.substring(0,tem.length() - 1)+")";
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- return opr;
|
|
|
|
|
|
+ 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]+"||";
|
|
|
-
|
|
|
+ public static String arrayEqlToString(String field, String value, String opr) {
|
|
|
+ StringBuilder reStr = new StringBuilder();
|
|
|
+ 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.append(i == fields.length - 1 && t == values.length - 1 ? fields[i] + opr + values[t] : fields[i] + opr + values[t] + "||");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- return reStr;
|
|
|
+
|
|
|
+ return reStr.toString();
|
|
|
}
|
|
|
}
|