diff --git a/algorithm_files/0697dcd7-b616-449f-a4f1-f5b94bbdb0a4_quick_sort.py b/algorithm_files/0697dcd7-b616-449f-a4f1-f5b94bbdb0a4_quick_sort.py
new file mode 100644
index 0000000..5901739
--- /dev/null
+++ b/algorithm_files/0697dcd7-b616-449f-a4f1-f5b94bbdb0a4_quick_sort.py
@@ -0,0 +1,57 @@
+import random
+import sys
+
+def quick_sort(arr):
+ """
+ 快速排序主函数,支持空数组处理
+ """
+ if len(arr) <= 1:
+ return arr
+
+ def partition(low, high):
+ pivot_index = random.randint(low, high) # 随机选择基准
+ arr[pivot_index], arr[high] = arr[high], arr[pivot_index]
+ pivot = arr[high]
+ i = low - 1
+
+ for j in range(low, high):
+ if arr[j] <= pivot:
+ i += 1
+ arr[i], arr[j] = arr[j], arr[i]
+
+ arr[i+1], arr[high] = arr[high], arr[i+1]
+ return i + 1
+
+ def recur_sort(low, high):
+ if low < high:
+ pi = partition(low, high)
+ recur_sort(low, pi - 1)
+ recur_sort(pi + 1, high)
+
+ recur_sort(0, len(arr) - 1)
+ return arr
+
+if __name__ == "__main__":
+ # 从命令行参数读取数据
+ if len(sys.argv) > 1:
+ try:
+ # 处理多种输入格式:逗号分隔、空格分隔或混合分隔
+ input_str = " ".join(sys.argv[1:])
+ input_data = [float(x) if '.' in x else int(x)
+ for x in input_str.replace(',', ' ').split()]
+
+ print("原始输入:", sys.argv[1:])
+ print("解析数据:", input_data)
+
+ sorted_arr = quick_sort(input_data.copy())
+ print("排序结果:", sorted_arr)
+
+ except ValueError:
+ print("错误:输入数据包含非数字字符,请确保只输入数字")
+ print("用法: python script.py [数字1 数字2 ...]")
+ print("示例: python script.py 3 0 8 7 2 1 9 4")
+ else:
+ print("未提供输入数据,使用默认测试用例")
+ test_case = [3, 0, 8, 7, 2, 1, 9, 4]
+ print("测试数据:", test_case)
+ print("排序结果:", quick_sort(test_case.copy()))
\ No newline at end of file
diff --git a/algorithm_files/4ec4bfbc-c0bf-4be3-a6c3-57e5c49208f4_quick_sort.py b/algorithm_files/4ec4bfbc-c0bf-4be3-a6c3-57e5c49208f4_quick_sort.py
new file mode 100644
index 0000000..5901739
--- /dev/null
+++ b/algorithm_files/4ec4bfbc-c0bf-4be3-a6c3-57e5c49208f4_quick_sort.py
@@ -0,0 +1,57 @@
+import random
+import sys
+
+def quick_sort(arr):
+ """
+ 快速排序主函数,支持空数组处理
+ """
+ if len(arr) <= 1:
+ return arr
+
+ def partition(low, high):
+ pivot_index = random.randint(low, high) # 随机选择基准
+ arr[pivot_index], arr[high] = arr[high], arr[pivot_index]
+ pivot = arr[high]
+ i = low - 1
+
+ for j in range(low, high):
+ if arr[j] <= pivot:
+ i += 1
+ arr[i], arr[j] = arr[j], arr[i]
+
+ arr[i+1], arr[high] = arr[high], arr[i+1]
+ return i + 1
+
+ def recur_sort(low, high):
+ if low < high:
+ pi = partition(low, high)
+ recur_sort(low, pi - 1)
+ recur_sort(pi + 1, high)
+
+ recur_sort(0, len(arr) - 1)
+ return arr
+
+if __name__ == "__main__":
+ # 从命令行参数读取数据
+ if len(sys.argv) > 1:
+ try:
+ # 处理多种输入格式:逗号分隔、空格分隔或混合分隔
+ input_str = " ".join(sys.argv[1:])
+ input_data = [float(x) if '.' in x else int(x)
+ for x in input_str.replace(',', ' ').split()]
+
+ print("原始输入:", sys.argv[1:])
+ print("解析数据:", input_data)
+
+ sorted_arr = quick_sort(input_data.copy())
+ print("排序结果:", sorted_arr)
+
+ except ValueError:
+ print("错误:输入数据包含非数字字符,请确保只输入数字")
+ print("用法: python script.py [数字1 数字2 ...]")
+ print("示例: python script.py 3 0 8 7 2 1 9 4")
+ else:
+ print("未提供输入数据,使用默认测试用例")
+ test_case = [3, 0, 8, 7, 2, 1, 9, 4]
+ print("测试数据:", test_case)
+ print("排序结果:", quick_sort(test_case.copy()))
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f1094d8..957533f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -185,7 +185,12 @@
jaxb-runtime
2.3.3
-
+
+ junit
+ junit
+ test
+
+
diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java
index aee19fe..9d4c466 100644
--- a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java
+++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java
@@ -14,7 +14,10 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+
@Tag(name ="算法创建相关接口")
@RestController
@RequestMapping("/api/algorithm")
@@ -31,16 +34,16 @@ public class AlgorithmInfoController {
@GetMapping("/{id}")
public ResponseEntity getById(@PathVariable Long id) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
- return algorithmInfo != null ?
- ResponseEntity.ok(algorithmInfo) :
+ return algorithmInfo != null ?
+ ResponseEntity.ok(algorithmInfo) :
ResponseEntity.notFound().build();
}
@GetMapping("/name/{algorithmName}")
public ResponseEntity getByName(@PathVariable String algorithmName) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getByName(algorithmName);
- return algorithmInfo != null ?
- ResponseEntity.ok(algorithmInfo) :
+ return algorithmInfo != null ?
+ ResponseEntity.ok(algorithmInfo) :
ResponseEntity.notFound().build();
}
@@ -56,18 +59,18 @@ public class AlgorithmInfoController {
if (!algorithmInfoService.validateAlgorithmInfo(algorithmInfo)) {
return ResponseEntity.badRequest().body("Invalid algorithm information");
}
-
+
boolean success = algorithmInfoService.update(algorithmInfo);
- return success ?
- ResponseEntity.ok("Update successful") :
+ return success ?
+ ResponseEntity.ok("Update successful") :
ResponseEntity.badRequest().body("Update failed");
}
@DeleteMapping("/{id}")
public ResponseEntity delete(@PathVariable Long id) {
boolean success = algorithmInfoService.delete(id);
- return success ?
- ResponseEntity.ok("Delete successful") :
+ return success ?
+ ResponseEntity.ok("Delete successful") :
ResponseEntity.badRequest().body("Delete failed");
}
@@ -103,11 +106,37 @@ public class AlgorithmInfoController {
* 算法运行
*/
@PostMapping("/run/{id}")
- @Operation(summary = "运行")
- public OptResult run(@PathVariable Long id,@RequestBody String param){
- log.info("运行",id);
- String result = algorithmInfoService.run(id,param);
- return OptResult.success("运行成功"+result);
+ @Operation(summary = "运行算法")
+ public OptResult run(@PathVariable Long id, @RequestBody String param) {
+ log.info("运行算法 ID: {}", id);
+ try {
+ AlgorithmInfo algorithm = algorithmInfoService.getById(id);
+ if (algorithm == null) {
+ return OptResult.error("算法不存在");
+ }
+
+ // 1. 解析前端传入的参数(JSON格式)
+ Map paramMap = objectMapper.readValue(param, Map.class);
+
+ // 2. 从参数中提取实际需要传递给Python脚本的参数列表
+ // 示例:假设前端传入 {"args": [3, 0, 8, 7, 2, 1, 9, 4]}
+ List args = new ArrayList<>();
+ if (paramMap.containsKey("args")) {
+ List