From dc3f9cc91759823ce59486f19b138be4b296a0f1 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 28 四月 2026 09:43:28 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java | 141 ++++++++++++++++++++++++++++++++++++++--------
1 files changed, 115 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java b/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
index 9578f23..a609520 100644
--- a/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
+++ b/src/main/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImpl.java
@@ -2,6 +2,8 @@
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.AutoTuneTaskSnapshot;
@@ -10,11 +12,13 @@
import com.zy.asrs.domain.vo.StationCycleCapacityVo;
import com.zy.asrs.domain.vo.StationCycleLoopVo;
import com.zy.asrs.entity.BasCrnp;
+import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasDualCrnp;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasCrnpService;
+import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.DeviceConfigService;
@@ -23,6 +27,7 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkStsType;
+import com.zy.core.model.StationObjModel;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.StationThread;
import com.zy.system.service.ConfigService;
@@ -33,9 +38,11 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
@Service("autoTuneSnapshotService")
public class AutoTuneSnapshotServiceImpl implements AutoTuneSnapshotService {
@@ -63,6 +70,9 @@
private BasStationService basStationService;
@Autowired
+ private BasDevpService basDevpService;
+
+ @Autowired
private BasCrnpService basCrnpService;
@Autowired
@@ -78,8 +88,27 @@
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(rule.getDynamicMaxSource());
+ item.setNote(rule.getNote());
+ result.add(item);
+ }
+ return result;
}
private AutoTuneTaskSnapshot buildTaskSnapshot() {
@@ -100,14 +129,16 @@
return Collections.emptyList();
}
QueryWrapper<WrkMast> wrapper = new QueryWrapper<>();
- wrapper.notIn("wrk_sts", Arrays.asList(
- WrkStsType.COMPLETE_INBOUND.sts,
- WrkStsType.SETTLE_INBOUND.sts,
- WrkStsType.COMPLETE_OUTBOUND.sts,
- WrkStsType.SETTLE_OUTBOUND.sts,
- WrkStsType.COMPLETE_LOC_MOVE.sts,
- WrkStsType.COMPLETE_CRN_MOVE.sts
- ));
+ wrapper.and(query -> query.notIn("wrk_sts", Arrays.asList(
+ WrkStsType.COMPLETE_INBOUND.sts,
+ WrkStsType.SETTLE_INBOUND.sts,
+ WrkStsType.COMPLETE_OUTBOUND.sts,
+ WrkStsType.SETTLE_OUTBOUND.sts,
+ WrkStsType.COMPLETE_LOC_MOVE.sts,
+ WrkStsType.COMPLETE_CRN_MOVE.sts
+ ))
+ .or()
+ .isNull("wrk_sts"));
return safeList(wrkMastService.list(wrapper));
}
@@ -212,11 +243,15 @@
"aiAutoTuneIntervalMinutes",
DEFAULT_AI_AUTO_TUNE_INTERVAL_MINUTES
));
- snapshot.setStationOutTaskLimits(loadStationOutTaskLimits());
- snapshot.setCrnMaxOutTask(loadCrnMaxOutTask());
- snapshot.setCrnMaxInTask(loadCrnMaxInTask());
- snapshot.setDualCrnMaxOutTask(loadDualCrnMaxOutTask());
- snapshot.setDualCrnMaxInTask(loadDualCrnMaxInTask());
+ List<BasCrnp> crnList = loadCrnList();
+ List<BasDualCrnp> dualCrnList = loadDualCrnList();
+ List<BasStation> outStationList = loadOutStationList();
+ snapshot.setStationOutTaskLimits(buildStationOutTaskLimitMap(outStationList));
+ snapshot.setStationOutBufferCapacities(buildStationOutBufferCapacityMap(outStationList));
+ snapshot.setCrnMaxOutTask(buildCrnMaxOutTask(crnList));
+ snapshot.setCrnMaxInTask(buildCrnMaxInTask(crnList));
+ snapshot.setDualCrnMaxOutTask(buildDualCrnMaxOutTask(dualCrnList));
+ snapshot.setDualCrnMaxInTask(buildDualCrnMaxInTask(dualCrnList));
return snapshot;
}
@@ -235,48 +270,102 @@
}
}
- private Map<String, Integer> loadStationOutTaskLimits() {
- Map<String, Integer> result = new LinkedHashMap<>();
+ private List<BasStation> loadOutStationList() {
if (basStationService == null) {
- return result;
+ return Collections.emptyList();
+ }
+ Set<Integer> outStationIds = loadOutStationIds();
+ if (outStationIds.isEmpty()) {
+ return Collections.emptyList();
}
QueryWrapper<BasStation> wrapper = new QueryWrapper<>();
+ wrapper.in("station_id", outStationIds);
wrapper.orderByAsc("station_id");
- for (BasStation station : safeList(basStationService.list(wrapper))) {
+ return safeList(basStationService.list(wrapper));
+ }
+
+ private Set<Integer> loadOutStationIds() {
+ LinkedHashSet<Integer> stationIds = new LinkedHashSet<>();
+ if (basDevpService == null) {
+ return stationIds;
+ }
+ QueryWrapper<BasDevp> wrapper = new QueryWrapper<>();
+ wrapper.eq("status", 1);
+ wrapper.orderByAsc("devp_no");
+ List<BasDevp> basDevpList = safeList(basDevpService.list(wrapper));
+ for (BasDevp basDevp : basDevpList) {
+ if (basDevp == null) {
+ continue;
+ }
+ List<StationObjModel> outStationList = safeList(basDevp.getOutStationList$());
+ for (StationObjModel stationObjModel : outStationList) {
+ if (stationObjModel != null && stationObjModel.getStationId() != null) {
+ stationIds.add(stationObjModel.getStationId());
+ }
+ }
+ }
+ return stationIds;
+ }
+
+ Map<String, Integer> buildStationOutTaskLimitMap(List<BasStation> stationList) {
+ Map<String, Integer> result = new LinkedHashMap<>();
+ for (BasStation station : safeList(stationList)) {
if (station != null && station.getStationId() != null) {
- result.put(String.valueOf(station.getStationId()), defaultInt(station.getOutTaskLimit()));
+ result.put(String.valueOf(station.getStationId()), station.getOutTaskLimit());
}
}
return result;
}
- private Map<String, Integer> loadCrnMaxOutTask() {
+ Map<String, Integer> buildStationOutBufferCapacityMap(List<BasStation> stationList) {
Map<String, Integer> result = new LinkedHashMap<>();
- for (BasCrnp crn : loadCrnList()) {
+ for (BasStation station : safeList(stationList)) {
+ if (station != null && station.getStationId() != null) {
+ result.put(String.valueOf(station.getStationId()), station.getOutBufferCapacity());
+ }
+ }
+ return result;
+ }
+
+ private Map<String, Integer> buildCrnMaxOutTask(List<BasCrnp> crnList) {
+ Map<String, Integer> result = new LinkedHashMap<>();
+ for (BasCrnp crn : safeList(crnList)) {
+ if (crn == null || crn.getCrnNo() == null) {
+ continue;
+ }
result.put(String.valueOf(crn.getCrnNo()), defaultInt(crn.getMaxOutTask()));
}
return result;
}
- private Map<String, Integer> loadCrnMaxInTask() {
+ private Map<String, Integer> buildCrnMaxInTask(List<BasCrnp> crnList) {
Map<String, Integer> result = new LinkedHashMap<>();
- for (BasCrnp crn : loadCrnList()) {
+ for (BasCrnp crn : safeList(crnList)) {
+ if (crn == null || crn.getCrnNo() == null) {
+ continue;
+ }
result.put(String.valueOf(crn.getCrnNo()), defaultInt(crn.getMaxInTask()));
}
return result;
}
- private Map<String, Integer> loadDualCrnMaxOutTask() {
+ private Map<String, Integer> buildDualCrnMaxOutTask(List<BasDualCrnp> dualCrnList) {
Map<String, Integer> result = new LinkedHashMap<>();
- for (BasDualCrnp dualCrn : loadDualCrnList()) {
+ for (BasDualCrnp dualCrn : safeList(dualCrnList)) {
+ if (dualCrn == null || dualCrn.getCrnNo() == null) {
+ continue;
+ }
result.put(String.valueOf(dualCrn.getCrnNo()), defaultInt(dualCrn.getMaxOutTask()));
}
return result;
}
- private Map<String, Integer> loadDualCrnMaxInTask() {
+ private Map<String, Integer> buildDualCrnMaxInTask(List<BasDualCrnp> dualCrnList) {
Map<String, Integer> result = new LinkedHashMap<>();
- for (BasDualCrnp dualCrn : loadDualCrnList()) {
+ for (BasDualCrnp dualCrn : safeList(dualCrnList)) {
+ if (dualCrn == null || dualCrn.getCrnNo() == null) {
+ continue;
+ }
result.put(String.valueOf(dualCrn.getCrnNo()), defaultInt(dualCrn.getMaxInTask()));
}
return result;
--
Gitblit v1.9.1