1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.r2.common.entity; |
17 | |
|
18 | |
import java.util.Date; |
19 | |
|
20 | |
import javax.persistence.Column; |
21 | |
import javax.persistence.Embeddable; |
22 | |
import javax.persistence.MappedSuperclass; |
23 | |
import javax.persistence.Temporal; |
24 | |
import javax.persistence.TemporalType; |
25 | |
|
26 | |
import org.kuali.student.common.dto.MetaInfo; |
27 | |
import org.kuali.student.common.util.security.SecurityUtils; |
28 | |
import org.kuali.student.core.entity.BaseEntity; |
29 | |
|
30 | |
@MappedSuperclass |
31 | |
@Embeddable |
32 | 0 | public abstract class MetaEntity extends BaseEntity{ |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
@Temporal(TemporalType.TIMESTAMP) |
39 | |
@Column(updatable=false) |
40 | |
private Date createTime; |
41 | |
|
42 | |
@Column(updatable=false) |
43 | |
private String createId; |
44 | |
|
45 | |
@Temporal(TemporalType.TIMESTAMP) |
46 | |
private Date updateTime; |
47 | |
|
48 | |
private String updateId; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public Date getCreateTime() { |
59 | 0 | return createTime; |
60 | |
} |
61 | |
|
62 | |
public void setCreateTime(Date createTime) { |
63 | 0 | this.createTime = createTime; |
64 | 0 | } |
65 | |
|
66 | |
public String getCreateId() { |
67 | 0 | return createId; |
68 | |
} |
69 | |
|
70 | |
public void setCreateId(String createId) { |
71 | 0 | this.createId = createId; |
72 | 0 | } |
73 | |
|
74 | |
public Date getUpdateTime() { |
75 | 0 | return updateTime; |
76 | |
} |
77 | |
|
78 | |
public void setUpdateTime(Date updateTime) { |
79 | 0 | this.updateTime = updateTime; |
80 | 0 | } |
81 | |
|
82 | |
public String getUpdateId() { |
83 | 0 | return updateId; |
84 | |
} |
85 | |
|
86 | |
public void setUpdateId(String updateId) { |
87 | 0 | this.updateId = updateId; |
88 | 0 | } |
89 | |
|
90 | |
@Override |
91 | |
protected void onPrePersist(){ |
92 | 0 | super.onPrePersist(); |
93 | 0 | setCreateTime(new Date()); |
94 | 0 | setUpdateTime(new Date()); |
95 | |
|
96 | 0 | String user = SecurityUtils.getCurrentUserId(); |
97 | 0 | setCreateId(user); |
98 | 0 | setUpdateId(user); |
99 | |
|
100 | 0 | } |
101 | |
|
102 | |
@Override |
103 | |
protected void onPreUpdate(){ |
104 | 0 | super.onPreUpdate(); |
105 | |
|
106 | 0 | if(getCreateTime() == null){ |
107 | 0 | setCreateTime(new Date()); |
108 | |
} |
109 | |
|
110 | 0 | String user = SecurityUtils.getCurrentUserId(); |
111 | 0 | setUpdateId(user); |
112 | 0 | } |
113 | |
|
114 | |
public MetaInfo toDTO() { |
115 | 0 | MetaInfo.Builder miBuilder = new MetaInfo.Builder(); |
116 | 0 | miBuilder.setCreateId(getCreateId()); |
117 | 0 | miBuilder.setCreateTime(getCreateTime()); |
118 | 0 | miBuilder.setUpdateId(getUpdateId()); |
119 | 0 | miBuilder.setUpdateTime(getUpdateTime()); |
120 | |
|
121 | 0 | return miBuilder.build(); |
122 | |
} |
123 | |
} |