|
@@ -38,21 +38,17 @@ public class RunPythonImpl implements RunAlgorithmService {
|
|
|
private SubAlgorithmMapper subAlgorithmMapper;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
-// @Override
|
|
|
-// public void runAlgorithm(String url, List<String> docAddress) {
|
|
|
-// // create httpclient, post method
|
|
|
-// // url/docAddress/
|
|
|
-// System.out.println("runPython!");
|
|
|
-// }
|
|
|
|
|
|
+ @Override
|
|
|
public BaseResponse runAlgorithm(Long id, String url, RequestDTO requestDto) {
|
|
|
+
|
|
|
+ // create http
|
|
|
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
|
|
|
httpRequestFactory.setConnectionRequestTimeout(3000);
|
|
|
httpRequestFactory.setConnectTimeout(3000);
|
|
|
httpRequestFactory.setReadTimeout(3000);
|
|
|
-// RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
|
|
|
-// BaseResponse response = restTemplate.postForObject(url, docAddress, BaseResponse.class);
|
|
|
WebClient webClient = WebClient.create(url);
|
|
|
+ // send post
|
|
|
Mono<BaseResponse> result = webClient.post() // 使用POST方法
|
|
|
.uri("/request") // 指定URI
|
|
|
.contentType(MediaType.APPLICATION_JSON) // 设置Content-Type为application/json
|
|
@@ -69,9 +65,13 @@ public class RunPythonImpl implements RunAlgorithmService {
|
|
|
return Mono.just(BaseResponse.error("Other error"));
|
|
|
}
|
|
|
}); // 将响应体转换为String
|
|
|
+ // get response
|
|
|
BaseResponse res = result.block();
|
|
|
+
|
|
|
+ // save result path to subAlgorithm
|
|
|
List<String> resultList = requestDto.getResultList();
|
|
|
List<Map> subAlgorithmOutputList = subAlgorithmMapper.selectSubAlgorithmOutputList(id);
|
|
|
+ // todo subAlgorithmOutputList == null || subAlgorithmOutputList.size == 0?
|
|
|
for (int i = 0; i < resultList.size(); i++) {
|
|
|
String resultPath = resultList.get(i);
|
|
|
Map subAlgorithmOutput = subAlgorithmOutputList.get(i);
|
|
@@ -89,6 +89,7 @@ public class RunPythonImpl implements RunAlgorithmService {
|
|
|
File resultFile = new File();
|
|
|
resultFile.setName(map.get("name"));
|
|
|
resultFile.setPath(map.get("path"));
|
|
|
+ // todo 魔鬼数字,创建静态变量在File中 xxx=1,yyy=2,这里引用
|
|
|
resultFile.setType("2");
|
|
|
resultFile.setCreateTime(DateUtils.getNowDate());
|
|
|
Long fileId = fileMapper.selectOutputFile(id);
|
|
@@ -105,20 +106,25 @@ public class RunPythonImpl implements RunAlgorithmService {
|
|
|
subAlgorithm.setFieldId((Long) subAlgorithmOutput.get("field_id"));
|
|
|
subAlgorithm.setUploadId(resultFile.getId());
|
|
|
subAlgorithm.setCreateTime(DateUtils.getNowDate());
|
|
|
+ // todo 只有update?
|
|
|
subAlgorithmMapper.updateSubAlgorithm(subAlgorithm);
|
|
|
}
|
|
|
else {
|
|
|
logger.error("存在未生成文件!");
|
|
|
+ // todo 对程序结果产生负面影响的分子,应反馈给前端
|
|
|
+ // update algorithm
|
|
|
}
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ // todo return type is Map<String,String>
|
|
|
public Map getFinalNameAndPath(String dirs, String prefixName) {
|
|
|
// 指定目录路径
|
|
|
java.io.File directory = new java.io.File(dirs);
|
|
|
|
|
|
// 已知的文件名前缀(不带扩展名)
|
|
|
+ // todo variable is redundant
|
|
|
String knownFileName = prefixName;
|
|
|
|
|
|
// 使用FilenameFilter筛选与已知文件名开头的文件
|
|
@@ -132,9 +138,11 @@ public class RunPythonImpl implements RunAlgorithmService {
|
|
|
map.put("path",dirs + '/' + matchingFiles[0]);
|
|
|
return map;
|
|
|
} else if (matchingFiles != null && matchingFiles.length > 1) {
|
|
|
+ // todo 工程内禁止使用System.out.print 日志统一使用log
|
|
|
System.out.println("找到多个匹配的文件,这不应该发生。");
|
|
|
return null;
|
|
|
} else {
|
|
|
+ // todo 工程内禁止使用System.out.print 日志统一使用log
|
|
|
System.out.println("没有找到匹配的文件。");
|
|
|
return null;
|
|
|
}
|