Fixiaobai
2023-08-29 15e7d7914452cb21646034e428d0bbf734d35edb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.yuanchu.limslaboratory.commandLineRunner;
 
import com.yuanchu.limslaboratory.annotation.AuthHandler;
import com.yuanchu.limslaboratory.mapper.RoleManageMapper;
import com.yuanchu.limslaboratory.utils.ArrayListUtil;
import com.yuanchu.limslaboratory.utils.MyClassUtil;
import com.yuanchu.limslaboratory.utils.SpringUtil;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
 
import java.lang.reflect.Method;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Author 张宾
 * @Date 2023/8/28
 */
@Component
@Order(1)
@Slf4j
public class ResolutionRequestsCommandLineRunner implements CommandLineRunner {
 
    @Autowired
    private RoleManageMapper roleManageMapper;
 
 
    @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);
    }
 
 
}