|
@@ -1,9 +1,11 @@
|
|
|
package com.jjt.biz.service.impl;
|
|
|
|
|
|
+import com.googlecode.aviator.AviatorEvaluator;
|
|
|
import com.jjt.biz.domain.*;
|
|
|
import com.jjt.biz.mapper.HlBaseMapper;
|
|
|
import com.jjt.biz.service.*;
|
|
|
import com.jjt.common.utils.DateUtils;
|
|
|
+import com.jjt.common.utils.StringUtils;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -13,6 +15,8 @@ import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +47,10 @@ public class HlBaseServiceImpl implements IHlBaseService {
|
|
|
private IHlDayDetailService dayDetailService;
|
|
|
@Resource
|
|
|
private IHlMetricsRelaService relaService;
|
|
|
+ @Resource
|
|
|
+ private IMetricsDefService defService;
|
|
|
+ @Resource
|
|
|
+ private IBizModelService modelService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -193,11 +201,14 @@ public class HlBaseServiceImpl implements IHlBaseService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void score() {
|
|
|
- Map<String, Long> relaMap = relaService.selectHlMetricsRelaList(new HlMetricsRela()).stream()
|
|
|
- .collect(Collectors.toMap(HlMetricsRela::getHlCode, HlMetricsRela::getMetricsId));
|
|
|
+ Map<String, String> expMap = relaService.selectHlMetricsRelaList(new HlMetricsRela()).stream()
|
|
|
+ .collect(Collectors.toMap(HlMetricsRela::getHlCode, HlMetricsRela::getExp));
|
|
|
+ Map<String, Long> defMap = defService.selectMetricsDefList(new MetricsDef()).stream().collect(Collectors.toMap(MetricsDef::getMetricsCode, MetricsDef::getMetricsId));
|
|
|
+
|
|
|
List<HlBase> list = selectHlBaseList(new HlBase());
|
|
|
list.forEach(base -> {
|
|
|
if (base.getModelId() != -1) {
|
|
|
+ Map<Long, List<BizObjMetrics>> metricsGroup = modelService.selectBizModelMetricsList(base.getModelId()).stream().collect(Collectors.groupingBy(BizObjMetrics::getMetricsId));
|
|
|
HlScore score = new HlScore();
|
|
|
score.setModelId(base.getModelId());
|
|
|
scoreService.insertHlScore(score);
|
|
@@ -223,14 +234,49 @@ public class HlBaseServiceImpl implements IHlBaseService {
|
|
|
scoreDetail.setHlScoreId(score.getHlScoreId());
|
|
|
scoreDetail.setHlType("DETAIL");
|
|
|
scoreDetail.setHlCode(d.getHlDetailCode());
|
|
|
- switch (d.getHlDetailCode()) {
|
|
|
+ String hlCode = d.getHlDetailCode();
|
|
|
+ String exp = expMap.get(hlCode);
|
|
|
+ BigDecimal standScore = new BigDecimal(d.getHlDetailScore());
|
|
|
+ switch (hlCode) {
|
|
|
case "C01":
|
|
|
case "C02":
|
|
|
case "C03":
|
|
|
- BigDecimal dc = random(d.getHlDetailScore());
|
|
|
- scoreDetail.setHlScore(dc);
|
|
|
- sc.set(sc.get().add(dc));
|
|
|
- scoreDetailService.insertHlScoreDetail(scoreDetail);
|
|
|
+ if (StringUtils.isNotEmpty(exp)) {
|
|
|
+ Matcher matcher = match(exp);
|
|
|
+ Map<String, List<BizObjMetrics>> originalMap = new HashMap<>();
|
|
|
+ //先拿到一个code,好获取组件数量
|
|
|
+ String oneCode = "";
|
|
|
+ while (matcher.find()) {
|
|
|
+ String code = matcher.group(1);
|
|
|
+ String old = String.format("${%s}", code);
|
|
|
+ String newCode = code.replace(".", "");
|
|
|
+ oneCode = newCode;
|
|
|
+ exp = exp.replace(old, newCode);
|
|
|
+
|
|
|
+ Long mid = defMap.get(code);
|
|
|
+ List<BizObjMetrics> omList = metricsGroup.get(mid);
|
|
|
+ originalMap.put(newCode, omList);
|
|
|
+ }
|
|
|
+ // 获取组件数量
|
|
|
+ int size = originalMap.get(oneCode).size();
|
|
|
+ int alarmSize = 0;
|
|
|
+ // 遍历列表并创建新的 Map
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ Map<String, Object> singleEntryMap = new HashMap<>();
|
|
|
+ for (String s : originalMap.keySet()) {
|
|
|
+ singleEntryMap.put(s, originalMap.get(s).get(i).getDValue().floatValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = evaluator(exp, singleEntryMap);
|
|
|
+ if (flag) {
|
|
|
+ alarmSize++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //最终得分(告警组件数量/总数量 )*细项分
|
|
|
+ BigDecimal df = standScore.subtract(BigDecimal.valueOf(alarmSize).divide(BigDecimal.valueOf(size)).multiply(standScore));
|
|
|
+ scoreDetail.setHlScore(df);
|
|
|
+ scoreDetailService.insertHlScoreDetail(scoreDetail);
|
|
|
+ }
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
@@ -326,4 +372,27 @@ public class HlBaseServiceImpl implements IHlBaseService {
|
|
|
int v = s.intValue() - randomNumber;
|
|
|
return BigDecimal.valueOf(v);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公式计算
|
|
|
+ *
|
|
|
+ * @param exp 表达式
|
|
|
+ * @param env 值
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ private boolean evaluator(String exp, Map<String, Object> env) {
|
|
|
+ return (boolean) AviatorEvaluator.execute(exp, env);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正则匹配
|
|
|
+ *
|
|
|
+ * @param exp 表达式
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ private Matcher match(String exp) {
|
|
|
+ //正则表达式匹配变量
|
|
|
+ Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}");
|
|
|
+ return pattern.matcher(exp);
|
|
|
+ }
|
|
|
}
|