From c254e2f94ca410ff09eef5533daaf89f695743c1 Mon Sep 17 00:00:00 2001
From: xiaohucoding <2307520758@qq.com>
Date: Wed, 30 Jul 2025 10:56:56 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E4=BD=93=E9=9C=80=E6=B1=82=E5=AE=8C?=
=?UTF-8?q?=E5=96=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 +-
.../controller/AlgorithmInfoController.java | 59 +++++--
.../controller/PublishController.java | 153 +++++++++++++++++-
.../controller/ServiceAPIController.java | 101 ++++++++----
.../enumeration/ServiceStatus.java | 31 ++++
.../mapper/ModelMapper.java | 6 +-
.../mapper/PublishMapper.java | 38 ++++-
.../pojo/AlgorithmInfo.java | 6 +-
.../pojo/ServicePublishDTO.java | 1 +
.../pojo/ServicePublishVO.java | 2 +
.../service/AlgorithmInfoService.java | 3 +-
.../Impl/AlgorithmInfoServiceImpl.java | 123 +++++++++-----
.../service/Impl/PublishServiceImpl.java | 27 +++-
.../service/PublishService.java | 11 +-
.../util/NacosServiceUtil.java | 95 ++++++++++-
src/main/resources/mapper/PublishMapper.xml | 15 +-
.../ServiceAPIControllerTest.java | 125 ++++++++++++++
17 files changed, 700 insertions(+), 103 deletions(-)
create mode 100644 src/main/java/com/bipt/intelligentapplicationorchestrationservice/enumeration/ServiceStatus.java
create mode 100644 src/test/java/com/bipt/intelligentapplicationorchestrationservice/ServiceAPIControllerTest.java
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