|
@@ -1,34 +1,116 @@
|
|
|
package com.css.simulation.resource.scheduler.service;
|
|
|
|
|
|
+import api.common.pojo.constants.DictConstants;
|
|
|
+import api.common.util.CollectionUtil;
|
|
|
+import api.common.util.StringUtil;
|
|
|
+import api.common.util.TimeUtil;
|
|
|
import com.css.simulation.resource.scheduler.feign.CommonService;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.IndexMapper;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.ProjectMapper;
|
|
|
+import com.css.simulation.resource.scheduler.mapper.TaskMapper;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.po.IndexPO;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.po.ProjectPO;
|
|
|
+import com.css.simulation.resource.scheduler.pojo.po.TaskPO;
|
|
|
+import com.css.simulation.resource.scheduler.util.ScoreUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
public class TaskService {
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private CommonService commonService;
|
|
|
+ @Autowired
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+ @Autowired
|
|
|
+ private TaskMapper taskMapper;
|
|
|
+ @Autowired
|
|
|
+ private IndexMapper indexMapper;
|
|
|
|
|
|
|
|
|
public void taskTick(String taskId) {
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ taskMapper.updateTickTime(taskId, TimeUtil.getNowForMysql());
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void taskState(String taskId, String taskState) {
|
|
|
+ public void taskState(String taskId, String state) {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ taskMapper.updateState(taskId, state);
|
|
|
+
|
|
|
+ ProjectPO projectPO = projectMapper.selectById(taskId);
|
|
|
+ String projectId = projectPO.getId();
|
|
|
+ String scenePackageId = projectPO.getScenePackageId();
|
|
|
+ int taskNum = projectMapper.selectTaskNumById(projectId);
|
|
|
+ int completedTaskNum = projectMapper.selectTaskNumByProjectIdAndState(projectId, DictConstants.TASK_COMPLETED);
|
|
|
+ if (taskNum != completedTaskNum) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<TaskPO> taskList = taskMapper.selectTaskListByProjectId(projectId);
|
|
|
+ List<IndexPO> leafIndexList = indexMapper.selectLeafIndexWithRuleDetailsByPackageId(scenePackageId);
|
|
|
|
|
|
+
|
|
|
+ for (IndexPO indexPO : leafIndexList) {
|
|
|
+ String ruleDetails = indexPO.getRuleDetails();
|
|
|
+ Set<String> sceneIdSet = new HashSet<>();
|
|
|
+ String naturalIds = indexPO.getSceneNaturalIds();
|
|
|
+ String standardIds = indexPO.getSceneStatueIds();
|
|
|
+ String accidentIds = indexPO.getSceneTrafficIds();
|
|
|
+ if (StringUtil.isNotEmpty(naturalIds)) {
|
|
|
+ String[] naturalIdArray = naturalIds.split(",");
|
|
|
+ sceneIdSet.addAll(Arrays.asList(naturalIdArray));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotEmpty(standardIds)) {
|
|
|
+ String[] standardArray = standardIds.split(",");
|
|
|
+ sceneIdSet.addAll(Arrays.asList(standardArray));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotEmpty(accidentIds)) {
|
|
|
+ String[] accidentIdArray = accidentIds.split(",");
|
|
|
+ sceneIdSet.addAll(Arrays.asList(accidentIdArray));
|
|
|
+ }
|
|
|
+ int resultNumberOfCurrentIndex = sceneIdSet.size();
|
|
|
+ double sum = taskList.stream()
|
|
|
+ .filter(task1 -> sceneIdSet.contains(task1.getSceneId()))
|
|
|
+ .mapToDouble(task2 -> {
|
|
|
+
|
|
|
+ double score = ScoreUtil.score(task2.getRunResult(), ruleDetails);
|
|
|
+ task2.setScore(score);
|
|
|
+ return score;
|
|
|
+ }).sum();
|
|
|
+ double indexScore = sum / resultNumberOfCurrentIndex;
|
|
|
+ indexPO.setScore(indexScore);
|
|
|
+ }
|
|
|
+
|
|
|
+ int unqualified = (int) taskList.stream().filter(taskPO -> taskPO.getScore() < 100).count();
|
|
|
+
|
|
|
+ double totalScore = compute(leafIndexList);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
public Boolean taskConfirm(String taskId) {
|
|
|
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public double compute(List<IndexPO> leaf) {
|
|
|
+ double result = 0.0;
|
|
|
+ Map<String, List<IndexPO>> groups = leaf.stream().collect(Collectors.groupingBy(IndexPO::getParentId));
|
|
|
+ Set<String> idSet = groups.keySet();
|
|
|
+ List<IndexPO> indexPOList = indexMapper.selectByIdList(CollectionUtil.setToList(idSet));
|
|
|
+ indexPOList.forEach(index1 -> {
|
|
|
+ double sum = groups.get(index1.getIndexId()).stream().mapToDouble(index2 -> index2.getScore() * Double.parseDouble(index2.getWeight())).sum();
|
|
|
+ index1.setScore(sum);
|
|
|
+ });
|
|
|
+ if (indexPOList.size() > 1) {
|
|
|
+ result = result + compute(indexPOList);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|