update 优化 统一补全代码注释

This commit is contained in:
疯狂的狮子Li
2026-03-13 19:36:14 +08:00
parent 916282ba68
commit 48992b574d
201 changed files with 2554 additions and 465 deletions

View File

@@ -39,6 +39,11 @@ public class GenConfig {
return author;
}
/**
* 注入代码生成作者配置。
*
* @param author 作者名称
*/
@Value("${author}")
public void setAuthor(String author) {
GenConfig.author = author;
@@ -48,6 +53,11 @@ public class GenConfig {
return packageName;
}
/**
* 注入代码生成基础包名配置。
*
* @param packageName 基础包名
*/
@Value("${packageName}")
public void setPackageName(String packageName) {
GenConfig.packageName = packageName;
@@ -57,6 +67,11 @@ public class GenConfig {
return autoRemovePre;
}
/**
* 注入是否自动移除表前缀配置。
*
* @param autoRemovePre 是否自动移除表前缀
*/
@Value("${autoRemovePre}")
public void setAutoRemovePre(boolean autoRemovePre) {
GenConfig.autoRemovePre = autoRemovePre;
@@ -66,6 +81,11 @@ public class GenConfig {
return tablePrefix;
}
/**
* 注入代码生成表前缀配置。
*
* @param tablePrefix 表前缀字符串
*/
@Value("${tablePrefix}")
public void setTablePrefix(String tablePrefix) {
GenConfig.tablePrefix = tablePrefix;

View File

@@ -25,6 +25,9 @@ import java.util.Map;
@Component
public class MyBatisDataSourceMonitor implements DataSourceMonitor {
/**
* 初始化 anyline 与动态数据源联动所需的元数据解析策略。
*/
public MyBatisDataSourceMonitor() {
// 调整执行模式为自定义
ConfigTable.KEEP_ADAPTER = 2;
@@ -72,6 +75,8 @@ public class MyBatisDataSourceMonitor implements DataSourceMonitor {
/**
* 数据源唯一标识 如果不实现则默认feature
*
* @param runtime 数据运行时上下文
* @param datasource 数据源
* @return String 返回null由上层自动提取
*/
@@ -90,6 +95,7 @@ public class MyBatisDataSourceMonitor implements DataSourceMonitor {
* ConfigTable.KEEP_ADAPTER=2 : 根据当前接口判断是否保持同一个数据源绑定同一个adapter<br/>
* DynamicRoutingDataSource类型的返回false,因为同一个DynamicRoutingDataSource可能对应多类数据库, 如果项目中只有一种数据库 应该直接返回true
*
* @param runtime 数据运行时上下文
* @param datasource 数据源
* @return boolean
*/

View File

@@ -180,7 +180,7 @@ public interface GenConstants {
String QUERY_EQ = "EQ";
/**
* 需要
* 必填标识,对应前端表单规则中的必填字段配置。
*/
String REQUIRE = "1";
}

View File

@@ -39,7 +39,11 @@ public class GenController extends BaseController {
private final IGenTableService genTableService;
/**
* 查询代码生成列表
* 分页查询代码生成业务列表
*
* @param genTable 查询条件
* @param pageQuery 分页参数
* @return 代码生成列表
*/
@SaCheckPermission("tool:gen:list")
@GetMapping("/list")
@@ -51,6 +55,7 @@ public class GenController extends BaseController {
* 修改代码生成业务
*
* @param tableId 表ID
* @return 表、字段与可选业务表信息
*/
@RepeatSubmit()
@SaCheckPermission("tool:gen:query")
@@ -67,7 +72,11 @@ public class GenController extends BaseController {
}
/**
* 查询数据库列表
* 分页查询数据库列表
*
* @param genTable 查询条件
* @param pageQuery 分页参数
* @return 数据库表列表
*/
@SaCheckPermission("tool:gen:list")
@GetMapping("/db/list")
@@ -79,6 +88,7 @@ public class GenController extends BaseController {
* 查询数据表字段列表
*
* @param tableId 表ID
* @return 字段列表
*/
@SaCheckPermission("tool:gen:list")
@GetMapping(value = "/column/{tableId}")
@@ -92,6 +102,7 @@ public class GenController extends BaseController {
*
* @param tables 表名串
* @param dataName 数据源名称
* @return 操作结果
*/
@SaCheckPermission("tool:gen:import")
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@@ -107,7 +118,10 @@ public class GenController extends BaseController {
}
/**
* 修改保存代码生成业务
* 保存代码生成业务配置。
*
* @param genTable 业务配置
* @return 操作结果
*/
@SaCheckPermission("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@@ -123,6 +137,7 @@ public class GenController extends BaseController {
* 删除代码生成
*
* @param tableIds 表ID串
* @return 操作结果
*/
@SaCheckPermission("tool:gen:remove")
@Log(title = "代码生成", businessType = BusinessType.DELETE)
@@ -136,6 +151,7 @@ public class GenController extends BaseController {
* 预览代码
*
* @param tableId 表ID
* @return 模板路径与生成代码内容映射
*/
@SaCheckPermission("tool:gen:preview")
@GetMapping("/preview/{tableId}")
@@ -147,6 +163,7 @@ public class GenController extends BaseController {
/**
* 生成代码(下载方式)
*
* @param response HTTP 响应
* @param tableId 表ID
*/
@SaCheckPermission("tool:gen:code")
@@ -161,6 +178,7 @@ public class GenController extends BaseController {
* 生成代码(自定义路径)
*
* @param tableId 表ID
* @return 操作结果
*/
@SaCheckPermission("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@@ -174,6 +192,7 @@ public class GenController extends BaseController {
* 同步数据库
*
* @param tableId 表ID
* @return 操作结果
*/
@SaCheckPermission("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@@ -187,6 +206,7 @@ public class GenController extends BaseController {
/**
* 批量生成代码
*
* @param response HTTP 响应
* @param tableIdStr 表ID串
*/
@SaCheckPermission("tool:gen:code")
@@ -199,7 +219,10 @@ public class GenController extends BaseController {
}
/**
* 生成zip文件
* 生成结果写出为 zip 文件流。
*
* @param response HTTP 响应
* @param data zip 二进制数据
*/
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset();
@@ -212,7 +235,9 @@ public class GenController extends BaseController {
}
/**
* 查询数据源名称列表
* 查询当前可用数据源名称列表
*
* @return 数据源名称集合
*/
@SaCheckPermission("tool:gen:list")
@GetMapping(value = "/getDataNames")

View File

@@ -152,7 +152,7 @@ public class GenTable extends BaseEntity {
@TableField(exist = false)
private String treeName;
/*
/**
* 菜单id列表
*/
@TableField(exist = false)
@@ -170,26 +170,61 @@ public class GenTable extends BaseEntity {
@TableField(exist = false)
private String parentMenuName;
/**
* 判断当前业务表是否采用树表模板。
*
* @return 树表模板返回 {@code true}
*/
public boolean isTree() {
return isTree(this.tplCategory);
}
/**
* 根据模板分类判断是否为树表模板。
*
* @param tplCategory 模板分类
* @return 树表模板返回 {@code true}
*/
public static boolean isTree(String tplCategory) {
return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
}
/**
* 判断当前业务表是否采用普通 CRUD 模板。
*
* @return 普通 CRUD 模板返回 {@code true}
*/
public boolean isCrud() {
return isCrud(this.tplCategory);
}
/**
* 根据模板分类判断是否为普通 CRUD 模板。
*
* @param tplCategory 模板分类
* @return 普通 CRUD 模板返回 {@code true}
*/
public static boolean isCrud(String tplCategory) {
return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
}
/**
* 判断指定 Java 字段是否属于基类公共字段。
*
* @param javaField Java 字段名
* @return 基类公共字段返回 {@code true}
*/
public boolean isSuperColumn(String javaField) {
return isSuperColumn(this.tplCategory, javaField);
}
/**
* 根据模板分类与字段名判断是否属于基类公共字段。
*
* @param tplCategory 模板分类
* @param javaField Java 字段名
* @return 基类公共字段返回 {@code true}
*/
public static boolean isSuperColumn(String tplCategory, String javaField) {
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}

View File

@@ -122,70 +122,163 @@ public class GenTableColumn extends BaseEntity {
*/
private Integer sort;
/**
* 获取首字母大写后的 Java 字段名。
*
* @return 首字母大写的 Java 字段名
*/
public String getCapJavaField() {
return StringUtils.capitalize(javaField);
}
/**
* 判断当前列是否为主键列。
*
* @return 主键列返回 {@code true}
*/
public boolean isPk() {
return isPk(this.isPk);
}
/**
* 根据标识判断是否为主键列。
*
* @param isPk 主键标识
* @return 主键列返回 {@code true}
*/
public boolean isPk(String isPk) {
return isPk != null && StringUtils.equals("1", isPk);
}
/**
* 判断当前列是否为自增列。
*
* @return 自增列返回 {@code true}
*/
public boolean isIncrement() {
return isIncrement(this.isIncrement);
}
/**
* 根据标识判断是否为自增列。
*
* @param isIncrement 自增标识
* @return 自增列返回 {@code true}
*/
public boolean isIncrement(String isIncrement) {
return isIncrement != null && StringUtils.equals("1", isIncrement);
}
/**
* 判断当前列是否必填。
*
* @return 必填返回 {@code true}
*/
public boolean isRequired() {
return isRequired(this.isRequired);
}
/**
* 根据标识判断当前列是否必填。
*
* @param isRequired 必填标识
* @return 必填返回 {@code true}
*/
public boolean isRequired(String isRequired) {
return isRequired != null && StringUtils.equals("1", isRequired);
}
/**
* 判断当前列是否参与新增。
*
* @return 参与新增返回 {@code true}
*/
public boolean isInsert() {
return isInsert(this.isInsert);
}
/**
* 根据标识判断当前列是否参与新增。
*
* @param isInsert 新增标识
* @return 参与新增返回 {@code true}
*/
public boolean isInsert(String isInsert) {
return isInsert != null && StringUtils.equals("1", isInsert);
}
/**
* 判断当前列是否参与编辑。
*
* @return 参与编辑返回 {@code true}
*/
public boolean isEdit() {
return isEdit(this.isEdit);
}
/**
* 根据标识判断当前列是否参与编辑。
*
* @param isEdit 编辑标识
* @return 参与编辑返回 {@code true}
*/
public boolean isEdit(String isEdit) {
return isEdit != null && StringUtils.equals("1", isEdit);
}
/**
* 判断当前列是否参与列表展示。
*
* @return 参与列表展示返回 {@code true}
*/
public boolean isList() {
return isList(this.isList);
}
/**
* 根据标识判断当前列是否参与列表展示。
*
* @param isList 列表展示标识
* @return 参与列表展示返回 {@code true}
*/
public boolean isList(String isList) {
return isList != null && StringUtils.equals("1", isList);
}
/**
* 判断当前列是否参与查询条件。
*
* @return 参与查询返回 {@code true}
*/
public boolean isQuery() {
return isQuery(this.isQuery);
}
/**
* 根据标识判断当前列是否参与查询条件。
*
* @param isQuery 查询标识
* @return 参与查询返回 {@code true}
*/
public boolean isQuery(String isQuery) {
return isQuery != null && StringUtils.equals("1", isQuery);
}
/**
* 判断当前列是否为基类公共字段。
*
* @return 基类公共字段返回 {@code true}
*/
public boolean isSuperColumn() {
return isSuperColumn(this.javaField);
}
/**
* 根据字段名判断是否为基类公共字段。
*
* @param javaField Java 字段名
* @return 基类公共字段返回 {@code true}
*/
public static boolean isSuperColumn(String javaField) {
return StringUtils.equalsAnyIgnoreCase(javaField,
// BaseEntity
@@ -194,15 +287,31 @@ public class GenTableColumn extends BaseEntity {
"parentName", "parentId");
}
/**
* 判断当前列是否属于生成页面需要保留的白名单字段。
*
* @return 白名单字段返回 {@code true}
*/
public boolean isUsableColumn() {
return isUsableColumn(javaField);
}
/**
* 根据字段名判断是否属于生成页面需要保留的白名单字段。
*
* @param javaField Java 字段名
* @return 白名单字段返回 {@code true}
*/
public static boolean isUsableColumn(String javaField) {
// isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
}
/**
* 从字段注释中解析字典读转换表达式。
*
* @return 形如 `0=男,1=女` 的转换表达式,无法解析时返回原始注释
*/
public String readConverterExp() {
String remarks = StringUtils.substringBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer();

View File

@@ -89,12 +89,25 @@ public class GenTableServiceImpl implements IGenTableService {
return genTable;
}
/**
* 分页查询已导入的代码生成业务表。
*
* @param genTable 业务表筛选条件
* @param pageQuery 分页参数
* @return 业务表分页结果
*/
@Override
public TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery) {
Page<GenTable> page = baseMapper.selectPage(pageQuery.build(), this.buildGenTableQueryWrapper(genTable));
return TableDataInfo.build(page);
}
/**
* 构造代码生成业务表查询条件。
*
* @param genTable 业务表筛选条件
* @return 包含数据源、表名、表注释和时间区间的查询包装器
*/
private QueryWrapper<GenTable> buildGenTableQueryWrapper(GenTable genTable) {
Map<String, Object> params = genTable.getParams();
QueryWrapper<GenTable> wrapper = Wrappers.query();
@@ -462,6 +475,9 @@ public class GenTableServiceImpl implements IGenTableService {
/**
* 查询表信息并生成代码
*
* @param tableId 业务表主键
* @param zip 代码压缩输出流
*/
private void generatorCode(Long tableId, ZipOutputStream zip) {
// 查询表信息
@@ -518,6 +534,12 @@ public class GenTableServiceImpl implements IGenTableService {
}
}
/**
* 查询业务表并补齐其列信息。
*
* @param tableId 业务表主键
* @return 包含字段集合的业务表实体
*/
private GenTable getGenTable(Long tableId) {
GenTable table = baseMapper.selectById(tableId);
if (ObjectUtil.isNull(table)) {
@@ -527,6 +549,12 @@ public class GenTableServiceImpl implements IGenTableService {
return table;
}
/**
* 批量填充业务表对应的字段列表。
*
* @param tables 业务表集合
* @return 已填充字段信息的业务表集合
*/
private List<GenTable> fillTableColumns(List<GenTable> tables) {
if (CollUtil.isEmpty(tables)) {
return tables;

View File

@@ -26,16 +26,18 @@ public interface IGenTableService {
/**
* 查询业务列表
*
* @param genTable 业务信息
* @return 业务集合
* @param genTable 业务信息
* @param pageQuery 分页参数
* @return 业务分页集合
*/
TableDataInfo<GenTable> selectPageGenTableList(GenTable genTable, PageQuery pageQuery);
/**
* 查询据库列表
*
* @param genTable 业务信息
* @return 数据库表集合
* @param genTable 业务信息
* @param pageQuery 分页参数
* @return 数据库表分页集合
*/
TableDataInfo<GenTable> selectPageDbTableList(GenTable genTable, PageQuery pageQuery);

View File

@@ -21,6 +21,8 @@ public class GenUtils {
/**
* 初始化表信息
*
* @param genTable 待初始化的业务表对象
*/
public static void initTable(GenTable genTable) {
genTable.setClassName(convertClassName(genTable.getTableName()));
@@ -35,6 +37,9 @@ public class GenUtils {
/**
* 初始化列属性字段
*
* @param column 待初始化的列对象
* @param table 所属业务表对象
*/
public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
@@ -166,6 +171,7 @@ public class GenUtils {
*
* @param replacementm 替换值
* @param searchList 替换列表
* @return 去除命中前缀后的字符串
*/
public static String replaceFirst(String replacementm, String[] searchList) {
String text = replacementm;
@@ -206,7 +212,7 @@ public class GenUtils {
* 获取字段长度
*
* @param columnType 列类型
* @return 截取后的列类型
* @return 字段长度,未声明长度时返回 0
*/
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {

View File

@@ -17,6 +17,8 @@ public class VelocityInitializer {
/**
* 初始化vm方法
*
* @throws RuntimeException 初始化 Velocity 引擎失败时抛出
*/
public static void initVelocity() {
Properties p = new Properties();

View File

@@ -43,7 +43,8 @@ public class VelocityUtils {
/**
* 设置模板变量信息
*
* @return 模板列表
* @param genTable 代码生成业务表对象
* @return 初始化后的 Velocity 上下文
*/
public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
@@ -78,6 +79,12 @@ public class VelocityUtils {
return velocityContext;
}
/**
* 向模板上下文写入菜单相关变量。
*
* @param context 模板上下文
* @param genTable 代码生成业务表对象
*/
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
Dict paramsObj = JsonUtils.parseMap(options);
@@ -85,6 +92,12 @@ public class VelocityUtils {
context.put("parentMenuId", parentMenuId);
}
/**
* 向树形模板上下文写入树字段相关变量。
*
* @param context 模板上下文
* @param genTable 代码生成业务表对象
*/
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
Dict paramsObj = JsonUtils.parseMap(options);
@@ -141,6 +154,10 @@ public class VelocityUtils {
/**
* 获取文件名
*
* @param template 模板路径
* @param genTable 代码生成业务表对象
* @return 模板对应的目标文件相对路径
*/
public static String getFileName(String template, GenTable genTable) {
// 文件名称