From 084c0c3ba5600e0b406ea9c7c7c158a527933d4c Mon Sep 17 00:00:00 2001
From: Fixiaobai <fixiaobai@163.com>
Date: 星期三, 30 八月 2023 09:12:58 +0800
Subject: [PATCH] 修改接口新增方式,

---
 sys/src/main/java/com/yuanchu/limslaboratory/commandLineRunner/ResolutionRequestsCommandLineRunner.java |  127 ++++++++++++++++++++++-------------------
 1 files changed, 68 insertions(+), 59 deletions(-)

diff --git a/sys/src/main/java/com/yuanchu/limslaboratory/commandLineRunner/ResolutionRequestsCommandLineRunner.java b/sys/src/main/java/com/yuanchu/limslaboratory/commandLineRunner/ResolutionRequestsCommandLineRunner.java
index 2ca5b77..4fbf344 100644
--- a/sys/src/main/java/com/yuanchu/limslaboratory/commandLineRunner/ResolutionRequestsCommandLineRunner.java
+++ b/sys/src/main/java/com/yuanchu/limslaboratory/commandLineRunner/ResolutionRequestsCommandLineRunner.java
@@ -1,6 +1,7 @@
 package com.yuanchu.limslaboratory.commandLineRunner;
 
 import com.yuanchu.limslaboratory.annotation.AuthHandler;
+import com.yuanchu.limslaboratory.mapper.MenuMapper;
 import com.yuanchu.limslaboratory.mapper.RoleManageMapper;
 import com.yuanchu.limslaboratory.utils.ArrayListUtil;
 import com.yuanchu.limslaboratory.utils.MyClassUtil;
@@ -38,69 +39,77 @@
     @Autowired
     private RoleManageMapper roleManageMapper;
 
