测试用户
2023-04-13 43393f2bb11cbf9e6af40077bbc5284660e8a754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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();
        }
    }
}