|
@@ -1,5 +1,6 @@
|
|
|
package com.pdaaphm.system.service.impl;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -19,9 +20,10 @@ import com.pdaaphm.system.service.IDataService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.pdaaphm.system.mapper.TDataProcessMapper;
|
|
|
import com.pdaaphm.system.domain.TDataProcess;
|
|
@@ -40,6 +42,9 @@ public class TDataProcessServiceImpl implements ITDataProcessService
|
|
|
{
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
+
|
|
|
@Autowired
|
|
|
private TDataProcessMapper tDataProcessMapper;
|
|
|
|
|
@@ -143,18 +148,9 @@ public class TDataProcessServiceImpl implements ITDataProcessService
|
|
|
logger.warn("无法查找到该DataProcess的数据,id:{},algConfig:{},data:{},bizAlgType:{}", id, algConfig, data, bizAlgType);
|
|
|
errorMsg = "数据有残缺";
|
|
|
} else {
|
|
|
- Map<String, String> resultMap = doRunDataProcess(algConfig, data, bizAlgType);
|
|
|
- if (resultMap.get("errorMsg") != null){
|
|
|
- // 成功场景
|
|
|
- // create new data
|
|
|
- Data newData = new Data();
|
|
|
- newData.setDataPath(resultMap.get("resultPath"));
|
|
|
- newData.setDataType("todo");
|
|
|
- dataService.insertData(newData);
|
|
|
- // update dataProcess
|
|
|
- } else {
|
|
|
- // 失败场景
|
|
|
- }
|
|
|
+ // 异步调用
|
|
|
+ ITDataProcessService proxy = applicationContext.getBean(ITDataProcessService.class);
|
|
|
+ proxy.asyncRunDataProcess(dataProcess, algConfig, data, bizAlgType);
|
|
|
}
|
|
|
} else {
|
|
|
logger.warn("无法查找到该DataProcess的数据,id:{}", id);
|
|
@@ -163,6 +159,36 @@ public class TDataProcessServiceImpl implements ITDataProcessService
|
|
|
return errorMsg;
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
+ public void asyncRunDataProcess(TDataProcess dataProcess, AlgConfig algConfig, Data data, String bizAlgType) {
|
|
|
+ // 状态设置为处理中
|
|
|
+ dataProcess.setProcessStatus("2");
|
|
|
+ dataProcess.setStartTime(new Date());
|
|
|
+ dataProcess.setEndTime(null);
|
|
|
+ this.updateTDataProcess(dataProcess);
|
|
|
+ Map<String, String> resultMap = doRunDataProcess(algConfig, data, bizAlgType);
|
|
|
+ if (resultMap.get("errorMsg") != null) {
|
|
|
+ // 成功场景
|
|
|
+ // create new data
|
|
|
+ Data newData = new Data();
|
|
|
+ String resultPath = resultMap.get("resultPath");
|
|
|
+ newData.setDataPath(resultPath);
|
|
|
+ newData.setDataType((Integer.parseInt(bizAlgType) + 1) + "");
|
|
|
+ newData.setDataName(FileUtils.getNameNotSuffix(resultPath));
|
|
|
+ dataService.insertData(newData);
|
|
|
+ // update dataProcess
|
|
|
+ dataProcess.setProcessStatus("3"); // 已完成
|
|
|
+ dataProcess.setEndTime(new Date());
|
|
|
+ this.updateTDataProcess(dataProcess);
|
|
|
+ } else {
|
|
|
+ // 失败场景
|
|
|
+ dataProcess.setProcessStatus("4"); // 失败
|
|
|
+ dataProcess.setEndTime(new Date());
|
|
|
+ dataProcess.setLog(resultMap.get("errorMsg"));
|
|
|
+ this.updateTDataProcess(dataProcess);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String,String> doRunDataProcess(AlgConfig algConfig, Data data, String bizAlgType) {
|
|
|
Map<String,String> result = new HashMap<>(2);
|
|
|
String resultPath = "";
|