瀏覽代碼

添加返回结果按照页面权限的列过滤数据

andy 1 年之前
父節點
當前提交
a7eb136de0
共有 1 個文件被更改,包括 63 次插入14 次删除
  1. 63 14
      src/main/java/com/scbfkj/uni/api/LogAop.java

+ 63 - 14
src/main/java/com/scbfkj/uni/api/LogAop.java

@@ -36,12 +36,9 @@ public class LogAop {
 //        请求
         String uri = RequestUtil.getUri();
 
-        System.out.println("请求 url:" + uri);
-
-
 //        请求参数
         Object[] args = joinPoint.getArgs();
-        ResponseEntity<Map<String, Object>> returnData = null;
+        Map<String, Object> returnData = null;
         String message = null;
 
         if (Config.isDebug()) {
@@ -49,13 +46,15 @@ public class LogAop {
             System.out.println("请求路径:" + uri);
             System.out.println("请求session:" + RequestUtil.getSessionId());
             System.out.println("请求ip:" + RequestUtil.getIpAddr());
+            System.out.println("请求userToken:" + RequestUtil.getUserToken());
             System.out.println("请求appToken:" + RequestUtil.getAppToken());
         }
 
+        Optional serviceid = Optional.empty();
+        String userId = RequestUtil.getUserId();
         try {
 
             Map body = null;
-            Optional serviceid = Optional.empty();
 
 //            判断服务状态是否为健康状态 runstate!=0
             if (args.length > 0) {
@@ -131,7 +130,7 @@ public class LogAop {
                                     return ResponseEntity.ok(UniReturnUtil.fail("token验证失败"));
                                 }
                                 if (body != null) {
-                                    List<Map<String, Object>> data = DATA_BASE.query(Config.getSecurityConnectionStr(), "select * from applicationpermissions where appid = ?", RequestUtil.getAppId());
+                                    List<Map<String, Object>> data = DATA_BASE.query(Config.getSecurityConnectionStr(), "select * from userpermissions where userid = ? and serviceid=?", userId, serviceid.get());
                                     if (data != null && !data.isEmpty()) {
                                         Map<String, Object> result = data.get(0);
                                         Object columnlist = result.get("columnlist");
@@ -143,7 +142,7 @@ public class LogAop {
                                         Object filterset = result.get("filterset");
                                         if (filterset != null) {
 
-                                            List list = DataFormatUtil.getObjectMapper().readValue(columnlist.toString(), List.class);
+                                            List list = DataFormatUtil.getObjectMapper().readValue(filterset.toString(), List.class);
                                             body.put("filterLines", list.stream().map(it -> {
                                                 try {
                                                     return DataFormatUtil.getObjectMapper().readValue(it.toString(), Map.class);
@@ -153,6 +152,10 @@ public class LogAop {
                                             }).toList());
                                         }
                                     }
+                                    body.put("filterColumns", new ArrayList<>() {{
+                                        add("*");
+                                    }});
+
                                 }
                             }
                             if (Objects.equals("usertoken", s)) {
@@ -166,7 +169,7 @@ public class LogAop {
                                 }
 
                                 if (body != null && serviceid.isPresent()) {
-                                    List<Map<String, Object>> data = DATA_BASE.query(Config.getSecurityConnectionStr(), "select * from userpermissions where userid = ? and serviceid=?", RequestUtil.getUserId(), serviceid.get());
+                                    List<Map<String, Object>> data = DATA_BASE.query(Config.getSecurityConnectionStr(), "select * from userpermissions where userid = ? and serviceid=?", userId, serviceid.get());
                                     if (data != null && !data.isEmpty()) {
                                         Map<String, Object> result = data.get(0);
                                         Object columnlist = result.get("selectcolumnlist");
@@ -234,8 +237,15 @@ public class LogAop {
                     }
                 }
             }
-
-            returnData = (ResponseEntity<Map<String, Object>>) joinPoint.proceed(args);
+            ResponseEntity<Map<String, Object>> responseEntity = (ResponseEntity<Map<String, Object>>) joinPoint.proceed(args);
+            if (!responseEntity.getStatusCode().is2xxSuccessful()) {
+                if (Config.isDebug()) {
+                    System.out.println("返回值:" + DataFormatUtil.toString(returnData));
+                }
+                return responseEntity;
+            } else {
+                returnData = responseEntity.getBody();
+            }
 
         } catch (Throwable e) {
             if (Config.isDebug()) {
@@ -243,7 +253,7 @@ public class LogAop {
             }
 //            错误异常消息
             message = UniReturnUtil.getMessage(e);
-            returnData = ResponseEntity.ok(UniReturnUtil.fail(message));
+            returnData = UniReturnUtil.fail(message);
         } finally {
             HashMap<String, Object> logData = new HashMap<>();
             logData.put("requesttime", requestTime);
@@ -256,8 +266,6 @@ public class LogAop {
             } catch (Exception e) {
                 if (Config.isDebug()) {
                     e.printStackTrace();
-                } else {
-                    System.out.println(UniReturnUtil.getMessage(e));
                 }
             }
             LoggerService.log(LoggerService.LogType.INTERFACE, logData);
@@ -266,6 +274,47 @@ public class LogAop {
         if (Config.isDebug()) {
             System.out.println("返回值:" + DataFormatUtil.toString(returnData));
         }
-        return returnData;
+
+        Optional<Map<String, Object>> userinfo = Optional.empty();
+        try {
+            userinfo = DATA_BASE.query(Config.getSecurityConnectionStr(), " select usergroupid from userinfo where userid =?", userId).stream().findFirst();
+        } catch (Exception e) {
+            if (Config.isDebug()) {
+                e.printStackTrace();
+            }
+//            错误异常消息
+            message = UniReturnUtil.getMessage(e);
+            returnData = UniReturnUtil.fail(message);
+        }
+
+        Object code = returnData.get("code");
+//        过滤数据
+        if (!Config.isDebug() && Objects.nonNull(code) && "0".equals(code.toString()) && userinfo.isPresent() && !"0".equals(userinfo.get().get("usergroupid").toString())) {
+            Object returnData1 = returnData.get("returnData");
+            if (returnData1 instanceof List<?> ls) {
+                if (serviceid.isPresent()) {
+                    try {
+                        List<String> columns = DATA_BASE.query(Config.getSecurityConnectionStr(), "select pagecode from pageconfiguration where pageconfiguration.pageconfigurationid  in (select userpermissions.pageconfigurationid from userpermissions where  userid =? and  serviceid = ?)", userId, serviceid.get()).stream().map(it -> it.get("pagecode").toString()).toList();
+                        List<Object> list = ls.stream().map(it -> {
+                            if (it instanceof Map<?, ?> map) {
+                                HashMap<Object, Object> map1 = new HashMap<>();
+                                columns.forEach(key -> {
+                                    map1.put(key, map.get(key));
+                                });
+                                return map1;
+                            } else {
+                                return it;
+                            }
+                        }).toList();
+                        returnData.put("returnData", list);
+
+                    } catch (Exception e) {
+                        returnData.put("returnData", new ArrayList<>());
+                    }
+
+                }
+            }
+        }
+        return ResponseEntity.ok(returnData);
     }
 }