|
|
@@ -3,6 +3,8 @@ package cc.smtweb.framework.core.common; |
|
|
|
import lombok.Data; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
import java.sql.Types; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by Akmm at 2022/3/23 9:39 |
|
|
|
* 系统的一些枚举变量 |
|
|
@@ -85,10 +87,12 @@ public interface SwEnum { |
|
|
|
public String sqlType; |
|
|
|
public int dataLength; |
|
|
|
public String javaType; |
|
|
|
//java.sql.Types里的值 |
|
|
|
public int type; |
|
|
|
public String defaultValue; |
|
|
|
public String editor; |
|
|
|
|
|
|
|
public DataTypeBean(String value, String name, String sqlType, int dataLength, String javaType, String defaultValue, String editor) { |
|
|
|
public DataTypeBean(String value, String name, String sqlType, int dataLength, String javaType, int type, String defaultValue, String editor) { |
|
|
|
super(value, name); |
|
|
|
this.sqlType = sqlType; |
|
|
|
this.dataLength = dataLength; |
|
|
@@ -112,26 +116,26 @@ public interface SwEnum { |
|
|
|
public final static String TYPE_DATETIME = "datetime"; |
|
|
|
|
|
|
|
public static DataType instance = new DataType(); |
|
|
|
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean CODE = instance.addEnum("code", "编码", "varchar", 32, "string", "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean NAME = instance.addEnum("name", "名称", "varchar", 100, "string", "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean REMARK = instance.addEnum("remark", "备注", "varchar", 255, "string", "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean TEXT = instance.addEnum("text", "大文本", "text", 0, "string", "", EditorType.TEXT.value); |
|
|
|
public static DataTypeBean INT = instance.addEnum("int", "整型", "int", 0, "int", "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean SHORT = instance.addEnum("short", "短整型", "smallint", 0, "short", "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean BOOL = instance.addEnum("bool", "布尔型", "tinyint", 0, "boolean", "0", EditorType.COMBO.value); |
|
|
|
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long", "0", EditorType.DATE.value); |
|
|
|
public static DataTypeBean TIME = instance.addEnum("time", "时间型", "bigint", 0, "long", "0", EditorType.TIME.value); |
|
|
|
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", "0", EditorType.DATETIME.value); |
|
|
|
public static DataTypeBean ID = instance.addEnum("id", "ID", "bigint", 0, "long", Types.BIGINT, "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean CODE = instance.addEnum("code", "编码", "varchar", 32, "string", Types.VARCHAR, "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean NAME = instance.addEnum("name", "名称", "varchar", 100, "string", Types.VARCHAR, "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean REMARK = instance.addEnum("remark", "备注", "varchar", 255, "string", Types.VARCHAR, "", EditorType.INPUT.value); |
|
|
|
public static DataTypeBean TEXT = instance.addEnum("text", "大文本", "text", 0, "string", Types.CLOB, "", EditorType.TEXT.value); |
|
|
|
public static DataTypeBean INT = instance.addEnum("int", "整型", "int", 0, "int", Types.INTEGER, "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean SHORT = instance.addEnum("short", "短整型", "smallint", 0, "short", Types.SMALLINT, "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean BOOL = instance.addEnum("bool", "布尔型", "tinyint", 0, "boolean", Types.TINYINT, "0", EditorType.COMBO.value); |
|
|
|
public static DataTypeBean CURRENCY = instance.addEnum("currency", "金额型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.NUMBER.value); |
|
|
|
public static DataTypeBean DATE = instance.addEnum("date", "日期型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.DATE.value); |
|
|
|
public static DataTypeBean TIME = instance.addEnum("time", "时间型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.TIME.value); |
|
|
|
public static DataTypeBean DATETIME = instance.addEnum("datetime", "日期时间型", "bigint", 0, "long", Types.BIGINT, "0", EditorType.DATETIME.value); |
|
|
|
|
|
|
|
@Override |
|
|
|
protected DataTypeBean buildBean(String value, String name) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public DataTypeBean addEnum(String value, String name, String sqlType, int dataLength, String javaType, String defaultValue, String editor) { |
|
|
|
final DataTypeBean bean = new DataTypeBean(value, name, sqlType, dataLength, javaType, defaultValue, editor); |
|
|
|
public DataTypeBean addEnum(String value, String name, String sqlType, int dataLength, String javaType, int type, String defaultValue, String editor) { |
|
|
|
final DataTypeBean bean = new DataTypeBean(value, name, sqlType, dataLength, javaType, type, defaultValue, editor); |
|
|
|
mapAll.put(value, bean); |
|
|
|
return bean; |
|
|
|
} |
|
|
@@ -141,6 +145,15 @@ public interface SwEnum { |
|
|
|
if (value == null) return null; |
|
|
|
return super.getByValue(value.toLowerCase()); |
|
|
|
} |
|
|
|
|
|
|
|
//根据数据库查询的metadata适配类型 |
|
|
|
public static DataTypeBean getBySqlType(int sqlType, int precision, int scale) { |
|
|
|
for (DataTypeBean bean: instance.mapAll.values()) { |
|
|
|
if (bean.type != sqlType) continue; |
|
|
|
if (bean.dataLength == 0 || bean.dataLength == precision) return bean; |
|
|
|
} |
|
|
|
return REMARK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|