diff --git a/.gitignore b/.gitignore index 09ba7d3..dbe2def 100644 --- a/.gitignore +++ b/.gitignore @@ -81,7 +81,6 @@ jre/ jdk/ # 数据库文件 -*.db *.db-shm *.db-wal *.sqlite diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c01c7c5..61cbb9d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "axios": "^1.13.2", + "echarts": "^5.6.0", "vue": "^3.5.24" }, "devDependencies": { @@ -593,6 +594,22 @@ "node": ">= 0.4" } }, + "node_modules/echarts": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/echarts/-/echarts-5.6.0.tgz", + "integrity": "sha512-oTbVTsXfKuEhxftHqL5xprgLoc0k7uScAwtryCgWF6hPYFLRwOUHiFmHGCBKP5NPFNkDVopOieyUqYGH8Fa3kA==", + "license": "Apache-2.0", + "dependencies": { + "tslib": "2.3.0", + "zrender": "5.6.1" + } + }, + "node_modules/echarts/node_modules/tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", + "license": "0BSD" + }, "node_modules/entities": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.0.tgz", @@ -1364,6 +1381,21 @@ "optional": true } } + }, + "node_modules/zrender": { + "version": "5.6.1", + "resolved": "https://registry.npmjs.org/zrender/-/zrender-5.6.1.tgz", + "integrity": "sha512-OFXkDJKcrlx5su2XbzJvj/34Q3m6PvyCZkVPHGYpcCJ52ek4U/ymZyfuV1nKE23AyBJ51E/6Yr0mhZ7xGTO4ag==", + "license": "BSD-3-Clause", + "dependencies": { + "tslib": "2.3.0" + } + }, + "node_modules/zrender/node_modules/tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", + "license": "0BSD" } } } diff --git a/frontend/package.json b/frontend/package.json index 12c11ad..5dfdb7f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "axios": "^1.13.2", + "echarts": "^5.6.0", "vue": "^3.5.24" }, "devDependencies": { diff --git a/frontend/src/components/index.vue b/frontend/src/components/index.vue new file mode 100644 index 0000000..6daeefe --- /dev/null +++ b/frontend/src/components/index.vue @@ -0,0 +1,706 @@ + + + + + + + + + 👤 + + 用户名 + 账户余额 + + + 登录 + 退出 + + + + + + + 输入1: + + + + + + 输入2: + + + 确认 + + + + + + + {{ tableError }} + 重试 + + + + + 数据表格 + + 加载中... + + + + + ID + 项目名称 + 数值 + 状态 + + + + + {{ item.id }} + {{ item.name }} + {{ item.value }} + + + {{ item.status }} + + + + + + + + + + + + + {{ error }} + 重试 + + + + + 加载中... + + + + + + + 加载中... + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/tem/bocai/BocaiApplication.java b/src/main/java/com/tem/bocai/BocaiApplication.java index 82fcf8b..0ece728 100644 --- a/src/main/java/com/tem/bocai/BocaiApplication.java +++ b/src/main/java/com/tem/bocai/BocaiApplication.java @@ -3,8 +3,10 @@ package com.tem.bocai; import com.tem.bocai.util.SQLiteUtil; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication +@EnableScheduling public class BocaiApplication { public static void main(String[] args) { diff --git a/src/main/java/com/tem/bocai/controller/ChartController.java b/src/main/java/com/tem/bocai/controller/ChartController.java new file mode 100644 index 0000000..9525127 --- /dev/null +++ b/src/main/java/com/tem/bocai/controller/ChartController.java @@ -0,0 +1,94 @@ +package com.tem.bocai.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.*; + +@RestController +@RequestMapping("/api") +public class ChartController { + + // 获取折线图1数据 + @GetMapping("/charts/line1") + public Map getLineChartData1() { + Map response = new HashMap<>(); + + // 模拟数据 - 实际项目中应该从数据库获取 + List data = Arrays.asList(65, 59, 80, 81, 56, 55, 40); + List labels = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月"); + + response.put("data", data); + response.put("labels", labels); + response.put("title", "折线图1数据"); + + return response; + } + + // 获取折线图2数据 + @GetMapping("/charts/line2") + public Map getLineChartData2() { + Map response = new HashMap<>(); + + // 模拟数据 - 实际项目中应该从数据库获取 + List data = Arrays.asList(28, 48, 40, 19, 86, 27, 90); + List labels = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月"); + + response.put("data", data); + response.put("labels", labels); + response.put("title", "折线图2数据"); + + return response; + } + + // 获取表格数据 + @GetMapping("/table") + public List> getTableData() { + List> tableData = new ArrayList<>(); + + // 模拟数据 - 实际项目中应该从数据库获取 + Map item1 = new HashMap<>(); + item1.put("id", 1); + item1.put("name", "项目1"); + item1.put("value", 120); + item1.put("status", "正常"); + tableData.add(item1); + + Map item2 = new HashMap<>(); + item2.put("id", 2); + item2.put("name", "项目2"); + item2.put("value", 230); + item2.put("status", "警告"); + tableData.add(item2); + + Map item3 = new HashMap<>(); + item3.put("id", 3); + item3.put("name", "项目3"); + item3.put("value", 180); + item3.put("status", "正常"); + tableData.add(item3); + + Map item4 = new HashMap<>(); + item4.put("id", 4); + item4.put("name", "项目4"); + item4.put("value", 90); + item4.put("status", "异常"); + tableData.add(item4); + + Map item5 = new HashMap<>(); + item5.put("id", 5); + item5.put("name", "项目5"); + item5.put("value", 320); + item5.put("status", "正常"); + tableData.add(item5); + + Map item6 = new HashMap<>(); + item6.put("id", 6); + item6.put("name", "项目6"); + item6.put("value", 270); + item6.put("status", "警告"); + tableData.add(item6); + + return tableData; + } +} \ No newline at end of file diff --git a/src/main/java/com/tem/bocai/schedules/GetPredictResultSchedule.java b/src/main/java/com/tem/bocai/schedules/GetPredictResultSchedule.java new file mode 100644 index 0000000..8cf4887 --- /dev/null +++ b/src/main/java/com/tem/bocai/schedules/GetPredictResultSchedule.java @@ -0,0 +1,112 @@ +package com.tem.bocai.schedules; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +@Component +public class GetPredictResultSchedule { + + /** + * 处理文件路径,确保路径正确 + * @param filePath 文件路径 + * @return 处理后的文件路径 + */ + private String handleFilePath(String filePath) { + // 处理路径分隔符,统一使用系统默认分隔符 + filePath = filePath.replace("/", System.getProperty("file.separator")); + filePath = filePath.replace("\\", System.getProperty("file.separator")); + + // 如果路径包含空格,确保路径被正确处理 + // Runtime.exec会自动处理带空格的路径,不需要手动添加引号 + + return filePath; + } + + // 每天凌晨2点执行 + @Scheduled(cron = "0 0 2 * * ?") + public void executePythonScript() { + System.out.println("开始执行Python脚本..."); + + // 示例1:基本参数 + // String[] params = {"param1", "param2", "param3"}; + // executePythonScriptWithParams("your_script.py", params); + + // 示例2:传递文件路径作为参数 + String[] paramsWithFiles = { + "--input", "data/input.csv", + "--output", "results/output.json", + "--config", "config/settings.ini" + }; + executePythonScriptWithParams("scripts/process_data.py", paramsWithFiles); + } + + /** + * 执行带参数的Python脚本 + * @param scriptPath Python脚本路径 + * @param params 脚本参数数组(可以包含文件路径) + */ + public void executePythonScriptWithParams(String scriptPath, String[] params) { + try { + // 处理脚本路径,确保路径正确 + scriptPath = handleFilePath(scriptPath); + + // 构建命令数组 + String[] command = new String[params.length + 2]; + command[0] = "python"; + command[1] = scriptPath; + + // 添加参数,处理文件路径参数 + for (int i = 0; i < params.length; i++) { + // 检查参数是否为文件路径(包含路径分隔符) + if (params[i].contains("\\") || params[i].contains("/")) { + command[i + 2] = handleFilePath(params[i]); + } else { + command[i + 2] = params[i]; + } + } + + System.out.println("执行命令: " + String.join(" ", command)); + + // 执行Python脚本 + Process process = Runtime.getRuntime().exec(command); + + // 读取脚本输出 + BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream(), "UTF-8") + ); + + String line; + StringBuilder output = new StringBuilder(); + while ((line = reader.readLine()) != null) { + output.append(line).append("\n"); + } + + // 读取错误输出 + BufferedReader errorReader = new BufferedReader( + new InputStreamReader(process.getErrorStream(), "UTF-8") + ); + + StringBuilder errorOutput = new StringBuilder(); + while ((line = errorReader.readLine()) != null) { + errorOutput.append(line).append("\n"); + } + + // 等待脚本执行完成 + int exitCode = process.waitFor(); + + System.out.println("Python脚本执行完成,退出码: " + exitCode); + System.out.println("脚本输出:\n" + output.toString()); + + if (exitCode != 0) { + System.err.println("脚本执行错误:\n" + errorOutput.toString()); + } + + } catch (IOException | InterruptedException e) { + System.err.println("执行Python脚本时发生错误:"); + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/a.jpg b/src/main/resources/a.jpg deleted file mode 100644 index 278c8ca..0000000 Binary files a/src/main/resources/a.jpg and /dev/null differ diff --git a/src/main/resources/b.jpg b/src/main/resources/b.jpg deleted file mode 100644 index 3bd1871..0000000 Binary files a/src/main/resources/b.jpg and /dev/null differ