From 5c724900e300929567d74bd83345bd2427edd38e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com>
Date: Fri, 16 Aug 2024 15:57:55 +0800
Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90):?=
=?UTF-8?q?=20=E9=80=82=E9=85=8Danyline?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pigx-visual/pigx-codegen/pom.xml | 2 +-
.../controller/GenDsConfController.java | 171 ++++++-----
.../controller/GenTableController.java | 225 +++++++--------
.../pigx/codegen/entity/GenCreateTable.java | 116 ++++----
.../codegen/entity/GenTemplateEntity.java | 116 ++++----
.../service/impl/GeneratorServiceImpl.java | 273 ++++++++++++++----
.../pig4cloud/pigx/codegen/util/GenKit.java | 35 +--
7 files changed, 535 insertions(+), 403 deletions(-)
diff --git a/pigx-visual/pigx-codegen/pom.xml b/pigx-visual/pigx-codegen/pom.xml
index 03fa294d4..6acaeca91 100755
--- a/pigx-visual/pigx-codegen/pom.xml
+++ b/pigx-visual/pigx-codegen/pom.xml
@@ -6,7 +6,7 @@
com.pig4cloud
pigx-visual
- 5.5.0
+ 5.6.0-SNAPSHOT
pigx-codegen
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java
index d71c980c4..4497684f3 100755
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenDsConfController.java
@@ -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.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.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);
+ }
}
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java
index ce5ef4687..2d112f644 100644
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/controller/GenTableController.java
@@ -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 getTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
- return R.ok(tableService.queryOrBuildTable(dsName, tableName));
- }
+ /**
+ * 获取表信息
+ * @param dsName 数据源
+ * @param tableName 表名称
+ */
+ @GetMapping("/{dsName}/{tableName}")
+ public R 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 syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
+ // 表配置删除
+ tableService.remove(
+ Wrappers.lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName));
+ // 字段配置删除
+ tableColumnService.remove(Wrappers.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 syncTable(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
- // 表配置删除
- tableService.remove(
- Wrappers.lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName));
- // 字段配置删除
- tableColumnService.remove(Wrappers.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 updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName,
- @RequestBody List tableFieldList) {
- tableColumnService.updateTableField(dsName, tableName, tableFieldList);
- return R.ok();
- }
-
- /**
- * 导出excel 表格
- *
- * @param table 查询条件
- * @return excel 文件流
- */
- @ResponseExcel
- @GetMapping("/export")
- public List export(GenTable table) {
- return tableService.list(Wrappers.query(table));
- }
+ /**
+ * 修改表字段数据
+ * @param dsName 数据源
+ * @param tableName 表名称
+ * @param tableFieldList 字段列表
+ */
+ @PutMapping("/field/{dsName}/{tableName}")
+ public R updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName,
+ @RequestBody List tableFieldList) {
+ tableColumnService.updateTableField(dsName, tableName, tableFieldList);
+ return R.ok();
+ }
+ /**
+ * 导出excel 表格
+ * @param table 查询条件
+ * @return excel 文件流
+ */
+ @ResponseExcel
+ @GetMapping("/export")
+ public List export(GenTable table) {
+ return tableService.list(Wrappers.query(table));
+ }
}
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenCreateTable.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenCreateTable.java
index 21957da29..e9680e669 100755
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenCreateTable.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenCreateTable.java
@@ -38,73 +38,73 @@ import java.time.LocalDateTime;
@Schema(description = "自动创建表管理")
public class GenCreateTable extends Model {
- 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;
}
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTemplateEntity.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTemplateEntity.java
index 557f9181b..f979a8b04 100644
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTemplateEntity.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/GenTemplateEntity.java
@@ -39,73 +39,73 @@ import java.time.LocalDateTime;
@Schema(description = "模板")
public class GenTemplateEntity extends Model {
- 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;
}
diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java
index a52eb138a..cd58d129c 100755
--- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java
+++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java
@@ -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 dataModel = getDataModel(tableId);
- Long style = (Long) dataModel.get("style");
+ Long style = (Long) dataModel.get(GenTable.Fields.style);
GroupVO groupVo = genGroupService.getGroupVoById(style);
List templateList = groupVo.getTemplateList();
- Map 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 dataModel = getDataModel(tableId);
- Long style = (Long) dataModel.get("style");
+ Long style = (Long) dataModel.get(GenTable.Fields.style);
// 获取模板列表,Lambda 表达式简化代码
List templateList = genGroupService.getGroupVoById(style).getTemplateList();
- Map 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