#
Junjie
2026-04-27 b83bc2ee89d5826b3ab5fe42ac3af5972360b55c
src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
@@ -2,8 +2,11 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.ai.domain.autotune.AutoTuneParameterSnapshot;
import com.zy.ai.domain.autotune.AutoTuneRuleDefinition;
import com.zy.ai.domain.autotune.AutoTuneRuleSnapshotItem;
import com.zy.ai.domain.autotune.AutoTuneSnapshot;
import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem;
import com.zy.ai.domain.autotune.AutoTuneTargetType;
import com.zy.ai.domain.autotune.AutoTuneTaskSnapshot;
import com.zy.ai.service.AutoTuneSnapshotService;
import com.zy.ai.service.FlowTopologySnapshotService;
@@ -86,10 +89,47 @@
        snapshot.setCycleLoadSnapshot(buildCycleLoadSnapshot());
        snapshot.setFlowTopologySnapshot(flowTopologySnapshotService.buildSnapshot(stationRuntimeSnapshot));
        snapshot.setCurrentParameterSnapshot(buildCurrentParameterSnapshot());
        snapshot.setRuleSnapshot(buildRuleSnapshot());
        snapshot.setSnapshotTime(new Date());
        return snapshot;
    }
    List<AutoTuneRuleSnapshotItem> buildRuleSnapshot() {
        List<AutoTuneRuleSnapshotItem> result = new ArrayList<>();
        for (AutoTuneRuleDefinition.Rule rule : AutoTuneRuleDefinition.rules().values()) {
            AutoTuneRuleSnapshotItem item = new AutoTuneRuleSnapshotItem();
            item.setTargetType(rule.getTargetType().getCode());
            item.setTargetKey(rule.getTargetKey());
            item.setMinValue(rule.getMinValue());
            item.setMaxValue(rule.getMaxValue());
            item.setMaxStep(rule.getMaxStep());
            item.setCooldownMinutes(rule.getCooldownMinutes());
            item.setDynamicMaxValue(rule.isDynamicMaxValue());
            item.setDynamicMaxSource(resolveDynamicMaxSource(rule));
            item.setNote(resolveRuleNote(rule));
            result.add(item);
        }
        return result;
    }
    private String resolveDynamicMaxSource(AutoTuneRuleDefinition.Rule rule) {
        if (!AutoTuneTargetType.STATION.equals(rule.getTargetType())) {
            return null;
        }
        if (!"outTaskLimit".equals(rule.getTargetKey())) {
            return null;
        }
        return "currentParameterSnapshot.stationOutBufferCapacities[targetId]";
    }
    private String resolveRuleNote(AutoTuneRuleDefinition.Rule rule) {
        if (AutoTuneTargetType.STATION.equals(rule.getTargetType())
                && "outTaskLimit".equals(rule.getTargetKey())) {
            return "单次调整幅度不能超过 maxStep;增大时不得超过对应站点 outBufferCapacity。";
        }
        return "单次调整幅度不能超过 maxStep。";
    }
    private AutoTuneTaskSnapshot buildTaskSnapshot() {
        List<WrkMast> activeTasks = loadActiveTasks();