Commit 73933f5a by 杨卫

feat:预警引擎自测条

1 parent b5cdd068
...@@ -45,9 +45,6 @@ public class WarningEngineService { ...@@ -45,9 +45,6 @@ public class WarningEngineService {
private BiMetricQueryService biMetricQueryService; private BiMetricQueryService biMetricQueryService;
@Resource @Resource
private EcoCoefficientQueryService ecoCoefficientQueryService;
@Resource
private ThresholdStrategyFactory thresholdFactory; private ThresholdStrategyFactory thresholdFactory;
@Resource @Resource
...@@ -798,25 +795,16 @@ public class WarningEngineService { ...@@ -798,25 +795,16 @@ public class WarningEngineService {
Integer warningType, PgWarningMetricDict dict, Integer warningType, PgWarningMetricDict dict,
Map<Integer, Map<String, ThresholdValue>> preloadedThresholds, Map<Integer, Map<String, ThresholdValue>> preloadedThresholds,
String merchantNo) { String merchantNo) {
if (triggeredCond.getMetricId() != null && triggeredValue != null) { MetricValueTransformStrategy matchedStrategy = findMatchingStrategy(warningType);
// 生态系数查询使用 record 中已设置的 metricCode BigDecimal warnValue = matchedStrategy.resolveDisplayValue(triggeredValue, record);
if (record.getMetricCode() != null) {
BigDecimal eco = ecoCoefficientQueryService.getCoefficient(
record.getMetricCode(), triggeredValue);
record.setEcoCoefficient(eco);
}
}
record.setOperator(triggeredCond.getOperator()); record.setOperator(triggeredCond.getOperator());
WarningOperatorEnum operator = WarningOperatorEnum.fromSymbol(triggeredCond.getOperator()); WarningOperatorEnum operator = WarningOperatorEnum.fromSymbol(triggeredCond.getOperator());
ThresholdValue threshold = resolveThresholdForCond(triggeredCond, preloadedThresholds, merchantNo); ThresholdValue threshold = resolveThresholdForCond(triggeredCond, preloadedThresholds, merchantNo);
// 通过策略构建 label 和获取 unit
MetricValueTransformStrategy matchedStrategy = findMatchingStrategy(warningType);
String metricName = triggeredCond.getMetricId() != null ? triggeredCond.getMetricName() : ""; String metricName = triggeredCond.getMetricId() != null ? triggeredCond.getMetricName() : "";
String label = matchedStrategy.buildWarningLabel(metricName, categoryExtension); String label = matchedStrategy.buildWarningLabel(metricName, categoryExtension);
String unit = matchedStrategy.getWarningUnit(dict); String unit = matchedStrategy.getWarningUnit(dict);
record.setWarningText(operator.buildWarningText( record.setWarningText(operator.buildWarningText(
label, unit, label, unit, warnValue,
record.getMetricDisplay(),
threshold != null ? threshold.getDisplay() : null, threshold != null ? threshold.getDisplay() : null,
threshold != null ? threshold.getMinDisplay() : null, threshold != null ? threshold.getMinDisplay() : null,
threshold != null ? threshold.getMaxDisplay() : null)); threshold != null ? threshold.getMaxDisplay() : null));
......
...@@ -3,6 +3,7 @@ package cn.com.glsx.dj.strategy.service.warning.threshold; ...@@ -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.MetricDataTypeEnum;
import cn.com.glsx.dj.strategy.enums.WarningTypeEnum; 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.PgWarningMetricDict;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningRecord;
import cn.com.glsx.dj.strategy.service.warning.EcoCoefficientQueryService; import cn.com.glsx.dj.strategy.service.warning.EcoCoefficientQueryService;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -49,6 +50,23 @@ public class EcoMetricValueTransformStrategy implements MetricValueTransformStra ...@@ -49,6 +50,23 @@ public class EcoMetricValueTransformStrategy implements MetricValueTransformStra
} }
@Override @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) { public BigDecimal transform(BigDecimal scaledValue, TransformContext ctx) {
if (scaledValue == null) { if (scaledValue == null) {
return null; return null;
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.dj.strategy.service.warning.threshold; ...@@ -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.enums.WarningTypeEnum;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict; 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 cn.hutool.core.util.StrUtil;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -56,4 +57,15 @@ public interface MetricValueTransformStrategy { ...@@ -56,4 +57,15 @@ public interface MetricValueTransformStrategy {
default String getWarningUnit(PgWarningMetricDict dict) { default String getWarningUnit(PgWarningMetricDict dict) {
return dict != null && dict.getUnit() != null ? dict.getUnit() : StrUtil.EMPTY; 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!