This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/domain/BaseEntity.java
2018-07-12 18:21:12 +08:00

204 lines
4.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.nis.domain;
import java.io.Serializable;
import java.util.Map;
import javax.xml.bind.annotation.XmlTransient;
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.util.StringUtil;
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;
/**
* 日志分页对象
*/
protected PageLog<T> pageLog;
/**
* 自定义SQLSQL标识SQL内容
*/
protected Map<String, String> sqlMap;
/**
* 是否是新记录默认false调用setIsNewRecord()设置新记录使用自定义ID。
* 设置为true后强制执行插入语句ID不会自动生成需从手动传入。
*/
protected boolean isNewRecord = false;
/**
* 筛选搜索框展开状态
*/
protected boolean isFilterAction = 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 PageLog<T> getPageLog() {
if (pageLog == null){
pageLog = new PageLog<T>();
}
return pageLog;
}
public PageLog<T> setPageLog(PageLog<T> pageLog) {
this.pageLog = pageLog;
return pageLog;
}
@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);
}
public void setIsFilterAction(boolean isFilterAction) {
this.isFilterAction = isFilterAction;
}
@JsonIgnore
public boolean getIsFilterAction() {
return isFilterAction;
}
}