Browse Source

授权管理

andy 1 year ago
parent
commit
ba964fcf40

+ 26 - 29
src/main/java/com/scbfkj/uni/library/script/AuthorizationScriptUtil.java

@@ -13,7 +13,7 @@ public class AuthorizationScriptUtil {
 
     public static Map<String, Object> authorization(Map<String, Object> data) throws Exception {
 
-        List<Object> dataContent = Optional.ofNullable(DataFormatUtil.toList(data.get("datacontent"))).orElse(new ArrayList<>());
+        List<Map<String,Object>> dataContent = Optional.ofNullable(DataFormatUtil.toList(data.get("datacontent"))).orElse(new ArrayList<>());
         if (dataContent.isEmpty()) {
             return UniReturnUtil.fail("datacontent 为空");
         }
@@ -27,41 +27,21 @@ public class AuthorizationScriptUtil {
                 sql = """
                         insert into userpermissions (userid, pageconfigurationid,serviceid)
                         values (?, ?, ?)""";
-                int[] result = DATABASE.updateBatch(Config.getSecurityConnectionStr(), sql, dataContent.stream().map(it -> {
-                    if (it instanceof Map<?, ?> map) {
-                        return new Object[]{id, map.get("pageconfigurationid"), map.get("serviceid")};
-                    } else {
-                        return new Object[]{it};
-                    }
-                }).toList());
+                int[] result = DATABASE.updateBatch(Config.getSecurityConnectionStr(), sql, dataContent.stream().map(it -> new Object[]{id, it.get("pageconfigurationid"), it.get("serviceid")}).toList());
                 return UniReturnUtil.success(result);
             } else if ("3".equals(event)) {
                 sql = """
                         delete
                         from userpermissions
                         where userid=? and pageconfigurationid = ?""";
-                int[] result = DATABASE.updateBatch(Config.getSecurityConnectionStr(), sql, dataContent.stream().map(it -> {
-                    if (it instanceof Map<?, ?> map) {
-                        return new Object[]{id, map.get("pageconfigurationid")};
-                    } else {
-                        return new Object[]{it};
-                    }
-                }).toList());
+                int[] result = DATABASE.updateBatch(Config.getSecurityConnectionStr(), sql, dataContent.stream().map(it -> new Object[]{id, it.get("pageconfigurationid")}).toList());
                 return UniReturnUtil.success(result);
             }
 
         } else if ("2".equals(type)) {
             Set<Object> childrenGroup = getChildrenGroup(id);
             Map<String, List<Object[]>> children = new HashMap<>();
-            ArrayList<Object[]> lines = new ArrayList<>();
-            for (Object o : dataContent) {
-                lines.add(new Object[]{id, o});
-            }
-            for (Object id1 : childrenGroup) {
-                for (Object o : dataContent) {
-                    lines.add(new Object[]{id1, o});
-                }
-            }
+
 
             ArrayList<Object[]> userInfoValues = new ArrayList<>();
             Set<Object> childrenUserInfo = getChildrenUserInfo(childrenGroup);
@@ -71,20 +51,37 @@ public class AuthorizationScriptUtil {
                 }
             }
             if ("1".equals(event)) {
-
+                ArrayList<Object[]> lines = new ArrayList<>();
+                for (Map o : dataContent) {
+                    lines.add(new Object[]{id, o.get("pageconfigurationid"),o.get("serviceid")});
+                }
+                for (Object id1 : childrenGroup) {
+                    for (Map o : dataContent) {
+                        lines.add(new Object[]{id1, o.get("pageconfigurationid"),o.get("serviceid")});
+                    }
+                }
                 sql = """
-                        insert into usergrouppermissions (usergroupid, pageconfigurationid)
-                        values (?, ?)""";
+                        insert into usergrouppermissions (usergroupid, pageconfigurationid,serviceid)
+                        values (?, ?,?)""";
                 children.put(sql, lines);
 
                 sql = """
-                        insert into userpermissions (userid, pageconfigurationid)
-                        values (?, ?)
+                        insert into userpermissions (userid, pageconfigurationid,serviceid)
+                        values (?, ?,?)
                         """;
                 children.put(sql, userInfoValues);
 
 
             } else if ("3".equals(event)) {
+                ArrayList<Object[]> lines = new ArrayList<>();
+                for (Map o : dataContent) {
+                    lines.add(new Object[]{id, o.get("pageconfigurationid")});
+                }
+                for (Object id1 : childrenGroup) {
+                    for (Map o : dataContent) {
+                        lines.add(new Object[]{id1, o.get("pageconfigurationid")});
+                    }
+                }
                 sql = """
                         delete
                         from usergrouppermissions