Commit 73933f5a by 杨卫

feat:预警引擎自测条

1 parent b5cdd068
......@@ -45,9 +45,6 @@ public class WarningEngineService {
private BiMetricQueryService biMetricQueryService;
@Resource
private EcoCoefficientQueryService ecoCoefficientQueryService;
@Resource
private ThresholdStrategyFactory thresholdFactory;
@Resource
......@@ -798,25 +795,16 @@ public class WarningEngineService {
Integer warningType, PgWarningMetricDict dict,
Map<Integer, Map<String, ThresholdValue>> preloadedThresholds,
String merchantNo) {
if (triggeredCond.getMetricId() != null && triggeredValue != null) {
// 生态系数查询使用 record 中已设置的 metricCode
if (record.getMetricCode() != null) {
BigDecimal eco = ecoCoefficientQueryService.getCoefficient(
record.getMetricCode(), triggeredValue);
record.setEcoCoefficient(eco);
}
}
MetricValueTransformStrategy matchedStrategy = findMatchingStrategy(warningType);
BigDecimal warnValue = matchedStrategy.resolveDisplayValue(triggeredValue, record);
record.setOperator(triggeredCond.getOperator());
WarningOperatorEnum operator = WarningOperatorEnum.fromSymbol(triggeredCond.getOperator());
ThresholdValue threshold = resolveThresholdForCond(triggeredCond, preloadedThresholds, merchantNo);
// 通过策略构建 label 和获取 unit
MetricValueTransformStrategy matchedStrategy = findMatchingStrategy(warningType);
String metricName = triggeredCond.getMetricId() != null ? triggeredCond.getMetricName() : "";
String label = matchedStrategy.buildWarningLabel(metricName, categoryExtension);
String unit = matchedStrategy.getWarningUnit(dict);
record.setWarningText(operator.buildWarningText(
label, unit,
record.getMetricDisplay(),
label, unit, warnValue,
threshold != null ? threshold.getDisplay() : null,
threshold != null ? threshold.getMinDisplay() : null,
threshold != null ? threshold.getMaxDisplay() : null));
......
......@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.enums.MetricDataTypeEnum;
import cn.com.glsx.dj.strategy.enums.WarningTypeEnum;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningRecord;
import cn.com.glsx.dj.strategy.service.warning.EcoCoefficientQueryService;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -49,6 +50,23 @@ public class EcoMetricValueTransformStrategy implements MetricValueTransformStra
}
@Override
public BigDecimal resolveDisplayValue(BigDecimal triggeredValue, PgWarningRecord record) {
if (triggeredValue == null || record.getMetricCode() == null) {
return record.getMetricDisplay();
}
try {
BigDecimal eco = ecoCoefficientQueryService.getCoefficient(record.getMetricCode(), triggeredValue);
if (eco != null) {
record.setEcoCoefficient(eco);
return eco;
}
} catch (Exception e) {
log.error("生态系数查询失败,metricCode={}", record.getMetricCode(), e);
}
return record.getMetricDisplay();
}
@Override
public BigDecimal transform(BigDecimal scaledValue, TransformContext ctx) {
if (scaledValue == null) {
return null;
......
......@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.service.warning.threshold;
import cn.com.glsx.dj.strategy.enums.WarningTypeEnum;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningRecord;
import cn.hutool.core.util.StrUtil;
import java.math.BigDecimal;
......@@ -56,4 +57,15 @@ public interface MetricValueTransformStrategy {
default String getWarningUnit(PgWarningMetricDict dict) {
return dict != null && dict.getUnit() != null ? dict.getUnit() : StrUtil.EMPTY;
}
/**
* 解析告警文案展示值并设置生态系数——生态预警查系数表,其余不做操作。
*
* @param triggeredValue BI 原值
* @param record 预警记录(生态策略会设置 ecoCoefficient)
* @return 告警文案展示值
*/
default BigDecimal resolveDisplayValue(BigDecimal triggeredValue, PgWarningRecord record) {
return record.getMetricDisplay();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!