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