cn.wizzer.framework.base.model.BaseModel Maven / Gradle / Ivy
package cn.wizzer.framework.base.model;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;
import org.nutz.lang.Times;
import org.nutz.mvc.Mvcs;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
/**
* Created by wizzer on 2016/6/21.
*/
public abstract class BaseModel implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Comment("操作人")
@PrevInsert(els = @EL("$me.uid()"))
@ColDefine(type = ColType.VARCHAR, width = 32)
private String opBy;
@Column
@Comment("操作时间")
@PrevInsert(els = @EL("$me.now()"))
//Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
private Long opAt;
@Column
@Comment("删除标记")
@PrevInsert(els = @EL("$me.flag()"))
@ColDefine(type = ColType.BOOLEAN)
private Boolean delFlag;
public String toJsonString() {
return Json.toJson(this, JsonFormat.compact());
}
public Boolean flag() {
return false;
}
public Long now() {
return Times.getTS();
}
public String uid() {
String uid = getOpBy();
if (Strings.isNotBlank(uid)) {
return uid;
}
try {
HttpServletRequest request = Mvcs.getReq();
if (request != null) {
return Strings.sNull(request.getSession(true).getAttribute("platform_uid"));
}
} catch (Exception e) {
}
return "";
}
public String getOpBy() {
return opBy;
}
public void setOpBy(String opBy) {
this.opBy = opBy;
}
public Long getOpAt() {
return opAt;
}
public void setOpAt(Long opAt) {
this.opAt = opAt;
}
public Boolean getDelFlag() {
return delFlag;
}
public void setDelFlag(Boolean delFlag) {
this.delFlag = delFlag;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy