瀏覽代碼

权限授权新增删除

andy 1 年之前
父節點
當前提交
2a773540e0
共有 1 個文件被更改,包括 0 次插入117 次删除
  1. 0 117
      src/main/java/com/scbfkj/uni/library/script/AuthorizationScript.java

+ 0 - 117
src/main/java/com/scbfkj/uni/library/script/AuthorizationScript.java

@@ -1,117 +0,0 @@
-package com.scbfkj.uni.library.script;
-
-import com.scbfkj.uni.library.DataFormatUtil;
-import com.scbfkj.uni.library.UniReturnUtil;
-import com.scbfkj.uni.process.DataBase;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-public class AuthorizationScript {
-
-
-    public Map<String, Object> authorization(String datasourceId, Map<String, Object> data) {
-
-        List<Map<String, Object>> dataContent = Optional.ofNullable(DataFormatUtil.toList(data.get("datacontent"))).map(it -> it.stream().map(d -> {
-            Map<?, ?> map = DataFormatUtil.toMap(d);
-            return (Map<String, Object>) map;
-        }).toList()).orElse(new ArrayList<>());
-        if (dataContent.isEmpty()) {
-            return UniReturnUtil.fail("datacontent 为空");
-        }
-        Object event = data.get("event").toString();
-        /**
-         * 继续对mapList做type分组
-         */
-        Map<Object, List<Map<String, Object>>> typeDatas = dataContent.stream().collect(Collectors.groupingBy(it -> it.get("type")));
-
-        Map<String, List<Object[]>> args = new HashMap<>();
-        typeDatas.entrySet().stream().forEach(it -> {
-            List<Map<String, Object>> itValue = it.getValue();
-            if (it.getKey().equals("1")) {
-                List<Object[]> values = itValue.stream().map(value -> {
-                    ArrayList<Object> arrayList = new ArrayList<>();
-                    arrayList.add(value.get("id"));
-                    arrayList.add(value.get("pageconfigurationid"));
-                    return arrayList.toArray();
-                }).toList();
-//                新增
-                if ("1".equals(event)) {
-
-                    args.put("""
-                            insert into userpermissions (userid, pageconfigurationid)
-                            values (?, ?)""", values);
-
-//                    删除
-                } else if ("3".equals(event)) {
-
-                    args.put("""
-                            delete
-                            from userpermissions
-                            where userid=? and pageconfigurationid=?""", values);
-                }
-            } else if (it.getKey().equals("2")) {
-                List<Object[]> values = itValue.stream().map(value -> {
-                    ArrayList<Object> arrayList = new ArrayList<>();
-                    arrayList.add(value.get("id"));
-                    arrayList.add(value.get("pageconfigurationid"));
-                    return arrayList.toArray();
-                }).toList();
-
-//                新增
-                if ("1".equals(event)) {
-                    args.put("""
-                            insert into usergrouppermissions (usergroupid, pageconfigurationid)
-                            values (?, ?)""", values);
-
-//                    删除
-                } else if ("3".equals(event)) {
-
-                    args.put("""
-                            delete
-                            from usergrouppermissions
-                            where usergroupid=? and pageconfigurationid=?""", values);
-                }
-            }
-        });
-        try {
-            DataBase.updateBatchExtend(DatabaseScriptUtil.queryConnectionStr(datasourceId), args);
-            return UniReturnUtil.success(true);
-        } catch (Exception exception) {
-            return UniReturnUtil.fail(exception);
-        }
-
-    }
-
-    public Map<String, Object> getAuthorization(String datasourceId, Map<String, Object> data) {
-        List<Map<String, Object>> dataContent = Optional.ofNullable(DataFormatUtil.toList(data.get("datacontent"))).map(it -> it.stream().map(d -> {
-            Map<?, ?> map = DataFormatUtil.toMap(d);
-            return (Map<String, Object>) map;
-        }).toList()).orElse(new ArrayList<>());
-        if (dataContent.isEmpty()) {
-            return UniReturnUtil.fail("datacontent 为空");
-        }
-        Map<String, Object> value = dataContent.get(0);
-        Object id = value.get("id");
-        List<Map<String, Object>> results;
-        try {
-            if (value.get("type").toString().equals("2")) {
-                results = DataBase.query(DatabaseScriptUtil.queryConnectionStr(datasourceId), """
-                        select distinct pageconfiguration.*
-                        from usergrouppermissions
-                                 right join pageconfiguration on pageconfiguration.pageconfigurationid = usergrouppermissions.pageconfigurationid
-                        where usergroupid = ?""", id);
-            } else {
-
-                results = DataBase.query(DatabaseScriptUtil.queryConnectionStr(datasourceId), """
-                        select  distinct pageconfiguration.* 
-                        from userpermissions 
-                            right join pageconfiguration on pageconfiguration.pageconfigurationid = userpermissions.pageconfigurationid  
-                        where userid =?""", id);
-            }
-        } catch (Exception e) {
-            return UniReturnUtil.fail(e);
-        }
-        return UniReturnUtil.success(results);
-    }
-}