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 String DEFAULT_RULE_NOTE = "单次调整幅度不能超过 maxStep。";
|
private static final String STATION_OUT_TASK_LIMIT_NOTE =
|
"单次调整幅度不能超过 maxStep;outBufferCapacity 代表出库站缓存位置数量,超过该容量可能使任务出现在主干道,仅作为风险参考,不是合法性上限。";
|
|
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, rule(AutoTuneTargetType.SYS_CONFIG, "aiAutoTuneIntervalMinutes")
|
.minValue(5)
|
.maxValue(60)
|
.maxStep(5)
|
.cooldownMinutes(30));
|
add(ruleMap, rule(AutoTuneTargetType.SYS_CONFIG, "conveyorStationTaskLimit")
|
.minValue(5)
|
.maxValue(200)
|
.maxStep(5)
|
.cooldownMinutes(20));
|
add(ruleMap, rule(AutoTuneTargetType.SYS_CONFIG, "crnOutBatchRunningLimit")
|
.minValue(1)
|
.maxValue(20)
|
.maxStep(3)
|
.cooldownMinutes(20));
|
add(ruleMap, rule(AutoTuneTargetType.STATION, "outTaskLimit")
|
.minValue(0)
|
.maxStep(3)
|
.cooldownMinutes(10)
|
.note(STATION_OUT_TASK_LIMIT_NOTE));
|
add(ruleMap, rule(AutoTuneTargetType.CRN, "maxOutTask")
|
.minValue(0)
|
.maxValue(10)
|
.maxStep(3)
|
.cooldownMinutes(10));
|
add(ruleMap, rule(AutoTuneTargetType.CRN, "maxInTask")
|
.minValue(0)
|
.maxValue(10)
|
.maxStep(3)
|
.cooldownMinutes(10));
|
add(ruleMap, rule(AutoTuneTargetType.DUAL_CRN, "maxOutTask")
|
.minValue(0)
|
.maxValue(10)
|
.maxStep(3)
|
.cooldownMinutes(10));
|
add(ruleMap, rule(AutoTuneTargetType.DUAL_CRN, "maxInTask")
|
.minValue(0)
|
.maxValue(10)
|
.maxStep(3)
|
.cooldownMinutes(10));
|
|
return Collections.unmodifiableMap(ruleMap);
|
}
|
|
private static RuleSpec rule(AutoTuneTargetType targetType, String targetKey) {
|
return new RuleSpec(targetType, targetKey);
|
}
|
|
private static void add(LinkedHashMap<String, Rule> ruleMap, RuleSpec ruleSpec) {
|
Rule rule = ruleSpec.toRule();
|
ruleMap.put(buildKey(rule.getTargetType().getCode(), rule.getTargetKey()), 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 final String dynamicMaxSource;
|
private final String note;
|
|
private Rule(AutoTuneTargetType targetType,
|
String targetKey,
|
Integer minValue,
|
Integer maxValue,
|
int maxStep,
|
int cooldownMinutes,
|
boolean dynamicMaxValue,
|
String dynamicMaxSource,
|
String note) {
|
this.targetType = targetType;
|
this.targetKey = targetKey;
|
this.minValue = minValue;
|
this.maxValue = maxValue;
|
this.maxStep = maxStep;
|
this.cooldownMinutes = cooldownMinutes;
|
this.dynamicMaxValue = dynamicMaxValue;
|
this.dynamicMaxSource = dynamicMaxSource;
|
this.note = note;
|
}
|
|
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;
|
}
|
|
public String getDynamicMaxSource() {
|
return dynamicMaxSource;
|
}
|
|
public String getNote() {
|
return note;
|
}
|
}
|
|
private static final class RuleSpec {
|
private final AutoTuneTargetType targetType;
|
private final String targetKey;
|
private Integer minValue;
|
private Integer maxValue;
|
private int maxStep;
|
private int cooldownMinutes;
|
private String dynamicMaxSource;
|
private String note = DEFAULT_RULE_NOTE;
|
|
private RuleSpec(AutoTuneTargetType targetType, String targetKey) {
|
this.targetType = targetType;
|
this.targetKey = targetKey;
|
}
|
|
private RuleSpec minValue(Integer minValue) {
|
this.minValue = minValue;
|
return this;
|
}
|
|
private RuleSpec maxValue(Integer maxValue) {
|
this.maxValue = maxValue;
|
return this;
|
}
|
|
private RuleSpec maxStep(int maxStep) {
|
this.maxStep = maxStep;
|
return this;
|
}
|
|
private RuleSpec cooldownMinutes(int cooldownMinutes) {
|
this.cooldownMinutes = cooldownMinutes;
|
return this;
|
}
|
|
private RuleSpec dynamicMaxSource(String dynamicMaxSource) {
|
this.dynamicMaxSource = dynamicMaxSource;
|
return this;
|
}
|
|
private RuleSpec note(String note) {
|
this.note = note;
|
return this;
|
}
|
|
private Rule toRule() {
|
return new Rule(
|
targetType,
|
targetKey,
|
minValue,
|
maxValue,
|
maxStep,
|
cooldownMinutes,
|
dynamicMaxSource != null,
|
dynamicMaxSource,
|
note
|
);
|
}
|
}
|
}
|