mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-14 22:29:00 +08:00
refactor(代码生成): 适配anyline
This commit is contained in:
1 parent
3c659c86bd
commit
5c724900e3
7 files changed
+535
-403
No files matched your search
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pigx-visual</artifactId>
|
||||
<version>5.5.0</version>
|
||||
<version>5.6.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pigx-codegen</artifactId>
|
||||
|
||||
+82
-89
@@ -49,104 +49,97 @@ import javax.sql.DataSource;
|
||||
@RequestMapping("/dsconf")
|
||||
public class GenDsConfController {
|
||||
|
||||
private final GenDatasourceConfService datasourceConfService;
|
||||
private final GenDatasourceConfService datasourceConfService;
|
||||
|
||||
private final Screw screw;
|
||||
private final Screw screw;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param datasourceConf 数据源表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getSysDatasourceConfPage(Page page, GenDatasourceConf datasourceConf) {
|
||||
return R.ok(datasourceConfService.page(page,
|
||||
Wrappers.<GenDatasourceConf>lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(datasourceConf.getDsName()), GenDatasourceConf::getDsName,
|
||||
datasourceConf.getDsName())));
|
||||
}
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param datasourceConf 数据源表
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getSysDatasourceConfPage(Page page, GenDatasourceConf datasourceConf) {
|
||||
return R.ok(datasourceConfService.page(page,
|
||||
Wrappers.<GenDatasourceConf>lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(datasourceConf.getDsName()), GenDatasourceConf::getDsName,
|
||||
datasourceConf.getDsName())));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部数据源
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Inner(value = false)
|
||||
public R list() {
|
||||
return R.ok(datasourceConfService.list());
|
||||
}
|
||||
/**
|
||||
* 查询全部数据源
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@Inner(value = false)
|
||||
public R list() {
|
||||
return R.ok(datasourceConfService.list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询数据源表
|
||||
*
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(datasourceConfService.getById(id));
|
||||
}
|
||||
/**
|
||||
* 通过id查询数据源表
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(datasourceConfService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据源表
|
||||
*
|
||||
* @param datasourceConf 数据源表
|
||||
* @return R
|
||||
*/
|
||||
@PostMapping
|
||||
@XssCleanIgnore
|
||||
public R save(@RequestBody GenDatasourceConf datasourceConf) {
|
||||
return R.ok(datasourceConfService.saveDsByEnc(datasourceConf));
|
||||
}
|
||||
/**
|
||||
* 新增数据源表
|
||||
* @param datasourceConf 数据源表
|
||||
* @return R
|
||||
*/
|
||||
@PostMapping
|
||||
@XssCleanIgnore
|
||||
public R save(@RequestBody GenDatasourceConf datasourceConf) {
|
||||
return R.ok(datasourceConfService.saveDsByEnc(datasourceConf));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据源表
|
||||
*
|
||||
* @param conf 数据源表
|
||||
* @return R
|
||||
*/
|
||||
@PutMapping
|
||||
@XssCleanIgnore
|
||||
public R updateById(@RequestBody GenDatasourceConf conf) {
|
||||
return R.ok(datasourceConfService.updateDsByEnc(conf));
|
||||
}
|
||||
/**
|
||||
* 修改数据源表
|
||||
* @param conf 数据源表
|
||||
* @return R
|
||||
*/
|
||||
@PutMapping
|
||||
@XssCleanIgnore
|
||||
public R updateById(@RequestBody GenDatasourceConf conf) {
|
||||
return R.ok(datasourceConfService.updateDsByEnc(conf));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除数据源表
|
||||
*
|
||||
* @param ids id
|
||||
* @return R
|
||||
*/
|
||||
@DeleteMapping
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(datasourceConfService.removeByDsId(ids));
|
||||
}
|
||||
/**
|
||||
* 通过id删除数据源表
|
||||
* @param ids id
|
||||
* @return R
|
||||
*/
|
||||
@DeleteMapping
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(datasourceConfService.removeByDsId(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源对应的文档
|
||||
*
|
||||
* @param dsName 数据源名称
|
||||
*/
|
||||
@SneakyThrows
|
||||
@GetMapping("/doc")
|
||||
public void generatorDoc(String dsName, HttpServletResponse response) {
|
||||
// 设置指定的数据源
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = SpringContextHolder.getBean(DynamicRoutingDataSource.class);
|
||||
DynamicDataSourceContextHolder.push(dsName);
|
||||
DataSource dataSource = dynamicRoutingDataSource.determineDataSource();
|
||||
/**
|
||||
* 查询数据源对应的文档
|
||||
* @param dsName 数据源名称
|
||||
*/
|
||||
@SneakyThrows
|
||||
@GetMapping("/doc")
|
||||
public void generatorDoc(String dsName, HttpServletResponse response) {
|
||||
// 设置指定的数据源
|
||||
DynamicRoutingDataSource dynamicRoutingDataSource = SpringContextHolder.getBean(DynamicRoutingDataSource.class);
|
||||
DynamicDataSourceContextHolder.push(dsName);
|
||||
DataSource dataSource = dynamicRoutingDataSource.determineDataSource();
|
||||
|
||||
// 设置指定的目标表
|
||||
ScrewProperties screwProperties = SpringContextHolder.getBean(ScrewProperties.class);
|
||||
// 设置指定的目标表
|
||||
ScrewProperties screwProperties = SpringContextHolder.getBean(ScrewProperties.class);
|
||||
|
||||
// 生成
|
||||
byte[] data = screw.documentGeneration(dsName, dataSource, screwProperties).toByteArray();
|
||||
response.reset();
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||
response.setContentType("application/octet-stream");
|
||||
IoUtil.write(response.getOutputStream(), Boolean.FALSE, data);
|
||||
}
|
||||
// 生成
|
||||
byte[] data = screw.documentGeneration(dsName, dataSource, screwProperties).toByteArray();
|
||||
response.reset();
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||
response.setContentType("application/octet-stream");
|
||||
IoUtil.write(response.getOutputStream(), Boolean.FALSE, data);
|
||||
}
|
||||
|
||||
}
|
||||
+107
-118
@@ -48,134 +48,123 @@ import java.util.List;
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class GenTableController {
|
||||
|
||||
private final GenTableColumnService tableColumnService;
|
||||
private final GenTableColumnService tableColumnService;
|
||||
|
||||
private final GenTableService tableService;
|
||||
private final GenTableService tableService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param table 列属性
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getTablePage(Page page, GenTable table) {
|
||||
return R.ok(tableService.queryTablePage(page, table));
|
||||
}
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param table 列属性
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getTablePage(Page page, GenTable table) {
|
||||
return R.ok(tableService.queryTablePage(page, table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询表信息(代码生成设置 + 表 + 字段设置)
|
||||
*
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
public R getTable(@PathVariable("id") Long id) {
|
||||
return R.ok(tableService.getById(id));
|
||||
}
|
||||
/**
|
||||
* 通过id查询表信息(代码生成设置 + 表 + 字段设置)
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
public R getTable(@PathVariable("id") Long id) {
|
||||
return R.ok(tableService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据源所有表
|
||||
*
|
||||
* @param dsName 数据源
|
||||
*/
|
||||
@GetMapping("/list/{dsName}")
|
||||
public R listTable(@PathVariable("dsName") String dsName) {
|
||||
return R.ok(tableService.queryTableList(dsName));
|
||||
}
|
||||
/**
|
||||
* 查询数据源所有表
|
||||
* @param dsName 数据源
|
||||
*/
|
||||
@GetMapping("/list/{dsName}")
|
||||
public R listTable(@PathVariable("dsName") String dsName) {
|
||||
return R.ok(tableService.queryTableList(dsName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表信息
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/{dsName}/{tableName}")
|
||||
public R<GenTable> getTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
|
||||
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
|
||||
}
|
||||
/**
|
||||
* 获取表信息
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/{dsName}/{tableName}")
|
||||
public R<GenTable> getTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
|
||||
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表DDL语句
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/column/{dsName}/{tableName}")
|
||||
public R getColumn(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception {
|
||||
return R.ok(tableService.queryTableColumn(dsName, tableName));
|
||||
}
|
||||
/**
|
||||
* 查询表DDL语句
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/column/{dsName}/{tableName}")
|
||||
public R getColumn(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception {
|
||||
return R.ok(tableService.queryTableColumn(dsName, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询表DDL语句
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/ddl/{dsName}/{tableName}")
|
||||
public R getDdl(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception {
|
||||
return R.ok(tableService.queryTableDdl(dsName, tableName));
|
||||
}
|
||||
/**
|
||||
* 查询表DDL语句
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/ddl/{dsName}/{tableName}")
|
||||
public R getDdl(@PathVariable("dsName") String dsName, @PathVariable String tableName) throws Exception {
|
||||
return R.ok(tableService.queryTableDdl(dsName, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步表信息
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/sync/{dsName}/{tableName}")
|
||||
public R<GenTable> syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
|
||||
// 表配置删除
|
||||
tableService.remove(
|
||||
Wrappers.<GenTable>lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName));
|
||||
// 字段配置删除
|
||||
tableColumnService.remove(Wrappers.<GenTableColumnEntity>lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, dsName)
|
||||
.eq(GenTableColumnEntity::getTableName, tableName));
|
||||
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步表信息
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@GetMapping("/sync/{dsName}/{tableName}")
|
||||
public R<GenTable> syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
|
||||
// 表配置删除
|
||||
tableService.remove(
|
||||
Wrappers.<GenTable>lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName));
|
||||
// 字段配置删除
|
||||
tableColumnService.remove(Wrappers.<GenTableColumnEntity>lambdaQuery()
|
||||
.eq(GenTableColumnEntity::getDsName, dsName)
|
||||
.eq(GenTableColumnEntity::getTableName, tableName));
|
||||
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
|
||||
}
|
||||
/**
|
||||
* 修改列属性
|
||||
* @param table 列属性
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "修改列属性", description = "修改列属性")
|
||||
@SysLog("修改列属性")
|
||||
@PutMapping
|
||||
public R updateById(@RequestBody GenTable table) {
|
||||
return R.ok(tableService.updateById(table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改列属性
|
||||
* @param table 列属性
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "修改列属性", description = "修改列属性")
|
||||
@SysLog("修改列属性")
|
||||
@PutMapping
|
||||
public R updateById(@RequestBody GenTable table) {
|
||||
return R.ok(tableService.updateById(table));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改表字段数据
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
* @param tableFieldList 字段列表
|
||||
*/
|
||||
@PutMapping("/field/{dsName}/{tableName}")
|
||||
public R<String> updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName,
|
||||
@RequestBody List<GenTableColumnEntity> tableFieldList) {
|
||||
tableColumnService.updateTableField(dsName, tableName, tableFieldList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
*
|
||||
* @param table 查询条件
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
public List<GenTable> export(GenTable table) {
|
||||
return tableService.list(Wrappers.query(table));
|
||||
}
|
||||
/**
|
||||
* 修改表字段数据
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
* @param tableFieldList 字段列表
|
||||
*/
|
||||
@PutMapping("/field/{dsName}/{tableName}")
|
||||
public R<String> updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName,
|
||||
@RequestBody List<GenTableColumnEntity> tableFieldList) {
|
||||
tableColumnService.updateTableField(dsName, tableName, tableFieldList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
* @param table 查询条件
|
||||
* @return excel 文件流
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
public List<GenTable> export(GenTable table) {
|
||||
return tableService.list(Wrappers.query(table));
|
||||
}
|
||||
|
||||
}
|
||||
+58
-58
@@ -38,73 +38,73 @@ import java.time.LocalDateTime;
|
||||
@Schema(description = "自动创建表管理")
|
||||
public class GenCreateTable extends Model<GenCreateTable> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@Schema(description = "数据源名称")
|
||||
private String dsName;
|
||||
/**
|
||||
* 数据源名称
|
||||
*/
|
||||
@Schema(description = "数据源名称")
|
||||
private String dsName;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@Schema(description = "表名称")
|
||||
private String tableName;
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@Schema(description = "表名称")
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
@Schema(description = "表注释")
|
||||
private String comments;
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
@Schema(description = "表注释")
|
||||
private String comments;
|
||||
|
||||
/**
|
||||
* 字段信息
|
||||
*/
|
||||
@Schema(description = "字段信息")
|
||||
private String columnInfo;
|
||||
/**
|
||||
* 字段信息
|
||||
*/
|
||||
@Schema(description = "字段信息")
|
||||
private String columnInfo;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "修改人")
|
||||
private String updateBy;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "修改人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
|
||||
}
|
||||
+58
-58
@@ -39,73 +39,73 @@ import java.time.LocalDateTime;
|
||||
@Schema(description = "模板")
|
||||
public class GenTemplateEntity extends Model<GenTemplateEntity> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
@Schema(description = "模板名称")
|
||||
private String templateName;
|
||||
/**
|
||||
* 模板名称
|
||||
*/
|
||||
@Schema(description = "模板名称")
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 模板路径
|
||||
*/
|
||||
@Schema(description = "模板路径")
|
||||
private String generatorPath;
|
||||
/**
|
||||
* 模板路径
|
||||
*/
|
||||
@Schema(description = "模板路径")
|
||||
private String generatorPath;
|
||||
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
@Schema(description = "模板描述")
|
||||
private String templateDesc;
|
||||
/**
|
||||
* 模板描述
|
||||
*/
|
||||
@Schema(description = "模板描述")
|
||||
private String templateDesc;
|
||||
|
||||
/**
|
||||
* 模板代码
|
||||
*/
|
||||
@Schema(description = "模板代码")
|
||||
private String templateCode;
|
||||
/**
|
||||
* 模板代码
|
||||
*/
|
||||
@Schema(description = "模板代码")
|
||||
private String templateCode;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "修改人")
|
||||
private String updateBy;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "修改人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
/**
|
||||
* 删除标识(0-正常,1-删除)
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
|
||||
}
|
||||
+213
-60
@@ -21,18 +21,31 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.NamingCase;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysMenu;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRouteConf;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteMenuService;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteRouteConfService;
|
||||
import com.pig4cloud.pigx.codegen.config.PigxCodeGenDefaultProperties;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenTable;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity;
|
||||
import com.pig4cloud.pigx.codegen.entity.GenTemplateEntity;
|
||||
import com.pig4cloud.pigx.codegen.service.*;
|
||||
import com.pig4cloud.pigx.codegen.util.DataModelConstants;
|
||||
import com.pig4cloud.pigx.codegen.util.GeneratorStyleEnum;
|
||||
import com.pig4cloud.pigx.codegen.util.VelocityKit;
|
||||
import com.pig4cloud.pigx.codegen.util.vo.GroupVO;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.MenuTypeEnum;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.YesNoEnum;
|
||||
import com.pig4cloud.pigx.common.core.exception.CheckedException;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.RetOps;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -55,6 +68,8 @@ import java.util.zip.ZipOutputStream;
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
private final PigxCodeGenDefaultProperties defaultProperties;
|
||||
|
||||
private final GenTableColumnService columnService;
|
||||
|
||||
private final GenFormConfService formConfService;
|
||||
@@ -67,6 +82,10 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
private final GenTemplateService genTemplateService;
|
||||
|
||||
private final RemoteMenuService menuService;
|
||||
|
||||
private final RemoteRouteConfService routeService;
|
||||
|
||||
/**
|
||||
* 生成代码zip写出
|
||||
*
|
||||
@@ -79,22 +98,23 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
|
||||
Long style = (Long) dataModel.get("style");
|
||||
Long style = (Long) dataModel.get(GenTable.Fields.style);
|
||||
|
||||
GroupVO groupVo = genGroupService.getGroupVoById(style);
|
||||
List<GenTemplateEntity> templateList = groupVo.getTemplateList();
|
||||
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
String frontendPath = defaultProperties.getFrontendPath();
|
||||
String backendPath = defaultProperties.getBackendPath();
|
||||
|
||||
// 同步数据
|
||||
this.syncRouteAndMenu(tableId);
|
||||
|
||||
for (GenTemplateEntity template : templateList) {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
dataModel.put(GenTable.Fields.frontendPath, frontendPath);
|
||||
dataModel.put(GenTable.Fields.backendPath, backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
|
||||
@@ -119,34 +139,42 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
|
||||
Long style = (Long) dataModel.get("style");
|
||||
Long style = (Long) dataModel.get(GenTable.Fields.style);
|
||||
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
|
||||
Map<String, Object> generatorConfig = tableService.getGeneratorConfig();
|
||||
JSONObject project = (JSONObject) generatorConfig.get("project");
|
||||
String frontendPath = project.getStr("frontendPath");
|
||||
String backendPath = project.getStr("backendPath");
|
||||
String frontendPath = defaultProperties.getFrontendPath();
|
||||
String backendPath = defaultProperties.getBackendPath();
|
||||
|
||||
// 如果是同步菜单的模式则不生成SQL
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
Long syncMenuId = MapUtil.getLong(dataModel, GenTable.Fields.syncMenuId);
|
||||
for (GenTemplateEntity template : templateList) {
|
||||
// 跳过菜单文件生成
|
||||
if (Objects.nonNull(syncMenuId) && template.getGeneratorPath().contains("menu.sql")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return templateList.stream().map(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
|
||||
// 预览模式下, 使用相对路径展示
|
||||
dataModel.put("frontendPath", frontendPath);
|
||||
dataModel.put("backendPath", backendPath);
|
||||
dataModel.put(GenTable.Fields.frontendPath, frontendPath);
|
||||
dataModel.put(GenTable.Fields.backendPath, backendPath);
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
|
||||
// 使用 map 简化代码
|
||||
return new HashMap<String, String>(4) {
|
||||
result.add(new HashMap<>(4) {
|
||||
{
|
||||
put("code", content);
|
||||
put("codePath", path);
|
||||
}
|
||||
};
|
||||
}).collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,18 +186,24 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
public void generatorCode(Long tableId) {
|
||||
// 数据模型
|
||||
Map<String, Object> dataModel = getDataModel(tableId);
|
||||
Long style = (Long) dataModel.get("style");
|
||||
Long style = (Long) dataModel.get(GenTable.Fields.style);
|
||||
|
||||
// 获取模板列表,Lambda 表达式简化代码
|
||||
List<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
Long syncMenuId = MapUtil.getLong(dataModel, GenTable.Fields.syncMenuId);
|
||||
this.syncRouteAndMenu(tableId);
|
||||
for (GenTemplateEntity template : templateList) {
|
||||
// 跳过菜单文件生成
|
||||
if (Objects.nonNull(syncMenuId) && template.getGeneratorPath().contains("menu.sql")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
templateList.forEach(template -> {
|
||||
String templateCode = template.getTemplateCode();
|
||||
String generatorPath = template.getGeneratorPath();
|
||||
String content = VelocityKit.renderStr(templateCode, dataModel);
|
||||
String path = VelocityKit.renderStr(generatorPath, dataModel);
|
||||
FileUtil.writeUtf8String(content, path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,16 +223,17 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
Map<String, Object> dataModel = getDataModel(genTable.getId());
|
||||
|
||||
// 获取模板信息,Lambda 表达式简化代码
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_JSON.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
|
||||
GenTemplateEntity genTemplateEntity = genTemplateService.getOneOpt(Wrappers.<GenTemplateEntity>lambdaQuery()
|
||||
.likeRight(GenTemplateEntity::getTemplateName, GeneratorStyleEnum.VFORM_JSON.getDesc())
|
||||
.orderByDesc(GenTemplateEntity::getCreateTime), false
|
||||
)
|
||||
.orElseThrow(() -> new CheckedException("模板不存在"));
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单设计器需要的 JSON 方法
|
||||
* 获取sfc vue
|
||||
*
|
||||
* @param id 表单配置 ID
|
||||
* @return JSON 字符串
|
||||
@@ -221,15 +256,132 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
// 遍历 widgetList
|
||||
dataModel.put("resultMap", resultMap);
|
||||
|
||||
// 获取模板信息
|
||||
GenTemplateEntity genTemplateEntity = Optional
|
||||
.ofNullable(genTemplateService.getById(GeneratorStyleEnum.VFORM_FORM.getTemplateId()))
|
||||
.orElseThrow(() -> new Exception("模板不存在"));
|
||||
// 获取模板信息 查询模板中最新的 vform.json 文件
|
||||
GenTemplateEntity genTemplateEntity = genTemplateService.getOneOpt(Wrappers.<GenTemplateEntity>lambdaQuery()
|
||||
.likeRight(GenTemplateEntity::getTemplateName, GeneratorStyleEnum.VFORM_VUE.getDesc())
|
||||
.orderByDesc(GenTemplateEntity::getCreateTime), false
|
||||
)
|
||||
.orElseThrow(() -> new CheckedException("模板不存在"));
|
||||
|
||||
// 渲染模板并返回结果
|
||||
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步路由和菜单
|
||||
*
|
||||
* @param tableId 表ID
|
||||
*/
|
||||
@Override
|
||||
public void syncRouteAndMenu(Long tableId) {
|
||||
GenTable table = tableService.getById(tableId);
|
||||
syncMenu(table);
|
||||
syncRoute(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步菜单,同步按钮
|
||||
*
|
||||
* @param table 表配置
|
||||
*/
|
||||
private void syncMenu(GenTable table) {
|
||||
if (Objects.isNull(table.getSyncMenuId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String menuName = String.format("%s管理", table.getTableComment());
|
||||
SysMenu query = new SysMenu();
|
||||
query.setName(menuName);
|
||||
query.setMenuType(MenuTypeEnum.LEFT_MENU.getType());
|
||||
|
||||
List<SysMenu> existingMenus = RetOps.of(menuService.getMenuDetails(query)).getData().orElse(Collections.emptyList());
|
||||
|
||||
if (!CollUtil.isEmpty(existingMenus)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SysMenu sysMenu = createMenu(table, menuName);
|
||||
R<SysMenu> sysMenuR = menuService.saveMenu(sysMenu);
|
||||
|
||||
if (sysMenuR.getData() != null) {
|
||||
createButtons(table, sysMenuR.getData().getMenuId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*
|
||||
* @param table 表配置
|
||||
* @param menuName 菜单名称
|
||||
* @return {@link SysMenu }
|
||||
*/
|
||||
private SysMenu createMenu(GenTable table, String menuName) {
|
||||
SysMenu sysMenu = new SysMenu();
|
||||
sysMenu.setParentId(table.getSyncMenuId());
|
||||
sysMenu.setName(menuName);
|
||||
sysMenu.setMenuType(MenuTypeEnum.LEFT_MENU.getType());
|
||||
sysMenu.setPath(String.format("/%s/%s/index", table.getModuleName(), table.getFunctionName()));
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建按钮
|
||||
*
|
||||
* @param table 表配置
|
||||
* @param parentId 父 ID
|
||||
*/
|
||||
private void createButtons(GenTable table, Long parentId) {
|
||||
String[] buttonNames = {"查看", "新增", "编辑", "删除", "导入导出"};
|
||||
String[] permissions = {"view", "add", "edit", "del", "export"};
|
||||
|
||||
for (int i = 0; i < buttonNames.length; i++) {
|
||||
SysMenu button = new SysMenu();
|
||||
button.setParentId(parentId);
|
||||
button.setMenuType(MenuTypeEnum.BUTTON.getType());
|
||||
button.setName(buttonNames[i]);
|
||||
button.setPermission(String.format("%s_%s_%s", table.getModuleName(), table.getFunctionName(), permissions[i]));
|
||||
menuService.saveMenu(button);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步路由
|
||||
*
|
||||
* @param table 表配置
|
||||
*/
|
||||
private void syncRoute(GenTable table) {
|
||||
if (!YesNoEnum.YES.getCode().equals(table.getSyncRoute())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<SysRouteConf> existingRoutes = RetOps.of(routeService.getRouteDetails()).getData().orElse(Collections.emptyList());
|
||||
boolean exist = existingRoutes.stream()
|
||||
.anyMatch(routeConf -> routeConf.getRouteId().equals(table.getModuleName()));
|
||||
|
||||
if (exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
SysRouteConf sysRouteConf = createRoute(table);
|
||||
routeService.saveSysRouteConf(sysRouteConf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建路由
|
||||
*
|
||||
* @param table 表配置
|
||||
* @return {@link SysRouteConf }
|
||||
*/
|
||||
private SysRouteConf createRoute(GenTable table) {
|
||||
SysRouteConf sysRouteConf = new SysRouteConf();
|
||||
sysRouteConf.setRouteId(table.getModuleName());
|
||||
sysRouteConf.setRouteName(table.getModuleName());
|
||||
sysRouteConf.setPredicates(String.format("[{\"args\": {\"_genkey_0\": \"/%s/**\"}, \"name\": \"Path\"}]", table.getModuleName()));
|
||||
sysRouteConf.setFilters("[]");
|
||||
sysRouteConf.setUri(String.format("lb://%s-biz", table.getModuleName()));
|
||||
return sysRouteConf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 Lambda 表达式优化的获取数据模型方法
|
||||
*
|
||||
@@ -252,33 +404,34 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
Map<String, Object> dataModel = new HashMap<>();
|
||||
|
||||
// 填充数据模型
|
||||
dataModel.put("isSpringBoot3", isSpringBoot3());
|
||||
dataModel.put("dbType", table.getDbType());
|
||||
dataModel.put("package", table.getPackageName());
|
||||
dataModel.put("packagePath", table.getPackageName().replace(".", "/"));
|
||||
dataModel.put("version", table.getVersion());
|
||||
dataModel.put("moduleName", table.getModuleName());
|
||||
dataModel.put("ModuleName", StrUtil.upperFirst(table.getModuleName()));
|
||||
dataModel.put("functionName", table.getFunctionName());
|
||||
dataModel.put("FunctionName", StrUtil.upperFirst(table.getFunctionName()));
|
||||
dataModel.put("formLayout", table.getFormLayout());
|
||||
dataModel.put("style", table.getStyle());
|
||||
dataModel.put("author", table.getAuthor());
|
||||
dataModel.put("datetime", DateUtil.now());
|
||||
dataModel.put("date", DateUtil.today());
|
||||
dataModel.put(DataModelConstants.IS_SPRING_BOOT_3, isSpringBoot3());
|
||||
dataModel.put(DataModelConstants.SYNC_MENU_ID, Objects.nonNull(table.getSyncMenuId()));
|
||||
dataModel.put(DataModelConstants.DB_TYPE, table.getDbType());
|
||||
dataModel.put(DataModelConstants.PACKAGE, table.getPackageName());
|
||||
dataModel.put(DataModelConstants.PACKAGE_PATH, table.getPackageName().replace(".", "/"));
|
||||
dataModel.put(DataModelConstants.VERSION, table.getVersion());
|
||||
dataModel.put(DataModelConstants.MODULE_NAME, table.getModuleName());
|
||||
dataModel.put(DataModelConstants.MODULE_NAME_UPPER_FIRST, StrUtil.upperFirst(table.getModuleName()));
|
||||
dataModel.put(DataModelConstants.FUNCTION_NAME, table.getFunctionName());
|
||||
dataModel.put(DataModelConstants.FUNCTION_NAME_UPPER_FIRST, StrUtil.upperFirst(table.getFunctionName()));
|
||||
dataModel.put(DataModelConstants.FORM_LAYOUT, table.getFormLayout());
|
||||
dataModel.put(DataModelConstants.STYLE, table.getStyle());
|
||||
dataModel.put(DataModelConstants.AUTHOR, table.getAuthor());
|
||||
dataModel.put(DataModelConstants.DATETIME, DateUtil.now());
|
||||
dataModel.put(DataModelConstants.DATE, DateUtil.today());
|
||||
setFieldTypeList(dataModel, table);
|
||||
|
||||
// 获取导入的包列表
|
||||
Set<String> importList = fieldTypeService.getPackageByTableId(table.getDsName(), table.getTableName());
|
||||
dataModel.put("importList", importList);
|
||||
dataModel.put("tableName", table.getTableName());
|
||||
dataModel.put("tableComment", table.getTableComment());
|
||||
dataModel.put("className", StrUtil.lowerFirst(table.getClassName()));
|
||||
dataModel.put("ClassName", table.getClassName());
|
||||
dataModel.put("fieldList", table.getFieldList());
|
||||
dataModel.put(DataModelConstants.IMPORT_LIST, importList);
|
||||
dataModel.put(DataModelConstants.TABLE_NAME, table.getTableName());
|
||||
dataModel.put(DataModelConstants.TABLE_COMMENT, table.getTableComment());
|
||||
dataModel.put(DataModelConstants.CLASS_NAME, StrUtil.lowerFirst(table.getClassName()));
|
||||
dataModel.put(DataModelConstants.CLASS_NAME_UPPER_FIRST, table.getClassName());
|
||||
dataModel.put(DataModelConstants.FIELD_LIST, table.getFieldList());
|
||||
|
||||
dataModel.put("backendPath", table.getBackendPath());
|
||||
dataModel.put("frontendPath", table.getFrontendPath());
|
||||
dataModel.put(DataModelConstants.BACKEND_PATH, table.getBackendPath());
|
||||
dataModel.put(DataModelConstants.FRONTEND_PATH, table.getFrontendPath());
|
||||
|
||||
// 设置子表
|
||||
String childTableName = table.getChildTableName();
|
||||
@@ -287,20 +440,20 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
.eq(GenTableColumnEntity::getDsName, table.getDsName())
|
||||
.eq(GenTableColumnEntity::getTableName, table.getChildTableName())
|
||||
.list();
|
||||
dataModel.put("childFieldList", childFieldList);
|
||||
dataModel.put("childTableName", childTableName);
|
||||
dataModel.put("mainField", NamingCase.toCamelCase(table.getMainField()));
|
||||
dataModel.put("childField", NamingCase.toCamelCase(table.getChildField()));
|
||||
dataModel.put("ChildClassName", NamingCase.toPascalCase(childTableName));
|
||||
dataModel.put("childClassName", StrUtil.lowerFirst(NamingCase.toPascalCase(childTableName)));
|
||||
dataModel.put(DataModelConstants.CHILD_FIELD_LIST, childFieldList);
|
||||
dataModel.put(DataModelConstants.CHILD_TABLE_NAME, childTableName);
|
||||
dataModel.put(DataModelConstants.MAIN_FIELD, NamingCase.toCamelCase(table.getMainField()));
|
||||
dataModel.put(DataModelConstants.CHILD_FIELD, NamingCase.toCamelCase(table.getChildField()));
|
||||
dataModel.put(DataModelConstants.CHILD_CLASS_NAME_UPPER_FIRST, NamingCase.toPascalCase(childTableName));
|
||||
dataModel.put(DataModelConstants.CHILD_CLASS_NAME, StrUtil.lowerFirst(NamingCase.toPascalCase(childTableName)));
|
||||
// 设置是否是多租户模式 (判断字段列表中是否包含 tenant_id 字段)
|
||||
childFieldList.stream().filter(genTableColumnEntity -> genTableColumnEntity.getFieldName().equals("tenant_id"))
|
||||
.findFirst().ifPresent(columnEntity -> dataModel.put("isChildTenant", true));
|
||||
.findFirst().ifPresent(columnEntity -> dataModel.put(DataModelConstants.IS_CHILD_TENANT, true));
|
||||
}
|
||||
|
||||
// 设置是否是多租户模式 (判断字段列表中是否包含 tenant_id 字段)
|
||||
table.getFieldList().stream().filter(genTableColumnEntity -> genTableColumnEntity.getFieldName().equals("tenant_id"))
|
||||
.findFirst().ifPresent(columnEntity -> dataModel.put("isTenant", true));
|
||||
.findFirst().ifPresent(columnEntity -> dataModel.put(DataModelConstants.IS_TENANT, true));
|
||||
|
||||
return dataModel;
|
||||
}
|
||||
|
||||
+16
-19
@@ -12,25 +12,22 @@ import lombok.experimental.UtilityClass;
|
||||
@UtilityClass
|
||||
public class GenKit {
|
||||
|
||||
/**
|
||||
* 获取功能名 sys_a_b sysAb
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return 功能名
|
||||
*/
|
||||
public String getFunctionName(String tableName) {
|
||||
return StrUtil.toCamelCase(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模块名称
|
||||
*
|
||||
* @param packageName 包名
|
||||
* @return 功能名
|
||||
*/
|
||||
public String getModuleName(String packageName) {
|
||||
return StrUtil.subAfter(packageName, ".", true);
|
||||
}
|
||||
/**
|
||||
* 获取功能名 sys_a_b sysAb
|
||||
* @param tableName 表名
|
||||
* @return 功能名
|
||||
*/
|
||||
public String getFunctionName(String tableName) {
|
||||
return StrUtil.toCamelCase(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模块名称
|
||||
* @param packageName 包名
|
||||
* @return 功能名
|
||||
*/
|
||||
public String getModuleName(String packageName) {
|
||||
return StrUtil.subAfter(packageName, ".", true);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user