AbsController.java
1.3 KB
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
package com.air.config;
import com.air.model.StationMap;
import com.air.model.SysRole;
import com.air.model.SysUser;
import com.jfinal.log.Log;
import com.teplot.common.BaseController;
import com.teplot.common.Utils;
/**
* Depiction:
* <p>
* Modify:
* <p>
* Author: Kevin Lynn
* <p>
* Create Date:2017年3月29日 上午10:46:31
*
*/
public class AbsController extends BaseController {
@Override
public void render(String view) {
setAttr("host", Utils.host());
setAttr("version", System.currentTimeMillis());
super.render(view);
}
/**
* 当前登录用户
*
* @return
*/
protected SysUser getLoginUser() {
return getSessionAttr("user");
}
/**
* 获取当前后台登录用户的角色
*
* @return
*/
protected SysRole getRole() {
SysRole role = null;
SysUser user = getLoginUser();
if (user == null || user.getInt("status") != 0) {
// 账户过期或者未启用
Log.getLog(getClass()).error("the user is null");
redirect("/login");
return role;
}
// 存在该账户,并且该账户处于启用状态
int roleLevel = user.getInt("roleLevel");
role = SysRole.dao.searchFirst("level", roleLevel);
return role;
}
protected String getStationArea() {
StationMap station = getLoginUser().get("station");
if (station != null) {
return station.getAreaCode();
}
return null;
}
}