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);