From e9b0289effe40d2ef0514b9af482708219b7166f Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期三, 22 九月 2021 11:09:42 +0800
Subject: [PATCH] update 优化代码生成 根据MP生成特性 调整导入表结构默认值合理化
---
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java | 11 ++++++++---
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java | 37 ++++++++++++++++++-------------------
2 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
index 1fa328e..072fb40 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
@@ -44,16 +44,21 @@
public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
"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",
- "update_time" };
+ "update_time", "version" };
/** 椤甸潰涓嶉渶瑕佹煡璇㈠瓧娈� */
public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by",
- "update_time", "remark" };
+ "update_time", "remark", "version" };
/** Entity鍩虹被瀛楁 */
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" };
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
index a64ac3e..bfa7598 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
@@ -33,8 +33,7 @@
/**
* 鍒濆鍖栧垪灞炴�у瓧娈�
*/
- public static void initColumnField(GenTableColumn column, GenTable table)
- {
+ public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName();
column.setTableId(table.getTableId());
@@ -44,48 +43,48 @@
// 璁剧疆榛樿绫诲瀷
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璁剧疆涓烘枃鏈煙
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
- }
- else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
- {
+ } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
- }
- else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
- {
+ } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 濡傛灉鏄诞鐐瑰瀷 缁熶竴鐢˙igDecimal
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);
}
// 濡傛灉鏄暣褰�
- 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);
}
// 闀挎暣褰�
- else
- {
+ else {
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);
}
+ // 缂栬緫闇�瑕佺殑璁剧疆蹇呴��
+ if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName))
+ {
+ column.setIsRequired(GenConstants.REQUIRE);
+ }
// 鍒楄〃瀛楁
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
{
--
Gitblit v1.9.3