|
|
|
package xyz.wbsite.dbtool.javafx.po;
|
|
|
|
|
|
|
|
import javafx.beans.property.BooleanProperty;
|
|
|
|
import javafx.beans.property.IntegerProperty;
|
|
|
|
import javafx.beans.property.SimpleBooleanProperty;
|
|
|
|
import javafx.beans.property.SimpleIntegerProperty;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import xyz.wbsite.dbtool.javafx.tool.Tool;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
public class Field extends Table {
|
|
|
|
|
|
|
|
public Field() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public Field(String fieldName) {
|
|
|
|
this.fieldName = fieldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 字段名
|
|
|
|
*/
|
|
|
|
private String fieldName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 字段类型
|
|
|
|
*/
|
|
|
|
private FieldType fieldType = FieldType.String_var50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 字段注释
|
|
|
|
*/
|
|
|
|
private String fieldComment = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 默认值
|
|
|
|
*/
|
|
|
|
private String defaultValue = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否可为NULL
|
|
|
|
*/
|
|
|
|
private boolean isMust = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否是主键
|
|
|
|
*/
|
|
|
|
private boolean isPrimaryKey = false;
|
|
|
|
|
|
|
|
private boolean isSearch = false;
|
|
|
|
|
|
|
|
private boolean isSystem = false;
|
|
|
|
|
|
|
|
private List<DictItem> dictItems = new ArrayList<>();
|
|
|
|
|
|
|
|
public List<DictItem> getDictItems() {
|
|
|
|
return dictItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDictItems(List<DictItem> dictItems) {
|
|
|
|
this.dictItems = dictItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTestValue() {
|
|
|
|
String value = "";
|
|
|
|
if (fieldType.name().matches("String_\\d+")) {
|
|
|
|
Pattern compile = Pattern.compile("String_(\\d+)");
|
|
|
|
Matcher matcher = compile.matcher(fieldType.name());
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
int len = Integer.parseInt(matcher.group(1));
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
|
|
|
StringBuilder sb = new StringBuilder("\"");
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
sb.append("A");
|
|
|
|
}
|
|
|
|
sb.append("\"");
|
|
|
|
value = sb.toString();
|
|
|
|
} else {
|
|
|
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > getFieldLength() ? getFieldLength() : this.fieldComment.length()) + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (fieldType.name().matches("String_var\\d+")) {
|
|
|
|
Pattern compile = Pattern.compile("String_var(\\d+)");
|
|
|
|
Matcher matcher = compile.matcher(fieldType.name());
|
|
|
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
int len = Integer.parseInt(matcher.group(1));
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
|
|
|
StringBuilder sb = new StringBuilder("");
|
|
|
|
sb.append("\"");
|
|
|
|
sb.append("A");
|
|
|
|
sb.append("\"");
|
|
|
|
value = sb.toString();
|
|
|
|
} else {
|
|
|
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > getFieldLength() ? getFieldLength() : this.fieldComment.length()) + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (fieldType.name().equals("String_var")) {
|
|
|
|
int len = getFieldLength();
|
|
|
|
if (StringUtils.isEmpty(this.fieldComment)) {
|
|
|
|
StringBuilder sb = new StringBuilder("");
|
|
|
|
sb.append("\"");
|
|
|
|
sb.append("A");
|
|
|
|
sb.append("\"");
|
|
|
|
value = sb.toString();
|
|
|
|
} else {
|
|
|
|
value = "\"" + this.fieldComment.substring(0, this.fieldComment.length() > getFieldLength() ? getFieldLength() : this.fieldComment.length()) + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (fieldType.name().matches("Boolean")) {
|
|
|
|
value = "true";
|
|
|
|
} else if (fieldType.name().matches("Dict")) {
|
|
|
|
value = "\"code\"";
|
|
|
|
} else if (fieldType.name().matches("Byte")) {
|
|
|
|
value = "(byte)1";
|
|
|
|
} else if (fieldType.name().matches("Short")) {
|
|
|
|
value = "(short)1";
|
|
|
|
} else if (fieldType.name().matches("Integer")) {
|
|
|
|
value = "1";
|
|
|
|
} else if (fieldType.name().matches("Bytes")) {
|
|
|
|
value = "null";
|
|
|
|
} else if (fieldType.name().matches("Long")) {
|
|
|
|
value = "1L";
|
|
|
|
} else if (fieldType.name().matches("Float")) {
|
|
|
|
value = "1.0f";
|
|
|
|
} else if (fieldType.name().matches("Double")) {
|
|
|
|
value = "1.0";
|
|
|
|
} else if (fieldType.name().matches("Character")) {
|
|
|
|
value = "'A'";
|
|
|
|
} else if (fieldType.name().matches("Date")) {
|
|
|
|
value = "new Date()";
|
|
|
|
} else if (fieldType.name().matches("BigDecimal")) {
|
|
|
|
value = "new BigDecimal()";
|
|
|
|
} else if (fieldType.name().matches("String_super")) {
|
|
|
|
value = "\"content\"";
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsSearch() {
|
|
|
|
return isSearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsSearch(boolean isSearch) {
|
|
|
|
this.isSearch = isSearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsSystem() {
|
|
|
|
return isSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsSystem(boolean isSystem) {
|
|
|
|
this.isSystem = isSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getterName() {
|
|
|
|
return "get" + Tool.ABB2Abb(this.fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String setterName() {
|
|
|
|
return "set" + Tool.ABB2Abb(this.fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 字段长度
|
|
|
|
private final IntegerProperty fieldLength = new SimpleIntegerProperty();
|
|
|
|
|
|
|
|
public IntegerProperty fieldLengthProperty() {
|
|
|
|
return fieldLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getFieldLength() {
|
|
|
|
return fieldLength.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldLength(int fieldLength) {
|
|
|
|
this.fieldLength.set(fieldLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
// isUnique 是否唯一,新怎前检查重复
|
|
|
|
private final BooleanProperty isUnique = new SimpleBooleanProperty();
|
|
|
|
|
|
|
|
public BooleanProperty isUniqueProperty() {
|
|
|
|
return isUnique;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsUnique() {
|
|
|
|
return isUnique.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsUnique(boolean isUnique) {
|
|
|
|
this.isUnique.set(isUnique);
|
|
|
|
}
|
|
|
|
|
|
|
|
// isQuery 是否作为查询条件
|
|
|
|
private final BooleanProperty isQuery = new SimpleBooleanProperty();
|
|
|
|
|
|
|
|
public BooleanProperty isQueryProperty() {
|
|
|
|
return isQuery;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsQuery() {
|
|
|
|
return isQuery.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsQuery(boolean isQuery) {
|
|
|
|
this.isQuery.set(isQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFieldName() {
|
|
|
|
return fieldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldName(String fieldName) {
|
|
|
|
this.fieldName = fieldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FieldType getFieldType() {
|
|
|
|
return fieldType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldType(FieldType fieldType) {
|
|
|
|
this.fieldType = fieldType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFieldComment() {
|
|
|
|
return fieldComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldComment(String fieldComment) {
|
|
|
|
this.fieldComment = fieldComment != null ? fieldComment : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDefaultValue() {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDefaultValue(String defaultValue) {
|
|
|
|
this.defaultValue = defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsMust() {
|
|
|
|
return isMust;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsMust(boolean isMust) {
|
|
|
|
this.isMust = isMust;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getIsPrimaryKey() {
|
|
|
|
return isPrimaryKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsPrimaryKey(boolean isPrimaryKey) {
|
|
|
|
this.isPrimaryKey = isPrimaryKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFName() {
|
|
|
|
return Tool.lineToFieldName(this.fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getCName() {
|
|
|
|
return Tool.ABB2Abb(this.fieldName);
|
|
|
|
}
|
|
|
|
}
|