Administrator
3 days ago 5b9d8648f3a0da63bb26fdb17c39d8999c9491c4
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
package cc.mrbird.febs.common.controller;
 
import cc.mrbird.febs.system.entity.User;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author MrBird
 */
public class BaseController {
 
    private Subject getSubject() {
        return SecurityUtils.getSubject();
    }
 
    protected User getCurrentUser() {
        return (User) getSubject().getPrincipal();
    }
 
    protected String getCurrentUserCompanyId() {
        String description = null;
        User user = (User) getSubject().getPrincipal();
        if (user != null){
            description = user.getDescription();
        }
        return description;
    }
 
    protected Session getSession() {
        return getSubject().getSession();
    }
 
    protected Session getSession(Boolean flag) {
        return getSubject().getSession(flag);
    }
 
    protected void login(AuthenticationToken token) {
        getSubject().login(token);
    }
 
    protected Map<String, Object> getDataTable(IPage<?> pageInfo) {
        return getDataTable(pageInfo, 2);
    }
 
    protected Map<String, Object> getDataTable(IPage<?> pageInfo, int dataMapInitialCapacity) {
        Map<String, Object> data = new HashMap<>(dataMapInitialCapacity);
        data.put("rows", pageInfo.getRecords());
        data.put("total", pageInfo.getTotal());
        return data;
    }
 
}