算法创建

This commit is contained in:
2025-06-05 12:37:44 +08:00
parent 99c291ca09
commit 46331fcade
4 changed files with 23 additions and 7 deletions

View File

@ -78,11 +78,18 @@ public class AlgorithmInfoController {
*/ */
@PostMapping("/run/{id}") @PostMapping("/run/{id}")
@Operation(summary = "运行") @Operation(summary = "运行")
public OptResult run(@PathVariable Long id){ public OptResult run(@PathVariable Long id,String param){
log.info("运行",id); log.info("运行",id);
algorithmInfoService.run(id); algorithmInfoService.run(id,param);
return OptResult.success("运行成功"); return OptResult.success("运行成功");
} }
/**
* 前端列表返回算法名称
*/
@GetMapping("/names")
@Operation(summary = "列表返回算法名称")
public List<String> getNames(){
return algorithmInfoService.getAllNames();
}
} }

View File

@ -33,4 +33,6 @@ public interface AlgorithmInfoMapper {
String getDescriptionById(Long id); String getDescriptionById(Long id);
@Select("select algorithm_file from algorithm_info where id = #{id}") @Select("select algorithm_file from algorithm_info where id = #{id}")
String getFileById(Long id); String getFileById(Long id);
@Select("select algorithm_name from algorithm_info")
List<String> getAllNames();
} }

View File

@ -14,5 +14,7 @@ public interface AlgorithmInfoService {
void save(AlgorithmInfo algorithmInfo); void save(AlgorithmInfo algorithmInfo);
void run(Long id); void run(Long id,String param);
List<String> getAllNames();
} }

View File

@ -88,8 +88,8 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
* @param id * @param id
*/ */
@Override @Override
public void run(Long id) { public void run(Long id,String param) {
String description = algorithmInfoMapper.getDescriptionById(id); /*String description = algorithmInfoMapper.getDescriptionById(id);*/
/*//拿到传入的描述,并且用逗号分隔 /*//拿到传入的描述,并且用逗号分隔
String[] commaParts = description.split(","); String[] commaParts = description.split(",");
@ -107,7 +107,7 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
String file = algorithmInfoMapper.getFileById(id); String file = algorithmInfoMapper.getFileById(id);
try { try {
// 构建命令,将 param 作为参数传递给 Python 脚本 // 构建命令,将 param 作为参数传递给 Python 脚本
ProcessBuilder pb = new ProcessBuilder("python", file, description); ProcessBuilder pb = new ProcessBuilder("python", file, param);
// 设置工作目录(如果 Python 脚本不在当前目录) // 设置工作目录(如果 Python 脚本不在当前目录)
// pb.directory(new File("/path/to/script")); // pb.directory(new File("/path/to/script"));
@ -136,4 +136,9 @@ public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
} }
} }
@Override
public List<String> getAllNames() {
return algorithmInfoMapper.getAllNames();
}
} }