package com.zy.ai.domain.autotune;
|
|
import java.util.Collections;
|
import java.util.LinkedHashMap;
|
import java.util.Map;
|
|
public final class AutoTuneRuleDefinition {
|
|
private static final Map<String, Rule> RULE_MAP = buildRuleMap();
|
|
private AutoTuneRuleDefinition() {
|
}
|
|
public static Rule findRule(String targetType, String targetKey) {
|
if (targetType == null || targetKey == null) {
|
return null;
|
}
|
return RULE_MAP.get(buildKey(targetType.trim(), targetKey.trim()));
|
}
|
|
public static Map<String, Rule> rules() {
|
return RULE_MAP;
|
}
|
|
private static Map<String, Rule> buildRuleMap() {
|
LinkedHashMap<String, Rule> ruleMap = new LinkedHashMap<>();
|
add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "aiAutoTuneIntervalMinutes", 5, 60, 5, 30, false);
|
add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "conveyorStationTaskLimit", 5, 200, 5, 20, false);
|
add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "crnOutBatchRunningLimit", 1, 20, 3, 20, false);
|
add(ruleMap, AutoTuneTargetType.STATION, "outTaskLimit", 0, null, 3, 10, true);
|
add(ruleMap, AutoTuneTargetType.CRN, "maxOutTask", 0, 10, 3, 10, false);
|
add(ruleMap, AutoTuneTargetType.CRN, "maxInTask", 0, 10, 3, 10, false);
|
add(ruleMap, AutoTuneTargetType.DUAL_CRN, "maxOutTask", 0, 10, 3, 10, false);
|
add(ruleMap, AutoTuneTargetType.DUAL_CRN, "maxInTask", 0, 10, 3, 10, false);
|
return Collections.unmodifiableMap(ruleMap);
|
}
|
|
private static void add(LinkedHashMap<String, Rule> ruleMap,
|
AutoTuneTargetType targetType,
|
String targetKey,
|
Integer minValue,
|
Integer maxValue,
|
int maxStep,
|
int cooldownMinutes,
|
boolean dynamicMaxValue) {
|
Rule rule = new Rule(targetType, targetKey, minValue, maxValue, maxStep, cooldownMinutes, dynamicMaxValue);
|
ruleMap.put(buildKey(targetType.getCode(), targetKey), rule);
|
}
|
|
private static String buildKey(String targetType, String targetKey) {
|
return targetType + ":" + targetKey;
|
}
|
|
public static final class Rule {
|
private final AutoTuneTargetType targetType;
|
private final String targetKey;
|
private final Integer minValue;
|
private final Integer maxValue;
|
private final int maxStep;
|
private final int cooldownMinutes;
|
private final boolean dynamicMaxValue;
|
|
private Rule(AutoTuneTargetType targetType,
|
String targetKey,
|
Integer minValue,
|
Integer maxValue,
|
int maxStep,
|
int cooldownMinutes,
|
boolean dynamicMaxValue) {
|
this.targetType = targetType;
|
this.targetKey = targetKey;
|
this.minValue = minValue;
|
this.maxValue = maxValue;
|
this.maxStep = maxStep;
|
this.cooldownMinutes = cooldownMinutes;
|
this.dynamicMaxValue = dynamicMaxValue;
|
}
|
|
public AutoTuneTargetType getTargetType() {
|
return targetType;
|
}
|
|
public String getTargetKey() {
|
return targetKey;
|
}
|
|
public Integer getMinValue() {
|
return minValue;
|
}
|
|
public Integer getMaxValue() {
|
return maxValue;
|
}
|
|
public int getMaxStep() {
|
return maxStep;
|
}
|
|
public int getCooldownMinutes() {
|
return cooldownMinutes;
|
}
|
|
public boolean isDynamicMaxValue() {
|
return dynamicMaxValue;
|
}
|
}
|
}
|