package cn.wizzer.framework.base.model;
import org.nutz.dao.entity.annotation.*;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.lang.Strings;
import org.nutz.lang.Times;
import org.nutz.lang.random.R;
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("操作人")
@Prev(els = @EL("$me.uid()"))
@ColDefine(type = ColType.VARCHAR, width = 32)
private String opBy;
@Column
@Comment("操作时间")
@Prev(els = @EL("$me.now()"))
//Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
private Long opAt;
@Column
@Comment("删除标记")
@Prev(els = @EL("$me.flag()"))
@ColDefine(type = ColType.BOOLEAN)
private Boolean delFlag;
@Override
public String toString() {
return String.format("/*%s*/%s", super.toString(), Json.toJson(this, JsonFormat.compact()));
}
public Boolean flag() {
return false;
}
public Long now() {
return System.currentTimeMillis();
}
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;
}
public String uuid() {
return R.UU32().toLowerCase();
}
}
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 "";
}
uid()不能使用了吗?
看到CmsArticleController.java 的addDo方法里面 需要手动赋值
article.setPublishAt(time[0] / 1000);
article.setEndAt(time[1] / 1000);
article.setSiteid(siteid);
article.setStatus(0);
article.setOpBy(StringUtil.getPlatformUid());
cmsArticleService.insert(article);