diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/controller/GenController.java b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/controller/GenController.java index 460e95245..5ddb47ec5 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/controller/GenController.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/controller/GenController.java @@ -172,20 +172,6 @@ public class GenController extends BaseController { genCode(response, data); } - /** - * 生成代码(自定义路径) - * - * @param tableId 表ID - * @return 操作结果 - */ - @SaCheckPermission("tool:gen:code") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/genCode/{tableId}") - public R genCode(@PathVariable("tableId") Long tableId) { - genTableService.generatorCode(tableId); - return R.ok(); - } - /** * 同步数据库 * diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/domain/GenTable.java b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/domain/GenTable.java index 29da27e17..581a6380e 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/domain/GenTable.java @@ -1,6 +1,5 @@ package org.dromara.gen.domain; -import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -92,17 +91,6 @@ public class GenTable extends BaseEntity { @NotBlank(message = "作者不能为空") private String functionAuthor; - /** - * 生成代码方式(0zip压缩包 1自定义路径) - */ - private String genType; - - /** - * 生成路径(不填默认项目路径) - */ - @TableField(updateStrategy = FieldStrategy.NOT_EMPTY) - private String genPath; - /** * 主键信息 */ diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/GenTableServiceImpl.java index b025c6b8b..4c0595004 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/GenTableServiceImpl.java @@ -22,7 +22,6 @@ import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.core.utils.file.FileUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.utils.IdGeneratorUtil; @@ -38,7 +37,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.*; @@ -341,39 +339,11 @@ public class GenTableServiceImpl implements IGenTableService { public byte[] downloadCode(Long tableId) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); - generatorCode(tableId, zip); + writeCodeToZip(tableId, zip); IoUtil.close(zip); return outputStream.toByteArray(); } - /** - * 生成代码(自定义路径) - * - * @param tableId 表名称 - */ - @Override - public void generatorCode(Long tableId) { - // 查询表信息 - GenTable table = getGenTable(tableId); - // 设置主键列信息 - setPkColumn(table); - - Dict context = TemplateEngineUtils.buildContext(table); - // 获取模板列表 - List templates = TemplateEngineUtils.getTemplateList(table.getTplCategory(), table.getDataName()); - for (PathNamedTemplate template : templates) { - String pathName = template.getPathName(); - try { - String render = template.render(context); - String path = getGenPath(table, pathName); - FileUtils.writeUtf8String(render, path); - } catch (Exception e) { - log.error("渲染模板失败,表名:{},模板:{}", table.getTableName(), pathName, e); - throw new ServiceException("渲染模板失败,表名:" + table.getTableName() + ",模板:" + pathName); - } - } - } - /** * 同步数据库 * @@ -437,7 +407,7 @@ public class GenTableServiceImpl implements IGenTableService { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); for (String tableId : tableIds) { - generatorCode(Long.parseLong(tableId), zip); + writeCodeToZip(Long.parseLong(tableId), zip); } IoUtil.close(zip); return outputStream.toByteArray(); @@ -449,7 +419,7 @@ public class GenTableServiceImpl implements IGenTableService { * @param tableId 业务表主键 * @param zip 代码压缩输出流 */ - private void generatorCode(Long tableId, ZipOutputStream zip) { + private void writeCodeToZip(Long tableId, ZipOutputStream zip) { RenderContext rc = buildRenderContext(tableId); GenTable table = rc.table(); for (PathNamedTemplate template : rc.templates()) { @@ -653,20 +623,5 @@ public class GenTableServiceImpl implements IGenTableService { } } - /** - * 获取代码生成地址 - * - * @param table 业务表信息 - * @param template 模板文件路径 - * @return 生成地址 - */ - public static String getGenPath(GenTable table, String template) { - String relativePath = StringUtils.replace(TemplateEngineUtils.getFileName(template, table), "/", File.separator); - String genPath = table.getGenPath(); - if (StringUtils.equals(genPath, "/")) { - return System.getProperty("user.dir") + File.separator + "src" + File.separator + relativePath; - } - return genPath + File.separator + relativePath; - } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/IGenTableService.java b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/IGenTableService.java index 93922d563..2a98d6b36 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/org/dromara/gen/service/IGenTableService.java @@ -105,13 +105,6 @@ public interface IGenTableService { */ byte[] downloadCode(Long tableId); - /** - * 生成代码(自定义路径) - * - * @param tableId 表名称 - */ - void generatorCode(Long tableId); - /** * 同步数据库 *