6c02d7dd7b00a4df924d048ab77fb553f2547550.svn-base
4.83 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/**
* Copyright © 2015-2018 ODM All rights reserved.
*/
package com.thinkgem.jeesite.modules.gen.entity;
import java.util.List;
import org.hibernate.validator.constraints.Length;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.persistence.DataEntity;
import com.thinkgem.jeesite.common.utils.StringUtils;
/**
* 业务表Entity
* @author ThinkGem
* @version 2013-10-15
*/
public class GenTable extends DataEntity<GenTable> {
private static final long serialVersionUID = 1L;
private String name; // 名称
private String comments; // 描述
private String className; // 实体类名称
private String parentTable; // 关联父表
private String parentTableFk; // 关联父表外键
private List<GenTableColumn> columnList = Lists.newArrayList(); // 表列
private String nameLike; // 按名称模糊查询
private List<String> pkList; // 当前表主键列表
private GenTable parent; // 父表对象
private List<GenTable> childList = Lists.newArrayList(); // 子表列表
public GenTable() {
super();
}
public GenTable(String id){
super(id);
}
@Length(min=1, max=200)
public String getName() {
return StringUtils.lowerCase(name);
}
public void setName(String name) {
this.name = name;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getParentTable() {
return StringUtils.lowerCase(parentTable);
}
public void setParentTable(String parentTable) {
this.parentTable = parentTable;
}
public String getParentTableFk() {
return StringUtils.lowerCase(parentTableFk);
}
public void setParentTableFk(String parentTableFk) {
this.parentTableFk = parentTableFk;
}
public List<String> getPkList() {
return pkList;
}
public void setPkList(List<String> pkList) {
this.pkList = pkList;
}
public String getNameLike() {
return nameLike;
}
public void setNameLike(String nameLike) {
this.nameLike = nameLike;
}
public GenTable getParent() {
return parent;
}
public void setParent(GenTable parent) {
this.parent = parent;
}
public List<GenTableColumn> getColumnList() {
return columnList;
}
public void setColumnList(List<GenTableColumn> columnList) {
this.columnList = columnList;
}
public List<GenTable> getChildList() {
return childList;
}
public void setChildList(List<GenTable> childList) {
this.childList = childList;
}
/**
* 获取列名和说明
* @return
*/
public String getNameAndComments() {
return getName() + (comments == null ? "" : " : " + comments);
}
/**
* 获取导入依赖包字符串
* @return
*/
public List<String> getImportList(){
List<String> importList = Lists.newArrayList(); // 引用列表
for (GenTableColumn column : getColumnList()){
if (column.getIsNotBaseField() || ("1".equals(column.getIsQuery()) && "between".equals(column.getQueryType())
&& ("createDate".equals(column.getSimpleJavaField()) || "updateDate".equals(column.getSimpleJavaField())))){
// 导入类型依赖包, 如果类型中包含“.”,则需要导入引用。
if (StringUtils.indexOf(column.getJavaType(), ".") != -1 && !importList.contains(column.getJavaType())){
importList.add(column.getJavaType());
}
}
if (column.getIsNotBaseField()){
// 导入JSR303、Json等依赖包
for (String ann : column.getAnnotationList()){
if (!importList.contains(StringUtils.substringBeforeLast(ann, "("))){
importList.add(StringUtils.substringBeforeLast(ann, "("));
}
}
}
}
// 如果有子表,则需要导入List相关引用
if (getChildList() != null && getChildList().size() > 0){
if (!importList.contains("java.util.List")){
importList.add("java.util.List");
}
if (!importList.contains("com.google.common.collect.Lists")){
importList.add("com.google.common.collect.Lists");
}
}
return importList;
}
/**
* 是否存在父类
* @return
*/
public Boolean getParentExists(){
return parent != null && StringUtils.isNotBlank(parentTable) && StringUtils.isNotBlank(parentTableFk);
}
/**
* 是否存在create_date列
* @return
*/
public Boolean getCreateDateExists(){
for (GenTableColumn c : columnList){
if ("create_date".equals(c.getName())){
return true;
}
}
return false;
}
/**
* 是否存在update_date列
* @return
*/
public Boolean getUpdateDateExists(){
for (GenTableColumn c : columnList){
if ("update_date".equals(c.getName())){
return true;
}
}
return false;
}
/**
* 是否存在del_flag列
* @return
*/
public Boolean getDelFlagExists(){
for (GenTableColumn c : columnList){
if ("del_flag".equals(c.getName())){
return true;
}
}
return false;
}
}