docs 补充项目注释
This commit is contained in:
+19
-2
@@ -460,8 +460,8 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
/**
|
||||
* 模板渲染上下文。
|
||||
*
|
||||
* @param table 生成表信息
|
||||
* @param context 模板上下文
|
||||
* @param table 生成表信息
|
||||
* @param context 模板上下文
|
||||
* @param templates 待渲染模板
|
||||
*/
|
||||
private record RenderContext(GenTable table, Dict context, List<PathNamedTemplate> templates) {
|
||||
@@ -488,6 +488,11 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验生成选项中配置的字段是否存在。
|
||||
*
|
||||
* @param genTable 业务表信息
|
||||
*/
|
||||
private void validateOptionColumns(GenTable genTable) {
|
||||
Map<String, Object> params = genTable.getParams();
|
||||
if (CollUtil.isEmpty(params) || CollUtil.isEmpty(genTable.getColumns())) {
|
||||
@@ -510,6 +515,13 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验单个选项字段。
|
||||
*
|
||||
* @param validFields 有效字段集合
|
||||
* @param field 待校验字段
|
||||
* @param label 字段显示名称
|
||||
*/
|
||||
private void validateOptionField(Set<String> validFields, Object field, String label) {
|
||||
if (ObjectUtil.isNull(field)) {
|
||||
return;
|
||||
@@ -523,6 +535,11 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化字段扩展配置。
|
||||
*
|
||||
* @param columns 表字段列表
|
||||
*/
|
||||
private void normalizeColumnOptions(List<GenTableColumn> columns) {
|
||||
if (CollUtil.isEmpty(columns)) {
|
||||
return;
|
||||
|
||||
@@ -134,6 +134,15 @@ public class GenUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析数值类型对应的 Java 类型。
|
||||
*
|
||||
* @param dataType 数据库字段类型
|
||||
* @param columnLength 字段长度
|
||||
* @param columnScale 小数位数
|
||||
* @param columnName 字段名称
|
||||
* @return Java 类型
|
||||
*/
|
||||
private static String resolveNumberJavaType(String dataType, Integer columnLength, Integer columnScale, String columnName) {
|
||||
if (isBooleanColumn(dataType, columnLength, columnScale, columnName)) {
|
||||
return GenConstants.TYPE_BOOLEAN;
|
||||
@@ -159,6 +168,12 @@ public class GenUtils {
|
||||
return GenConstants.TYPE_LONG;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据整数字段长度解析 Java 类型。
|
||||
*
|
||||
* @param columnLength 字段长度
|
||||
* @return Java 类型
|
||||
*/
|
||||
private static String resolveIntegerJavaType(Integer columnLength) {
|
||||
if (columnLength > 0 && columnLength <= 9) {
|
||||
return GenConstants.TYPE_INTEGER;
|
||||
@@ -166,6 +181,15 @@ public class GenUtils {
|
||||
return GenConstants.TYPE_LONG;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字段是否适合按布尔类型生成。
|
||||
*
|
||||
* @param dataType 数据库字段类型
|
||||
* @param columnLength 字段长度
|
||||
* @param columnScale 小数位数
|
||||
* @param columnName 字段名称
|
||||
* @return 是否布尔字段
|
||||
*/
|
||||
private static boolean isBooleanColumn(String dataType, Integer columnLength, Integer columnScale, String columnName) {
|
||||
if (columnScale > 0) {
|
||||
return false;
|
||||
@@ -180,6 +204,12 @@ public class GenUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字段名称是否为开关类字段。
|
||||
*
|
||||
* @param columnName 字段名称
|
||||
* @return 是否开关类字段
|
||||
*/
|
||||
private static boolean isSwitchColumn(String columnName) {
|
||||
return StringUtils.endsWithAny(columnName, "status", "flag", "enabled", "disabled", "available", "visible")
|
||||
|| columnName.startsWith("is_")
|
||||
@@ -188,6 +218,12 @@ public class GenUtils {
|
||||
|| columnName.startsWith("disable_");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字段名称是否为排序字段。
|
||||
*
|
||||
* @param columnName 字段名称
|
||||
* @return 是否排序字段
|
||||
*/
|
||||
private static boolean isSortColumn(String columnName) {
|
||||
return StringUtils.endsWithAny(columnName, "sort", "order_num", "order", "rank", "seq", "sequence");
|
||||
}
|
||||
|
||||
+41
-5
@@ -140,9 +140,9 @@ public class TemplateEngineUtils {
|
||||
/**
|
||||
* 向树形模板上下文写入树字段相关变量。
|
||||
*
|
||||
* @param context 模板上下文
|
||||
* @param genTable 代码生成业务表对象
|
||||
* @param paramsObj 已解析的 options 参数(避免重复解析)
|
||||
* @param context 模板上下文
|
||||
* @param genTable 代码生成业务表对象
|
||||
* @param paramsObj 已解析的 options 参数(避免重复解析)
|
||||
*/
|
||||
public static void setTreeContext(Dict context, GenTable genTable, Dict paramsObj) {
|
||||
String treeCode = getTreeCode(paramsObj);
|
||||
@@ -328,7 +328,7 @@ public class TemplateEngineUtils {
|
||||
/**
|
||||
* 添加字典列表
|
||||
*
|
||||
* @param dicts 字典列表
|
||||
* @param dicts 字典列表
|
||||
* @param columns 列集合
|
||||
*/
|
||||
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
|
||||
@@ -408,7 +408,7 @@ public class TemplateEngineUtils {
|
||||
/**
|
||||
* 获取树根节点值。
|
||||
*
|
||||
* @param paramsObj 其他选项
|
||||
* @param paramsObj 其他选项
|
||||
* @param treeParentColumn 父节点字段
|
||||
* @return 树根节点值
|
||||
*/
|
||||
@@ -423,6 +423,14 @@ public class TemplateEngineUtils {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取布尔类型生成选项。
|
||||
*
|
||||
* @param paramsObj 生成选项
|
||||
* @param key 选项键
|
||||
* @param defaultValue 默认值
|
||||
* @return 选项值
|
||||
*/
|
||||
private static boolean getBooleanOption(Dict paramsObj, String key, boolean defaultValue) {
|
||||
if (CollUtil.isEmpty(paramsObj) || !paramsObj.containsKey(key)) {
|
||||
return defaultValue;
|
||||
@@ -430,6 +438,13 @@ public class TemplateEngineUtils {
|
||||
return Convert.toBool(paramsObj.get(key), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段名查找业务表字段。
|
||||
*
|
||||
* @param genTable 业务表
|
||||
* @param field 字段名称或 Java 属性名
|
||||
* @return 业务表字段
|
||||
*/
|
||||
private static GenTableColumn getColumn(GenTable genTable, String field) {
|
||||
if (StringUtils.isBlank(field) || CollUtil.isEmpty(genTable.getColumns())) {
|
||||
return null;
|
||||
@@ -442,6 +457,13 @@ public class TemplateEngineUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段配置查找业务表字段列表。
|
||||
*
|
||||
* @param genTable 业务表
|
||||
* @param fieldValues 字段配置值
|
||||
* @return 业务表字段列表
|
||||
*/
|
||||
private static List<GenTableColumn> getColumns(GenTable genTable, Object fieldValues) {
|
||||
List<String> fields = new ArrayList<>();
|
||||
if (fieldValues instanceof Collection<?> collection) {
|
||||
@@ -459,6 +481,13 @@ public class TemplateEngineUtils {
|
||||
return columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 Java 字面量。
|
||||
*
|
||||
* @param column 业务表字段
|
||||
* @param value 字段值
|
||||
* @return Java 字面量
|
||||
*/
|
||||
private static String getJavaLiteral(GenTableColumn column, String value) {
|
||||
if (ObjectUtil.isNull(column) || StringUtils.isBlank(value)) {
|
||||
return "null";
|
||||
@@ -472,6 +501,13 @@ public class TemplateEngineUtils {
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为 TypeScript 字面量。
|
||||
*
|
||||
* @param column 业务表字段
|
||||
* @param value 字段值
|
||||
* @return TypeScript 字面量
|
||||
*/
|
||||
private static String getTsLiteral(GenTableColumn column, String value) {
|
||||
if (ObjectUtil.isNull(column) || StringUtils.isBlank(value)) {
|
||||
return "undefined";
|
||||
|
||||
+32
-2
@@ -23,26 +23,56 @@ public class PathNamedTemplate implements Template {
|
||||
|
||||
private final Template delegate;
|
||||
|
||||
/**
|
||||
* 创建基于路径命名的模板。
|
||||
*
|
||||
* @param pathName 路径名称
|
||||
* @param delegate 委托模板
|
||||
*/
|
||||
private PathNamedTemplate(String pathName, Template delegate) {
|
||||
this.pathName = pathName;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板到字符输出器。
|
||||
*
|
||||
* @param bindingMap 模板绑定数据
|
||||
* @param writer 字符输出器
|
||||
*/
|
||||
@Override
|
||||
public void render(Map<?, ?> bindingMap, Writer writer) {
|
||||
delegate.render(bindingMap, writer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板到输出流。
|
||||
*
|
||||
* @param bindingMap 模板绑定数据
|
||||
* @param out 输出流
|
||||
*/
|
||||
@Override
|
||||
public void render(Map<?, ?> bindingMap, OutputStream out) {
|
||||
delegate.render(bindingMap, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板到文件。
|
||||
*
|
||||
* @param bindingMap 模板绑定数据
|
||||
* @param file 输出文件
|
||||
*/
|
||||
@Override
|
||||
public void render(Map<?, ?> bindingMap, File file) {
|
||||
delegate.render(bindingMap, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染模板为字符串。
|
||||
*
|
||||
* @param bindingMap 模板绑定数据
|
||||
* @return 渲染结果
|
||||
*/
|
||||
@Override
|
||||
public String render(Map<?, ?> bindingMap) {
|
||||
return delegate.render(bindingMap);
|
||||
@@ -66,8 +96,8 @@ public class PathNamedTemplate implements Template {
|
||||
* @param pathName 路径名称
|
||||
* @return 带路径名称的模板
|
||||
*/
|
||||
public static PathNamedTemplate form(TemplateEngine templateEngine,String pathName) {
|
||||
return new PathNamedTemplate(pathName,templateEngine.getTemplate(pathName));
|
||||
public static PathNamedTemplate form(TemplateEngine templateEngine, String pathName) {
|
||||
return new PathNamedTemplate(pathName, templateEngine.getTemplate(pathName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user