/**
|
* Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
|
*/
|
package com.cloud.model.common;
|
|
import com.cloud.model.sys.AppUser;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.google.common.collect.Maps;
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
import org.springframework.util.StringUtils;
|
|
import javax.xml.bind.annotation.XmlTransient;
|
import java.io.Serializable;
|
import java.util.Map;
|
|
|
/**
|
* Entity支持类
|
* @author bsk
|
* @version 2018-05-16
|
*/
|
public abstract class BaseStringEntity<T> implements Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
/**
|
* 实体编号(唯一标识)
|
*/
|
protected String id;
|
|
/**
|
* 当前用户
|
*/
|
/*protected LoginAppUser currentUser;*/
|
/**
|
* 当前实体分页对象
|
*/
|
/* protected Page<T> page;*/
|
|
/**
|
* 自定义SQL(SQL标识,SQL内容)
|
*/
|
protected Map<String, String> sqlMap;
|
|
/**
|
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
*/
|
protected boolean isNewRecord = false;
|
|
public BaseStringEntity() {
|
|
}
|
|
public BaseStringEntity(String id) {
|
this();
|
this.id = id;
|
}
|
|
public String getId() {
|
return id;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
|
@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;
|
}
|
|
|
/**
|
* 插入之前执行方法,子类实现
|
* @param user
|
*/
|
public abstract void preInsert(AppUser user);
|
|
|
/**
|
* 更新之前执行方法,子类实现
|
* @param user
|
*/
|
public abstract void preUpdate(AppUser user);
|
|
/**
|
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
* @return
|
*/
|
public boolean getIsNewRecord() {
|
return isNewRecord || StringUtils.isEmpty(getId());
|
}
|
|
/**
|
* 是否是新记录(默认:false),调用setIsNewRecord()设置新记录,使用自定义ID。
|
* 设置为true后强制执行插入语句,ID不会自动生成,需从手动传入。
|
*/
|
public void setIsNewRecord(boolean isNewRecord) {
|
this.isNewRecord = isNewRecord;
|
}
|
|
|
|
@Override
|
public boolean equals(Object obj) {
|
if (null == obj) {
|
return false;
|
}
|
if (this == obj) {
|
return true;
|
}
|
if (!getClass().equals(obj.getClass())) {
|
return false;
|
}
|
BaseStringEntity<?> that = (BaseStringEntity<?>) obj;
|
return null == this.getId() ? false : this.getId().equals(that.getId());
|
}
|
|
@Override
|
public String toString() {
|
return ReflectionToStringBuilder.toString(this);
|
}
|
|
/**
|
* 删除标记(0:正常;1:删除;2:审核;)
|
*/
|
public static final String DEL_FLAG_NORMAL = "0";
|
public static final String DEL_FLAG_DELETE = "1";
|
public static final String DEL_FLAG_AUDIT = "2";
|
|
}
|