Files
msgexchange-v2/src/main/kotlin/com/gzzn/omms/msgexchange/config/OperationDayProps.kt
T
windyboy 9554b1aae8 fix(config): fail fast on invalid operation-day zone
运营日时区只认 PARAM:msgx.operation-day.zone:JobRunner、HistorySweepJob、JdbcSnapshotLogRepository.purgeBefore 改走注入的 OperationDayProps;ScheduleProcessor/AdftProcessor 删除「非法值回退字面量」;新增 @Context 启动自检 OperationDayZoneCheck,配置错位在启动时暴露。

验证:./gradlew test 126 tests / 0 fail(新增 OperationDayPropsTest 覆盖合法解析与非法即失败)。
2026-09-12 20:34:56 +08:00

41 lines
1.6 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.gzzn.omms.msgexchange.config
import io.micronaut.context.annotation.ConfigurationProperties
import io.micronaut.context.annotation.Context
import jakarta.inject.Singleton
import java.time.ZoneId
/**
* 算航班运营保障日(OPERATION_DAY)要用的两个参数,对应配置里的 `msgx.operation-day.*`
* 机场时区和切日边界。运营日由计划运行时间 SODT 加时区推出来,不是接收日也不是落库日,
* 算出来就固定不变。
*
* 不能假设运营日等于自然日,民航的一天从几点开始由业务定。默认 0 点只是占位,待确认。
*/
@ConfigurationProperties("msgx.operation-day")
class OperationDayProps {
/** 机场所在时区,用 IANA 名称,比如 Asia/Shanghai。 */
var zone: String = "Asia/Shanghai"
/** 切日边界小时:SODT 的本地时刻早于这个点就归属前一个运营日。取值 0–23。 */
var cutoffHour: Int = 0
/**
* 解析机场时区。非法值直接失败,**不回退到代码字面量**:
* `PARAM:msgx.operation-day.zone` 是运营日时区的唯一出处,回退会把配置错位藏起来。
*/
fun zoneId(): ZoneId =
try {
ZoneId.of(zone)
} catch (e: Exception) {
throw IllegalStateException("msgx.operation-day.zone is not a valid IANA zone: '$zone'", e)
}
}
/** 启动自检:时区非法必须在启动时失败,而不是等第一条报文进来才炸;`@Context` 使其急切创建。 */
@Singleton
@Context
class OperationDayZoneCheck(props: OperationDayProps) {
private val zone: ZoneId = props.zoneId()
}