value
2024-04-30 ce10da906c58596fce43bffa6a6d177268ca177b
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
package com.yuanchu.mom.common;
 
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.annotation.ValueClassify;
import com.yuanchu.mom.mapper.AuthMapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
 
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.Map;
 
@Component
public class AllController {
    @Resource
    WebApplicationContext applicationContext;
 
    @Resource
    private AuthMapper authMapper;
 
    public void addAllController() {
        RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
        Map<RequestMappingInfo, HandlerMethod> methodMap = mapping.getHandlerMethods();
        authMapper.deletePower();
        for (HandlerMethod value : methodMap.values()) {
            ApiOperation annotation = value.getMethodAnnotation(ApiOperation.class);
            ValueAuth valueAuth = value.getMethodAnnotation(ValueAuth.class);
            ValueClassify valueClassify = value.getMethodAnnotation(ValueClassify.class);
            if (valueAuth == null) {
                if (valueClassify !=null) {
                    String type = valueClassify.value();
                    String remark = annotation.value();
                    authMapper.insertPower(value.getMethod().getName(),remark,type);
                }else{
                    if (annotation != null) {
                        String remark = annotation.value();
                        String type = "修改";
                        if (remark.contains("获取") || remark.contains("查询")) {
                            type = "查询";
                        } else if (remark.contains("删除")) {
                            type = "删除";
                        } else if (remark.contains("添加") || remark.contains("新增") || remark.contains("认领")) {
                            type = "添加";
                        } else if (remark.contains("导入")) {
                            type = "导入";
                        } else if (remark.contains("导出")) {
                            type = "导出";
                        }
                        try {
                            authMapper.insertPower(value.getMethod().getName(), remark, type);
                        } catch (Exception e) {
                            System.err.println(value.getMethod());
                            e.printStackTrace();
                        }
                    }
                }
                }
            }
            System.out.println("********************权限菜单完成********************");
        }
 
    @PostConstruct
    public void pingStart() {
        addAllController();
    }
}