169 lines
3.6 KiB
Java
169 lines
3.6 KiB
Java
package com.nis.domain;
|
||
|
||
import java.io.Serializable;
|
||
import java.util.Map;
|
||
|
||
import javax.xml.bind.annotation.XmlTransient;
|
||
|
||
import com.zdjizhi.utils.StringUtil;
|
||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||
import com.google.common.collect.Maps;
|
||
import com.nis.supcan.SupCol;
|
||
import com.nis.supcan.SupTreeList;
|
||
import com.nis.util.Configurations;
|
||
import com.nis.web.security.UserUtils;
|
||
|
||
/**
|
||
* Entity支持类
|
||
* @author ThinkGem
|
||
* @version 2014-05-16
|
||
*/
|
||
@SupTreeList
|
||
public abstract class BaseEntity<T> implements Serializable {
|
||
|
||
private static final long serialVersionUID = 1L;
|
||
|
||
/**
|
||
* 删除标记(1:正常;0:删除;2:审核;)
|
||
*/
|
||
public static final String DEL_FLAG_NORMAL = "1";
|
||
public static final String DEL_FLAG_DELETE = "0";
|
||
public static final String DEL_FLAG_AUDIT = "2";
|
||
|
||
/**
|
||
* 实体编号(唯一标识)
|
||
*/
|
||
protected Long id;
|
||
|
||
/**
|
||
* 当前用户
|
||
*/
|
||
protected SysUser currentUser;
|
||
|
||
/**
|
||
* 当前实体分页对象
|
||
*/
|
||
protected Page<T> page;
|
||
|
||
/**
|
||
* 自定义SQL(SQL标识,SQL内容)
|
||
*/
|
||
protected Map<String, String> sqlMap;
|
||
|
||
/**
|
||
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
||
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
||
*/
|
||
protected boolean isNewRecord = false;
|
||
|
||
public BaseEntity() {
|
||
|
||
}
|
||
|
||
public BaseEntity(Long id) {
|
||
this();
|
||
this.id = id;
|
||
}
|
||
|
||
@SupCol(isUnique="true", isHide="true")
|
||
public Long getId() {
|
||
return id;
|
||
}
|
||
|
||
public void setId(Long id) {
|
||
this.id = id;
|
||
}
|
||
|
||
@JsonIgnore
|
||
@XmlTransient
|
||
public SysUser getCurrentUser() {
|
||
if(currentUser == null){
|
||
currentUser = UserUtils.getUser();
|
||
}
|
||
return currentUser;
|
||
}
|
||
|
||
public void setCurrentUser(SysUser currentUser) {
|
||
this.currentUser = currentUser;
|
||
}
|
||
|
||
@JsonIgnore
|
||
@XmlTransient
|
||
public Page<T> getPage() {
|
||
if (page == null){
|
||
page = new Page<T>();
|
||
}
|
||
return page;
|
||
}
|
||
|
||
public Page<T> setPage(Page<T> page) {
|
||
this.page = page;
|
||
return page;
|
||
}
|
||
|
||
@JsonIgnore
|
||
@XmlTransient
|
||
public Map<String, String> getSqlMap() {
|
||
if (sqlMap == null){
|
||
sqlMap = Maps.newHashMap();
|
||
}
|
||
return sqlMap;
|
||
}
|
||
|
||
public void setSqlMap(Map<String, String> sqlMap) {
|
||
this.sqlMap = sqlMap;
|
||
}
|
||
|
||
|
||
/**
|
||
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
||
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
||
* @return
|
||
*/
|
||
@JsonIgnore
|
||
public boolean getIsNewRecord() {
|
||
return isNewRecord || StringUtil.isEmpty(getId());
|
||
}
|
||
|
||
/**
|
||
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
||
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
||
*/
|
||
public void setIsNewRecord(boolean isNewRecord) {
|
||
this.isNewRecord = isNewRecord;
|
||
}
|
||
|
||
/**
|
||
* 获取数据库名称
|
||
*/
|
||
@JsonIgnore
|
||
public String getDbName(){
|
||
return Configurations.getStringProperty("jdbc.type", "mysql");
|
||
}
|
||
|
||
@Override
|
||
public boolean equals(Object obj) {
|
||
if (null == obj) {
|
||
return false;
|
||
}
|
||
if (this == obj) {
|
||
return true;
|
||
}
|
||
if (!getClass().equals(obj.getClass())) {
|
||
return false;
|
||
}
|
||
BaseEntity<?> that = (BaseEntity<?>) obj;
|
||
return null == this.getId() ? false : this.getId().equals(that.getId());
|
||
}
|
||
|
||
@Override
|
||
public String toString() {
|
||
return ReflectionToStringBuilder.toString(this);
|
||
}
|
||
|
||
|
||
|
||
}
|