liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
 * Copyright &copy; 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";
    
}