Compare commits
3 Commits
dc-feature
...
46331fcade
Author | SHA1 | Date | |
---|---|---|---|
46331fcade | |||
99c291ca09 | |||
b926506ede |
12
pom.xml
12
pom.xml
@ -126,10 +126,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -146,7 +142,15 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<exclusions>
|
||||
<!-- 排除 RabbitMQ 自动配置 -->
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
|
@ -73,5 +73,23 @@ public class AlgorithmInfoController {
|
||||
algorithmInfoService.save(algorithmInfo);
|
||||
return OptResult.success("算法创建成功");
|
||||
}
|
||||
/**
|
||||
* 算法运行
|
||||
*/
|
||||
@PostMapping("/run/{id}")
|
||||
@Operation(summary = "运行")
|
||||
public OptResult run(@PathVariable Long id,String param){
|
||||
log.info("运行",id);
|
||||
algorithmInfoService.run(id,param);
|
||||
return OptResult.success("运行成功");
|
||||
}
|
||||
/**
|
||||
* 前端列表返回算法名称
|
||||
*/
|
||||
@GetMapping("/names")
|
||||
@Operation(summary = "列表返回算法名称")
|
||||
public List<String> getNames(){
|
||||
return algorithmInfoService.getAllNames();
|
||||
}
|
||||
|
||||
}
|
@ -29,4 +29,10 @@ public interface AlgorithmInfoMapper {
|
||||
|
||||
@Delete("DELETE FROM algorithm_info WHERE id = #{id}")
|
||||
int deleteById(Long id);
|
||||
}
|
||||
@Select("select description from algorithm_info where id = #{id}")
|
||||
String getDescriptionById(Long id);
|
||||
@Select("select algorithm_file from algorithm_info where id = #{id}")
|
||||
String getFileById(Long id);
|
||||
@Select("select algorithm_name from algorithm_info")
|
||||
List<String> getAllNames();
|
||||
}
|
@ -14,4 +14,7 @@ public interface AlgorithmInfoService {
|
||||
|
||||
void save(AlgorithmInfo algorithmInfo);
|
||||
|
||||
void run(Long id,String param);
|
||||
|
||||
List<String> getAllNames();
|
||||
}
|
@ -8,6 +8,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -72,11 +75,70 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
|
||||
//查找表里是否有重复的算法,如果有则报错
|
||||
AlgorithmInfo duplicateName = algorithmInfoMapper.selectByName(algorithmName);
|
||||
if (duplicateName != null){
|
||||
throw new RuntimeException("算法已存在");
|
||||
throw new RuntimeException("算法已存在,请去修改算法");
|
||||
}
|
||||
//todo 算法文件分布式存入分布式存储中
|
||||
|
||||
//todo 算法文件分布式存入分布式存储中
|
||||
|
||||
algorithmInfoMapper.insert(algorithmInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 算法执行
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void run(Long id,String param) {
|
||||
/*String description = algorithmInfoMapper.getDescriptionById(id);*/
|
||||
/*//拿到传入的描述,并且用逗号分隔
|
||||
String[] commaParts = description.split(",");
|
||||
|
||||
List<String> results = new ArrayList<>();
|
||||
for (String part : commaParts) {
|
||||
String[] semicolonParts = part.split(";", 2);
|
||||
if (semicolonParts.length > 1) {
|
||||
results.add(semicolonParts[1]);
|
||||
} else {
|
||||
throw new RuntimeException("描述格式错误,请修改描述格式");
|
||||
}
|
||||
}
|
||||
String bag = results.getFirst();
|
||||
String function = results.get(1);*/
|
||||
String file = algorithmInfoMapper.getFileById(id);
|
||||
try {
|
||||
// 构建命令,将 param 作为参数传递给 Python 脚本
|
||||
ProcessBuilder pb = new ProcessBuilder("python", file, param);
|
||||
|
||||
// 设置工作目录(如果 Python 脚本不在当前目录)
|
||||
// pb.directory(new File("/path/to/script"));
|
||||
|
||||
// 启动进程
|
||||
Process process = pb.start();
|
||||
|
||||
// 获取进程输出
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
// 获取错误输出
|
||||
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String errorLine;
|
||||
while ((errorLine = errorReader.readLine()) != null) {
|
||||
System.err.println("Error: " + errorLine);
|
||||
}
|
||||
// 等待进程完成
|
||||
int exitCode = process.waitFor();
|
||||
System.out.println("Exit Code: " + exitCode);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllNames() {
|
||||
return algorithmInfoMapper.getAllNames();
|
||||
}
|
||||
}
|
@ -38,4 +38,6 @@ logging.level.org.springframework.web=DEBUG
|
||||
|
||||
#SQL ????????
|
||||
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
|
||||
management.health.rabbit.enabled=false
|
Reference in New Issue
Block a user