AbsController.java 1.3 KB
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;
	}
}