Browse Source

代码提交 行权限 还未修改完成

pms 2 năm trước cách đây
mục cha
commit
72a562a181

+ 2 - 2
mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java

@@ -183,7 +183,7 @@ public class MainFactoryApplication {
         try {
             myDbHelper.execute("CREATE TABLE if not EXISTS `log_success` (  `id` int PRIMARY KEY  NOT NULL  ,  `success` TEXT  DEFAULT NULL,  `location` TEXT DEFAULT NULL,  `logContent` TEXT,  `serviceId`INT  DEFAULT NULL,  `workId` INT  DEFAULT NULL,  `iNDataContent` TEXT DEFAULT NULL, `outDataContent` TEXT DEFAULT NULL,`calculationLocation` TEXT DEFAULT NULL, `dataObjectId` TEXT DEFAULT NULL,`event` TEXT DEFAULT NULL,`createtime` timestamp not null default current_timestamp)");
             myDbHelper.execute("CREATE TABLE if not EXISTS `log_error` (  `id` int  PRIMARY KEY  NOT NULL   ,  `success` TEXT  DEFAULT NULL,  `location` TEXT DEFAULT NULL,  `logContent` TEXT,  `serviceId` INT  DEFAULT NULL,  `workId` INT  DEFAULT NULL,  `iNDataContent` TEXT DEFAULT NULL, `outDataContent` TEXT DEFAULT NULL,`calculationLocation` TEXT DEFAULT NULL,  `dataObjectId` TEXT DEFAULT NULL,`event` TEXT DEFAULT NULL,`createtime` timestamp not null default current_timestamp)");
-            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fullData` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId `TEXT  DEFAULT NULL,`fullData` TEXT DEFAULT NULL)");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fulldata` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId `TEXT  DEFAULT NULL,`fullData` TEXT DEFAULT NULL)");
         } catch (Exception e) {
             return false;
         }
@@ -241,7 +241,7 @@ public class MainFactoryApplication {
             //远程表日志表结构结构
             myDbHelper.execute("CREATE TABLE if not EXISTS `log_success` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `success` varchar(8)  DEFAULT NULL,  `location` varchar(255) DEFAULT NULL,  `logContent` varchar(1024)  DEFAULT NULL,  `serviceId` int(11) DEFAULT NULL,  `workId` int(11) DEFAULT NULL,`event` varchar(2) DEFAULT NULL, `iNDataContent` varchar(2048) DEFAULT NULL, `outDataContent` varchar(2048) DEFAULT NULL,`calculationLocation` varchar(8)  DEFAULT NULL,   `dataObjectId` varchar(32) DEFAULT NULL,`createtime` datetime )");
             myDbHelper.execute("CREATE TABLE if not EXISTS `log_error` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `success` varchar(8)  DEFAULT NULL,  `location` varchar(255) DEFAULT NULL, `logContent` varchar(1024)  DEFAULT NULL,  `serviceId` int(11) DEFAULT NULL,  `workId` int(11) DEFAULT NULL,  `event` varchar(2) DEFAULT NULL,`iNDataContent` varchar(2048) DEFAULT NULL, `outDataContent` varchar(2048) DEFAULT NULL,`calculationLocation` varchar(8)  DEFAULT NULL,  `dataObjectId` varchar(32) DEFAULT NULL,`createtime`datetime)");
-            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fullData` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId` varchar(32) DEFAULT NULL,`fullData` longtext DEFAULT NULL)");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fulldata` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId` varchar(32) DEFAULT NULL,`fullData` longtext DEFAULT NULL)");
             return true;
         } catch (Exception e) {
             return false;

+ 1 - 1
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -150,6 +150,6 @@ public class CommonApi {
             errMap.put("message","服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
             return errMap;
         }
-        return dataProcessObj.processData(params);
+        return dataProcessObj.processData(params,token.get("user_id"));
     }
 }

+ 64 - 115
mainFactory/src/main/java/org/bfkj/application/DataProcess.java

@@ -121,14 +121,39 @@ public class DataProcess {
         }
         String dataObjectId = (String) inputData.get("dataObjectId");
         Object event = inputData.get("event"); //  服务表新增一个字段:用于标识当前服务支持的事件,用于限制入参的事件
