代码生成模板支持主子表

This commit is contained in:
RuoYi
2021-01-08 11:08:59 +08:00
parent c5899bfbf0
commit 5891960756
22 changed files with 1326 additions and 761 deletions

View File

@@ -59,7 +59,7 @@ public class GenUtils
{
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
{

View File

@@ -23,13 +23,13 @@ public class VelocityUtils
/** mybatis空间路径 */
private static final String MYBATIS_PATH = "main/resources/mapper";
/** 默认上级菜单,系统工具 */
private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
* 设置模板变量信息
*
*
* @return 模板列表
*/
public static VelocityContext prepareContext(GenTable genTable)
@@ -54,7 +54,7 @@ public class VelocityUtils
velocityContext.put("author", genTable.getFunctionAuthor());
velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn());
velocityContext.put("importList", getImportList(genTable.getColumns()));
velocityContext.put("importList", getImportList(genTable));
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
@@ -63,9 +63,13 @@ public class VelocityUtils
{
setTreeVelocityContext(velocityContext, genTable);
}
if (GenConstants.TPL_SUB.equals(tplCategory))
{
setSubVelocityContext(velocityContext, genTable);
}
return velocityContext;
}
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
String options = genTable.getOptions();
@@ -96,9 +100,27 @@ public class VelocityUtils
}
}
public static void setSubVelocityContext(VelocityContext context, GenTable genTable)
{
GenTable subTable = genTable.getSubTable();
String subTableName = genTable.getSubTableName();
String subTableFkName = genTable.getSubTableFkName();
String subClassName = genTable.getSubTable().getClassName();
String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
context.put("subTable", subTable);
context.put("subTableName", subTableName);
context.put("subTableFkName", subTableFkName);
context.put("subTableFkClassName", subTableFkClassName);
context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
context.put("subClassName", subClassName);
context.put("subclassName", StringUtils.uncapitalize(subClassName));
context.put("subImportList", getImportList(genTable.getSubTable()));
}
/**
* 获取模板信息
*
*
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory)
@@ -120,6 +142,11 @@ public class VelocityUtils
{
templates.add("vm/vue/index-tree.vue.vm");
}
else if (GenConstants.TPL_SUB.equals(tplCategory))
{
templates.add("vm/vue/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
}
return templates;
}
@@ -147,6 +174,10 @@ public class VelocityUtils
{
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
}
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
}
else if (template.contains("mapper.java.vm"))
{
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
@@ -188,7 +219,7 @@ public class VelocityUtils
/**
* 获取包前缀
*
*
* @param packageName 包名称
* @return 包前缀名称
*/
@@ -202,12 +233,18 @@ public class VelocityUtils
/**
* 根据列类型获取导入包
*
* @param columns 列集合
* @param genTable 业务表对象
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(List<GenTableColumn> columns)
public static HashSet<String> getImportList(GenTable genTable)
{
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable();
HashSet<String> importList = new HashSet<String>();
if (StringUtils.isNotNull(subGenTable))
{
importList.add("java.util.List");
}
for (GenTableColumn column : columns)
{
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
@@ -225,7 +262,7 @@ public class VelocityUtils
/**
* 获取权限前缀
*
*
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
@@ -237,7 +274,7 @@ public class VelocityUtils
/**
* 获取上级菜单ID字段
*
*
* @param paramsObj 生成其他选项
* @return 上级菜单ID字段
*/
@@ -252,7 +289,7 @@ public class VelocityUtils
/**
* 获取树编码
*
*
* @param paramsObj 生成其他选项
* @return 树编码
*/
@@ -267,7 +304,7 @@ public class VelocityUtils
/**
* 获取树父编码
*
*
* @param paramsObj 生成其他选项
* @return 树父编码
*/
@@ -282,7 +319,7 @@ public class VelocityUtils
/**
* 获取树名称
*
*
* @param paramsObj 生成其他选项
* @return 树名称
*/
@@ -297,7 +334,7 @@ public class VelocityUtils
/**
* 获取需要在哪一列上面显示展开按钮
*
*
* @param genTable 业务表对象
* @return 展开按钮列序号
*/