|
@@ -33,6 +33,7 @@ public class DataProcess {
|
|
|
add("event");
|
|
|
add("page");
|
|
|
add("pageSize");
|
|
|
+ add("dataObjectId");
|
|
|
}};
|
|
|
|
|
|
|
|
@@ -127,33 +128,32 @@ public class DataProcess {
|
|
|
//通过用户编号,服务编号,从用户权限表获取行列权限
|
|
|
// 如果列权限为空则 直接返回空
|
|
|
// 重新组建入口参数:添加filter(行权限)
|
|
|
- if (event.equals("0") && Objects.nonNull(user_id)) {
|
|
|
- inputData = initParam(inputData);
|
|
|
+ Map<String, Object> authServiceMap = myDbHelper.queryByParamsReturnList("SELECT auth_id FROM t_auth WHERE serviceID = ? and auth_id = ? ", serviceId, inputData.get("auth_id"));
|
|
|
+ if (authServiceMap.get("code").equals("-1")) return authServiceMap;
|
|
|
+ if (event.equals("0") && Objects.nonNull(user_id) && authServiceMap.get("returnData") instanceof List<?> returnDataList && !returnDataList.isEmpty()) {
|
|
|
//判断filter不为空 且 filter不包含left---{"filter":[{"user_id":""}]} ---- >[{filter:[{left:,column:},{left:,column:}
|
|
|
- //更新服务的活跃时间
|
|
|
-// List<Map<String,Object>> queryByParamsDataList =(List<Map<String,Object>>) queryByParamsReturnList.get("returnData");
|
|
|
-// if (queryByParamsDataList.isEmpty()) return processFail("获取列权限失败:列权限为空",null);
|
|
|
-//// Map<String, Object> filterMap = queryByParamsDataList.get(0);
|
|
|
-// Map<String,Object> dataContent =(Map<String,Object>) inputData.get("dataContent");
|
|
|
-// if (!inputData.toString().contains("filter:")){
|
|
|
-// //如果queryByParamsDataList是逗号分割则
|
|
|
-// dataContent.put("filter",);
|
|
|
-// inputData.put("dataContent",dataContent);
|
|
|
-// }else {
|
|
|
-// Object filter = dataContent.get("filter");
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
- String sql = "SELECT QCS.columnName,TUA.row_auth FROMt_user_group_auth TUALEFT JOIN querytemplatecolumnset QCS on TUA.queryTemplateColumnSetID = QCS.queryTemplateColumnSetID WHERETUA.user_id = ?\n" +
|
|
|
- "AND TUA.queryTemplateColumnSetID IS NOT NULL";
|
|
|
- Map<String, Object> userDataAuthMap = myDbHelper.queryByParamsReturnList(sql, user_id[0]);
|
|
|
+ /*获取权限filter*/
|
|
|
+ Map<String, Object> userDataAuthMap = myDbHelper.queryByParamsReturnList("SELECT QCS.columnName,TUA.row_auth FROM t_user_group_auth TUA LEFT JOIN querytemplatecolumnset QCS on TUA.queryTemplateColumnSetID = QCS.queryTemplateColumnSetID WHERE TUA.user_id = ? AND TUA.auth_id = ? AND TUA.queryTemplateColumnSetID IS NOT NULL", user_id[0], inputData.get("auth_id"));
|
|
|
if (userDataAuthMap.get("code").equals("-1")) return userDataAuthMap;
|
|
|
- List<Map<String,Object>> arrayList = new ArrayList<>();
|
|
|
- authoParams((List<Map<String, Object>>) userDataAuthMap.get("returnData"), arrayList);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ List<Object> userList = new ArrayList<>();
|
|
|
+ ((List<Map<String, Object>>) userDataAuthMap.get("returnData")).stream().filter(map -> Objects.nonNull(map.get("row_auth"))).forEach(tempMap -> {
|
|
|
+ String[] row_auths = tempMap.get("row_auth").toString().split(",");
|
|
|
+ for (String row_auth : row_auths) {
|
|
|
+ if (Objects.isNull(row_auth)) continue;
|
|
|
+ HashMap<String, Object> hashMap = new HashMap<>();
|
|
|
+ hashMap.put(tempMap.get("columnName").toString(), row_auth.startsWith("!")?row_auth.substring(1):row_auth);
|
|
|
+ if (row_auth.startsWith("!")) {
|
|
|
+ userList.addAll(changeSignFilter(hashMap, "!", "or"));
|
|
|
+ }else {
|
|
|
+ userList.addAll(changeSignFilter(hashMap, null, "or"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /*userList第一个以及最后一个添加()*/
|
|
|
+ ((Map<String,Object>)userList.get(0)).put("left","(");
|
|
|
+ ((Map<String,Object>)userList.get(userList.size()-1)).put("connector"," and ");
|
|
|
+ ((Map<String,Object>)userList.get(userList.size()-1)).put("right"," ) ");
|
|
|
+ inputData= initParam(inputData, "0", userList);
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> calculationResult = new ArrayList<>();//定义算法全量结果列表
|
|
@@ -179,117 +179,159 @@ public class DataProcess {
|
|
|
return processSuccess(collect.get(collect.size() - 1));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 添加行权限
|
|
|
- *
|
|
|
- * @param inputData
|
|
|
- * @return
|
|
|
- */
|
|
|
- private static Map<String, Object> initParam(Map<String, Object> inputData) {
|
|
|
- Object dataContent = inputData.get("dataContent");
|
|
|
- if (Objects.isNull(dataContent)) {// null
|
|
|
- dataContent = MapTools.removeKey(inputData, baseInfo);
|
|
|
- }
|
|
|
- /*如果dataContent不是数组也不是map则返回inData,--不是map数组 返回InData*/
|
|
|
- if (!(dataContent instanceof Map<?, ?>) && (dataContent instanceof List<?> && !(((List<?>) dataContent).get(0) instanceof Map))) {
|
|
|
- return inputData;
|
|
|
+
|
|
|
+ private static Map<String, Object> initParam(Map<String, Object> inputData, String event, List<Object> authList) { // authList 转换:left过后的
|
|
|
+ Object dataContent = inputData.get("dataContent");//这个就是最终的dataContent,所有的变化都是针对它进行
|
|
|
+ if (Objects.isNull(dataContent)) {//如果为空则默认为inputData中除去常规变量的其它变量,最终可以是一个空Map
|
|
|
+ Map<String, Object> tempDataContent = new HashMap<>(inputData);//因为inputData并不会发生变化,所以使用浅拷贝即可:
|
|
|
+ baseInfo.forEach(tempDataContent.keySet()::remove);//移除常规不参与计算的键值
|
|
|
+ dataContent = tempDataContent;//处理为Map,后续继续处理
|
|
|
}
|
|
|
- if (dataContent instanceof Map<?, ?> temMap) {
|
|
|
- List<Object> tempList = new ArrayList<>();
|
|
|
- tempList.add(temMap);
|
|
|
- dataContent = tempList;
|
|
|
+ if (dataContent instanceof Map<?, ?> dataContentMap) {//如果是一个Map则转数组
|
|
|
+ List<Map<?, ?>> tempDataContent = new ArrayList<>();//初始化一个数组
|
|
|
+ tempDataContent.add(dataContentMap);
|
|
|
+ dataContent = tempDataContent;
|
|
|
}
|
|
|
- /*同步添加Value*/
|
|
|
- List<Map<String, Object>> tempDataList = (List<Map<String, Object>>) dataContent;
|
|
|
- if (!((tempDataList).get(0)).containsKey("filter")) { //[{a=1,b=2},{a=2,b=3}] ---->[{"filter":[{a=1,b=2}]},{"filter":[{a=2,b=3}]}]
|
|
|
- List<Object> tempList = new ArrayList<>();
|
|
|
- for (Object tempMap : tempDataList) { //[{a=1,b=2},{a=2,b=3}]
|
|
|
- List<Object> tepList = new ArrayList<>() {{
|
|
|
- add(tempMap);
|
|
|
- }};
|
|
|
- Map<Object, Object> tmpData = new HashMap<>();
|
|
|
- tmpData.put("filter", tepList);
|
|
|
- tempList.add(tmpData);
|
|
|
+ if (dataContent instanceof List dataContentList) {//如果是一个数组则循环转标准格式
|
|
|
+ List<Map<String, Object>> returnDataContent = new ArrayList<>();
|
|
|
+ for (Object signDataContent : dataContentList) {//循环List
|
|
|
+ if (!(signDataContent instanceof Map)) return inputData; //如果不是一个Map则不进行处理
|
|
|
+ returnDataContent.add(createStandardParameters((Map<String, Object>) signDataContent, event, authList)); //得到Filter里面的内容
|
|
|
}
|
|
|
- dataContent = tempList;
|
|
|
+ dataContent = returnDataContent;
|
|
|
}
|
|
|
- if (tempDataList.get(0).get("filter") instanceof Map<?, ?> filterMap) { //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
- List<Map<String, Object>> returnDataList = new ArrayList<>();
|
|
|
- for (Map<String, Object> temp : tempDataList) {
|
|
|
- List<Object> tempList = new ArrayList<>();
|
|
|
- tempList.add(filterMap);
|
|
|
- temp.put("filter", tempList);
|
|
|
- returnDataList.add(temp);
|
|
|
+ inputData.put("dataContent", dataContent);
|
|
|
+ return inputData;//
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> createStandardParameters(Map<String, Object> inDataContent, String event, List<Object> authList) {
|
|
|
+ Map<String, Object> returnData = new HashMap<>();//创建返回值returnData{}
|
|
|
+ if ("1,2".contains(event)) {//如果事件是新增或更新则(查询和删除无需处理value)
|
|
|
+ Object tempValueObject = inDataContent.get("Value");//获取Value----{c1:"123",c2:}
|
|
|
+ if (Objects.isNull(tempValueObject)) {//如果入参数inDataContent不包含Value则等于整个inDataContent -- //处理value
|
|
|
+ HashMap<String, Object> tempValue = new HashMap<>(inDataContent);//深拷贝
|
|
|
+ tempValue.remove("filter");//先移除filter,理论上不存在
|
|
|
+ tempValueObject = tempValue;
|
|
|
}
|
|
|
- dataContent = returnDataList; // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
|
|
|
+ returnData.put((tempValueObject instanceof Map) ? "Value" : "newValue", tempValueObject);//重命名避免后期处理错误
|
|
|
}
|
|
|
- List<Map<String, Object>> data = new ArrayList<>();
|
|
|
- if (dataContent instanceof List<?> temList && temList.get(0) instanceof Map temMap && !temMap.containsKey("left")) {
|
|
|
- for (Map<String, Object> itemMap : (List<Map<String, Object>>) temList ) { //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
- List<Map<String, Object>> filter = (List<Map<String, Object>>) itemMap.get("filter");
|
|
|
- authoParams(filter, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
+ if (!("1".equals(event))) {//如果事件不是新增(新增无需处理filter)
|
|
|
+ Object tempFilterObject = inDataContent.get("filter");//获取filter
|
|
|
+ tempFilterObject = Objects.isNull(tempFilterObject) ? inDataContent : tempFilterObject;//如果不存在filter则等于原始MAP
|
|
|
+ if (tempFilterObject instanceof Map) {////如果filter是单个Map则
|
|
|
+ authList.addAll(changeSignFilter((Map)tempFilterObject,null,null));
|
|
|
+ returnData.put("filter", authList);//转换为标准条件集
|
|
|
+ } else {
|
|
|
+ if (tempFilterObject instanceof List tempFilterObjectList && tempFilterObjectList.get(0) instanceof Map) {//如果filter是List则"123"
|
|
|
+ List<Object> tempFilterList = new ArrayList<>(authList);
|
|
|
+ for (Object o : tempFilterObjectList) {//循环List -{c1:c2,c3:c4}
|
|
|
+ tempFilterList.addAll(changeSignFilter((Map) o,null,null)); //循环添加
|
|
|
+ }
|
|
|
+ returnData.put("filter", tempFilterList);//转换为标准条件集
|
|
|
+ } else {//此时tempFilterObject既不是List也不是Map:1、dataContent包含filter且filter是一个字符串
|
|
|
+ returnData.put("newFilter", tempFilterObject);
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- data = (List<Map<String, Object>>) dataContent;
|
|
|
}
|
|
|
- inputData.put("dataContent", data);
|
|
|
-
|
|
|
- return inputData;
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- HashMap<String, Object> objectHashMap = new HashMap<>();
|
|
|
- objectHashMap.put("serviceId", "1");
|
|
|
- objectHashMap.put("user_id", "1");
|
|
|
- objectHashMap.put("dataContent", new ArrayList<>() {{
|
|
|
- add(new HashMap<>() {{
|
|
|
- put("data", "xxxx");
|
|
|
- put("data2", "xxxx");
|
|
|
- }});
|
|
|
- add(new HashMap<>() {{
|
|
|
- put("data3", "xxxx");
|
|
|
- put("data4", "xxxx");
|
|
|
- }});
|
|
|
- }});
|
|
|
-
|
|
|
-// objectHashMap.put("dataContent",new ArrayList<>(){{
|
|
|
-// add(new HashMap<>(){{
|
|
|
-// put("filter",new ArrayList<>(){{
|
|
|
-// add(new HashMap<>(){{
|
|
|
-// put("a",null);
|
|
|
-// }});
|
|
|
-// }});
|
|
|
-// }});
|
|
|
-// }});
|
|
|
-// System.out.println(addRowPermission(objectHashMap, "1"));
|
|
|
+ return returnData;//返回组建好的参数
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
- private static void authoParams(List<Map<String, Object>> ListInMap, List<Map<String, Object>> filterMapList) {
|
|
|
-// String filterTemplate = "{\"left\":\"左括号\",\"column\":\"字段\",\"comparator\":\"=\",\"value\":\"值\",\"right\":\"右括号\",\"connector\":\"连接符\"}";
|
|
|
- for (Map<String, Object> filterKey : ListInMap) {
|
|
|
- List<Object> filterValue = new ArrayList<>();
|
|
|
- for (String filKey : filterKey.keySet()) {
|
|
|
- HashMap<String, Object> filterMap = new HashMap<>();
|
|
|
- Object keyValues = filterKey.get(filKey);
|
|
|
- filterMap.put("left", "");
|
|
|
- filterMap.put("column", filKey);
|
|
|
- filterMap.put("comparator", " = ");
|
|
|
- if (Objects.isNull(keyValues)) {
|
|
|
- filterMap.put("comparator", " is null ");
|
|
|
- }
|
|
|
- filterMap.put("value", keyValues);
|
|
|
- filterMap.put("right", "");
|
|
|
- filterMap.put("connector", " and ");
|
|
|
- filterValue.add(filterMap);
|
|
|
- }
|
|
|
- HashMap<String, Object> hashMap = new HashMap<>();
|
|
|
- hashMap.put("filter", filterValue);
|
|
|
- filterMapList.add(hashMap);
|
|
|
+ private static List<Map<String, Object>> changeSignFilter(Map<String, Object> filterMap, String compare, String connect) {
|
|
|
+ List<Map<String, Object>> objects = new ArrayList<>();
|
|
|
+ if (filterMap.containsKey("left")) {
|
|
|
+ objects.add(filterMap);
|
|
|
+ return objects;
|
|
|
+ }
|
|
|
+ for (Object filterKey : filterMap.keySet()) {
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+ Object keyValues = filterMap.get(filterKey);
|
|
|
+ returnMap.put("left", "");
|
|
|
+ returnMap.put("column", filterKey);
|
|
|
+ returnMap.put("comparator",(Objects.nonNull(compare) && compare.startsWith("!"))?"!=":" = ");
|
|
|
+ if (Objects.isNull(keyValues)) {
|
|
|
+ returnMap.put("comparator", " is null ");
|
|
|
}
|
|
|
+ returnMap.put("value", keyValues);
|
|
|
+ returnMap.put("right", "");
|
|
|
+ returnMap.put("connector", Objects.nonNull(connect)?(" "+connect): " and ");
|
|
|
+ objects.add(returnMap);
|
|
|
+ }
|
|
|
+ return objects;
|
|
|
}
|
|
|
|
|
|
+// private static Map<String, Object> initParam(Map<String, Object> inputData) {
|
|
|
+// Object dataContent = inputData.get("dataContent");
|
|
|
+// if (Objects.isNull(dataContent)) {// null
|
|
|
+// dataContent = MapTools.removeKey(inputData, baseInfo);
|
|
|
+// }
|
|
|
+// /*如果dataContent不是数组也不是map则返回inData,--不是map数组 返回InData*/
|
|
|
+// if (!(dataContent instanceof Map<?, ?>) && (dataContent instanceof List<?> && !(((List<?>) dataContent).get(0) instanceof Map))) {
|
|
|
+// return inputData;
|
|
|
+// }
|
|
|
+// if (dataContent instanceof Map<?, ?> temMap) {
|
|
|
+// List<Object> tempList = new ArrayList<>();
|
|
|
+// tempList.add(temMap);
|
|
|
+// dataContent = tempList;
|
|
|
+// }
|
|
|
+// /*同步添加Value*/
|
|
|
+// List<Map<String, Object>> tempDataList = (List<Map<String, Object>>) dataContent;
|
|
|
+// if (!tempDataList.get(0).containsKey("filter")) { //[{a=1,b=2},{a=2,b=3}] ---->[{"filter":[{a=1,b=2}]},{"filter":[{a=2,b=3}]}]
|
|
|
+// List<Object> tempList = new ArrayList<>();
|
|
|
+// for (Object tempMap : tempDataList) { //[{a=1,b=2},{a=2,b=3}]
|
|
|
+// List<Object> tepList = new ArrayList<>();
|
|
|
+// tepList.add(tempMap);
|
|
|
+// Map<Object, Object> tmpData = new HashMap<>();
|
|
|
+// tmpData.put("filter", tepList);
|
|
|
+// tempList.add(tmpData);
|
|
|
+// }
|
|
|
+// dataContent = tempList;
|
|
|
+// }
|
|
|
+// if (tempDataList.get(0).get("filter") instanceof Map<?, ?> filterMap) { //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
+// List<Map<String, Object>> returnDataList = new ArrayList<>();
|
|
|
+// for (Map<String, Object> temp : tempDataList) {
|
|
|
+// List<Object> tempList = new ArrayList<>();
|
|
|
+// tempList.add(filterMap);
|
|
|
+// temp.put("filter", tempList);
|
|
|
+// returnDataList.add(temp);
|
|
|
+// }
|
|
|
+// dataContent = returnDataList; // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
|
|
|
+// }
|
|
|
+// List<Map<String, Object>> data = new ArrayList<>();
|
|
|
+// List<Map<String, Object>> filterList = ((List<Map<String, List<Map<String, Object>>>>) dataContent).get(0).get("filter");
|
|
|
+// if (!filterList.get(0).containsKey("left")) {
|
|
|
+// authoParams(filterList, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
+// } else {
|
|
|
+// data = (List<Map<String, Object>>) dataContent;
|
|
|
+// }
|
|
|
+// inputData.put("dataContent", data);
|
|
|
+// return inputData;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
|
|
|
+// private static void authoParams(List<Map<String, Object>> ListInMap, List<Map<String, Object>> filterMapList) {
|
|
|
+//// String filterTemplate = "{\"left\":\"左括号\",\"column\":\"字段\",\"comparator\":\"=\",\"value\":\"值\",\"right\":\"右括号\",\"connector\":\"连接符\"}";
|
|
|
+// List<Object> filterValue = new ArrayList<>();
|
|
|
+// for (Map<String, Object> filterKey : ListInMap) {
|
|
|
+// for (String filKey : filterKey.keySet()) {
|
|
|
+// HashMap<String, Object> filterMap = new HashMap<>();
|
|
|
+// Object keyValues = filterKey.get(filKey);
|
|
|
+// filterMap.put("left", "");
|
|
|
+// filterMap.put("column", filKey);
|
|
|
+// filterMap.put("comparator", " = ");
|
|
|
+// if (Objects.isNull(keyValues)) {
|
|
|
+// filterMap.put("comparator", " is null ");
|
|
|
+// }
|
|
|
+// filterMap.put("value", keyValues);
|
|
|
+// filterMap.put("right", "");
|
|
|
+// filterMap.put("connector", " and ");
|
|
|
+// filterValue.add(filterMap);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// HashMap<String, Object> hashMap = new HashMap<>();
|
|
|
+// hashMap.put("filter", filterValue);
|
|
|
+// filterMapList.add(hashMap);
|
|
|
+// }
|
|
|
+
|
|
|
public Map<String, List<Map<String, Object>>> execCalultion(List<Map<String, Object>> inData, String beginLibraryId, Object event, String dataObjectId, Object page, Object pageSize) {
|
|
|
Map<String, List<Map<String, Object>>> returnData = new HashMap<>();
|
|
|
List<Map<String, Object>> preData = new ArrayList<>();
|