+
         //初始化 列权限为空
         // 如果存在用户编号 且事件为查询
         //通过用户编号,服务编号,从用户权限表获取行列权限
         // 如果列权限为空则 直接返回空
         // 重新组建入口参数:添加filter(行权限)
         if (event.equals("0") && Objects.nonNull(user_id)) {
-            Map<String, Object> addRowPermissionMap = addRowPermission(inputData, user_id[0]);
-            inputData.put("dataContent", addRowPermissionMap);
+            inputData = initParam(inputData);
+            //判断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]);
+            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<Map<String, Object>> calculationResult = new ArrayList<>();//定义算法全量结果列表
@@ -158,10 +183,9 @@ public class DataProcess {
      * 添加行权限
      *
      * @param inputData
-     * @param userId
      * @return
      */
-    private static Map<String, Object> addRowPermission(Map<String, Object> inputData, String userId) {
+    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);
@@ -175,11 +199,14 @@ public class DataProcess {
             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<>(){{add(tempMap);}};
+                List<Object> tepList = new ArrayList<>() {{
+                    add(tempMap);
+                }};
                 Map<Object, Object> tmpData = new HashMap<>();
                 tmpData.put("filter", tepList);
                 tempList.add(tmpData);
@@ -197,128 +224,51 @@ public class DataProcess {
             dataContent = returnDataList;  // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
         }
         List<Map<String, Object>> data = new ArrayList<>();
-        if (dataContent instanceof List<?> temList && temList.get(0) instanceof Map temMap &&  !temMap.containsKey("left")) {
-            authoParams((List<Map<String, Object>>) temList, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
-        }else {
-            data = (List<Map<String, Object>>) dataContent;
-        }
-        inputData.put("dataContent",data);
-        //判断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");
-//
-//
-//        }
-        return inputData;
-    }
-
-    private static Map<String, Object> addRowPermission2(Map<String, Object> inputData, String userId) {
-        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;
-        }
-        List<?> tempDataList = dataContent instanceof List<?> tempDataContent ? tempDataContent:null;
-        if (Objects.nonNull(tempDataList) &&  tempDataList.get(0) instanceof Map  currentMap &&  !(currentMap.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<?> 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}}]
             }
-            dataContent = tempList;
-        }
-        if (Objects.nonNull(tempDataList) &&  tempDataList.get(0) instanceof Map  currentMap && currentMap.get("filter") instanceof Map<?, ?> filterMap) {  //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
-            List<Object> returnDataList = new ArrayList<>();
-            for (Object temp : tempDataList) {
-                if (temp instanceof Map itemMap){
-                    List<Object> tempList = new ArrayList<>();
-                    tempList.add(filterMap);
-                    itemMap.put("filter", tempList);
-                    returnDataList.add(itemMap);
-                }
-
-            }
-            dataContent = returnDataList;  // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
-        }
-        List<Map<String, Object>> data = new ArrayList<>();
-        if (dataContent instanceof List<?> temList && temList.get(0) instanceof Map temMap &&  !temMap.containsKey("left")) {
-            authoParams((List<Map<String, Object>>) temList, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
-        }else {
+        } else {
             data = (List<Map<String, Object>>) dataContent;
         }
-        inputData.put("dataContent",data);
-        //判断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");
-//
-//
-//        }
+        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("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("data","xxxx");
-//                put("data2","xxxx");
-//            }});
-//            add(new HashMap<>(){{
-//                put("data3","xxxx");
-//                put("data4","xxxx");
+//                put("filter",new ArrayList<>(){{
+//                    add(new HashMap<>(){{
+//                        put("a",null);
+//                    }});
+//                }});
 //            }});
 //        }});
-
-        objectHashMap.put("dataContent",new ArrayList<>(){{
-            add(new HashMap<>(){{
-                put("filter",new ArrayList<>(){{
-                    add(new HashMap<>(){{
-                        put("a",null);
-                    }});
-                }});
-            }});
-
-        }});
-        System.out.println(addRowPermission(objectHashMap, "1"));
+//        System.out.println(addRowPermission(objectHashMap, "1"));
     }
 
 
-
-
-    private  static  void authoParams(List<Map<String, Object>> ListInMap, List<Map<String, Object>> filterMapList) {
-        for (Map<String, Object> itemMap : ListInMap) { //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
-            List<Map<String,Object>> filter = (List<Map<String,Object>>)itemMap.get("filter");
-            for (Map<String, Object> filterKey : filter) {
+    //[{"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<>();
@@ -335,10 +285,9 @@ public class DataProcess {
                     filterValue.add(filterMap);
                 }
                 HashMap<String, Object> hashMap = new HashMap<>();
-                hashMap.put("filter",filterValue);
-                filterMapList.add(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) {

+ 1 - 1
mainFactory/src/main/java/org/bfkj/utils/LogUtils.java

@@ -58,7 +58,7 @@ public class LogUtils { // 依据服务编号ID获取服务类型,如果是异
             System.out.println("记录日志: 写入" + dbText + "日志失败 :" + shortMap.get("message") + "\n数据:" + MapTools.objectToString(logParam));
         }
         if (MapTools.isNotBlank(inData) && inData.length()>1024){
-            Map<String, Object> fullMap = myDbHelper.generalProcess("1", "log_fullData", null, null, logParam, false, null, null);
+            Map<String, Object> fullMap = myDbHelper.generalProcess("1", "log_fulldata", null, null, logParam, false, null, null);
             if (!fullMap.get("code").equals("0")) {
                 System.out.println("记录日志(超长全量数据): 写入" + dbText + "日志失败 :" + fullMap.get("message") + "\n数据:" + MapTools.objectToString(logParam));
             }

+ 2 - 2
mainFactory/src/main/java/org/bfkj/utils/MyDbHelper.java

@@ -76,7 +76,7 @@ public class MyDbHelper {
             DatabaseMetaData tempMetaData = theConnect.getMetaData();
             tablesRsesult = tempMetaData.getTables(theConnect.getCatalog(), theConnect.getCatalog(), null, new String[]{"TABLE"});
             while (tablesRsesult.next()) {//缓存当前数据库的所有表名
-                tableList.add(tablesRsesult.getString("TABLE_NAME"));//获取表名
+                tableList.add(tablesRsesult.getString("TABLE_NAME").toLowerCase());//获取表名
             }
 
         } catch (Exception e) {
@@ -529,7 +529,7 @@ public class MyDbHelper {
     }
 
     private Map<String, Object> getMetaDataByTable(String tableName, boolean isActive) {
-        if (!MapTools.isBlank(tableName) && !tableList.contains(tableName)) {
+        if (!MapTools.isBlank(tableName) && !tableList.contains(tableName.toLowerCase())) {
             if (isActive) {
                 try {
                     String tempSql = "CREATE TABLE if not EXISTS " + tableName + " (" + tableName + "_id int(11) NOT NULL AUTO_INCREMENT  PRIMARY KEY,`dataObjectId` VARCHAR(32) DEFAULT NULL ,`createtime` datetime  ) ";