|
@@ -44,69 +44,126 @@ public class SchedulerTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void redisTemplate() throws ApiException {
|
|
public void redisTemplate() throws ApiException {
|
|
- redisTemplate.opsForValue().set("a:b","test");
|
|
|
|
- redisTemplate.opsForValue().set("a:b:c","test");
|
|
|
|
|
|
+ redisTemplate.opsForValue().set("a:b", "test");
|
|
|
|
+ redisTemplate.opsForValue().set("a:b:c", "test");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void test() {
|
|
|
|
|
|
+ public void compute() {
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+TaskIndexPO(id=0a8cd6c061a24ed2bbb36a45b3a003d4,
|
|
|
|
+ pId=e8337795555541639659d773e28eafd5,
|
|
|
|
+ indexId=433838e404a74f87ba8f78c617134eec,
|
|
|
|
+ parentId=018ae110ca51413ba22268f36c125a03,
|
|
|
|
+ rootId=018ae110ca51413ba22268f36c125a03,
|
|
|
|
+ target=433838e404a74f87ba8f78c617134eec,
|
|
|
|
+ notStandardSceneNum=0, score=100.0, weight=40,
|
|
|
|
+ scoreExplain=1) 未发生碰撞>,得分 100;2) 发生碰撞,得分 0。),
|
|
|
|
+
|
|
|
|
+TaskIndexPO(id=24a53877c1b34b3bb61dc9d7e28035d2,
|
|
|
|
+ pId=e8337795555541639659d773e28eafd5,
|
|
|
|
+ indexId=a2a1866e5c7047c3bddc905971540043,
|
|
|
|
+ parentId=148c7e1fb6474cdf8c106215f92b0d9d,
|
|
|
|
+ rootId=018ae110ca51413ba22268f36c125a03,
|
|
|
|
+ target=a2a1866e5c7047c3bddc905971540043,
|
|
|
|
+ notStandardSceneNum=1,
|
|
|
|
+ score=0.0,
|
|
|
|
+ weight=70, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。),
|
|
|
|
+
|
|
|
|
+TaskIndexPO(id=94a9225873534e97be79b25c98861b83,
|
|
|
|
+ pId=e8337795555541639659d773e28eafd5,
|
|
|
|
+ indexId=df913a81a34742808cefc76829bfa398,
|
|
|
|
+ parentId=e28c9687cfdd4fec956d4c3a7fa061ec,
|
|
|
|
+ rootId=018ae110ca51413ba22268f36c125a03,
|
|
|
|
+ target=df913a81a34742808cefc76829bfa398,
|
|
|
|
+ notStandardSceneNum=0, score=100.0, weight=60, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。),
|
|
|
|
+
|
|
|
|
+TaskIndexPO(id=14d0017b489844bcb33118f7cfeee04c,
|
|
|
|
+ pId=e8337795555541639659d773e28eafd5,
|
|
|
|
+ indexId=eefbf9234bad410b801ed860b4add56f,
|
|
|
|
+ parentId=e28c9687cfdd4fec956d4c3a7fa061ec,
|
|
|
|
+ rootId=018ae110ca51413ba22268f36c125a03,
|
|
|
|
+ target=eefbf9234bad410b801ed860b4add56f,
|
|
|
|
+ notStandardSceneNum=1, score=0.0, weight=40, scoreExplain=1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)]
|
|
|
|
+ */
|
|
|
|
|
|
|
|
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
List<TaskIndexPO> leafTaskIndexList = new ArrayList<>();
|
|
|
|
+
|
|
TaskIndexPO taskIndexPO1 = TaskIndexPO.builder()
|
|
TaskIndexPO taskIndexPO1 = TaskIndexPO.builder()
|
|
- .id("9e64a4aa3df7414097ffd1c82a8bdaa3")
|
|
|
|
- .pId("7586e4196699414d87f63ffbbf281122")
|
|
|
|
- .indexId("12db82c7acbf49a6a9274243e7eebc6a")
|
|
|
|
- .parentId("046155104e934910b19305a6ba27a784")
|
|
|
|
- .rootId("059c582c7cf3422b8d9bb8583f6b7c5a")
|
|
|
|
- .target("12db82c7acbf49a6a9274243e7eebc6a")
|
|
|
|
|
|
+ .id("0a8cd6c061a24ed2bbb36a45b3a003d4")
|
|
|
|
+ .pId("e8337795555541639659d773e28eafd5")
|
|
|
|
+ .indexId("433838e404a74f87ba8f78c617134eec")
|
|
|
|
+ .parentId("018ae110ca51413ba22268f36c125a03")
|
|
|
|
+ .rootId("018ae110ca51413ba22268f36c125a03")
|
|
|
|
+ .target("433838e404a74f87ba8f78c617134eec")
|
|
.notStandardSceneNum(0)
|
|
.notStandardSceneNum(0)
|
|
.score(100.0)
|
|
.score(100.0)
|
|
- .weight("50")
|
|
|
|
|
|
+ .weight("40")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
|
|
+ .packageLevel(1)
|
|
.build();
|
|
.build();
|
|
leafTaskIndexList.add(taskIndexPO1);
|
|
leafTaskIndexList.add(taskIndexPO1);
|
|
|
|
|
|
TaskIndexPO taskIndexPO2 = TaskIndexPO.builder()
|
|
TaskIndexPO taskIndexPO2 = TaskIndexPO.builder()
|
|
- .id("fc16c0aa3292496fb37daa635dd2d506")
|
|
|
|
- .pId("7586e4196699414d87f63ffbbf281122")
|
|
|
|
- .indexId("393a4b959d684eec9b5b777c8fc38bcf")
|
|
|
|
- .parentId("046155104e934910b19305a6ba27a784")
|
|
|
|
- .rootId("059c582c7cf3422b8d9bb8583f6b7c5a")
|
|
|
|
- .target("393a4b959d684eec9b5b777c8fc38bcf")
|
|
|
|
- .notStandardSceneNum(0)
|
|
|
|
- .score(100.0)
|
|
|
|
- .weight("50")
|
|
|
|
|
|
+ .id("24a53877c1b34b3bb61dc9d7e28035d2")
|
|
|
|
+ .pId("e8337795555541639659d773e28eafd5")
|
|
|
|
+ .indexId("a2a1866e5c7047c3bddc905971540043")
|
|
|
|
+ .parentId("148c7e1fb6474cdf8c106215f92b0d9d")
|
|
|
|
+ .rootId("018ae110ca51413ba22268f36c125a03")
|
|
|
|
+ .target("a2a1866e5c7047c3bddc905971540043")
|
|
|
|
+ .notStandardSceneNum(1)
|
|
|
|
+ .score(0.0)
|
|
|
|
+ .weight("70")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
|
|
+ .packageLevel(2)
|
|
.build();
|
|
.build();
|
|
leafTaskIndexList.add(taskIndexPO2);
|
|
leafTaskIndexList.add(taskIndexPO2);
|
|
|
|
|
|
TaskIndexPO taskIndexPO3 = TaskIndexPO.builder()
|
|
TaskIndexPO taskIndexPO3 = TaskIndexPO.builder()
|
|
- .id("300fbafab2d3432aac2b7926bb89456a")
|
|
|
|
- .pId("7586e4196699414d87f63ffbbf281122")
|
|
|
|
- .indexId("5b95a89d5a764af0ad93164753ab8caa")
|
|
|
|
- .parentId("059c582c7cf3422b8d9bb8583f6b7c5a")
|
|
|
|
- .rootId("059c582c7cf3422b8d9bb8583f6b7c5a")
|
|
|
|
- .target("5b95a89d5a764af0ad93164753ab8caa")
|
|
|
|
|
|
+ .id("94a9225873534e97be79b25c98861b83")
|
|
|
|
+ .pId("e8337795555541639659d773e28eafd5")
|
|
|
|
+ .indexId("df913a81a34742808cefc76829bfa398")
|
|
|
|
+ .parentId("e28c9687cfdd4fec956d4c3a7fa061ec")
|
|
|
|
+ .rootId("018ae110ca51413ba22268f36c125a03")
|
|
|
|
+ .target("df913a81a34742808cefc76829bfa398")
|
|
.notStandardSceneNum(0)
|
|
.notStandardSceneNum(0)
|
|
.score(100.0)
|
|
.score(100.0)
|
|
.weight("60")
|
|
.weight("60")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
.scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
|
|
+ .packageLevel(3)
|
|
.build();
|
|
.build();
|
|
leafTaskIndexList.add(taskIndexPO3);
|
|
leafTaskIndexList.add(taskIndexPO3);
|
|
|
|
|
|
- computeFirst(leafTaskIndexList, "7586e4196699414d87f63ffbbf281122");
|
|
|
|
|
|
+
|
|
|
|
+ TaskIndexPO taskIndexPO4 = TaskIndexPO.builder()
|
|
|
|
+ .id("14d0017b489844bcb33118f7cfeee04c")
|
|
|
|
+ .pId("e8337795555541639659d773e28eafd5")
|
|
|
|
+ .indexId("eefbf9234bad410b801ed860b4add56f")
|
|
|
|
+ .parentId("e28c9687cfdd4fec956d4c3a7fa061ec")
|
|
|
|
+ .rootId("018ae110ca51413ba22268f36c125a03")
|
|
|
|
+ .target("eefbf9234bad410b801ed860b4add56f")
|
|
|
|
+ .notStandardSceneNum(1)
|
|
|
|
+ .score(0.0)
|
|
|
|
+ .weight("40")
|
|
|
|
+ .scoreExplain("1) 未发生碰撞,得分 100;2) 发生碰撞,得分 0。)")
|
|
|
|
+ .packageLevel(3)
|
|
|
|
+ .build();
|
|
|
|
+ leafTaskIndexList.add(taskIndexPO4);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ computeFirst(leafTaskIndexList, "e8337795555541639659d773e28eafd5", 3);
|
|
}
|
|
}
|
|
|
|
|
|
- public void computeFirst(List<TaskIndexPO> leafTaskIndexList, String projectId) {
|
|
|
|
|
|
+ public void computeFirst(List<TaskIndexPO> leafTaskIndexList, String projectId, int maxLevel) {
|
|
|
|
|
|
log.info("------- /state computeFirst 计算父指标得分:" + leafTaskIndexList);
|
|
log.info("------- /state computeFirst 计算父指标得分:" + leafTaskIndexList);
|
|
Iterator<TaskIndexPO> leafTaskIndexIterator = leafTaskIndexList.iterator();
|
|
Iterator<TaskIndexPO> leafTaskIndexIterator = leafTaskIndexList.iterator();
|
|
|
|
+ // 把 1 级的指标得分直接保存
|
|
while (leafTaskIndexIterator.hasNext()) {
|
|
while (leafTaskIndexIterator.hasNext()) {
|
|
TaskIndexPO leafTaskIndex = leafTaskIndexIterator.next();
|
|
TaskIndexPO leafTaskIndex = leafTaskIndexIterator.next();
|
|
- String parentId = leafTaskIndex.getParentId();
|
|
|
|
- String rootId = leafTaskIndex.getRootId();
|
|
|
|
- if (parentId.equals(rootId)) {
|
|
|
|
|
|
+ if (leafTaskIndex.getPackageLevel() == 1) {
|
|
leafTaskIndex.setCreateUserId(USER_ID);
|
|
leafTaskIndex.setCreateUserId(USER_ID);
|
|
leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
leafTaskIndex.setCreateTime(TimeUtil.getNowForMysql());
|
|
leafTaskIndex.setModifyUserId(USER_ID);
|
|
leafTaskIndex.setModifyUserId(USER_ID);
|
|
@@ -115,18 +172,24 @@ public class SchedulerTest {
|
|
taskIndexMapper.insertFirstIndex(leafTaskIndex);
|
|
taskIndexMapper.insertFirstIndex(leafTaskIndex);
|
|
leafTaskIndexIterator.remove();
|
|
leafTaskIndexIterator.remove();
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
if (leafTaskIndexList.size() > 0) {
|
|
if (leafTaskIndexList.size() > 0) {
|
|
- Map<String, List<TaskIndexPO>> sonTaskIndexMap = leafTaskIndexList.stream().collect(Collectors.groupingBy(TaskIndexPO::getParentId));
|
|
|
|
|
|
+
|
|
|
|
+ List<TaskIndexPO> nextLevelIndexList = new ArrayList<>();
|
|
|
|
+ // 找出等级和 maxLevel 不相同的指标暂时不计算
|
|
|
|
+ leafTaskIndexList.stream()
|
|
|
|
+ .filter(po -> maxLevel != po.getPackageLevel())
|
|
|
|
+ .forEach(nextLevelIndexList::add);
|
|
|
|
+ // 找出等级和 maxLevel 相同的指标并根据父指标分组
|
|
|
|
+ Map<String, List<TaskIndexPO>> sonTaskIndexMap = leafTaskIndexList.stream()
|
|
|
|
+ .filter(po -> maxLevel == po.getPackageLevel())
|
|
|
|
+ .collect(Collectors.groupingBy(TaskIndexPO::getParentId));
|
|
Set<String> parentIdSet = sonTaskIndexMap.keySet();
|
|
Set<String> parentIdSet = sonTaskIndexMap.keySet();
|
|
List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
|
|
List<String> parentIdList = CollectionUtil.setToList(parentIdSet);
|
|
List<IndexTemplatePO> parentIndexTemplateList = indexTemplateMapper.selectByIdList(parentIdList);
|
|
List<IndexTemplatePO> parentIndexTemplateList = indexTemplateMapper.selectByIdList(parentIdList);
|
|
// 计算父指标得分
|
|
// 计算父指标得分
|
|
- List<TaskIndexPO> parentIndexList = new ArrayList<>();
|
|
|
|
parentIndexTemplateList.forEach(indexTemplate -> {
|
|
parentIndexTemplateList.forEach(indexTemplate -> {
|
|
String weight = indexTemplate.getWeight();
|
|
String weight = indexTemplate.getWeight();
|
|
-
|
|
|
|
List<TaskIndexPO> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
|
|
List<TaskIndexPO> sonTaskIndexList = sonTaskIndexMap.get(indexTemplate.getIndexId());
|
|
double parentScore = sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum();
|
|
double parentScore = sonTaskIndexList.stream().mapToDouble(taskIndex -> taskIndex.getScore() * Double.parseDouble(taskIndex.getWeight()) / 100).sum();
|
|
TaskIndexPO parentTaskIndex = TaskIndexPO.builder()
|
|
TaskIndexPO parentTaskIndex = TaskIndexPO.builder()
|
|
@@ -138,11 +201,12 @@ public class SchedulerTest {
|
|
.parentId(indexTemplate.getParentId())
|
|
.parentId(indexTemplate.getParentId())
|
|
.rootId(indexTemplate.getRootId())
|
|
.rootId(indexTemplate.getRootId())
|
|
.weight(weight)
|
|
.weight(weight)
|
|
|
|
+ .packageLevel(maxLevel - 1)
|
|
.build();
|
|
.build();
|
|
- parentIndexList.add(parentTaskIndex);
|
|
|
|
|
|
+ nextLevelIndexList.add(parentTaskIndex);
|
|
});
|
|
});
|
|
// 将父指标作为叶子指标递归
|
|
// 将父指标作为叶子指标递归
|
|
- computeFirst(parentIndexList, projectId);
|
|
|
|
|
|
+ computeFirst(nextLevelIndexList, projectId, maxLevel - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|