办学质量监测教学评价系统
康鲁杰
7 天以前 3041043370ee9dbbd7917b7843f4c72c03081e5e
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package org.ruoyi.system.domain;
 
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.ruoyi.common.core.constant.Constants;
import org.ruoyi.common.core.constant.UserConstants;
import org.ruoyi.common.core.utils.StringUtils;
import org.ruoyi.core.domain.BaseEntity;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 菜单权限表 sys_menu
 *
 * @author Lion Li
 */
 
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("SYS_MENU")
public class SysMenu extends BaseEntity {
 
    @TableId(value = "MENU_ID")
    private Long menuId;
 
    @TableField("PARENT_ID")
    private Long parentId;
 
    @TableField("MENU_NAME")
    private String menuName;
 
    @TableField("ORDER_NUM")
    private Integer orderNum;
 
    @TableField("PATH")
    private String path;
 
    @TableField("COMPONENT")
    private String component;
 
    @TableField("QUERY_PARAM")
    private String queryParam;
 
    @TableField("IS_FRAME")
    private String isFrame;
 
    @TableField("IS_CACHE")
    private String isCache;
 
    @TableField("MENU_TYPE")
    private String menuType;
 
    @TableField("VISIBLE")
    private String visible;
 
    @TableField("STATUS")
    private String status;
 
    @TableField("PERMS")
    private String perms;
 
    @TableField("ICON")
    private String icon;
 
    @TableField("REMARK")
    private String remark;
 
    /**
     * 父菜单名称
     */
    @TableField(exist = false)
    private String parentName;
 
    /**
     * 子菜单
     */
    @TableField(exist = false)
    private List<SysMenu> children = new ArrayList<>();
 
    /**
     * 获取路由名称
     */
    public String getRouteName() {
        String routerName = StringUtils.capitalize(path);
        // 非外链并且是一级目录(类型为目录)
        if (isMenuFrame()) {
            routerName = StringUtils.EMPTY;
        }
        return routerName;
    }
 
    /**
     * 获取路由地址
     */
    public String getRouterPath() {
        String routerPath = this.path;
        // 内链打开外网方式
        if (getParentId() != 0L && isInnerLink()) {
            routerPath = innerLinkReplaceEach(routerPath);
        }
        // 非外链并且是一级目录(类型为目录)
        if (0L == getParentId() && UserConstants.TYPE_DIR.equals(getMenuType())
            && UserConstants.NO_FRAME.equals(getIsFrame())) {
            routerPath = "/" + this.path;
        }
        // 非外链并且是一级目录(类型为菜单)
        else if (isMenuFrame()) {
            routerPath = "/";
        }
        return routerPath;
    }
 
    /**
     * 获取组件信息
     */
    public String getComponentInfo() {
        String component = UserConstants.LAYOUT;
        if (StringUtils.isNotEmpty(this.component) && !isMenuFrame()) {
            component = this.component;
        } else if (StringUtils.isEmpty(this.component) && getParentId() != 0L && isInnerLink()) {
            component = UserConstants.INNER_LINK;
        } else if (StringUtils.isEmpty(this.component) && isParentView()) {
            component = UserConstants.PARENT_VIEW;
        }
        return component;
    }
 
    /**
     * 是否为菜单内部跳转
     */
    public boolean isMenuFrame() {
        return getParentId() == 0L && UserConstants.TYPE_MENU.equals(menuType) && isFrame.equals(UserConstants.NO_FRAME);
    }
 
    /**
     * 是否为内链组件
     */
    public boolean isInnerLink() {
        return isFrame.equals(UserConstants.NO_FRAME) && StringUtils.ishttp(path);
    }
 
    /**
     * 是否为parent_view组件
     */
    public boolean isParentView() {
        return getParentId() != 0L && UserConstants.TYPE_DIR.equals(menuType);
    }
 
    /**
     * 内链域名特殊字符替换
     */
    public static String innerLinkReplaceEach(String path) {
        return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
            new String[]{"", "", "", "/"});
    }
}