+    @Autowired
+    private MenuMapper menuMapper;
 
     @SneakyThrows
     @Override
     public void run(String... args) throws Exception {
-        //log.info("瀹瑰櫒鐢熸垚涔嬪悗鎵ц");
-        //List<Class<?>> classList = MyClassUtil.getClassList("com.yuanchu.limslaboratory.controller");
-        //List<Map<String, Object>> requestListInfo = new ArrayList<Map<String, Object>>();
-        //List<Map<String, Object>> urlList = new ArrayList<Map<String, Object>>();
-        //classList.stream().forEach(c -> {
-        //    Method[] methods = c.getMethods();
-        //    //鍘绘帀瀵硅薄鏂规硶
-        //    List<Method> methodList = Arrays.stream(methods)
-        //            .filter(m -> !"notify".equals(m.getName()) && !"getClass".equals(m.getName())
-        //                    && !"hashCode".equals(m.getName()) && !"toString".equals(m.getName())
-        //                    && !"equals".equals(m.getName()) && !"wait".equals(m.getName()) && !"notifyAll".equals(m.getName()))
-        //            .collect(Collectors.toList());
-        //
-        //    for (int i = 0; i < methodList.size(); i++) {
-        //        Method method = methodList.get(i);
-        //        if (method.isAnnotationPresent(AuthHandler.class)) {
-        //            //鑾峰彇绫讳笂璇锋眰鍦板潃
-        //            RequestMapping annotation = c.getAnnotation(RequestMapping.class);
-        //            StringBuilder builder = new StringBuilder();
-        //            String apiInfo = null;
-        //            builder.append(annotation.value()[0]);
-        //            //鑾峰彇鏂规硶涓婃敞瑙�
-        //            if (method.isAnnotationPresent(PostMapping.class)) {
-        //                PostMapping post = method.getAnnotation(PostMapping.class);
-        //                builder.append(post.value()[0]);
-        //            }
-        //            if (method.isAnnotationPresent(GetMapping.class)) {
-        //                GetMapping get = method.getAnnotation(GetMapping.class);
-        //                builder.append(get.value()[0]);
-        //            }
-        //            if (method.isAnnotationPresent(DeleteMapping.class)) {
-        //                DeleteMapping delete = method.getAnnotation(DeleteMapping.class);
-        //                builder.append(delete.value()[0]);
-        //            }
-        //            if (method.isAnnotationPresent(PutMapping.class)) {
-        //                PutMapping put = method.getAnnotation(PutMapping.class);
-        //                builder.append(put.value()[0]);
-        //            }
-        //            if (method.isAnnotationPresent(ApiOperation.class)) {
-        //                ApiOperation api = method.getAnnotation(ApiOperation.class);
-        //                apiInfo = api.value();
-        //            }
-        //            Map<String, Object> map = new HashMap<String, Object>();
-        //            map.put("url", builder);
-        //            map.put("name", apiInfo);
-        //            urlList.add(map);
-        //            requestListInfo.add(map);
-        //        }
-        //    }
-        //});
-        //requestListInfo.forEach(System.out::println);
-        //List<Map<String, Object>> allInterfaces = roleManageMapper.getAllInterfaces();
-        //System.out.println(requestListInfo.size());
-        //List<Map<String, Object>> mapList = urlList.stream().filter(item -> !allInterfaces.stream()
-        //                .map(e -> e).distinct().collect(Collectors.toList())
-        //                .contains(item))
-        //        .collect(Collectors.toList());
-        //System.out.println("=======================");
-        //mapList.forEach(System.out::println);
+        log.info("瀹瑰櫒鐢熸垚涔嬪悗鎵ц");
+        List<Class<?>> classList = MyClassUtil.getClassList("com.yuanchu.limslaboratory.controller");
+        List<Map<String, String>> requestListInfo = new ArrayList<Map<String, String>>();
+        classList.stream().forEach(c -> {
+            Method[] methods = c.getMethods();
+            //鍘绘帀瀵硅薄鏂规硶
+            List<Method> methodList = Arrays.stream(methods)
+                    .filter(m -> !"notify".equals(m.getName()) && !"getClass".equals(m.getName())
+                            && !"hashCode".equals(m.getName()) && !"toString".equals(m.getName())
+                            && !"equals".equals(m.getName()) && !"wait".equals(m.getName()) && !"notifyAll".equals(m.getName()))
+                    .collect(Collectors.toList());
+
+            for (int i = 0; i < methodList.size(); i++) {
+                Method method = methodList.get(i);
+                boolean annotationPresent = method.isAnnotationPresent(AuthHandler.class);
+                if (annotationPresent&&method.getAnnotation(AuthHandler.class).isAdd()) {
+                    //鑾峰彇绫讳笂璇锋眰鍦板潃
+                    RequestMapping annotation = c.getAnnotation(RequestMapping.class);
+                    StringBuilder builder = new StringBuilder();
+                    String apiInfo = null;
+                    builder.append(annotation.value()[0]);
+                    //鑾峰彇鏂规硶涓婃敞瑙�
+                    if (method.isAnnotationPresent(PostMapping.class)) {
+                        PostMapping post = method.getAnnotation(PostMapping.class);
+                        builder.append(post.value()[0]);
+                    }
+                    if (method.isAnnotationPresent(GetMapping.class)) {
+                        GetMapping get = method.getAnnotation(GetMapping.class);
+                        builder.append(get.value()[0]);
+                    }
+                    if (method.isAnnotationPresent(DeleteMapping.class)) {
+                        DeleteMapping delete = method.getAnnotation(DeleteMapping.class);
+                        builder.append(delete.value()[0]);
+                    }
+                    if (method.isAnnotationPresent(PutMapping.class)) {
+                        PutMapping put = method.getAnnotation(PutMapping.class);
+                        builder.append(put.value()[0]);
+                    }
+                    if (method.isAnnotationPresent(ApiOperation.class)) {
+                        ApiOperation api = method.getAnnotation(ApiOperation.class);
+                        apiInfo = api.value();
+                    }
+                    Map<String, String> map = new HashMap<String, String>();
+                    AuthHandler auth = method.getAnnotation(AuthHandler.class);
+                    map.put("menuId", String.valueOf(auth.menuId().getId()));
+                    map.put("type",String.valueOf(auth.type().getNum()));
+                    map.put("url", builder.toString());
+                    map.put("name", apiInfo);
+                    requestListInfo.add(map);
+                }
+            }
+        });
+        List<Map<String, String>> allInterfaces = roleManageMapper.getAllInterfaces();
+        List<Map<String, String>> differentMaps = requestListInfo.stream()
+                .filter(map1 -> allInterfaces.stream()
+                        .map(map2 -> map2.get("url"))  // 鑾峰彇鎸囧畾閿殑鍊�
+                        .noneMatch(value2 -> value2.equals(map1.get("url")))  // 鏌ユ壘涓嶅悓鐨勫��
+                ).collect(Collectors.toList());
+        if(differentMaps.size()>0){
+            int insertInterfaceList = roleManageMapper.insertInterfaceList(differentMaps);
+            if (insertInterfaceList>0) log.info("鏂板鎺ュ彛鎴愬姛锛�");
+        }else {
+            log.info("鏃犻渶澧炲姞鏂扮殑鎺ュ彛锛�");
+        }
+
     }
 
 

--
Gitblit v1.9.3