package com.klp.task; import com.klp.service.impl.DrMigrationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * 应用启动后自动执行双机架历史道次版本迁移。 * 逻辑幂等:若已迁移完毕则无任何 DB 写操作,仅打印一条 info 日志。 */ @Slf4j @Order(100) @Component @RequiredArgsConstructor public class DrMigrationRunner implements ApplicationRunner { private final DrMigrationService migrationService; @Override public void run(ApplicationArguments args) { log.info("[DR迁移] 开始检查历史道次版本迁移..."); try { migrationService.migrateOrphanPassesToV1(); } catch (Exception e) { // 迁移失败不阻断服务启动,只记录错误 log.error("[DR迁移] 执行异常,请人工检查 mill_process_pass 表", e); } } }