yeg
2026-09-05 78f53edb9542a83d9579714cf4e1e8133fc89ee9
battery-business/src/main/java/com/battery/business/service/impl/TestWarningExceptionService.java
@@ -10,11 +10,19 @@
import com.battery.business.domain.TTestWarningThreshold;
import com.battery.business.mapper.TTestMapper;
/** 对成功接收的测量值执行测试阈值判断;设备状态和缺失数据不经过此服务。 */
/** 分别记录测量超限与接收中的离线事实;缺失测量不参与阈值判断。 */
@Service
public class TestWarningExceptionService {
    private final TTestMapper mapper;
    public TestWarningExceptionService(TTestMapper mapper) { this.mapper = mapper; }
    /** 调用方须持有测试事务锁;仅在接收中记录当前绑定来源的离线事实。 */
    public void recordOfflineSources(TTest test, Date occurredAt) {
        if (test == null || !"RUNNING".equals(test.getTestStatus()) || !"RECEIVING".equals(test.getReceptionStatus())) return;
        for (var source : mapper.selectOfflineTestSources(test.getTestId())) {
            mapper.upsertOfflineException(test.getTestId(), source.sourceType(), source.sourceIdentity(), occurredAt);
        }
    }
    /** 仅对成功接收的非空测量值判定阈值,并聚合更新开放异常及规则快照。 */
    public void evaluate(TTest test, String sourceType, String sourceIdentity, String metricCode, BigDecimal value, String unit, Date occurredAt) {
        if (value == null || test == null || test.getThresholds() == null) return;