update 优化代码生成 根据MP生成特性 调整导入表结构默认值合理化
This commit is contained in:
parent
40984e201e
commit
e9b0289eff
@ -44,16 +44,21 @@ public class GenConstants
|
|||||||
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
|
||||||
"bit", "bigint", "float", "double", "decimal" };
|
"bit", "bigint", "float", "double", "decimal" };
|
||||||
|
|
||||||
|
/** 页面不需要添加字段 */
|
||||||
|
public static final String[] COLUMNNAME_NOT_ADD = { "create_by", "create_time", "del_flag", "update_by",
|
||||||
|
"update_time", "version" };
|
||||||
|
|
||||||
/** 页面不需要编辑字段 */
|
/** 页面不需要编辑字段 */
|
||||||
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };
|
public static final String[] COLUMNNAME_NOT_EDIT = { "create_by", "create_time", "del_flag", "update_by",
|
||||||
|
"update_time", "version" };
|
||||||
|
|
||||||
/** 页面不需要显示的列表字段 */
|
/** 页面不需要显示的列表字段 */
|
||||||
public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by",
|
public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||||
"update_time" };
|
"update_time", "version" };
|
||||||
|
|
||||||
/** 页面不需要查询字段 */
|
/** 页面不需要查询字段 */
|
||||||
public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
|
public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
|
||||||
"update_time", "remark" };
|
"update_time", "remark", "version" };
|
||||||
|
|
||||||
/** Entity基类字段 */
|
/** Entity基类字段 */
|
||||||
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
|
||||||
|
@ -33,8 +33,7 @@ public class GenUtils
|
|||||||
/**
|
/**
|
||||||
* 初始化列属性字段
|
* 初始化列属性字段
|
||||||
*/
|
*/
|
||||||
public static void initColumnField(GenTableColumn column, GenTable table)
|
public static void initColumnField(GenTableColumn column, GenTable table) {
|
||||||
{
|
|
||||||
String dataType = getDbType(column.getColumnType());
|
String dataType = getDbType(column.getColumnType());
|
||||||
String columnName = column.getColumnName();
|
String columnName = column.getColumnName();
|
||||||
column.setTableId(table.getTableId());
|
column.setTableId(table.getTableId());
|
||||||
@ -44,48 +43,48 @@ public class GenUtils
|
|||||||
// 设置默认类型
|
// 设置默认类型
|
||||||
column.setJavaType(GenConstants.TYPE_STRING);
|
column.setJavaType(GenConstants.TYPE_STRING);
|
||||||
|
|
||||||
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
|
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
|
||||||
{
|
|
||||||
// 字符串长度超过500设置为文本域
|
// 字符串长度超过500设置为文本域
|
||||||
Integer columnLength = getColumnLength(column.getColumnType());
|
Integer columnLength = getColumnLength(column.getColumnType());
|
||||||
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
|
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
|
||||||
column.setHtmlType(htmlType);
|
column.setHtmlType(htmlType);
|
||||||
}
|
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
|
||||||
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
|
|
||||||
{
|
|
||||||
column.setJavaType(GenConstants.TYPE_DATE);
|
column.setJavaType(GenConstants.TYPE_DATE);
|
||||||
column.setHtmlType(GenConstants.HTML_DATETIME);
|
column.setHtmlType(GenConstants.HTML_DATETIME);
|
||||||
}
|
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
|
||||||
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
|
|
||||||
{
|
|
||||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
column.setHtmlType(GenConstants.HTML_INPUT);
|
||||||
|
|
||||||
// 如果是浮点型 统一用BigDecimal
|
// 如果是浮点型 统一用BigDecimal
|
||||||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
|
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
|
||||||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
|
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
|
||||||
{
|
|
||||||
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
||||||
}
|
}
|
||||||
// 如果是整形
|
// 如果是整形
|
||||||
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
|
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
|
||||||
{
|
|
||||||
column.setJavaType(GenConstants.TYPE_INTEGER);
|
column.setJavaType(GenConstants.TYPE_INTEGER);
|
||||||
}
|
}
|
||||||
// 长整形
|
// 长整形
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
column.setJavaType(GenConstants.TYPE_LONG);
|
column.setJavaType(GenConstants.TYPE_LONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入字段(默认所有字段都需要插入)
|
// 插入字段(默认所有字段都需要插入)
|
||||||
column.setIsInsert(GenConstants.REQUIRE);
|
// 主键不需要添加
|
||||||
|
if (!arraysContains(GenConstants.COLUMNNAME_NOT_ADD, columnName) && !column.isPk()) {
|
||||||
|
column.setIsInsert(GenConstants.REQUIRE);
|
||||||
|
}
|
||||||
// 编辑字段
|
// 编辑字段
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
|
// 编辑需要主键
|
||||||
|
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName))
|
||||||
{
|
{
|
||||||
column.setIsEdit(GenConstants.REQUIRE);
|
column.setIsEdit(GenConstants.REQUIRE);
|
||||||
}
|
}
|
||||||
|
// 编辑需要的设置必选
|
||||||
|
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName))
|
||||||
|
{
|
||||||
|
column.setIsRequired(GenConstants.REQUIRE);
|
||||||
|
}
|
||||||
// 列表字段
|
// 列表字段
|
||||||
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
|
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user