|
@@ -2,8 +2,10 @@ package com.pdaaphm.biz.service.impl;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import com.pdaaphm.biz.domain.AlgorithmSubType;
|
|
|
import com.pdaaphm.biz.domain.SubAlgorithm;
|
|
@@ -20,6 +22,7 @@ import com.pdaaphm.common.utils.DateUtils;
|
|
|
import com.pdaaphm.common.utils.file.FileUploadUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.pdaaphm.biz.mapper.AlgorithmMapper;
|
|
|
import com.pdaaphm.biz.domain.Algorithm;
|
|
@@ -102,8 +105,6 @@ public class AlgorithmServiceImpl implements IAlgorithmService
|
|
|
|
|
|
@Override
|
|
|
public int addOrUpdateDto(AlgorithmDTO algorithmDto) {
|
|
|
- // todo dto 2 domain, save doman
|
|
|
- // get ioSubList, save SubAlgorithm
|
|
|
int res;
|
|
|
Algorithm algorithm = new Algorithm();
|
|
|
BeanUtils.copyProperties(algorithmDto,algorithm);
|
|
@@ -167,19 +168,17 @@ public class AlgorithmServiceImpl implements IAlgorithmService
|
|
|
@Override
|
|
|
public List<Map> getOption() { return algorithmMapper.getOption(); }
|
|
|
|
|
|
+ @Async
|
|
|
@Override
|
|
|
- public int runAlgorithms(Long id) throws IOException {
|
|
|
- int res = 0;
|
|
|
- //1. update Algorithm.startTime to now
|
|
|
- //2. run algorithmImpl
|
|
|
+ public void runAlgorithms(Long id) throws IOException {
|
|
|
+ Date startTime = DateUtils.getNowDate();
|
|
|
+ algorithmMapper.updateStartTimeById(id, startTime);
|
|
|
List<Map> list = algorithmMapper.selectUrlAndAddressById(id);
|
|
|
Algorithm algorithm = this.selectAlgorithmById(id);
|
|
|
AlgorithmSubType algorithmSubType = algorithmSubTypeMapper.selectAlgorithmSubTypeById(algorithm.getSubTypeId());
|
|
|
RunAlgorithmService runAlgorithmService = algorithmFactory.createRun(algorithmSubType.getRunType());
|
|
|
- // todo remove this code
|
|
|
- PadaphmConfig.getProfile();
|
|
|
if(CollectionUtils.isEmpty(list)){
|
|
|
- return res;
|
|
|
+ return;
|
|
|
}
|
|
|
List<String> docAddress = new ArrayList<>(list.size());
|
|
|
List<String> resultAddress = new ArrayList<>(list.size());
|
|
@@ -187,8 +186,7 @@ public class AlgorithmServiceImpl implements IAlgorithmService
|
|
|
String prefix2 = PadaphmConfig.getResultPath();
|
|
|
int j = 1;
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
- // todo "1".equals(list.get(i).get("type"))
|
|
|
- if (list.get(i).get("type").equals("1")) {
|
|
|
+ if ("1".equals(list.get(i).get("type"))) {
|
|
|
String s = (String)list.get(i).get("path");
|
|
|
if (s.startsWith("/profile")) {
|
|
|
s = s.replace("/profile", prefix);
|
|
@@ -211,6 +209,11 @@ public class AlgorithmServiceImpl implements IAlgorithmService
|
|
|
requestDto.setResultList(resultAddress);
|
|
|
runAlgorithmService.runAlgorithm(id, (String)list.get(0).get("url"), requestDto);
|
|
|
//3. todo update Algorithm.completedTime and Algorithm.costSecond
|
|
|
- return res;
|
|
|
+ Date completedTime = DateUtils.getNowDate();
|
|
|
+ algorithmMapper.updateCompletedTimeById(id, completedTime);
|
|
|
+ Long diffInMillies = completedTime.getTime() - startTime.getTime();
|
|
|
+ Long costSecond = TimeUnit.MILLISECONDS.toSeconds(diffInMillies);
|
|
|
+ algorithmMapper.updateCostSecondById(id, costSecond);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|