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("${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;
|
}
|
}
|