longz
2026-08-04 ddca93b2ce73312a485cb79ea9f65c8cdf604cb0
fix: sync storage dashboard after startup (#23885)
2个文件已修改
21 ■■■■■ 已修改文件
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/service/EmindStationSyncScheduler.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/emind/service/EmindStationSyncSchedulerTest.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/emind/service/EmindStationSyncScheduler.java
@@ -2,6 +2,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -32,6 +34,13 @@
        runSyncStep("eMind储能能量块", energyBlockSyncService::syncEnergyBlocks);
    }
    /** 发布完成后立即刷新一次,避免部署刚好错过整点/半点同步。 */
    @EventListener(ApplicationReadyEvent.class)
    public void syncOnStartup() {
        log.info("eMind服务启动完成,执行首次同步");
        sync();
    }
    private void runSyncStep(String name, SyncStep step) {
        try {
            int count = step.execute();
ruoyi-service/ruoyi-other/src/test/java/com/ruoyi/other/emind/service/EmindStationSyncSchedulerTest.java
@@ -43,6 +43,18 @@
        order.verify(energyBlockSyncService).syncEnergyBlocks();
    }
    @Test
    void synchronizesImmediatelyWhenApplicationIsReady() {
        EmindStationSyncScheduler scheduler = scheduler();
        scheduler.syncOnStartup();
        verify(stationSyncService).syncStations();
        verify(dashboardSyncService).syncDashboardData();
        verify(energyChainSyncService).syncEnergyChains();
        verify(energyBlockSyncService).syncEnergyBlocks();
    }
    private EmindStationSyncScheduler scheduler() {
        return new EmindStationSyncScheduler(stationSyncService, energyChainSyncService,
                energyBlockSyncService, dashboardSyncService);