From a6165ff2c8246ed79bc1a934b5bd1d571cd1c3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Wed, 6 May 2026 15:39:11 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=80=A7CVE=E6=BC=8F=E6=B4=9E=20=E7=A6=81?= =?UTF-8?q?=E6=AD=A2=E4=BD=BF=E7=94=A8=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=88=B0=E6=9C=AC=E5=9C=B0=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/gen/controller/GenController.java | 13 ----- .../java/org/dromara/gen/domain/GenTable.java | 4 +- .../gen/service/GenTableServiceImpl.java | 52 +------------------ .../dromara/gen/service/IGenTableService.java | 7 --- 4 files changed, 4 insertions(+), 72 deletions(-) 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 ca2731592..dbefc6ff0 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 @@ -157,19 +157,6 @@ public class GenController extends BaseController { genCode(response, data); } - /** - * 生成代码(自定义路径) - * - * @param tableId 表ID - */ - @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 cc2847898..e40aa4ade 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 @@ -101,12 +101,12 @@ public class GenTable extends BaseEntity { private String functionAuthor; /** - * 生成代码方式(0zip压缩包 1自定义路径) + * 生成代码方式(固定为0zip压缩包) */ 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 0711cc5a5..d3e39d652 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 @@ -23,7 +23,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.core.page.TableDataInfo; @@ -40,7 +39,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.io.StringWriter; import java.nio.charset.StandardCharsets; @@ -222,6 +220,8 @@ public class GenTableServiceImpl implements IGenTableService { @Transactional(rollbackFor = Exception.class) @Override public void updateGenTable(GenTable genTable) { + genTable.setGenType("0"); + genTable.setGenPath("/"); String options = JsonUtils.toJsonString(genTable.getParams()); genTable.setOptions(options); int row = baseMapper.updateById(genTable); @@ -357,40 +357,6 @@ public class GenTableServiceImpl implements IGenTableService { return outputStream.toByteArray(); } - /** - * 生成代码(自定义路径) - * - * @param tableId 表名称 - */ - @Override - public void generatorCode(Long tableId) { - // 查询表信息 - GenTable table = baseMapper.selectGenTableById(tableId); - // 设置主键列信息 - setPkColumn(table); - - VelocityInitializer.initVelocity(); - - VelocityContext context = VelocityUtils.prepareContext(table); - - // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getDataName()); - for (String template : templates) { - if (!StringUtils.containsAny(template, "sql.vm", "api.ts.vm", "types.ts.vm", "index.vue.vm", "index-tree.vue.vm")) { - // 渲染模板 - StringWriter sw = new StringWriter(); - Template tpl = Velocity.getTemplate(template, Constants.UTF8); - tpl.merge(context, sw); - try { - String path = getGenPath(table, template); - FileUtils.writeUtf8String(sw.toString(), path); - } catch (Exception e) { - throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); - } - } - } - } - /** * 同步数据库 * @@ -560,19 +526,5 @@ public class GenTableServiceImpl implements IGenTableService { } } - /** - * 获取代码生成地址 - * - * @param table 业务表信息 - * @param template 模板文件路径 - * @return 生成地址 - */ - public static String getGenPath(GenTable table, String template) { - String genPath = table.getGenPath(); - if (StringUtils.equals(genPath, "/")) { - return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); - } - return genPath + File.separator + VelocityUtils.getFileName(template, table); - } } 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 4389f1291..be10f7134 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 @@ -110,13 +110,6 @@ public interface IGenTableService { */ byte[] downloadCode(Long tableId); - /** - * 生成代码(自定义路径) - * - * @param tableId 表名称 - */ - void generatorCode(Long tableId); - /** * 同步数据库 *