From a2a0f54e84e2538dffec8a4d142a895c4abe4bd5 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Wed, 13 Aug 2025 15:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rs/controller/SqlUpdateController.java | 115 +++++++++--------- .../org/dromara/rs/util/SqlScriptRunner.java | 80 ++++++------ 2 files changed, 100 insertions(+), 95 deletions(-) diff --git a/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/controller/SqlUpdateController.java b/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/controller/SqlUpdateController.java index ce22c297..d30ba72a 100644 --- a/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/controller/SqlUpdateController.java +++ b/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/controller/SqlUpdateController.java @@ -1,7 +1,7 @@ package org.dromara.rs.controller; import org.dromara.common.core.domain.R; -import org.dromara.rs.mapper.RsSystemMapper; +// import org.dromara.rs.mapper.RsSystemMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -23,66 +23,69 @@ import java.util.Map; @RequestMapping("/rs/db") public class SqlUpdateController { - @Autowired - private RsSystemMapper rsSystemMapper; + // 编译不过,吴自龙注释, + // @Autowired + // private RsSystemMapper rsSystemMapper; /** * 执行培训模块SQL更新脚本 */ - @GetMapping("/update/training") - public R> executeTrainingUpdateScript() { - Map result = new HashMap<>(); - try { - // 读取SQL脚本 - InputStream is = getClass().getClassLoader().getResourceAsStream("mapper/rs/training-update.sql"); - if (is == null) { - result.put("success", false); - result.put("message", "SQL脚本文件不存在"); - return R.ok(result); - } + // @GetMapping("/update/training") + // public R> executeTrainingUpdateScript() { + // Map result = new HashMap<>(); + // try { + // // 读取SQL脚本 + // InputStream is = + // getClass().getClassLoader().getResourceAsStream("mapper/rs/training-update.sql"); + // if (is == null) { + // result.put("success", false); + // result.put("message", "SQL脚本文件不存在"); + // return R.ok(result); + // } - // 解析SQL语句 - BufferedReader reader = new BufferedReader(new InputStreamReader(is)); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - // 忽略注释行 - if (line.trim().startsWith("--") || line.trim().isEmpty()) { - continue; - } - sb.append(line); - - // 如果是SQL语句结束 - if (line.trim().endsWith(";")) { - String sql = sb.toString().trim(); - if (sql.endsWith(";")) { - sql = sql.substring(0, sql.length() - 1); // 移除分号,MyBatis会自动处理 - } - executeSql(sql); - sb = new StringBuilder(); - } - } - - result.put("success", true); - result.put("message", "SQL脚本执行成功"); - return R.ok(result); - } catch (Exception e) { - e.printStackTrace(); - result.put("success", false); - result.put("message", "执行SQL脚本出错: " + e.getMessage()); - return R.fail("执行SQL脚本出错: " + e.getMessage()); - } - } - + // // 解析SQL语句 + // BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + // StringBuilder sb = new StringBuilder(); + // String line; + // while ((line = reader.readLine()) != null) { + // // 忽略注释行 + // if (line.trim().startsWith("--") || line.trim().isEmpty()) { + // continue; + // } + // sb.append(line); + + // // 如果是SQL语句结束 + // if (line.trim().endsWith(";")) { + // String sql = sb.toString().trim(); + // if (sql.endsWith(";")) { + // sql = sql.substring(0, sql.length() - 1); // 移除分号,MyBatis会自动处理 + // } + // executeSql(sql); + // sb = new StringBuilder(); + // } + // } + + // result.put("success", true); + // result.put("message", "SQL脚本执行成功"); + // return R.ok(result); + // } catch (Exception e) { + // e.printStackTrace(); + // result.put("success", false); + // result.put("message", "执行SQL脚本出错: " + e.getMessage()); + // return R.fail("执行SQL脚本出错: " + e.getMessage()); + // } + // } + + //// 编译不过,吴自龙注释, /** * 执行单条SQL语句 */ - private void executeSql(String sql) { - try { - rsSystemMapper.executeSql(sql); - } catch (Exception e) { - // 记录错误但继续执行 - System.out.println("SQL执行警告: " + e.getMessage()); - } - } -} \ No newline at end of file + // private void executeSql(String sql) { + // try { + // rsSystemMapper.executeSql(sql); + // } catch (Exception e) { + // // 记录错误但继续执行 + // System.out.println("SQL执行警告: " + e.getMessage()); + // } + // } +} diff --git a/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/util/SqlScriptRunner.java b/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/util/SqlScriptRunner.java index d473d69c..0f597541 100644 --- a/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/util/SqlScriptRunner.java +++ b/backend/ruoyi-modules/ruoyi-rs/src/main/java/org/dromara/rs/util/SqlScriptRunner.java @@ -1,6 +1,6 @@ package org.dromara.rs.util; -import org.dromara.rs.mapper.RsSystemMapper; +// import org.dromara.rs.mapper.RsSystemMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; @@ -14,42 +14,44 @@ import java.io.InputStreamReader; @Component public class SqlScriptRunner { - @Autowired - private RsSystemMapper rsSystemMapper; + // 吴自龙注释,编译不过 + // @Autowired + // private RsSystemMapper rsSystemMapper; - /** - * 执行SQL脚本 - * - * @param scriptPath 脚本路径(相对于classpath) - * @throws Exception 执行异常 - */ - public void executeScript(String scriptPath) throws Exception { - ClassPathResource resource = new ClassPathResource(scriptPath); - try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { - StringBuilder sb = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - // 忽略注释行和空行 - if (line.trim().startsWith("--") || line.trim().isEmpty()) { - continue; - } - sb.append(line); - - // 如果是SQL语句结束 - if (line.trim().endsWith(";")) { - String sql = sb.toString().trim(); - if (sql.endsWith(";")) { - sql = sql.substring(0, sql.length() - 1); // 移除分号,MyBatis会自动处理 - } - try { - rsSystemMapper.executeSql(sql); - } catch (Exception e) { - // 记录错误但继续执行 - System.out.println("SQL执行警告: " + e.getMessage()); - } - sb = new StringBuilder(); - } - } - } - } -} \ No newline at end of file + // /** + // * 执行SQL脚本 + // * + // * @param scriptPath 脚本路径(相对于classpath) + // * @throws Exception 执行异常 + // */ + // public void executeScript(String scriptPath) throws Exception { + // ClassPathResource resource = new ClassPathResource(scriptPath); + // try (BufferedReader reader = new BufferedReader(new + // InputStreamReader(resource.getInputStream()))) { + // StringBuilder sb = new StringBuilder(); + // String line; + // while ((line = reader.readLine()) != null) { + // // 忽略注释行和空行 + // if (line.trim().startsWith("--") || line.trim().isEmpty()) { + // continue; + // } + // sb.append(line); + + // // 如果是SQL语句结束 + // if (line.trim().endsWith(";")) { + // String sql = sb.toString().trim(); + // if (sql.endsWith(";")) { + // sql = sql.substring(0, sql.length() - 1); // 移除分号,MyBatis会自动处理 + // } + // try { + // rsSystemMapper.executeSql(sql); + // } catch (Exception e) { + // // 记录错误但继续执行 + // System.out.println("SQL执行警告: " + e.getMessage()); + // } + // sb = new StringBuilder(); + // } + // } + // } + // } +}