com.sicheng.admin.sys.entity.User Maven / Gradle / Ivy
/**
* 本作品使用 木兰公共许可证,第2版(Mulan PubL v2) 开源协议,请遵守相关条款,或者联系sicheng.net获取商用授权。
* Copyright (c) 2016 SiCheng.Net
* This software is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
package com.sicheng.admin.sys.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.sicheng.admin.sys.dao.RoleDao;
import com.sicheng.admin.sys.dao.SysUserRoleDao;
import com.sicheng.common.persistence.wrapper.Wrapper;
import com.sicheng.common.utils.Collections3;
import com.sicheng.common.web.SpringContextHolder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 用户 Entity 子类,请把你的业务代码写在这里
*
* @author fxx
* @version 2017-02-08
*/
public class User extends UserBase {
private static final long serialVersionUID = 1L;
private Role role; // 根据角色查询用户条件
private String oldLoginName;// 原登录名
private String newPassword; // 新密码
private String oldLoginIp; // 上次登录IP
private Date oldLoginDate; // 上次登录日期
private List roleList = Lists.newArrayList(); // 拥有角色列表
private List roleIdList = Lists.newArrayList(); // 拥有角色列表
public User() {
super();
}
public User(Long id) {
super(id);
}
public User(Long id, String loginName) {
super(id);
setLoginName(loginName);
}
public User(Role role) {
super();
this.role = role;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
@JsonIgnore
//系统拆分时做的修改 zl 2017-3-16
//@ExcelField(title="拥有角色", align=1, sort=800, fieldType=RoleListType.class)
public List getRoleList() {
return roleList;
}
public void setRoleList(List roleList) {
this.roleList = roleList;
}
@JsonIgnore
public List getRoleIdList() {
SysUserRoleDao sysUserRoleDao = SpringContextHolder.getBean(SysUserRoleDao.class);
List sysUserRoles = sysUserRoleDao.selectByWhere(null, new Wrapper(new SysUserRole()).and("user_id=", this.getId()));
if (!sysUserRoles.isEmpty()) {
List roleIds = new ArrayList();
for (int i = 0; i < sysUserRoles.size(); i++) {
roleIds.add(sysUserRoles.get(i).getRoleId());
}
RoleDao roleDao = SpringContextHolder.getBean(RoleDao.class);
roleList = roleDao.selectByWhere(null, new Wrapper().and("id in", roleIds));
}
for (Role role : roleList) {
roleIdList.add(role.getId());
}
return roleIdList;
}
public void setRoleIdList(List roleIdList) {
this.roleIdList = roleIdList;
}
/**
* 用户拥有的角色名称字符串, 多个角色名称用','分隔.
*/
public String getRoleNames() {
return Collections3.extractToString(roleList, "name", ",");
}
public boolean isAdmin() {
return isAdmin(this.id);
}
public static boolean isAdmin(Long id) {
return id == 1L;
}
@Override
public String toString() {
return String.valueOf(id);
}
public String getOldLoginName() {
return oldLoginName;
}
public void setOldLoginName(String oldLoginName) {
this.oldLoginName = oldLoginName;
}
public String getNewPassword() {
return newPassword;
}
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}
public String getOldLoginIp() {
return oldLoginIp;
}
public void setOldLoginIp(String oldLoginIp) {
this.oldLoginIp = oldLoginIp;
}
public Date getOldLoginDate() {
return oldLoginDate;
}
public void setOldLoginDate(Date oldLoginDate) {
this.oldLoginDate = oldLoginDate;
}
}