| | |
| | | package com.zy.ai.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.ai.domain.autotune.AutoTuneControlModeSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneTaskDetailItem; |
| | | import com.zy.ai.domain.autotune.AutoTuneParameterSnapshot; |
| | | import com.zy.ai.domain.autotune.AutoTuneRoutePressureSnapshot; |
| | | 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; |
| | | import com.zy.ai.service.AutoTuneControlModeService; |
| | | import com.zy.ai.service.AutoTuneSnapshotService; |
| | | import com.zy.ai.service.FlowTopologySnapshotService; |
| | | import com.zy.ai.service.RoutePressureSnapshotService; |
| | | import com.zy.asrs.domain.vo.StationCycleCapacityVo; |
| | | import com.zy.asrs.domain.vo.StationCycleLoopVo; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.system.service.ConfigService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Service("autoTuneSnapshotService") |
| | | public class AutoTuneSnapshotServiceImpl implements AutoTuneSnapshotService { |
| | | |
| | | private static final Logger LOGGER = LoggerFactory.getLogger(AutoTuneSnapshotServiceImpl.class); |
| | | |
| | | private static final int DEFAULT_CRN_OUT_BATCH_RUNNING_LIMIT = 5; |
| | | private static final int DEFAULT_CONVEYOR_STATION_TASK_LIMIT = 30; |
| | | private static final int DEFAULT_AI_AUTO_TUNE_INTERVAL_MINUTES = 10; |
| | | private static final int OUTBOUND_TASK_SAMPLE_LIMIT = 50; |
| | | private static final int STATION_LIMIT_BLOCKED_TASK_LIMIT = 50; |
| | | private static final int SYSTEM_MESSAGE_LIMIT = 160; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private FlowTopologySnapshotService flowTopologySnapshotService; |
| | | |
| | | @Autowired |
| | | private RoutePressureSnapshotService routePressureSnapshotService; |
| | | |
| | | @Autowired |
| | | private AutoTuneControlModeService autoTuneControlModeService; |
| | | |
| | | @Autowired |
| | | private ConfigService configService; |
| | |
| | | |
| | | @Override |
| | | public AutoTuneSnapshot buildSnapshot() { |
| | | List<WrkMast> activeTasks = loadActiveTasks(); |
| | | AutoTuneTaskSnapshot taskSnapshot = buildTaskSnapshot(activeTasks); |
| | | List<AutoTuneStationRuntimeItem> stationRuntimeSnapshot = buildStationRuntimeSnapshot(); |
| | | AutoTuneRoutePressureSnapshot routePressureSnapshot = buildRoutePressureSnapshot( |
| | | activeTasks, |
| | | taskSnapshot, |
| | | stationRuntimeSnapshot |
| | | ); |
| | | |
| | | AutoTuneSnapshot snapshot = new AutoTuneSnapshot(); |
| | | snapshot.setTaskSnapshot(buildTaskSnapshot()); |
| | | snapshot.setTaskSnapshot(taskSnapshot); |
| | | snapshot.setStationRuntimeSnapshot(stationRuntimeSnapshot); |
| | | snapshot.setRoutePressureSnapshot(routePressureSnapshot); |
| | | snapshot.setCycleLoadSnapshot(buildCycleLoadSnapshot()); |
| | | snapshot.setFlowTopologySnapshot(flowTopologySnapshotService.buildSnapshot(stationRuntimeSnapshot)); |
| | | snapshot.setCurrentParameterSnapshot(buildCurrentParameterSnapshot()); |
| | | snapshot.setRuleSnapshot(buildRuleSnapshot()); |
| | | snapshot.setControlModeSnapshot(buildControlModeSnapshot()); |
| | | snapshot.setSnapshotTime(new Date()); |
| | | return snapshot; |
| | | } |
| | | |
| | | private AutoTuneControlModeSnapshot buildControlModeSnapshot() { |
| | | return autoTuneControlModeService.currentMode(); |
| | | } |
| | | |
| | | List<AutoTuneRuleSnapshotItem> buildRuleSnapshot() { |
| | |
| | | } |
| | | |
| | | private AutoTuneTaskSnapshot buildTaskSnapshot() { |
| | | List<WrkMast> activeTasks = loadActiveTasks(); |
| | | return buildTaskSnapshot(loadActiveTasks()); |
| | | } |
| | | |
| | | private AutoTuneTaskSnapshot buildTaskSnapshot(List<WrkMast> activeTasks) { |
| | | AutoTuneTaskSnapshot snapshot = new AutoTuneTaskSnapshot(); |
| | | snapshot.setActiveTaskCount(activeTasks.size()); |
| | | snapshot.setStationLimitBlockedTasks(buildStationLimitBlockedTasks(activeTasks)); |
| | |
| | | snapshot.setByDualCrn(countByDualCrn(activeTasks)); |
| | | snapshot.setByIoType(countByIoType(activeTasks)); |
| | | return snapshot; |
| | | } |
| | | |
| | | private AutoTuneRoutePressureSnapshot buildRoutePressureSnapshot(List<WrkMast> activeTasks, |
| | | AutoTuneTaskSnapshot taskSnapshot, |
| | | List<AutoTuneStationRuntimeItem> stationRuntimeSnapshot) { |
| | | if (routePressureSnapshotService == null) { |
| | | return new AutoTuneRoutePressureSnapshot(); |
| | | } |
| | | try { |
| | | AutoTuneRoutePressureSnapshot snapshot = routePressureSnapshotService.buildSnapshot( |
| | | activeTasks, |
| | | taskSnapshot, |
| | | stationRuntimeSnapshot |
| | | ); |
| | | return snapshot == null ? new AutoTuneRoutePressureSnapshot() : snapshot; |
| | | } catch (Exception exception) { |
| | | LOGGER.warn( |
| | | "Build auto tune route pressure snapshot failed, fallback to empty snapshot. activeTaskCount={}, stationRuntimeCount={}", |
| | | safeList(activeTasks).size(), |
| | | safeList(stationRuntimeSnapshot).size(), |
| | | exception |
| | | ); |
| | | return new AutoTuneRoutePressureSnapshot(); |
| | | } |
| | | } |
| | | |
| | | private List<AutoTuneTaskDetailItem> buildStationLimitBlockedTasks(List<WrkMast> activeTasks) { |
| | |
| | | item.setAutoing(protocol.isAutoing() ? 1 : 0); |
| | | item.setLoading(protocol.isLoading() ? 1 : 0); |
| | | item.setTaskNo(protocol.getTaskNo() == null ? 0 : protocol.getTaskNo()); |
| | | item.setRunBlock(protocol.isRunBlock() ? 1 : 0); |
| | | item.setIoMode(protocol.getIoMode() == null ? null : String.valueOf(protocol.getIoMode())); |
| | | return item; |
| | | } |