kongzy
2023-11-28 59d9ea33f503e363f2e2941c7c00cc9dd9d9d1c7
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
package com.nanometer.smartlab.controller;
 
import com.nanometer.smartlab.entity.SysUser;
import com.nanometer.smartlab.util.Constants;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Value;
 
import java.io.Serializable;
 
/**
 * Created by johnny on 15/12/24.
 */
public class BaseController implements Serializable {
 
 
    @Value("${institute.name}")
    private String title;
 
    @Value("${institute.logo}")
    private String logo;
 
    @Value("${institute.copyright}")
    private String copyright;
 
    @Value("${activeEnv}")
    private String activeEnv;
 
    public Subject getSubject() {
        return SecurityUtils.getSubject();
    }
 
    public boolean isPermitted(String code) {
        if (StringUtils.isBlank(code)) {
            return true;
        }
        return this.getSubject().isPermitted(code);
    }
 
    public SysUser getUser() {
        Object obj = this.getSubject().getSession(true).getAttribute(Constants.SESSION_USER);
        if (obj != null) {
            return (SysUser) obj;
        }
        return null;
    }
 
    public String getUserName() {
        SysUser user = this.getUser();
        if (user != null) {
            return user.getName();
        }
        return "";
    }
 
    public String getUserId() {
        SysUser user = this.getUser();
        if (user != null) {
            return user.getId();
        }
        return null;
    }
 
    public String getUserDepartment() {
        SysUser user = this.getUser();
        if (user != null) {
            return user.getDepartment();
        }
        return null;
    }
 
    public String getUserProject() {
        SysUser user = this.getUser();
        if (user != null) {
            return user.getProject();
        }
        return null;
    }
 
    public String getTitle(){
        if(StringUtils.isBlank(this.title)){
            return "中国科学院苏州纳米技术与纳米仿生研究所";
        }
        return this.title;
    }
 
    public String getLogo(){
        if(StringUtils.isBlank(this.logo)){
            return "/resources/images/中国科学院苏州纳米技术与纳米仿生研究所logo.png";
        }
        return this.logo;
    }
 
    public String getActiveEnv(){
        return this.activeEnv;
    }
 
    public String getCopyright() {
        return copyright;
    }
}