package com.common.core.domain;
|
|
import com.common.annotation.Table;
|
import com.common.core.utils.DateUtils;
|
import com.common.security.utils.SecurityUtils;
|
import com.jfinal.kit.StrKit;
|
import com.jfinal.plugin.activerecord.Model;
|
import com.jfinal.plugin.activerecord.Page;
|
|
import java.util.*;
|
|
/**
|
* @author 廖振钦
|
* @date 20/12/2021
|
*/
|
public abstract class BaseModel<M extends BaseModel> extends Model<M> {
|
|
public void setId(Long id) {
|
set("id", id);
|
}
|
|
public Long getId() {
|
return getLong("id");
|
}
|
|
public void setIsDelete(Integer isDelete) {
|
set("is_delete", isDelete);
|
}
|
|
public Integer getIsDelete() {
|
return getInt("is_delete");
|
}
|
|
public void setCreateBy(String createBy) {
|
set("create_by", createBy);
|
}
|
|
public String getCreateBy(){
|
return get("create_by");
|
}
|
|
public void setUpdateBy(String UpdateBy) {
|
set("update_by", UpdateBy);
|
}
|
|
public String getUpdateBy(){
|
return get("update_by");
|
}
|
|
public void setCreateTime(Date createTime) {
|
set("create_time", createTime);
|
}
|
|
public Date getCreateTime() {
|
return getDate("create_time");
|
}
|
|
public void setUpdateTime(Date updateTime) {
|
set("update_time", updateTime);
|
}
|
|
public Date getUpdateTime() {
|
return getDate("update_time");
|
}
|
|
public Page<M> pageQuery(int cpage, int pageSize, String orderField, String orderDirection,
|
String where, int dataright) {
|
String sql_select = "select *";
|
StringBuffer conf = new StringBuffer(" from "+getTableName()+" where is_delete=? ");
|
List<String> params = new ArrayList<String>();
|
params.add("0");
|
if(StrKit.notBlank(where)){
|
conf.append(where);
|
}
|
|
if (StrKit.notBlank(orderField, orderDirection)) {
|
conf.append(" ORDER BY ").append(" ").append(orderField).append(" ").append(orderDirection);
|
}
|
|
Page<M> page = paginate(cpage, pageSize, sql_select, conf.toString(), params.toArray());
|
return page;
|
}
|
|
|
|
@Override
|
public boolean save(){
|
String appid = SecurityUtils.byId();
|
setIsDelete(0);
|
setCreateTime(DateUtils.now());
|
setUpdateTime(DateUtils.now());
|
setCreateBy(appid);
|
setUpdateBy(appid);
|
return super.save();
|
}
|
|
@Override
|
public boolean update(){
|
String appid = SecurityUtils.byId();
|
setUpdateTime(DateUtils.now());
|
setUpdateBy(appid);
|
return super.update();
|
}
|
|
public String getTableName(){
|
Table table = getClass().getAnnotation(Table.class);
|
return table.tableName();
|
}
|
|
public List<M> findList(){
|
return dao().find("select * from "+getTableName()+ " where is_delete = '0'");
|
}
|
|
public List<M> findList(String where){
|
return dao().find("select * from "+getTableName()+ " where is_delete = '0' "+where);
|
}
|
|
public boolean saveOrUpdate(){
|
if(null == getId()){
|
return this.save();
|
} else{
|
return this.update();
|
}
|
}
|
}
|